Module: FHIR

Defined in:
lib/fhir_models/fhir.rb,
lib/fhir_models/version.rb,
lib/fhir_models/deprecate.rb,
lib/fhir_models/bootstrap/xml.rb,
lib/fhir_models/fhir/metadata.rb,
lib/fhir_models/bootstrap/json.rb,
lib/fhir_models/fhir/types/Age.rb,
lib/fhir_models/bootstrap/field.rb,
lib/fhir_models/bootstrap/model.rb,
lib/fhir_models/fhir/types/Meta.rb,
lib/fhir_models/fhir/types/Count.rb,
lib/fhir_models/fhir/types/Money.rb,
lib/fhir_models/fhir/types/Range.rb,
lib/fhir_models/fhir/types/Ratio.rb,
lib/fhir_models/fhir/types/Coding.rb,
lib/fhir_models/fhir/types/Dosage.rb,
lib/fhir_models/fhir/types/Period.rb,
lib/fhir_models/fhir/types/Timing.rb,
lib/fhir_models/bootstrap/hashable.rb,
lib/fhir_models/bootstrap/template.rb,
lib/fhir_models/fhir/types/Address.rb,
lib/fhir_models/fhir/types/Element.rb,
lib/fhir_models/bootstrap/generator.rb,
lib/fhir_models/fhir/resources/Flag.rb,
lib/fhir_models/fhir/resources/Goal.rb,
lib/fhir_models/fhir/resources/List.rb,
lib/fhir_models/fhir/resources/Slot.rb,
lib/fhir_models/fhir/resources/Task.rb,
lib/fhir_models/fhir/types/Distance.rb,
lib/fhir_models/fhir/types/Duration.rb,
lib/fhir_models/fhir/types/Quantity.rb,
lib/fhir_models/bootstrap/preprocess.rb,
lib/fhir_models/fhir/resources/Basic.rb,
lib/fhir_models/fhir/resources/Claim.rb,
lib/fhir_models/fhir/resources/Group.rb,
lib/fhir_models/fhir/resources/Media.rb,
lib/fhir_models/fhir/types/Extension.rb,
lib/fhir_models/fhir/types/HumanName.rb,
lib/fhir_models/fhir/types/Narrative.rb,
lib/fhir_models/fhir/types/Reference.rb,
lib/fhir_models/fhir/types/Signature.rb,
lib/fhir_models/bootstrap/definitions.rb,
lib/fhir_models/fhir/resources/Binary.rb,
lib/fhir_models/fhir/resources/Bundle.rb,
lib/fhir_models/fhir/resources/Device.rb,
lib/fhir_models/fhir/resources/Person.rb,
lib/fhir_models/fhir/types/Annotation.rb,
lib/fhir_models/fhir/types/Attachment.rb,
lib/fhir_models/fhir/types/Expression.rb,
lib/fhir_models/fhir/types/Identifier.rb,
lib/fhir_models/fhir/types/Population.rb,
lib/fhir_models/fhir/resources/Account.rb,
lib/fhir_models/fhir/resources/Consent.rb,
lib/fhir_models/fhir/resources/Invoice.rb,
lib/fhir_models/fhir/resources/Library.rb,
lib/fhir_models/fhir/resources/Linkage.rb,
lib/fhir_models/fhir/resources/Measure.rb,
lib/fhir_models/fhir/resources/Patient.rb,
lib/fhir_models/fhir/types/Contributor.rb,
lib/fhir_models/fhir/types/SampledData.rb,
lib/fhir_models/fhir/resources/CarePlan.rb,
lib/fhir_models/fhir/resources/CareTeam.rb,
lib/fhir_models/fhir/resources/Contract.rb,
lib/fhir_models/fhir/resources/Coverage.rb,
lib/fhir_models/fhir/resources/Endpoint.rb,
lib/fhir_models/fhir/resources/Evidence.rb,
lib/fhir_models/fhir/resources/Location.rb,
lib/fhir_models/fhir/resources/Resource.rb,
lib/fhir_models/fhir/resources/Schedule.rb,
lib/fhir_models/fhir/resources/Specimen.rb,
lib/fhir_models/fhir/resources/ValueSet.rb,
lib/fhir_models/fhir/types/ContactPoint.rb,
lib/fhir_models/fhir/types/UsageContext.rb,
lib/fhir_models/fhir/resources/Condition.rb,
lib/fhir_models/fhir/resources/Encounter.rb,
lib/fhir_models/fhir/resources/Procedure.rb,
lib/fhir_models/fhir/resources/Substance.rb,
lib/fhir_models/fhir/types/ContactDetail.rb,
lib/fhir_models/fhir/resources/AuditEvent.rb,
lib/fhir_models/fhir/resources/ChargeItem.rb,
lib/fhir_models/fhir/resources/CodeSystem.rb,
lib/fhir_models/fhir/resources/ConceptMap.rb,
lib/fhir_models/fhir/resources/Medication.rb,
lib/fhir_models/fhir/resources/Parameters.rb,
lib/fhir_models/fhir/resources/Provenance.rb,
lib/fhir_models/fhir/resources/TestReport.rb,
lib/fhir_models/fhir/resources/TestScript.rb,
lib/fhir_models/fhir/resources/Appointment.rb,
lib/fhir_models/fhir/resources/Composition.rb,
lib/fhir_models/fhir/resources/Observation.rb,
lib/fhir_models/fhir/types/BackboneElement.rb,
lib/fhir_models/fhir/types/CodeableConcept.rb,
lib/fhir_models/fhir/types/DataRequirement.rb,
lib/fhir_models/fhir/types/MarketingStatus.rb,
lib/fhir_models/fhir/types/RelatedArtifact.rb,
lib/fhir_models/fhir/types/SubstanceAmount.rb,
lib/fhir_models/fhir/resources/AdverseEvent.rb,
lib/fhir_models/fhir/resources/CatalogEntry.rb,
lib/fhir_models/fhir/resources/DeviceMetric.rb,
lib/fhir_models/fhir/resources/ImagingStudy.rb,
lib/fhir_models/fhir/resources/Immunization.rb,
lib/fhir_models/fhir/resources/NamingSystem.rb,
lib/fhir_models/fhir/resources/Organization.rb,
lib/fhir_models/fhir/resources/Practitioner.rb,
lib/fhir_models/fhir/resources/RequestGroup.rb,
lib/fhir_models/fhir/resources/StructureMap.rb,
lib/fhir_models/fhir/resources/Subscription.rb,
lib/fhir_models/fhir/types/ProductShelfLife.rb,
lib/fhir_models/fhir_ext/element_definition.rb,
lib/fhir_models/fhir/resources/BodyStructure.rb,
lib/fhir_models/fhir/resources/ClaimResponse.rb,
lib/fhir_models/fhir/resources/Communication.rb,
lib/fhir_models/fhir/resources/DetectedIssue.rb,
lib/fhir_models/fhir/resources/DeviceRequest.rb,
lib/fhir_models/fhir/resources/EpisodeOfCare.rb,
lib/fhir_models/fhir/resources/InsurancePlan.rb,
lib/fhir_models/fhir/resources/MeasureReport.rb,
lib/fhir_models/fhir/resources/MessageHeader.rb,
lib/fhir_models/fhir/resources/PaymentNotice.rb,
lib/fhir_models/fhir/resources/Questionnaire.rb,
lib/fhir_models/fhir/resources/RelatedPerson.rb,
lib/fhir_models/fhir/resources/ResearchStudy.rb,
lib/fhir_models/fhir/resources/SupplyRequest.rb,
lib/fhir_models/fhir/types/ElementDefinition.rb,
lib/fhir_models/fhir/types/TriggerDefinition.rb,
lib/fhir_models/fhir/resources/DomainResource.rb,
lib/fhir_models/fhir/resources/NutritionOrder.rb,
lib/fhir_models/fhir/resources/PlanDefinition.rb,
lib/fhir_models/fhir/resources/RiskAssessment.rb,
lib/fhir_models/fhir/resources/ServiceRequest.rb,
lib/fhir_models/fhir/resources/SupplyDelivery.rb,
lib/fhir_models/fhir/types/ProdCharacteristic.rb,
lib/fhir_models/fhir_ext/structure_definition.rb,
lib/fhir_models/fhir/resources/EventDefinition.rb,
lib/fhir_models/fhir/resources/ExampleScenario.rb,
lib/fhir_models/fhir/resources/GraphDefinition.rb,
lib/fhir_models/fhir/resources/ResearchSubject.rb,
lib/fhir_models/fhir/resources/SearchParameter.rb,
lib/fhir_models/fhir/types/ParameterDefinition.rb,
lib/fhir_models/fhir/resources/DeviceDefinition.rb,
lib/fhir_models/fhir/resources/DiagnosticReport.rb,
lib/fhir_models/fhir/resources/DocumentManifest.rb,
lib/fhir_models/fhir/resources/EvidenceVariable.rb,
lib/fhir_models/fhir/resources/GuidanceResponse.rb,
lib/fhir_models/fhir/resources/MedicinalProduct.rb,
lib/fhir_models/fhir/resources/OperationOutcome.rb,
lib/fhir_models/fhir/resources/PractitionerRole.rb,
lib/fhir_models/fhir/resources/SubstancePolymer.rb,
lib/fhir_models/fhir/resources/SubstanceProtein.rb,
lib/fhir_models/fhir/resources/DocumentReference.rb,
lib/fhir_models/fhir/resources/EnrollmentRequest.rb,
lib/fhir_models/fhir/resources/HealthcareService.rb,
lib/fhir_models/fhir/resources/MedicationRequest.rb,
lib/fhir_models/fhir/resources/MessageDefinition.rb,
lib/fhir_models/fhir/resources/MolecularSequence.rb,
lib/fhir_models/fhir/resources/ActivityDefinition.rb,
lib/fhir_models/fhir/resources/AllergyIntolerance.rb,
lib/fhir_models/fhir/resources/ClinicalImpression.rb,
lib/fhir_models/fhir/resources/DeviceUseStatement.rb,
lib/fhir_models/fhir/resources/EnrollmentResponse.rb,
lib/fhir_models/fhir/resources/MedicationDispense.rb,
lib/fhir_models/fhir/resources/ResearchDefinition.rb,
lib/fhir_models/fhir/resources/SpecimenDefinition.rb,
lib/fhir_models/fhir/resources/VerificationResult.rb,
lib/fhir_models/fhir/resources/VisionPrescription.rb,
lib/fhir_models/fhir/resources/AppointmentResponse.rb,
lib/fhir_models/fhir/resources/CapabilityStatement.rb,
lib/fhir_models/fhir/resources/FamilyMemberHistory.rb,
lib/fhir_models/fhir/resources/ImplementationGuide.rb,
lib/fhir_models/fhir/resources/MedicationKnowledge.rb,
lib/fhir_models/fhir/resources/MedicationStatement.rb,
lib/fhir_models/fhir/resources/OperationDefinition.rb,
lib/fhir_models/fhir/resources/StructureDefinition.rb,
lib/fhir_models/fhir/resources/ChargeItemDefinition.rb,
lib/fhir_models/fhir/resources/CommunicationRequest.rb,
lib/fhir_models/fhir/resources/ExplanationOfBenefit.rb,
lib/fhir_models/fhir/resources/SubstanceNucleicAcid.rb,
lib/fhir_models/fhir/resources/CompartmentDefinition.rb,
lib/fhir_models/fhir/resources/ObservationDefinition.rb,
lib/fhir_models/fhir/resources/PaymentReconciliation.rb,
lib/fhir_models/fhir/resources/QuestionnaireResponse.rb,
lib/fhir_models/fhir/resources/RiskEvidenceSynthesis.rb,
lib/fhir_models/fhir/resources/ImmunizationEvaluation.rb,
lib/fhir_models/fhir/resources/SubstanceSpecification.rb,
lib/fhir_models/fhir_ext/structure_definition_compare.rb,
lib/fhir_models/fhir_ext/structure_definition_finding.rb,
lib/fhir_models/fhir/resources/EffectEvidenceSynthesis.rb,
lib/fhir_models/fhir/resources/OrganizationAffiliation.rb,
lib/fhir_models/fhir/resources/SubstanceSourceMaterial.rb,
lib/fhir_models/fhir/resources/TerminologyCapabilities.rb,
lib/fhir_models/fhir/resources/MedicationAdministration.rb,
lib/fhir_models/fhir/resources/MedicinalProductPackaged.rb,
lib/fhir_models/fhir/resources/ResearchElementDefinition.rb,
lib/fhir_models/fhir/resources/BiologicallyDerivedProduct.rb,
lib/fhir_models/fhir/resources/CoverageEligibilityRequest.rb,
lib/fhir_models/fhir/resources/ImmunizationRecommendation.rb,
lib/fhir_models/fhir/resources/MedicinalProductIndication.rb,
lib/fhir_models/fhir/resources/MedicinalProductIngredient.rb,
lib/fhir_models/fhir/resources/CoverageEligibilityResponse.rb,
lib/fhir_models/fhir/resources/MedicinalProductInteraction.rb,
lib/fhir_models/fhir/resources/MedicinalProductManufactured.rb,
lib/fhir_models/fhir/resources/MedicinalProductAuthorization.rb,
lib/fhir_models/fhir/resources/SubstanceReferenceInformation.rb,
lib/fhir_models/fhir/resources/MedicinalProductPharmaceutical.rb,
lib/fhir_models/fhir/resources/MedicinalProductContraindication.rb,
lib/fhir_models/fhir/resources/MedicinalProductUndesirableEffect.rb

