Module: FHIR::Xml

Extended by:
Deprecate
Included in:
Account, Account::Coverage, Account::Guarantor, ActivityDefinition, ActivityDefinition::DynamicValue, ActivityDefinition::Participant, Address, AdverseEvent, AdverseEvent::SuspectEntity, AdverseEvent::SuspectEntity::Causality, Age, AllergyIntolerance, AllergyIntolerance::Reaction, Annotation, Appointment, Appointment::Participant, AppointmentResponse, Attachment, AuditEvent, AuditEvent::Agent, AuditEvent::Agent::Network, AuditEvent::Entity, AuditEvent::Entity::Detail, AuditEvent::Source, BackboneElement, Basic, Binary, BiologicallyDerivedProduct, BiologicallyDerivedProduct::Collection, BiologicallyDerivedProduct::Manipulation, BiologicallyDerivedProduct::Processing, BiologicallyDerivedProduct::Storage, BodyStructure, Bundle, Bundle::Entry, Bundle::Entry::Request, Bundle::Entry::Response, Bundle::Entry::Search, Bundle::Link, CapabilityStatement, CapabilityStatement::Document, CapabilityStatement::Implementation, CapabilityStatement::Messaging, CapabilityStatement::Messaging::Endpoint, CapabilityStatement::Messaging::SupportedMessage, CapabilityStatement::Rest, CapabilityStatement::Rest::Interaction, CapabilityStatement::Rest::Resource, CapabilityStatement::Rest::Resource::Interaction, CapabilityStatement::Rest::Resource::Operation, CapabilityStatement::Rest::Resource::SearchParam, CapabilityStatement::Rest::Security, CapabilityStatement::Software, CarePlan, CarePlan::Activity, CarePlan::Activity::Detail, CareTeam, CareTeam::Participant, CatalogEntry, CatalogEntry::RelatedEntry, ChargeItem, ChargeItem::Performer, ChargeItemDefinition, ChargeItemDefinition::Applicability, ChargeItemDefinition::PropertyGroup, ChargeItemDefinition::PropertyGroup::PriceComponent, Claim, Claim::Accident, Claim::CareTeam, Claim::Diagnosis, Claim::Insurance, Claim::Item, Claim::Item::Detail, Claim::Item::Detail::SubDetail, Claim::Payee, Claim::Procedure, Claim::Related, Claim::SupportingInfo, ClaimResponse, ClaimResponse::AddItem, ClaimResponse::AddItem::Detail, ClaimResponse::AddItem::Detail::SubDetail, ClaimResponse::Error, ClaimResponse::Insurance, ClaimResponse::Item, ClaimResponse::Item::Adjudication, ClaimResponse::Item::Detail, ClaimResponse::Item::Detail::SubDetail, ClaimResponse::Payment, ClaimResponse::ProcessNote, ClaimResponse::Total, ClinicalImpression, ClinicalImpression::Finding, ClinicalImpression::Investigation, CodeSystem, CodeSystem::Concept, CodeSystem::Concept::Designation, CodeSystem::Concept::Property, CodeSystem::Filter, CodeSystem::Property, CodeableConcept, Coding, Communication, Communication::Payload, CommunicationRequest, CommunicationRequest::Payload, CompartmentDefinition, CompartmentDefinition::Resource, Composition, Composition::Attester, Composition::Event, Composition::RelatesTo, Composition::Section, ConceptMap, ConceptMap::Group, ConceptMap::Group::Element, ConceptMap::Group::Element::Target, ConceptMap::Group::Element::Target::DependsOn, ConceptMap::Group::Unmapped, Condition, Condition::Evidence, Condition::Stage, Consent, Consent::Policy, Consent::Provision, Consent::Provision::Actor, Consent::Provision::Data, Consent::Verification, ContactDetail, ContactPoint, Contract, Contract::ContentDefinition, Contract::Friendly, Contract::Legal, Contract::Rule, Contract::Signer, Contract::Term, Contract::Term::Action, Contract::Term::Action::Subject, Contract::Term::Asset, Contract::Term::Asset::Context, Contract::Term::Asset::ValuedItem, Contract::Term::Offer, Contract::Term::Offer::Answer, Contract::Term::Offer::Party, Contract::Term::SecurityLabel, Contributor, Count, Coverage, Coverage::Class, Coverage::CostToBeneficiary, Coverage::CostToBeneficiary::Exception, CoverageEligibilityRequest, CoverageEligibilityRequest::Insurance, CoverageEligibilityRequest::Item, CoverageEligibilityRequest::Item::Diagnosis, CoverageEligibilityRequest::SupportingInfo, CoverageEligibilityResponse, CoverageEligibilityResponse::Error, CoverageEligibilityResponse::Insurance, CoverageEligibilityResponse::Insurance::Item, CoverageEligibilityResponse::Insurance::Item::Benefit, DataRequirement, DataRequirement::CodeFilter, DataRequirement::DateFilter, DataRequirement::Sort, DetectedIssue, DetectedIssue::Evidence, DetectedIssue::Mitigation, Device, Device::DeviceName, Device::Property, Device::Specialization, Device::UdiCarrier, Device::Version, DeviceDefinition, DeviceDefinition::Capability, DeviceDefinition::DeviceName, DeviceDefinition::Material, DeviceDefinition::Property, DeviceDefinition::Specialization, DeviceDefinition::UdiDeviceIdentifier, DeviceMetric, DeviceMetric::Calibration, DeviceRequest, DeviceRequest::Parameter, DeviceUseStatement, DiagnosticReport, DiagnosticReport::Media, Distance, DocumentManifest, DocumentManifest::Related, DocumentReference, DocumentReference::Content, DocumentReference::Context, DocumentReference::RelatesTo, DomainResource, Dosage, Dosage::DoseAndRate, Duration, EffectEvidenceSynthesis, EffectEvidenceSynthesis::Certainty, EffectEvidenceSynthesis::Certainty::CertaintySubcomponent, EffectEvidenceSynthesis::EffectEstimate, EffectEvidenceSynthesis::EffectEstimate::PrecisionEstimate, EffectEvidenceSynthesis::ResultsByExposure, EffectEvidenceSynthesis::SampleSize, Element, ElementDefinition, ElementDefinition::Base, ElementDefinition::Binding, ElementDefinition::Constraint, ElementDefinition::Example, ElementDefinition::Mapping, ElementDefinition::Slicing, ElementDefinition::Slicing::Discriminator, ElementDefinition::Type, Encounter, Encounter::ClassHistory, Encounter::Diagnosis, Encounter::Hospitalization, Encounter::Location, Encounter::Participant, Encounter::StatusHistory, Endpoint, EnrollmentRequest, EnrollmentResponse, EpisodeOfCare, EpisodeOfCare::Diagnosis, EpisodeOfCare::StatusHistory, EventDefinition, Evidence, EvidenceVariable, EvidenceVariable::Characteristic, ExampleScenario, ExampleScenario::Actor, ExampleScenario::Instance, ExampleScenario::Instance::ContainedInstance, ExampleScenario::Instance::Version, ExampleScenario::Process, ExampleScenario::Process::Step, ExampleScenario::Process::Step::Alternative, ExampleScenario::Process::Step::Operation, ExplanationOfBenefit, ExplanationOfBenefit::Accident, ExplanationOfBenefit::AddItem, ExplanationOfBenefit::AddItem::Detail, ExplanationOfBenefit::AddItem::Detail::SubDetail, ExplanationOfBenefit::BenefitBalance, ExplanationOfBenefit::BenefitBalance::Financial, ExplanationOfBenefit::CareTeam, ExplanationOfBenefit::Diagnosis, ExplanationOfBenefit::Insurance, ExplanationOfBenefit::Item, ExplanationOfBenefit::Item::Adjudication, ExplanationOfBenefit::Item::Detail, ExplanationOfBenefit::Item::Detail::SubDetail, ExplanationOfBenefit::Payee, ExplanationOfBenefit::Payment, ExplanationOfBenefit::Procedure, ExplanationOfBenefit::ProcessNote, ExplanationOfBenefit::Related, ExplanationOfBenefit::SupportingInfo, ExplanationOfBenefit::Total, Expression, Extension, FamilyMemberHistory, FamilyMemberHistory::Condition, Flag, Goal, Goal::Target, GraphDefinition, GraphDefinition::Link, GraphDefinition::Link::Target, GraphDefinition::Link::Target::Compartment, Group, Group::Characteristic, Group::Member, GuidanceResponse, HealthcareService, HealthcareService::AvailableTime, HealthcareService::Eligibility, HealthcareService::NotAvailable, HumanName, Identifier, ImagingStudy, ImagingStudy::Series, ImagingStudy::Series::Instance, ImagingStudy::Series::Performer, Immunization, Immunization::Education, Immunization::Performer, Immunization::ProtocolApplied, Immunization::Reaction, ImmunizationEvaluation, ImmunizationRecommendation, ImmunizationRecommendation::Recommendation, ImmunizationRecommendation::Recommendation::DateCriterion, ImplementationGuide, ImplementationGuide::Definition, ImplementationGuide::Definition::Grouping, ImplementationGuide::Definition::Page, ImplementationGuide::Definition::Parameter, ImplementationGuide::Definition::Resource, ImplementationGuide::Definition::Template, ImplementationGuide::DependsOn, ImplementationGuide::Global, ImplementationGuide::Manifest, ImplementationGuide::Manifest::Page, ImplementationGuide::Manifest::Resource, InsurancePlan, InsurancePlan::Contact, InsurancePlan::Coverage, InsurancePlan::Coverage::Benefit, InsurancePlan::Coverage::Benefit::Limit, InsurancePlan::Plan, InsurancePlan::Plan::GeneralCost, InsurancePlan::Plan::SpecificCost, InsurancePlan::Plan::SpecificCost::Benefit, InsurancePlan::Plan::SpecificCost::Benefit::Cost, Invoice, Invoice::LineItem, Invoice::LineItem::PriceComponent, Invoice::Participant, Library, Linkage, Linkage::Item, List, List::Entry, Location, Location::HoursOfOperation, Location::Position, MarketingStatus, Measure, Measure::Group, Measure::Group::Population, Measure::Group::Stratifier, Measure::Group::Stratifier::Component, Measure::SupplementalData, MeasureReport, MeasureReport::Group, MeasureReport::Group::Population, MeasureReport::Group::Stratifier, MeasureReport::Group::Stratifier::Stratum, MeasureReport::Group::Stratifier::Stratum::Component, MeasureReport::Group::Stratifier::Stratum::Population, Media, Medication, Medication::Batch, Medication::Ingredient, MedicationAdministration, MedicationAdministration::Dosage, MedicationAdministration::Performer, MedicationDispense, MedicationDispense::Performer, MedicationDispense::Substitution, MedicationKnowledge, MedicationKnowledge::AdministrationGuidelines, MedicationKnowledge::AdministrationGuidelines::Dosage, MedicationKnowledge::AdministrationGuidelines::PatientCharacteristics, MedicationKnowledge::Cost, MedicationKnowledge::DrugCharacteristic, MedicationKnowledge::Ingredient, MedicationKnowledge::Kinetics, MedicationKnowledge::MedicineClassification, MedicationKnowledge::MonitoringProgram, MedicationKnowledge::Monograph, MedicationKnowledge::Packaging, MedicationKnowledge::Regulatory, MedicationKnowledge::Regulatory::MaxDispense, MedicationKnowledge::Regulatory::Schedule, MedicationKnowledge::Regulatory::Substitution, MedicationKnowledge::RelatedMedicationKnowledge, MedicationRequest, MedicationRequest::DispenseRequest, MedicationRequest::DispenseRequest::InitialFill, MedicationRequest::Substitution, MedicationStatement, MedicinalProduct, MedicinalProduct::ManufacturingBusinessOperation, MedicinalProduct::Name, MedicinalProduct::Name::CountryLanguage, MedicinalProduct::Name::NamePart, MedicinalProduct::SpecialDesignation, MedicinalProductAuthorization, MedicinalProductAuthorization::JurisdictionalAuthorization, MedicinalProductAuthorization::Procedure, MedicinalProductContraindication, MedicinalProductContraindication::OtherTherapy, MedicinalProductIndication, MedicinalProductIndication::OtherTherapy, MedicinalProductIngredient, MedicinalProductIngredient::SpecifiedSubstance, MedicinalProductIngredient::SpecifiedSubstance::Strength, MedicinalProductIngredient::SpecifiedSubstance::Strength::ReferenceStrength, MedicinalProductIngredient::Substance, MedicinalProductInteraction, MedicinalProductInteraction::Interactant, MedicinalProductManufactured, MedicinalProductPackaged, MedicinalProductPackaged::BatchIdentifier, MedicinalProductPackaged::PackageItem, MedicinalProductPharmaceutical, MedicinalProductPharmaceutical::Characteristics, MedicinalProductPharmaceutical::RouteOfAdministration, MedicinalProductPharmaceutical::RouteOfAdministration::TargetSpecies, MedicinalProductPharmaceutical::RouteOfAdministration::TargetSpecies::WithdrawalPeriod, MedicinalProductUndesirableEffect, MessageDefinition, MessageDefinition::AllowedResponse, MessageDefinition::Focus, MessageHeader, MessageHeader::Destination, MessageHeader::Response, MessageHeader::Source, Meta, MolecularSequence, MolecularSequence::Quality, MolecularSequence::Quality::Roc, MolecularSequence::ReferenceSeq, MolecularSequence::Repository, MolecularSequence::StructureVariant, MolecularSequence::StructureVariant::Inner, MolecularSequence::StructureVariant::Outer, MolecularSequence::Variant, Money, NamingSystem, NamingSystem::UniqueId, Narrative, NutritionOrder, NutritionOrder::EnteralFormula, NutritionOrder::EnteralFormula::Administration, NutritionOrder::OralDiet, NutritionOrder::OralDiet::Nutrient, NutritionOrder::OralDiet::Texture, NutritionOrder::Supplement, Observation, Observation::Component, Observation::ReferenceRange, ObservationDefinition, ObservationDefinition::QualifiedInterval, ObservationDefinition::QuantitativeDetails, OperationDefinition, OperationDefinition::Overload, OperationDefinition::Parameter, OperationDefinition::Parameter::Binding, OperationDefinition::Parameter::ReferencedFrom, OperationOutcome, OperationOutcome::Issue, Organization, Organization::Contact, OrganizationAffiliation, ParameterDefinition, Parameters, Parameters::Parameter, Patient, Patient::Communication, Patient::Contact, Patient::Link, PaymentNotice, PaymentReconciliation, PaymentReconciliation::Detail, PaymentReconciliation::ProcessNote, Period, Person, Person::Link, PlanDefinition, PlanDefinition::Action, PlanDefinition::Action::Condition, PlanDefinition::Action::DynamicValue, PlanDefinition::Action::Participant, PlanDefinition::Action::RelatedAction, PlanDefinition::Goal, PlanDefinition::Goal::Target, Population, Practitioner, Practitioner::Qualification, PractitionerRole, PractitionerRole::AvailableTime, PractitionerRole::NotAvailable, Procedure, Procedure::FocalDevice, Procedure::Performer, ProdCharacteristic, ProductShelfLife, Provenance, Provenance::Agent, Provenance::Entity, Quantity, Questionnaire, Questionnaire::Item, Questionnaire::Item::AnswerOption, Questionnaire::Item::EnableWhen, Questionnaire::Item::Initial, QuestionnaireResponse, QuestionnaireResponse::Item, QuestionnaireResponse::Item::Answer, Range, Ratio, Reference, RelatedArtifact, RelatedPerson, RelatedPerson::Communication, RequestGroup, RequestGroup::Action, RequestGroup::Action::Condition, RequestGroup::Action::RelatedAction, ResearchDefinition, ResearchElementDefinition, ResearchElementDefinition::Characteristic, ResearchStudy, ResearchStudy::Arm, ResearchStudy::Objective, ResearchSubject, Resource, RiskAssessment, RiskAssessment::Prediction, RiskEvidenceSynthesis, RiskEvidenceSynthesis::Certainty, RiskEvidenceSynthesis::Certainty::CertaintySubcomponent, RiskEvidenceSynthesis::RiskEstimate, RiskEvidenceSynthesis::RiskEstimate::PrecisionEstimate, RiskEvidenceSynthesis::SampleSize, SampledData, Schedule, SearchParameter, SearchParameter::Component, ServiceRequest, Signature, Slot, Specimen, Specimen::Collection, Specimen::Container, Specimen::Processing, SpecimenDefinition, SpecimenDefinition::TypeTested, SpecimenDefinition::TypeTested::Container, SpecimenDefinition::TypeTested::Container::Additive, SpecimenDefinition::TypeTested::Handling, StructureDefinition, StructureDefinition::Context, StructureDefinition::Differential, StructureDefinition::Mapping, StructureDefinition::Snapshot, StructureMap, StructureMap::Group, StructureMap::Group::Input, StructureMap::Group::Rule, StructureMap::Group::Rule::Dependent, StructureMap::Group::Rule::Source, StructureMap::Group::Rule::Target, StructureMap::Group::Rule::Target::Parameter, StructureMap::Structure, Subscription, Subscription::Channel, Substance, Substance::Ingredient, Substance::Instance, SubstanceAmount, SubstanceAmount::ReferenceRange, SubstanceNucleicAcid, SubstanceNucleicAcid::Subunit, SubstanceNucleicAcid::Subunit::Linkage, SubstanceNucleicAcid::Subunit::Sugar, SubstancePolymer, SubstancePolymer::MonomerSet, SubstancePolymer::MonomerSet::StartingMaterial, SubstancePolymer::Repeat, SubstancePolymer::Repeat::RepeatUnit, SubstancePolymer::Repeat::RepeatUnit::DegreeOfPolymerisation, SubstancePolymer::Repeat::RepeatUnit::StructuralRepresentation, SubstanceProtein, SubstanceProtein::Subunit, SubstanceReferenceInformation, SubstanceReferenceInformation::Classification, SubstanceReferenceInformation::Gene, SubstanceReferenceInformation::GeneElement, SubstanceReferenceInformation::Target, SubstanceSourceMaterial, SubstanceSourceMaterial::FractionDescription, SubstanceSourceMaterial::Organism, SubstanceSourceMaterial::Organism::Author, SubstanceSourceMaterial::Organism::Hybrid, SubstanceSourceMaterial::Organism::OrganismGeneral, SubstanceSourceMaterial::PartDescription, SubstanceSpecification, SubstanceSpecification::Code, SubstanceSpecification::Moiety, SubstanceSpecification::Name, SubstanceSpecification::Name::Official, SubstanceSpecification::Property, SubstanceSpecification::Relationship, SubstanceSpecification::Structure, SubstanceSpecification::Structure::Isotope, SubstanceSpecification::Structure::Isotope::MolecularWeight, SubstanceSpecification::Structure::Representation, SupplyDelivery, SupplyDelivery::SuppliedItem, SupplyRequest, SupplyRequest::Parameter, Task, Task::Input, Task::Output, Task::Restriction, TerminologyCapabilities, TerminologyCapabilities::Closure, TerminologyCapabilities::CodeSystem, TerminologyCapabilities::CodeSystem::Version, TerminologyCapabilities::CodeSystem::Version::Filter, TerminologyCapabilities::Expansion, TerminologyCapabilities::Expansion::Parameter, TerminologyCapabilities::Implementation, TerminologyCapabilities::Software, TerminologyCapabilities::Translation, TerminologyCapabilities::ValidateCode, TestReport, TestReport::Participant, TestReport::Setup, TestReport::Setup::Action, TestReport::Setup::Action::Assert, TestReport::Setup::Action::Operation, TestReport::Teardown, TestReport::Teardown::Action, TestReport::Test, TestReport::Test::Action, TestScript, TestScript::Destination, TestScript::Fixture, TestScript::Metadata, TestScript::Metadata::Capability, TestScript::Metadata::Link, TestScript::Origin, TestScript::Setup, TestScript::Setup::Action, TestScript::Setup::Action::Assert, TestScript::Setup::Action::Operation, TestScript::Setup::Action::Operation::RequestHeader, TestScript::Teardown, TestScript::Teardown::Action, TestScript::Test, TestScript::Test::Action, TestScript::Variable, Timing, Timing::Repeat, TriggerDefinition, UsageContext, ValueSet, ValueSet::Compose, ValueSet::Compose::Include, ValueSet::Compose::Include::Concept, ValueSet::Compose::Include::Concept::Designation, ValueSet::Compose::Include::Filter, ValueSet::Expansion, ValueSet::Expansion::Contains, ValueSet::Expansion::Parameter, VerificationResult, VerificationResult::Attestation, VerificationResult::PrimarySource, VerificationResult::Validator, VisionPrescription, VisionPrescription::LensSpecification, VisionPrescription::LensSpecification::Prism
Defined in:
lib/fhir_models/bootstrap/xml.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Deprecate