Defined Under Namespace

Modules: Boot, Deprecate, Hashable, Json, Models, Xml Classes: Account, ActivityDefinition, Address, AdverseEvent, Age, AllergyIntolerance, Annotation, Appointment, AppointmentResponse, Attachment, AuditEvent, BackboneElement, Basic, Binary, BiologicallyDerivedProduct, BodyStructure, Bundle, CapabilityStatement, CarePlan, CareTeam, CatalogEntry, ChargeItem, ChargeItemDefinition, Claim, ClaimResponse, ClinicalImpression, CodeSystem, CodeableConcept, Coding, Communication, CommunicationRequest, CompartmentDefinition, Composition, ConceptMap, Condition, Consent, ContactDetail, ContactPoint, Contract, Contributor, Count, Coverage, CoverageEligibilityRequest, CoverageEligibilityResponse, DataRequirement, Definitions, DetectedIssue, Device, DeviceDefinition, DeviceMetric, DeviceRequest, DeviceUseStatement, DiagnosticReport, Distance, DocumentManifest, DocumentReference, DomainResource, Dosage, Duration, EffectEvidenceSynthesis, Element, ElementDefinition, Encounter, Endpoint, EnrollmentRequest, EnrollmentResponse, EpisodeOfCare, EventDefinition, Evidence, EvidenceVariable, ExampleScenario, ExplanationOfBenefit, Expression, Extension, FamilyMemberHistory, Field, Flag, Goal, GraphDefinition, Group, GuidanceResponse, HealthcareService, HumanName, Identifier, ImagingStudy, Immunization, ImmunizationEvaluation, ImmunizationRecommendation, ImplementationGuide, InsurancePlan, Invoice, Library, Linkage, List, Location, MarketingStatus, Measure, MeasureReport, Media, Medication, MedicationAdministration, MedicationDispense, MedicationKnowledge, MedicationRequest, MedicationStatement, MedicinalProduct, MedicinalProductAuthorization, MedicinalProductContraindication, MedicinalProductIndication, MedicinalProductIngredient, MedicinalProductInteraction, MedicinalProductManufactured, MedicinalProductPackaged, MedicinalProductPharmaceutical, MedicinalProductUndesirableEffect, MessageDefinition, MessageHeader, Meta, Model, MolecularSequence, Money, NamingSystem, Narrative, NutritionOrder, Observation, ObservationDefinition, OperationDefinition, OperationOutcome, Organization, OrganizationAffiliation, ParameterDefinition, Parameters, Patient, PaymentNotice, PaymentReconciliation, Period, Person, PlanDefinition, Population, Practitioner, PractitionerRole, Procedure, ProdCharacteristic, ProductShelfLife, Provenance, Quantity, Questionnaire, QuestionnaireResponse, Range, Ratio, Reference, RelatedArtifact, RelatedPerson, RequestGroup, ResearchDefinition, ResearchElementDefinition, ResearchStudy, ResearchSubject, Resource, RiskAssessment, RiskEvidenceSynthesis, SampledData, Schedule, SearchParameter, ServiceRequest, Signature, Slot, Specimen, SpecimenDefinition, StructureDefinition, StructureDefinitionFinding, StructureMap, Subscription, Substance, SubstanceAmount, SubstanceNucleicAcid, SubstancePolymer, SubstanceProtein, SubstanceReferenceInformation, SubstanceSourceMaterial, SubstanceSpecification, SupplyDelivery, SupplyRequest, Task, TerminologyCapabilities, TestReport, TestScript, Timing, TriggerDefinition, UsageContext, ValueSet, VerificationResult, VisionPrescription

Constant Summary collapse

PRIMITIVES =
{
  'base64Binary' => {'type'=>'string', 'regex'=>'(\\s*([0-9a-zA-Z\\+/=]){4}\\s*)+'},
  'boolean' => {'type'=>'boolean', 'regex'=>'true|false'},
  'canonical' => {'type'=>'string', 'regex'=>'\\S*'},
  'code' => {'type'=>'string', 'regex'=>'[^\\s]+(\\s[^\\s]+)*'},
  'date' => {'type'=>'string', 'regex'=>'([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1]))?)?'},
  'dateTime' => {'type'=>'string', 'regex'=>'([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\\.[0-9]+)?(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)))?)?)?'},
  'decimal' => {'type'=>'number', 'regex'=>'-?(0|[1-9][0-9]*)(\\.[0-9]+)?([eE][+-]?[0-9]+)?'},
  'id' => {'type'=>'string', 'regex'=>'[A-Za-z0-9\\-\\.]{1,64}'},
  'instant' => {'type'=>'string', 'regex'=>'([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\\.[0-9]+)?(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))'},
  'integer' => {'type'=>'number', 'regex'=>'-?([0]|([1-9][0-9]*))'},
  'markdown' => {'type'=>'string', 'regex'=>'[ \\r\\n\\t\\S]+'},
  'oid' => {'type'=>'string', 'regex'=>'urn:oid:[0-2](\\.(0|[1-9][0-9]*))+'},
  'positiveInt' => {'type'=>'number', 'regex'=>'[1-9][0-9]*'},
  'string' => {'type'=>'string', 'regex'=>'[ \\r\\n\\t\\S]+'},
  'time' => {'type'=>'string', 'regex'=>'([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\\.[0-9]+)?'},
  'unsignedInt' => {'type'=>'number', 'regex'=>'[0]|([1-9][0-9]*)'},
  'uri' => {'type'=>'string', 'regex'=>'\\S*'},
  'url' => {'type'=>'string', 'regex'=>'\\S*'},
  'uuid' => {'type'=>'string', 'regex'=>'urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'},
  'xhtml' => {'type'=>'string'}
}
TYPES =
['Element', 'BackboneElement', 'Address', 'Age', 'Annotation', 'Attachment', 'CodeableConcept', 'Coding', 'ContactDetail', 'ContactPoint', 'Contributor', 'Count', 'DataRequirement', 'Distance', 'Dosage', 'Duration', 'ElementDefinition', 'Expression', 'Extension', 'HumanName', 'Identifier', 'MarketingStatus', 'Meta', 'Money', 'Narrative', 'ParameterDefinition', 'Period', 'Population', 'ProdCharacteristic', 'ProductShelfLife', 'Quantity', 'Range', 'Ratio', 'Reference', 'RelatedArtifact', 'SampledData', 'Signature', 'SubstanceAmount', 'Timing', 'TriggerDefinition', 'UsageContext']
RESOURCES =
['Resource', 'Account', 'ActivityDefinition', 'AdverseEvent', 'AllergyIntolerance', 'Appointment', 'AppointmentResponse', 'AuditEvent', 'Basic', 'Binary', 'BiologicallyDerivedProduct', 'BodyStructure', 'Bundle', 'CapabilityStatement', 'CarePlan', 'CareTeam', 'CatalogEntry', 'ChargeItem', 'ChargeItemDefinition', 'Claim', 'ClaimResponse', 'ClinicalImpression', 'CodeSystem', 'Communication', 'CommunicationRequest', 'CompartmentDefinition', 'Composition', 'ConceptMap', 'Condition', 'Consent', 'Contract', 'Coverage', 'CoverageEligibilityRequest', 'CoverageEligibilityResponse', 'DetectedIssue', 'Device', 'DeviceDefinition', 'DeviceMetric', 'DeviceRequest', 'DeviceUseStatement', 'DiagnosticReport', 'DocumentManifest', 'DocumentReference', 'DomainResource', 'EffectEvidenceSynthesis', 'Encounter', 'Endpoint', 'EnrollmentRequest', 'EnrollmentResponse', 'EpisodeOfCare', 'EventDefinition', 'Evidence', 'EvidenceVariable', 'ExampleScenario', 'ExplanationOfBenefit', 'FamilyMemberHistory', 'Flag', 'Goal', 'GraphDefinition', 'Group', 'GuidanceResponse', 'HealthcareService', 'ImagingStudy', 'Immunization', 'ImmunizationEvaluation', 'ImmunizationRecommendation', 'ImplementationGuide', 'InsurancePlan', 'Invoice', 'Library', 'Linkage', 'List', 'Location', 'Measure', 'MeasureReport', 'Media', 'Medication', 'MedicationAdministration', 'MedicationDispense', 'MedicationKnowledge', 'MedicationRequest', 'MedicationStatement', 'MedicinalProduct', 'MedicinalProductAuthorization', 'MedicinalProductContraindication', 'MedicinalProductIndication', 'MedicinalProductIngredient', 'MedicinalProductInteraction', 'MedicinalProductManufactured', 'MedicinalProductPackaged', 'MedicinalProductPharmaceutical', 'MedicinalProductUndesirableEffect', 'MessageDefinition', 'MessageHeader', 'MolecularSequence', 'NamingSystem', 'NutritionOrder', 'Observation', 'ObservationDefinition', 'OperationDefinition', 'OperationOutcome', 'Organization', 'OrganizationAffiliation', 'Parameters', 'Patient', 'PaymentNotice', 'PaymentReconciliation', 'Person', 'PlanDefinition', 'Practitioner', 'PractitionerRole', 'Procedure', 'Provenance', 'Questionnaire', 'QuestionnaireResponse', 'RelatedPerson', 'RequestGroup', 'ResearchDefinition', 'ResearchElementDefinition', 'ResearchStudy', 'ResearchSubject', 'RiskAssessment', 'RiskEvidenceSynthesis', 'Schedule', 'SearchParameter', 'ServiceRequest', 'Slot', 'Specimen', 'SpecimenDefinition', 'StructureDefinition', 'StructureMap', 'Subscription', 'Substance', 'SubstanceNucleicAcid', 'SubstancePolymer', 'SubstanceProtein', 'SubstanceReferenceInformation', 'SubstanceSourceMaterial', 'SubstanceSpecification', 'SupplyDelivery', 'SupplyRequest', 'Task', 'TerminologyCapabilities', 'TestReport', 'TestScript', 'ValueSet', 'VerificationResult', 'VisionPrescription']