deprecate

Class Method Details

.from_xml(xml) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/fhir_models/bootstrap/xml.rb', line 70

def self.from_xml(xml)
  doc = Nokogiri::XML(xml)
  doc.root.add_namespace_definition('f', 'http://hl7.org/fhir')
  doc.root.add_namespace_definition('x', 'http://www.w3.org/1999/xhtml')
  hash = xml_node_to_hash(doc.root)

  resource = nil
  begin
    resource_type = doc.root.name
    klass = Module.const_get("FHIR::#{resource_type}")
    resource = klass.new(hash)
  rescue => ex
    FHIR.logger.error("Failed to deserialize XML:\n#{ex.backtrace}")
    FHIR.logger.debug("XML:\n#{xml}")
    resource = nil
  end
  resource
end

.valid?(xml) ⇒ Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/fhir_models/bootstrap/xml.rb', line 127

def self.valid?(xml)
  validate(xml).empty?
end

.validate(xml) ⇒ Object



132
133
134
135
136
137
# File 'lib/fhir_models/bootstrap/xml.rb', line 132

def self.validate(xml)
  defns = File.expand_path '../definitions/schema', File.dirname(File.absolute_path(__FILE__))
  schema = File.join(defns, 'fhir-all.xsd')
  xsd = Nokogiri::XML::Schema(File.new(schema))
  xsd.validate(Nokogiri::XML(xml))
end

Instance Method Details

#to_xmlObject

This module includes methods to serialize or deserialize FHIR resources to and from XML.



9
10
11
12
13
14
15
16
17
# File 'lib/fhir_models/bootstrap/xml.rb', line 9

def to_xml
  hash = to_hash
  hash.delete('resourceType')
  doc = Nokogiri::XML::Document.new
  doc.encoding = 'utf-8'
  doc.root = hash_to_xml_node(resourceType, hash, doc)
  doc.root.default_namespace = 'http://hl7.org/fhir'
  doc.to_xml
end