Class Method Summary collapse

Class Method Details

.default_loggerObject



13
14
15
# File 'lib/fhir_models/fhir.rb', line 13

def self.default_logger
  @default_logger ||= Logger.new(ENV['FHIR_LOGGER'] || STDOUT)
end

.from_contents(contents) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/fhir_models/fhir.rb', line 17

def self.from_contents(contents)
  doc = Nokogiri::XML(contents)
  if doc.errors.empty?
    FHIR::Xml.from_xml(contents)
  else
    FHIR::Json.from_json(contents)
  end
end

.loggerObject



5
6
7
# File 'lib/fhir_models/fhir.rb', line 5

def self.logger
  @logger || default_logger
end

.logger=(logger) ⇒ Object



9
10
11
# File 'lib/fhir_models/fhir.rb', line 9

def self.logger=(logger)
  @logger = logger
end

.primitive?(datatype:, value:) ⇒ Boolean

TODO: pull regexes from metadata

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fhir_models/fhir.rb', line 27

def self.primitive?(datatype:, value:)
  # Remaining data types: handle special cases before checking type StructureDefinitions
  case datatype.downcase
  when 'boolean'
    !(value.to_s =~ /\A(true|false)\Z/).nil?
  when 'integer'
    !(value.to_s =~ /\A(0|[-+]?[1-9][0-9]*)\Z/).nil?
  when 'string', 'markdown'
    value.is_a?(String)
  when 'decimal'
    !(value.to_s =~ /\A([-+]?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?)\Z/).nil?
  when 'uri'
    begin
      !URI.parse(value).nil?
    rescue
      false
    end
  when 'base64binary'
    # According to RFC-4648 base64binary encoding includes digits 0-9, a-z, A-Z, =, +, /, and whitespace
    # an empty string is considered valid
    # whitespace is not significant so we strip it out before doing the regex so that we can be sure that
    # the number of characters is a multiple of 4.
    # https://tools.ietf.org/html/rfc4648
    !(value.to_s.gsub(/\s/, '') =~ %r{\A(|[0-9a-zA-Z\+=/]{4}+)\Z}).nil?
  when 'instant'
    formatted_value = value.respond_to?(:xmlschema) ? value.xmlschema : value.to_s
    !(formatted_value =~ /\A([0-9]{4}(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\.[0-9]+)?(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))))))\Z/).nil?
  when 'date'
    !(value.to_s =~ /\A(-?[0-9]{4}(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1]))?)?)\Z/).nil?
    # NOTE: we don't try to instantiate and verify  a Date because ruby does not natively suppport
    # partial dates, which the FHIR standard allows.
  when 'datetime'
    !(value.to_s =~ /\A(-?[0-9]{4}(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\.[0-9]+)?(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)))?)?)?)\Z/).nil?
    # NOTE: we don't try to instantiate and verify a DateTime because ruby does not natively suppport
    # partial dates, which the FHIR standard allows.
  when 'time'
    !(value.to_s =~ /\A(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\.[0-9]+)?)\Z/).nil?
  when 'code'
    !(value.to_s =~ /\A[^\s]+([\s]?[^\s]+)*\Z/).nil?
  when 'oid'
    !(value.to_s =~ /\Aurn:oid:[0-2](\.[1-9]\d*)+\Z/).nil?
  when 'id'
    !(value.to_s =~ /\A[A-Za-z0-9\-\.]{1,64}\Z/).nil?
  when 'xhtml'
    fragment = Nokogiri::HTML::DocumentFragment.parse(value)
    value.is_a?(String) && fragment.errors.size.zero?
  when 'unsignedint'
    !(value.to_s =~ /\A([0]|([1-9][0-9]*))\Z/).nil?
  when 'positiveint'
    !(value.to_s =~ /\A+?[1-9][0-9]*\Z/).nil?
  else
    FHIR.logger.warn "Unable to check #{value} for datatype #{datatype}"
    false
  end
end