@medplum/ccda 4.0.1 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- "use strict";var Be=Object.defineProperty;var Hn=Object.getOwnPropertyDescriptor;var jn=Object.getOwnPropertyNames;var qn=Object.prototype.hasOwnProperty;var Wn=(t,e)=>{for(var i in e)Be(t,i,{get:e[i],enumerable:!0})},Qn=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of jn(e))!qn.call(t,r)&&r!==i&&Be(t,r,{get:()=>e[r],enumerable:!(n=Hn(e,r))||n.enumerable});return t};var zn=t=>Qn(Be({},"__esModule",{value:!0}),t);var Ao={};Wn(Ao,{ACT_CODE_SYSTEM:()=>It,ADDRESS_USE_MAPPER:()=>le,ADDRESS_USE_VALUE_SET:()=>dn,ADMINISTRATIVE_GENDER_VALUE_SET:()=>hn,ALLERGIES_SECTION_TEMPLATE_IDS:()=>Rn,ALLERGY_CATEGORY_MAPPER:()=>Nt,ALLERGY_CLINICAL_CODE_SYSTEM:()=>re,ALLERGY_SEVERITY_MAPPER:()=>he,ALLERGY_STATUS_MAPPER:()=>pe,ALLERGY_VERIFICATION_CODE_SYSTEM:()=>Me,ASSESSMENTS_SECTION_TEMPLATE_IDS:()=>Un,CARE_TEAM_SECTION_TEMPLATE_IDS:()=>Gn,CCDA_NARRATIVE_REFERENCE_URL:()=>ae,CCDA_TEMPLATE_CODE_SYSTEM:()=>mo,CCDA_TEMPLATE_IDS:()=>Ut,CLINICAL_CONDITION_CODE_SYSTEM:()=>Ve,CLINICAL_NOTES_SECTION_TEMPLATE_IDS:()=>So,CONDITION_CATEGORY_CODE_SYSTEM:()=>Et,CONDITION_VERIFICATION_CODE_SYSTEM:()=>mt,CONDITION_VER_STATUS_CODE_SYSTEM:()=>we,CONFIDENTIALITY_CODE_SYSTEM:()=>un,CONFIDENTIALITY_MAPPER:()=>At,CONTACT_ENTITY_USE_VALUE_SET:()=>fn,CVX_URL:()=>gn,DEVICES_SECTION_TEMPLATE_IDS:()=>Co,DIAGNOSIS_ROLE_CODE_SYSTEM:()=>Ot,ENCOUNTERS_SECTION_TEMPLATE_IDS:()=>Vn,ENCOUNTER_STATUS_MAPPER:()=>Dt,EnumMapper:()=>m,FHIR_CVX_URL:()=>An,GENDER_MAPPER:()=>Rt,GOALS_SECTION_TEMPLATE_IDS:()=>wn,HEALTH_CONCERNS_SECTION_TEMPLATE_IDS:()=>Mn,HTTP:()=>b,HUMAN_NAME_USE_MAPPER:()=>ue,IMMUNIZATIONS_SECTION_TEMPLATE_IDS:()=>ke,IMMUNIZATION_STATUS_MAPPER:()=>_e,INSURANCE_SECTION_TEMPLATE_IDS:()=>Yn,LAB_TESTS_SECTION_TEMPLATE_IDS:()=>yo,LANGUAGE_MODE_CODE_SYSTEM:()=>uo,LANGUAGE_MODE_URL:()=>ho,LANGUAGE_PROFICIENCY_CODE_SYSTEM:()=>lo,LANGUAGE_PROFICIENCY_URL:()=>fo,LOINC_TO_TEMPLATE_IDS:()=>Lt,MEDICATIONS_SECTION_TEMPLATE_IDS:()=>Nn,MEDICATION_REQUEST_STATUS_VALUE_SET:()=>_n,MEDICATION_STATUS_MAPPER:()=>me,MENTAL_STATUS_SECTION_TEMPLATE_IDS:()=>Bn,NAME_USE_VALUE_SET:()=>pn,NCI_THESAURUS_URL:()=>mn,NDFRT_URL:()=>Cn,NUCC_TAXONOMY_URL:()=>Sn,OBSERVATION_CATEGORY_CODE_SYSTEM:()=>ln,OBSERVATION_CATEGORY_MAPPER:()=>Ee,PARTICIPATION_CODE_SYSTEM:()=>Tt,PATIENT_NOTES_SECTION_TEMPLATE_IDS:()=>Fn,PLAN_OF_TREATMENT_SECTION_TEMPLATE_IDS:()=>Ln,PROBLEMS_SECTION_TEMPLATE_IDS:()=>Dn,PROBLEM_STATUS_MAPPER:()=>fe,PROCEDURES_SECTION_TEMPLATE_IDS:()=>Pn,PROCEDURE_STATUS_MAPPER:()=>xt,RACE_CODE_SYSTEM:()=>po,REASON_FOR_REFERRAL_SECTION_TEMPLATE_IDS:()=>kn,RESULTS_SECTION_TEMPLATE_IDS:()=>bn,SOCIAL_HISTORY_SECTION_TEMPLATE_IDS:()=>vn,SYSTEM_MAPPER:()=>ce,TELECOM_USE_MAPPER:()=>de,UNII_URL:()=>On,US_CORE_CONDITION_URL:()=>St,US_CORE_ETHNICITY_URL:()=>se,US_CORE_MEDICATION_REQUEST_URL:()=>yt,US_CORE_PATIENT_URL:()=>_o,US_CORE_RACE_URL:()=>oe,US_DRIVER_LICENSE_URL:()=>In,US_NPI_URL:()=>Tn,US_SSN_URL:()=>En,VA_MEDRT_URL:()=>yn,VITAL_SIGNS_SECTION_TEMPLATE_IDS:()=>xn,XSI_URL:()=>Ct,convertCcdaToFhir:()=>Oo,convertCcdaToXml:()=>To,convertFhirToCcda:()=>go,convertToCompactXml:()=>Pt,convertXmlToCcda:()=>Io,mapCcdaSystemToFhir:()=>F,mapCcdaToFhirDate:()=>ge,mapCcdaToFhirDateTime:()=>f,mapCodeableConceptToCcdaCode:()=>p,mapCodeableConceptToCcdaValue:()=>G,mapCodingToCcdaCode:()=>_t,mapFhirSystemToCcda:()=>gt,mapFhirToCcdaDate:()=>V,mapFhirToCcdaDateTime:()=>O,parseXml:()=>vt});module.exports=zn(Ao);var Zn=class{constructor(t,e){this.operator=t,this.child=e}toString(){return`${this.operator}(${this.child.toString()})`}},q=class{constructor(t,e,i){this.operator=t,this.left=e,this.right=i}toString(){return`${this.left.toString()} ${this.operator} ${this.right.toString()}`}},Xn=class{constructor(){this.prefixParselets={},this.infixParselets={}}registerInfix(t,e){return this.infixParselets[t]=e,this}registerPrefix(t,e){return this.prefixParselets[t]=e,this}prefix(t,e,i){return this.registerPrefix(t,{parse(n,r){let o=n.consumeAndParse(e);return i(r,o)}})}infixLeft(t,e,i){return this.registerInfix(t,{parse(n,r,o){let s=n.consumeAndParse(e);return i(r,o,s)},precedence:e})}construct(t){return new Jn(t,this.prefixParselets,this.infixParselets)}},Jn=class{constructor(t,e,i){this.tokens=t,this.prefixParselets=e,this.infixParselets=i}hasMore(){return this.tokens.length>0}match(t){return this.peek()?.id!==t?!1:(this.consume(),!0)}consumeAndParse(t=1/0){let e=this.consume(),i=this.prefixParselets[e.id];if(!i)throw Error(`Parse error at "${e.value}" (line ${e.line}, column ${e.column}). No matching prefix parselet.`);let n=i.parse(this,e);for(;t>this.getPrecedence();){let r=this.consume();n=this.getInfixParselet(r).parse(this,n,r)}return n}getPrecedence(){let t=this.peek();if(!t)return 1/0;let e=this.getInfixParselet(t);return e?e.precedence:1/0}consume(t,e){if(!this.tokens.length)throw Error("Cant consume unknown more tokens.");if(t&&this.peek()?.id!==t){let i=this.peek();throw Error(`Expected ${t} but got "${i.id}" (${i.value}) at line ${i.line} column ${i.column}.`)}if(e&&this.peek()?.value!==e){let i=this.peek();throw Error(`Expected "${e}" but got "${i.value}" at line ${i.line} column ${i.column}.`)}return this.tokens.shift()}peek(){return this.tokens.length>0?this.tokens[0]:void 0}removeComments(){this.tokens=this.tokens.filter(t=>t.id!=="Comment")}getInfixParselet(t){return this.infixParselets[t.id==="Symbol"?t.value:t.id]}},Ge="http://unitsofmeasure.org",ye="http://loinc.org",Ye="http://snomed.info/sct",Yt="http://www.nlm.nih.gov/research/umls/rxnorm",$t="http://www.ama-assn.org/go/cpt";var Ht="http://hl7.org/fhir/sid/ndc",_="http://hl7.org",I="http://terminology.hl7.org";var Kn="unauthorized";var Oe={resourceType:"OperationOutcome",id:Kn,issue:[{severity:"error",code:"login",details:{text:"Unauthorized"}}]},No={...Oe,issue:[...Oe.issue,{severity:"error",code:"expired",details:{text:"Token expired"}}]},Do={...Oe,issue:[...Oe.issue,{severity:"error",code:"invalid",details:{text:"Token not issued for this audience"}}]};function er(t,e){let i=e.max&&e.max===Number.MAX_SAFE_INTEGER?Number.POSITIVE_INFINITY:e.max;return{path:t,description:"",type:e.type??[],min:e.min??0,max:i??1,isArray:!!i&&i>1,constraints:[]}}function tr(t){let e=Object.create(null);for(let[i,n]of Object.entries(t))e[i]={name:i,type:i,path:i,elements:Object.fromEntries(Object.entries(n.elements).map(([r,o])=>[r,er(r,o)])),constraints:[],innerTypes:[]};return e}var ir={Element:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]}}},BackboneElement:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]}}},Address:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},use:{type:[{code:"code"}]},type:{type:[{code:"code"}]},text:{type:[{code:"string"}]},line:{max:9007199254740991,type:[{code:"string"}]},city:{type:[{code:"string"}]},district:{type:[{code:"string"}]},state:{type:[{code:"string"}]},postalCode:{type:[{code:"string"}]},country:{type:[{code:"string"}]},period:{type:[{code:"Period"}]}}},Age:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Annotation:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},"author[x]":{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Organization"]},{code:"string"}]},time:{type:[{code:"dateTime"}]},text:{min:1,type:[{code:"markdown"}]}}},Attachment:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},contentType:{type:[{code:"code"}]},language:{type:[{code:"code"}]},data:{type:[{code:"base64Binary"}]},url:{type:[{code:"url"}]},size:{type:[{code:"unsignedInt"}]},hash:{type:[{code:"base64Binary"}]},title:{type:[{code:"string"}]},creation:{type:[{code:"dateTime"}]}}},CodeableConcept:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},coding:{max:9007199254740991,type:[{code:"Coding"}]},text:{type:[{code:"string"}]}}},Coding:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},system:{type:[{code:"uri"}]},version:{type:[{code:"string"}]},code:{type:[{code:"code"}]},display:{type:[{code:"string"}]},userSelected:{type:[{code:"boolean"}]}}},ContactDetail:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},name:{type:[{code:"string"}]},telecom:{max:9007199254740991,type:[{code:"ContactPoint"}]}}},ContactPoint:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},system:{type:[{code:"code"}]},value:{type:[{code:"string"}]},use:{type:[{code:"code"}]},rank:{type:[{code:"positiveInt"}]},period:{type:[{code:"Period"}]}}},Contributor:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},name:{min:1,type:[{code:"string"}]},contact:{max:9007199254740991,type:[{code:"ContactDetail"}]}}},Count:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},DataRequirement:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},profile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]},"subject[x]":{type:[{code:"CodeableConcept"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Group"]}]},mustSupport:{max:9007199254740991,type:[{code:"string"}]},codeFilter:{max:9007199254740991,type:[{code:"DataRequirementCodeFilter"}]},dateFilter:{max:9007199254740991,type:[{code:"DataRequirementDateFilter"}]},limit:{type:[{code:"positiveInt"}]},sort:{max:9007199254740991,type:[{code:"DataRequirementSort"}]}}},DataRequirementCodeFilter:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{type:[{code:"string"}]},searchParam:{type:[{code:"string"}]},valueSet:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/ValueSet"]}]},code:{max:9007199254740991,type:[{code:"Coding"}]}}},DataRequirementDateFilter:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{type:[{code:"string"}]},searchParam:{type:[{code:"string"}]},"value[x]":{type:[{code:"dateTime"},{code:"Period"},{code:"Duration"}]}}},DataRequirementSort:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},direction:{min:1,type:[{code:"code"}]}}},Distance:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Dosage:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},sequence:{type:[{code:"integer"}]},text:{type:[{code:"string"}]},additionalInstruction:{max:9007199254740991,type:[{code:"CodeableConcept"}]},patientInstruction:{type:[{code:"string"}]},timing:{type:[{code:"Timing"}]},"asNeeded[x]":{type:[{code:"boolean"},{code:"CodeableConcept"}]},site:{type:[{code:"CodeableConcept"}]},route:{type:[{code:"CodeableConcept"}]},method:{type:[{code:"CodeableConcept"}]},doseAndRate:{max:9007199254740991,type:[{code:"DosageDoseAndRate"}]},maxDosePerPeriod:{type:[{code:"Ratio"}]},maxDosePerAdministration:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},maxDosePerLifetime:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},DosageDoseAndRate:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{type:[{code:"CodeableConcept"}]},"dose[x]":{type:[{code:"Range"},{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},"rate[x]":{type:[{code:"Ratio"},{code:"Range"},{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},Duration:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},ElementDefinition:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},representation:{max:9007199254740991,type:[{code:"code"}]},sliceName:{type:[{code:"string"}]},sliceIsConstraining:{type:[{code:"boolean"}]},label:{type:[{code:"string"}]},code:{max:9007199254740991,type:[{code:"Coding"}]},slicing:{type:[{code:"ElementDefinitionSlicing"}]},short:{type:[{code:"string"}]},definition:{type:[{code:"markdown"}]},comment:{type:[{code:"markdown"}]},requirements:{type:[{code:"markdown"}]},alias:{max:9007199254740991,type:[{code:"string"}]},min:{type:[{code:"unsignedInt"}]},max:{type:[{code:"string"}]},base:{type:[{code:"ElementDefinitionBase"}]},contentReference:{type:[{code:"uri"}]},type:{max:9007199254740991,type:[{code:"ElementDefinitionType"}]},"defaultValue[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},meaningWhenMissing:{type:[{code:"markdown"}]},orderMeaning:{type:[{code:"string"}]},"fixed[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},"pattern[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},example:{max:9007199254740991,type:[{code:"ElementDefinitionExample"}]},"minValue[x]":{type:[{code:"date"},{code:"dateTime"},{code:"instant"},{code:"time"},{code:"decimal"},{code:"integer"},{code:"positiveInt"},{code:"unsignedInt"},{code:"Quantity"}]},"maxValue[x]":{type:[{code:"date"},{code:"dateTime"},{code:"instant"},{code:"time"},{code:"decimal"},{code:"integer"},{code:"positiveInt"},{code:"unsignedInt"},{code:"Quantity"}]},maxLength:{type:[{code:"integer"}]},condition:{max:9007199254740991,type:[{code:"id"}]},constraint:{max:9007199254740991,type:[{code:"ElementDefinitionConstraint"}]},mustSupport:{type:[{code:"boolean"}]},isModifier:{type:[{code:"boolean"}]},isModifierReason:{type:[{code:"string"}]},isSummary:{type:[{code:"boolean"}]},binding:{type:[{code:"ElementDefinitionBinding"}]},mapping:{max:9007199254740991,type:[{code:"ElementDefinitionMapping"}]}}},ElementDefinitionSlicingDiscriminator:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},path:{min:1,type:[{code:"string"}]}}},ElementDefinitionSlicing:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},discriminator:{max:9007199254740991,type:[{code:"ElementDefinitionSlicingDiscriminator"}]},description:{type:[{code:"string"}]},ordered:{type:[{code:"boolean"}]},rules:{min:1,type:[{code:"code"}]}}},ElementDefinitionBase:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},min:{min:1,type:[{code:"unsignedInt"}]},max:{min:1,type:[{code:"string"}]}}},ElementDefinitionType:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},code:{min:1,type:[{code:"uri"}]},profile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition","http://hl7.org/fhir/StructureDefinition/ImplementationGuide"]}]},targetProfile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition","http://hl7.org/fhir/StructureDefinition/ImplementationGuide"]}]},aggregation:{max:9007199254740991,type:[{code:"code"}]},versioning:{type:[{code:"code"}]}}},ElementDefinitionExample:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},label:{min:1,type:[{code:"string"}]},"value[x]":{min:1,type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]}}},ElementDefinitionConstraint:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},key:{min:1,type:[{code:"id"}]},requirements:{type:[{code:"string"}]},severity:{min:1,type:[{code:"code"}]},human:{min:1,type:[{code:"string"}]},expression:{type:[{code:"string"}]},xpath:{type:[{code:"string"}]},source:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]}}},ElementDefinitionBinding:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},strength:{min:1,type:[{code:"code"}]},description:{type:[{code:"string"}]},valueSet:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/ValueSet"]}]}}},ElementDefinitionMapping:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},identity:{min:1,type:[{code:"id"}]},language:{type:[{code:"code"}]},map:{min:1,type:[{code:"string"}]},comment:{type:[{code:"string"}]}}},Expression:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},description:{type:[{code:"string"}]},name:{type:[{code:"id"}]},language:{min:1,type:[{code:"code"}]},expression:{type:[{code:"string"}]},reference:{type:[{code:"uri"}]}}},Extension:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},url:{min:1,type:[{code:"uri"}]},"value[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]}}},HumanName:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},use:{type:[{code:"code"}]},text:{type:[{code:"string"}]},family:{type:[{code:"string"}]},given:{max:9007199254740991,type:[{code:"string"}]},prefix:{max:9007199254740991,type:[{code:"string"}]},suffix:{max:9007199254740991,type:[{code:"string"}]},period:{type:[{code:"Period"}]}}},Identifier:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},use:{type:[{code:"code"}]},type:{type:[{code:"CodeableConcept"}]},system:{type:[{code:"uri"}]},value:{type:[{code:"string"}]},period:{type:[{code:"Period"}]},assigner:{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Organization"]}]}}},MarketingStatus:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},country:{min:1,type:[{code:"CodeableConcept"}]},jurisdiction:{type:[{code:"CodeableConcept"}]},status:{min:1,type:[{code:"CodeableConcept"}]},dateRange:{min:1,type:[{code:"Period"}]},restoreDate:{type:[{code:"dateTime"}]}}},Meta:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},versionId:{type:[{code:"id"}]},lastUpdated:{type:[{code:"instant"}]},source:{type:[{code:"uri"}]},profile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]},security:{max:9007199254740991,type:[{code:"Coding"}]},tag:{max:9007199254740991,type:[{code:"Coding"}]},project:{type:[{code:"uri"}]},author:{type:[{code:"Reference"}]},onBehalfOf:{type:[{code:"Reference"}]},account:{type:[{code:"Reference"}]},accounts:{max:9007199254740991,type:[{code:"Reference"}]},compartment:{max:9007199254740991,type:[{code:"Reference"}]}}},Money:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},currency:{type:[{code:"code"}]}}},Narrative:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},status:{min:1,type:[{code:"code"}]},div:{min:1,type:[{code:"xhtml"}]}}},ParameterDefinition:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},name:{type:[{code:"code"}]},use:{min:1,type:[{code:"code"}]},min:{type:[{code:"integer"}]},max:{type:[{code:"string"}]},documentation:{type:[{code:"string"}]},type:{min:1,type:[{code:"code"}]},profile:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]}}},Period:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},start:{type:[{code:"dateTime"}]},end:{type:[{code:"dateTime"}]}}},Population:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},"age[x]":{type:[{code:"Range"},{code:"CodeableConcept"}]},gender:{type:[{code:"CodeableConcept"}]},race:{type:[{code:"CodeableConcept"}]},physiologicalCondition:{type:[{code:"CodeableConcept"}]}}},ProdCharacteristic:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},height:{type:[{code:"Quantity"}]},width:{type:[{code:"Quantity"}]},depth:{type:[{code:"Quantity"}]},weight:{type:[{code:"Quantity"}]},nominalVolume:{type:[{code:"Quantity"}]},externalDiameter:{type:[{code:"Quantity"}]},shape:{type:[{code:"string"}]},color:{max:9007199254740991,type:[{code:"string"}]},imprint:{max:9007199254740991,type:[{code:"string"}]},image:{max:9007199254740991,type:[{code:"Attachment"}]},scoring:{type:[{code:"CodeableConcept"}]}}},ProductShelfLife:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},identifier:{type:[{code:"Identifier"}]},type:{min:1,type:[{code:"CodeableConcept"}]},period:{min:1,type:[{code:"Quantity"}]},specialPrecautionsForStorage:{max:9007199254740991,type:[{code:"CodeableConcept"}]}}},Quantity:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Range:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},low:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},high:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},Ratio:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},numerator:{type:[{code:"Quantity"}]},denominator:{type:[{code:"Quantity"}]}}},Reference:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},reference:{type:[{code:"string"}]},type:{type:[{code:"uri"}]},identifier:{type:[{code:"Identifier"}]},display:{type:[{code:"string"}]}}},RelatedArtifact:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},label:{type:[{code:"string"}]},display:{type:[{code:"string"}]},citation:{type:[{code:"markdown"}]},url:{type:[{code:"url"}]},document:{type:[{code:"Attachment"}]},resource:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/Resource"]}]}}},SampledData:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},origin:{min:1,type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},period:{min:1,type:[{code:"decimal"}]},factor:{type:[{code:"decimal"}]},lowerLimit:{type:[{code:"decimal"}]},upperLimit:{type:[{code:"decimal"}]},dimensions:{min:1,type:[{code:"positiveInt"}]},data:{type:[{code:"string"}]}}},Signature:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,max:9007199254740991,type:[{code:"Coding"}]},when:{min:1,type:[{code:"instant"}]},who:{min:1,type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/PractitionerRole","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/Device","http://hl7.org/fhir/StructureDefinition/Organization"]}]},onBehalfOf:{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/PractitionerRole","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/Device","http://hl7.org/fhir/StructureDefinition/Organization"]}]},targetFormat:{type:[{code:"code"}]},sigFormat:{type:[{code:"code"}]},data:{type:[{code:"base64Binary"}]}}},SubstanceAmount:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},"amount[x]":{type:[{code:"Quantity"},{code:"Range"},{code:"string"}]},amountType:{type:[{code:"CodeableConcept"}]},amountText:{type:[{code:"string"}]},referenceRange:{type:[{code:"SubstanceAmountReferenceRange"}]}}},SubstanceAmountReferenceRange:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},lowLimit:{type:[{code:"Quantity"}]},highLimit:{type:[{code:"Quantity"}]}}},Timing:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},event:{max:9007199254740991,type:[{code:"dateTime"}]},repeat:{type:[{code:"TimingRepeat"}]},code:{type:[{code:"CodeableConcept"}]}}},TimingRepeat:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},"bounds[x]":{type:[{code:"Duration"},{code:"Range"},{code:"Period"}]},count:{type:[{code:"positiveInt"}]},countMax:{type:[{code:"positiveInt"}]},duration:{type:[{code:"decimal"}]},durationMax:{type:[{code:"decimal"}]},durationUnit:{type:[{code:"code"}]},frequency:{type:[{code:"positiveInt"}]},frequencyMax:{type:[{code:"positiveInt"}]},period:{type:[{code:"decimal"}]},periodMax:{type:[{code:"decimal"}]},periodUnit:{type:[{code:"code"}]},dayOfWeek:{max:9007199254740991,type:[{code:"code"}]},timeOfDay:{max:9007199254740991,type:[{code:"time"}]},when:{max:9007199254740991,type:[{code:"code"}]},offset:{type:[{code:"unsignedInt"}]}}},TriggerDefinition:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},name:{type:[{code:"string"}]},"timing[x]":{type:[{code:"Timing"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Schedule"]},{code:"date"},{code:"dateTime"}]},data:{max:9007199254740991,type:[{code:"DataRequirement"}]},condition:{type:[{code:"Expression"}]}}},UsageContext:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},code:{min:1,type:[{code:"Coding"}]},"value[x]":{min:1,type:[{code:"CodeableConcept"},{code:"Quantity"},{code:"Range"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/PlanDefinition","http://hl7.org/fhir/StructureDefinition/ResearchStudy","http://hl7.org/fhir/StructureDefinition/InsurancePlan","http://hl7.org/fhir/StructureDefinition/HealthcareService","http://hl7.org/fhir/StructureDefinition/Group","http://hl7.org/fhir/StructureDefinition/Location","http://hl7.org/fhir/StructureDefinition/Organization"]}]}}},MoneyQuantity:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},SimpleQuantity:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{max:0,type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},IdentityProvider:{elements:{authorizeUrl:{min:1,type:[{code:"string"}]},tokenUrl:{min:1,type:[{code:"string"}]},tokenAuthMethod:{type:[{code:"code"}]},userInfoUrl:{min:1,type:[{code:"string"}]},clientId:{min:1,type:[{code:"string"}]},clientSecret:{min:1,type:[{code:"string"}]},usePkce:{type:[{code:"boolean"}]},useSubject:{type:[{code:"boolean"}]}}}};var nr=tr(ir);var wt=Object.create(null);function rr(t){let e;return e=wt[t],e||(e=wt[t]=Object.create(null)),e}function or(t,e){if(e){let i=rr(e)[t];if(i)return i}return nr[t]}var jt={base64Binary:/^([A-Za-z\d+/]{4})*([A-Za-z\d+/]{2}==|[A-Za-z\d+/]{3}=)?$/,canonical:/^\S*$/,code:/^[^\s]+( [^\s]+)*$/,date:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1]))?)?$/,dateTime:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1])(T([01]\d|2[0-3])(:[0-5]\d:([0-5]\d|60)(\.\d{1,9})?)?)?)?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00)?)?)?$/,id:/^[A-Za-z0-9\-.]{1,64}$/,instant:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])T([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00))$/,markdown:/^[\r\n\t\u0020-\uFFFF]+$/,oid:/^urn:oid:[0-2](\.(0|[1-9]\d*))+$/,string:/^[\r\n\t\u0020-\uFFFF]+$/,time:/^([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?$/,uri:/^\S*$/,url:/^\S*$/,uuid:/^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,xhtml:/.*/};function a(t){return[{type:u.boolean,value:t}]}function L(t){return t==null?{type:"undefined",value:void 0}:Number.isSafeInteger(t)?{type:u.integer,value:t}:typeof t=="number"?{type:u.decimal,value:t}:typeof t=="boolean"?{type:u.boolean,value:t}:typeof t=="string"?{type:u.string,value:t}:y(t)?{type:u.Quantity,value:t}:Q(t)?{type:t.resourceType,value:t}:Jt(t)?{type:u.CodeableConcept,value:t}:Xt(t)?{type:u.Coding,value:t}:{type:u.BackboneElement,value:t}}function x(t){return t.length===0?!1:!!t[0].value}function v(t,e){if(t.length!==0){if(t.length===1&&(!e||t[0].type===e))return t[0];throw new Error(`Expected singleton of type ${e}, but found ${JSON.stringify(t)}`)}}function sr(t,e,i){if(!t.value)return;let n=xr(t.type,e,i?.profileUrl);return n?ar(t,e,n):cr(t,e)}function ar(t,e,i){let n=t.value,r=i.type;if(!r||r.length===0)return;let o,s="undefined",c,d=i.path.lastIndexOf("."),N=i.path.substring(d+1);for(let E of r){let $=N.replace("[x]",W(E.code));if(o=n[$],c=n["_"+$],o!==void 0||c!==void 0){s=E.code;break}}if(c)if(Array.isArray(o)){o=o.slice();for(let E=0;E<Math.max(o.length,c.length);E++)o[E]=Ft(o[E],c[E])}else o=Ft(o,c);if(!j(o))return(s==="Element"||s==="BackboneElement")&&(s=i.type[0].code),Array.isArray(o)?o.map(E=>Mt(E,s)):Mt(o,s)}function Mt(t,e){return e==="Resource"&&Q(t)&&(e=t.resourceType),{type:e,value:t}}function cr(t,e){let i=t.value;if(!i||typeof i!="object")return;let n;if(e in i){let r=i[e];Array.isArray(r)?n=r.map(L):n=L(r)}else{let r=e.endsWith("[x]")?e.substring(0,e.length-3):e;for(let o of Object.values(u)){let s=r+W(o);if(s in i){let c=i[s];Array.isArray(c)?n=c.map(d=>({type:o,value:d})):n={type:o,value:c};break}}}if(Array.isArray(n)){if(n.length===0||j(n[0]))return}else if(j(n))return;return n}function qt(t){let e=[];for(let i of t){let n=!1;for(let r of e)if(x($e(i,r))){n=!0;break}n||e.push(i)}return e}function ur(t){return a(!x(t))}function lr(t,e){return t.length===0||e.length===0?[]:t.length!==e.length?a(!1):a(t.every((i,n)=>x($e(i,e[n]))))}function dr(t,e){return t.length===0||e.length===0?[]:t.length!==e.length?a(!0):a(t.some((i,n)=>!x($e(i,e[n]))))}function $e(t,e){let i=t.value?.valueOf(),n=e.value?.valueOf();return typeof i=="number"&&typeof n=="number"?a(Math.abs(i-n)<1e-8):y(i)&&y(n)?a(zt(i,n)):a(typeof i=="object"&&typeof n=="object"?He(t,e):i===n)}function Wt(t,e){return t.length===0&&e.length===0?a(!0):t.length!==e.length?a(!1):(t.sort(kt),e.sort(kt),a(t.every((i,n)=>x(pr(i,e[n])))))}function pr(t,e){let{type:i,value:n}=t,{type:r,value:o}=e,s=n?.valueOf(),c=o?.valueOf();return typeof s=="number"&&typeof c=="number"?a(Math.abs(s-c)<.01):y(s)&&y(c)?a(zt(s,c)):a(i==="Coding"&&r==="Coding"?typeof s!="object"||typeof c!="object"?!1:s.code===c.code&&s.system===c.system:typeof s=="object"&&typeof c=="object"?He({...s,id:void 0},{...c,id:void 0}):typeof s=="string"&&typeof c=="string"?s.toLowerCase()===c.toLowerCase():s===c)}function kt(t,e){let i=t.value?.valueOf(),n=e.value?.valueOf();return typeof i=="number"&&typeof n=="number"?i-n:typeof i=="string"&&typeof n=="string"?i.localeCompare(n):0}function Qt(t,e){let{value:i}=t;if(i==null)return!1;switch(e){case"Boolean":return typeof i=="boolean";case"Decimal":case"Integer":return typeof i=="number";case"Date":return hr(i);case"DateTime":return Fe(i);case"Time":return typeof i=="string"&&!!/^T\d/.exec(i);case"Period":return fr(i);case"Quantity":return y(i);default:return t.type===e||typeof i=="object"&&i?.resourceType===e}}function hr(t){return typeof t=="string"&&!!jt.date.exec(t)}function Fe(t){return typeof t=="string"&&!!jt.dateTime.exec(t)}function fr(t){return!!(t&&typeof t=="object"&&("start"in t&&Fe(t.start)||"end"in t&&Fe(t.end)))}function y(t){return!!(t&&typeof t=="object"&&"value"in t&&typeof t.value=="number")}function zt(t,e){return Math.abs(t.value-e.value)<.01&&(t.unit===e.unit||t.code===e.code||t.unit===e.code||t.code===e.unit)}function He(t,e){let i=Object.keys(t),n=Object.keys(e);if(i.length!==n.length)return!1;for(let r of i){let o=t[r],s=e[r];if(Bt(o)&&Bt(s)){if(!He(o,s))return!1}else if(o!==s)return!1}return!0}function Bt(t){return t!==null&&typeof t=="object"}function Ft(t,e){if(e){if(typeof e!="object")throw new Error("Primitive extension must be an object");return _r(t??{},e)}return t}function _r(t,e){return delete e.__proto__,delete e.constructor,Object.assign(t,e)}function mr(t,e){return Q(t,e)&&"id"in t&&typeof t.id=="string"}function h(t){let e=Zt(t)??"undefined/undefined",i=Tr(t);return i===e?{reference:e}:{reference:e,display:i}}function Zt(t){if(Kt(t))return t.reference;if(mr(t))return`${t.resourceType}/${t.id}`}function Er(t){if(t)return Kt(t)?t.reference.split("/")[1]:t.id}function Ir(t){return t.resourceType==="Patient"||t.resourceType==="Practitioner"||t.resourceType==="RelatedPerson"}function Tr(t){if(Ir(t)){let e=Or(t);if(e)return e}if(t.resourceType==="Device"){let e=Sr(t);if(e)return e}if(t.resourceType==="MedicationRequest"&&t.medicationCodeableConcept)return Gt(t.medicationCodeableConcept);if(t.resourceType==="Subscription"&&t.criteria)return t.criteria;if(t.resourceType==="User"&&t.email)return t.email;if("name"in t&&t.name&&typeof t.name=="string")return t.name;if("code"in t&&t.code){let e=t.code;if(Array.isArray(e)&&(e=e[0]),Jt(e))return Gt(e);if(Ar(e))return e.text}return Zt(t)??""}function Or(t){let e=t.name;if(e&&e.length>0)return Nr(e[0])}function Sr(t){let e=t.deviceName;if(e&&e.length>0)return e[0].name}function yr(t,e){let i=new Date(t);i.setUTCHours(0,0,0,0);let n=e?new Date(e):new Date;n.setUTCHours(0,0,0,0);let r=i.getUTCFullYear(),o=i.getUTCMonth(),s=i.getUTCDate(),c=n.getUTCFullYear(),d=n.getUTCMonth(),N=n.getUTCDate(),E=c-r;(d<o||d===o&&N<s)&&E--;let $=c*12+d-(r*12+o);N<s&&$--;let $n=Math.floor((n.getTime()-i.getTime())/(1e3*60*60*24));return{years:E,months:$,days:$n}}function Cr(t,...e){let i=t;for(let n=0;n<e.length&&i;n++)i=i?.extension?.find(r=>r.url===e[n]);return i}function j(t){if(t==null)return!0;let e=typeof t;return e==="string"||e==="object"?!gr(t):!1}function gr(t){if(t==null)return!1;let e=typeof t;return e==="string"&&t!==""||e==="object"&&("length"in t&&t.length>0||Object.keys(t).length>0)}function je(t){return!!/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i.exec(t)}function qe(t){return t!==null&&typeof t=="object"}function Xt(t){return qe(t)&&"code"in t&&typeof t.code=="string"}function Jt(t){return qe(t)&&"coding"in t&&Array.isArray(t.coding)&&t.coding.every(Xt)}function Ar(t){return qe(t)&&"text"in t&&typeof t.text=="string"}var Rr=[];for(let t=0;t<256;t++)Rr.push(t.toString(16).padStart(2,"0"));function W(t){return t?t.charAt(0).toUpperCase()+t.substring(1):""}function Nr(t,e){let i=[];if(t.prefix&&e?.prefix!==!1&&i.push(...t.prefix),t.given&&i.push(...t.given),t.family&&i.push(t.family),t.suffix&&e?.suffix!==!1&&i.push(...t.suffix),t.use&&(e?.all||e?.use)&&i.push("["+t.use+"]"),i.length===0){let n=H(t.text);if(n)return n}return i.join(" ").trim()}function Gt(t){return t?H(t.text)||(t.coding?t.coding.map(i=>Dr(i)).join(", "):""):""}function Dr(t,e){let i=H(t?.display);if(i){let n=e?H(t?.code):void 0;return`${i}${n?" ("+n+")":""}`}return H(t?.code)??""}function H(t){return typeof t=="string"?t:void 0}var u={Address:"Address",Age:"Age",Annotation:"Annotation",Attachment:"Attachment",BackboneElement:"BackboneElement",CodeableConcept:"CodeableConcept",Coding:"Coding",ContactDetail:"ContactDetail",ContactPoint:"ContactPoint",Contributor:"Contributor",Count:"Count",DataRequirement:"DataRequirement",Distance:"Distance",Dosage:"Dosage",Duration:"Duration",Expression:"Expression",Extension:"Extension",HumanName:"HumanName",Identifier:"Identifier",MarketingStatus:"MarketingStatus",Meta:"Meta",Money:"Money",Narrative:"Narrative",ParameterDefinition:"ParameterDefinition",Period:"Period",Population:"Population",ProdCharacteristic:"ProdCharacteristic",ProductShelfLife:"ProductShelfLife",Quantity:"Quantity",Range:"Range",Ratio:"Ratio",Reference:"Reference",RelatedArtifact:"RelatedArtifact",SampledData:"SampledData",Signature:"Signature",SubstanceAmount:"SubstanceAmount",SystemString:"http://hl7.org/fhirpath/System.String",Timing:"Timing",TriggerDefinition:"TriggerDefinition",UsageContext:"UsageContext",base64Binary:"base64Binary",boolean:"boolean",canonical:"canonical",code:"code",date:"date",dateTime:"dateTime",decimal:"decimal",id:"id",instant:"instant",integer:"integer",markdown:"markdown",oid:"oid",positiveInt:"positiveInt",string:"string",time:"time",unsignedInt:"unsignedInt",uri:"uri",url:"url",uuid:"uuid"};function xr(t,e,i){let n=or(t,i);if(n)return vr(n.elements,e)}function vr(t,e){let i=t[e]??t[e+"[x]"];if(i)return i;for(let n=0;n<e.length;n++){let r=e[n];if(r>="A"&&r<="Z"){let o=e.slice(0,n)+"[x]",s=t[o];if(s)return s}}}function Q(t,e){return!(!t||typeof t!="object"||!("resourceType"in t)||e&&t.resourceType!==e)}function Kt(t){return!!(t&&typeof t=="object"&&"reference"in t&&typeof t.reference=="string")}function Te(t){if(t.startsWith("T"))return t+"T00:00:00.000Z".substring(t.length);if(t.length<=10)return t;try{return new Date(t).toISOString()}catch{return t}}var D=()=>[],T={empty:(t,e)=>a(e.length===0||e.every(i=>j(i.value))),hasValue:(t,e)=>a(e.length!==0),exists:(t,e,i)=>a(i?e.filter(n=>x(i.eval(t,[n]))).length>0:e.length>0&&e.every(n=>!j(n.value))),all:(t,e,i)=>a(e.every(n=>x(i.eval(t,[n])))),allTrue:(t,e)=>{for(let i of e)if(!i.value)return a(!1);return a(!0)},anyTrue:(t,e)=>{for(let i of e)if(i.value)return a(!0);return a(!1)},allFalse:(t,e)=>{for(let i of e)if(i.value)return a(!1);return a(!0)},anyFalse:(t,e)=>{for(let i of e)if(!i.value)return a(!0);return a(!1)},subsetOf:(t,e,i)=>{if(e.length===0)return a(!0);let n=i.eval(t,U(t));return n.length===0?a(!1):a(e.every(r=>n.some(o=>o.value===r.value)))},supersetOf:(t,e,i)=>{let n=i.eval(t,U(t));return n.length===0?a(!0):e.length===0?a(!1):a(n.every(r=>e.some(o=>o.value===r.value)))},count:(t,e)=>[{type:u.integer,value:e.length}],distinct:(t,e)=>{let i=[];for(let n of e)i.some(r=>r.value===n.value)||i.push(n);return i},isDistinct:(t,e)=>a(e.length===T.distinct(t,e).length),where:(t,e,i)=>e.filter(n=>x(i.eval(t,[n]))),select:(t,e,i)=>e.map(n=>i.eval({parent:t,variables:{$this:n}},[n])).flat(),repeat:D,ofType:(t,e,i)=>e.filter(n=>n.type===i.name),single:(t,e)=>{if(e.length>1)throw new Error("Expected input length one for single()");return e.length===0?[]:e.slice(0,1)},first:(t,e)=>e.length===0?[]:e.slice(0,1),last:(t,e)=>e.length===0?[]:e.slice(e.length-1,e.length),tail:(t,e)=>e.length===0?[]:e.slice(1,e.length),skip:(t,e,i)=>{let n=i.eval(t,e)[0]?.value;if(typeof n!="number")throw new Error("Expected a number for skip(num)");return n>=e.length?[]:n<=0?e:e.slice(n,e.length)},take:(t,e,i)=>{let n=i.eval(t,e)[0]?.value;if(typeof n!="number")throw new Error("Expected a number for take(num)");return n>=e.length?e:n<=0?[]:e.slice(0,n)},intersect:(t,e,i)=>{if(!i)return e;let n=i.eval(t,U(t)),r=[];for(let o of e)!r.some(s=>s.value===o.value)&&n.some(s=>s.value===o.value)&&r.push(o);return r},exclude:(t,e,i)=>{if(!i)return e;let n=i.eval(t,U(t)),r=[];for(let o of e)n.some(s=>s.value===o.value)||r.push(o);return r},union:(t,e,i)=>{if(!i)return e;let n=i.eval(t,U(t));return qt([...e,...n])},combine:(t,e,i)=>{if(!i)return e;let n=i.eval(t,U(t));return[...e,...n]},htmlChecks:(t,e,i)=>[L(!0)],iif:(t,e,i,n,r)=>{let o=i.eval(t,e);if(o.length>1||o.length===1&&typeof o[0].value!="boolean")throw new Error("Expected criterion to evaluate to a Boolean");return x(o)?n.eval(t,e):r?r.eval(t,e):[]},toBoolean:(t,e)=>{if(e.length===0)return[];let[{value:i}]=R(e,1);if(typeof i=="boolean")return[{type:u.boolean,value:i}];if(typeof i=="number"&&(i===0||i===1))return a(!!i);if(typeof i=="string"){let n=i.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(n))return a(!0);if(["false","f","no","n","0","0.0"].includes(n))return a(!1)}return[]},convertsToBoolean:(t,e)=>e.length===0?[]:a(T.toBoolean(t,e).length===1),toInteger:(t,e)=>{if(e.length===0)return[];let[{value:i}]=R(e,1);return typeof i=="number"?[{type:u.integer,value:i}]:typeof i=="string"&&/^[+-]?\d+$/.exec(i)?[{type:u.integer,value:parseInt(i,10)}]:typeof i=="boolean"?[{type:u.integer,value:i?1:0}]:[]},convertsToInteger:(t,e)=>e.length===0?[]:a(T.toInteger(t,e).length===1),toDate:(t,e)=>{if(e.length===0)return[];let[{value:i}]=R(e,1);return typeof i=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(i)?[{type:u.date,value:Te(i)}]:[]},convertsToDate:(t,e)=>e.length===0?[]:a(T.toDate(t,e).length===1),toDateTime:(t,e)=>{if(e.length===0)return[];let[{value:i}]=R(e,1);return typeof i=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(i)?[{type:u.dateTime,value:Te(i)}]:[]},convertsToDateTime:(t,e)=>e.length===0?[]:a(T.toDateTime(t,e).length===1),toDecimal:(t,e)=>{if(e.length===0)return[];let[{value:i}]=R(e,1);return typeof i=="number"?[{type:u.decimal,value:i}]:typeof i=="string"&&/^-?\d{1,9}(\.\d{1,9})?$/.exec(i)?[{type:u.decimal,value:parseFloat(i)}]:typeof i=="boolean"?[{type:u.decimal,value:i?1:0}]:[]},convertsToDecimal:(t,e)=>e.length===0?[]:a(T.toDecimal(t,e).length===1),toQuantity:(t,e)=>{if(e.length===0)return[];let[{value:i}]=R(e,1);return y(i)?[{type:u.Quantity,value:i}]:typeof i=="number"?[{type:u.Quantity,value:{value:i,unit:"1"}}]:typeof i=="string"&&/^-?\d{1,9}(\.\d{1,9})?/.exec(i)?[{type:u.Quantity,value:{value:parseFloat(i),unit:"1"}}]:typeof i=="boolean"?[{type:u.Quantity,value:{value:i?1:0,unit:"1"}}]:[]},convertsToQuantity:(t,e)=>e.length===0?[]:a(T.toQuantity(t,e).length===1),toString:(t,e)=>{if(e.length===0)return[];let[{value:i}]=R(e,1);return i==null?[]:y(i)?[{type:u.string,value:`${i.value} '${i.unit}'`}]:[{type:u.string,value:i.toString()}]},convertsToString:(t,e)=>e.length===0?[]:a(T.toString(t,e).length===1),toTime:(t,e)=>{if(e.length===0)return[];let[{value:i}]=R(e,1);if(typeof i=="string"){let n=/^T?(\d{2}(:\d{2}(:\d{2})?)?)/.exec(i);if(n)return[{type:u.time,value:Te("T"+n[1])}]}return[]},convertsToTime:(t,e)=>e.length===0?[]:a(T.toTime(t,e).length===1),indexOf:(t,e,i)=>S((n,r)=>n.indexOf(r),t,e,i),substring:(t,e,i,n)=>S((r,o,s)=>{let c=o,d=s?c+s:r.length;return c<0||c>=r.length?void 0:r.substring(c,d)},t,e,i,n),startsWith:(t,e,i)=>S((n,r)=>n.startsWith(r),t,e,i),endsWith:(t,e,i)=>S((n,r)=>n.endsWith(r),t,e,i),contains:(t,e,i)=>S((n,r)=>n.includes(r),t,e,i),upper:(t,e)=>S(i=>i.toUpperCase(),t,e),lower:(t,e)=>S(i=>i.toLowerCase(),t,e),replace:(t,e,i,n)=>S((r,o,s)=>r.replaceAll(o,s),t,e,i,n),matches:(t,e,i)=>S((n,r)=>!!new RegExp(r).exec(n),t,e,i),replaceMatches:(t,e,i,n)=>S((r,o,s)=>r.replaceAll(o,s),t,e,i,n),length:(t,e)=>S(i=>i.length,t,e),toChars:(t,e)=>S(i=>i?i.split(""):void 0,t,e),encode:D,decode:D,escape:D,unescape:D,trim:D,split:D,join:(t,e,i)=>{let n=i?.eval(t,U(t))[0]?.value??"";if(typeof n!="string")throw new Error("Separator must be a string.");return[{type:u.string,value:e.map(r=>r.value?.toString()??"").join(n)}]},abs:(t,e)=>A(Math.abs,t,e),ceiling:(t,e)=>A(Math.ceil,t,e),exp:(t,e)=>A(Math.exp,t,e),floor:(t,e)=>A(Math.floor,t,e),ln:(t,e)=>A(Math.log,t,e),log:(t,e,i)=>A((n,r)=>Math.log(n)/Math.log(r),t,e,i),power:(t,e,i)=>A(Math.pow,t,e,i),round:(t,e)=>A(Math.round,t,e),sqrt:(t,e)=>A(Math.sqrt,t,e),truncate:(t,e)=>A(i=>i|0,t,e),children:D,descendants:D,trace:(t,e,i)=>e,now:()=>[{type:u.dateTime,value:new Date().toISOString()}],timeOfDay:()=>[{type:u.time,value:new Date().toISOString().substring(11)}],today:()=>[{type:u.date,value:new Date().toISOString().substring(0,10)}],between:(t,e,i,n,r)=>{let o=T.toDateTime(t,i.eval(t,e));if(o.length===0)throw new Error("Invalid start date");let s=T.toDateTime(t,n.eval(t,e));if(s.length===0)throw new Error("Invalid end date");let c=r.eval(t,e)[0]?.value;if(c!=="years"&&c!=="months"&&c!=="days")throw new Error("Invalid units");let d=yr(o[0].value,s[0].value);return[{type:u.Quantity,value:{value:d[c],unit:c}}]},is:(t,e,i)=>{let n="";return i instanceof Se?n=i.name:i instanceof ei&&(n=i.left.name+"."+i.right.name),n?e.map(r=>({type:u.boolean,value:Qt(r,n)})):[]},not:(t,e)=>T.toBoolean(t,e).map(i=>({type:u.boolean,value:!i.value})),resolve:(t,e)=>e.map(i=>{let n=i.value,r;if(typeof n=="string")r=n;else if(typeof n=="object"){let o=n;if(o.resource)return L(o.resource);o.reference?r=o.reference:o.type&&o.identifier&&(r=`${o.type}?identifier=${o.identifier.system}|${o.identifier.value}`)}if(r?.includes("?")){let[o]=r.split("?");return{type:o,value:{resourceType:o}}}if(r?.includes("/")){let[o,s]=r.split("/");return{type:o,value:{resourceType:o,id:s}}}return{type:u.BackboneElement,value:void 0}}).filter(i=>!!i.value),as:(t,e)=>e,type:(t,e)=>e.map(({value:i})=>typeof i=="boolean"?{type:u.BackboneElement,value:{namespace:"System",name:"Boolean"}}:typeof i=="number"?{type:u.BackboneElement,value:{namespace:"System",name:"Integer"}}:Q(i)?{type:u.BackboneElement,value:{namespace:"FHIR",name:i.resourceType}}:{type:u.BackboneElement,value:null}),conformsTo:(t,e,i)=>{let n=i.eval(t,e)[0].value;if(!n.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");let r=n.replace("http://hl7.org/fhir/StructureDefinition/","");return e.map(o=>({type:u.boolean,value:o.value?.resourceType===r}))},getResourceKey:(t,e)=>{let i=e[0].value;return i?.id?[{type:u.id,value:i.id}]:[]},getReferenceKey:(t,e,i)=>{let n=e[0].value;if(!n?.reference)return[];let r="";return i instanceof Se&&(r=i.name),r&&!n.reference.startsWith(r+"/")?[]:[{type:u.id,value:Er(n)}]},extension:(t,e,i)=>{let n=i.eval(t,e)[0].value,r=e?.[0]?.value;if(r){let o=Cr(r,n);if(o)return[{type:u.Extension,value:o}]}return[]}};function S(t,e,i,...n){if(i.length===0)return[];let[{value:r}]=R(i,1);if(typeof r!="string")throw new Error("String function cannot be called with non-string");let o=t(r,...n.map(s=>s?.eval(e,i)[0]?.value));return o===void 0?[]:Array.isArray(o)?o.map(L):[L(o)]}function A(t,e,i,...n){if(i.length===0)return[];let[{value:r}]=R(i,1),o=y(r),s=o?r.value:r;if(typeof s!="number")throw new Error("Math function cannot be called with non-number");let c=t(s,...n.map(E=>E.eval(e,i)[0]?.value)),d=o?u.Quantity:i[0].type,N=o?{...r,value:c}:c;return[{type:d,value:N}]}function R(t,e){if(t.length!==e)throw new Error(`Expected ${e} arguments`);for(let i of t)if(i==null)throw new Error("Expected non-null argument");return t}function U(t){let e=t;for(;e.parent?.variables.$this;)e=e.parent;return[e.variables.$this]}var w=class{constructor(t){this.value=t}eval(){return[this.value]}toString(){let t=this.value.value;return typeof t=="string"?`'${t}'`:t.toString()}},Se=class{constructor(t){this.name=t}eval(t,e){if(this.name==="$this")return e;let i=this.getVariable(t);if(i)return[i];if(this.name.startsWith("%"))throw new Error(`Undefined variable ${this.name}`);return e.flatMap(n=>this.evalValue(n)).filter(n=>n?.value!==void 0)}getVariable(t){let e=t.variables[this.name];if(e!==void 0)return e;if(t.parent)return this.getVariable(t.parent)}evalValue(t){let e=t.value;if(!(!e||typeof e!="object"))return Q(e,this.name)?t:sr(t,this.name)}toString(){return this.name}},Pr=class{eval(){return[]}toString(){return"{}"}},br=class extends Zn{constructor(t,e,i){super(t,e),this.impl=i}eval(t,e){return this.impl(this.child.eval(t,e))}toString(){return this.operator+this.child.toString()}},Ur=class extends q{constructor(t,e){super("as",t,e)}eval(t,e){return T.ofType(t,this.left.eval(t,e),this.right)}},C=class extends q{},g=class extends C{constructor(t,e,i,n){super(t,e,i),this.impl=n}eval(t,e){let i=this.left.eval(t,e);if(i.length!==1)return[];let n=this.right.eval(t,e);if(n.length!==1)return[];let r=i[0].value,o=n[0].value,s=y(r)?r.value:r,c=y(o)?o.value:o,d=this.impl(s,c);return typeof d=="boolean"?a(d):y(r)?[{type:u.Quantity,value:{...r,value:d}}]:[L(d)]}},Lr=class extends q{constructor(t,e){super("&",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e),r=[...i,...n];return r.length>0&&r.every(o=>typeof o.value=="string")?[{type:u.string,value:r.map(o=>o.value).join("")}]:r}},Vr=class extends C{constructor(t,e){super("contains",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return a(i.some(r=>r.value===n[0].value))}},wr=class extends C{constructor(t,e){super("in",t,e)}eval(t,e){let i=v(this.left.eval(t,e)),n=this.right.eval(t,e);return i?a(n.some(r=>r.value===i.value)):[]}},ei=class extends q{constructor(t,e){super(".",t,e)}eval(t,e){return this.right.eval(t,this.left.eval(t,e))}toString(){return`${this.left.toString()}.${this.right.toString()}`}},Mr=class extends q{constructor(t,e){super("|",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return qt([...i,...n])}},kr=class extends C{constructor(t,e){super("=",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return lr(i,n)}},Br=class extends C{constructor(t,e){super("!=",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return dr(i,n)}},Fr=class extends C{constructor(t,e){super("~",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return Wt(i,n)}},Gr=class extends C{constructor(t,e){super("!~",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return ur(Wt(i,n))}},Yr=class extends C{constructor(t,e){super("is",t,e)}eval(t,e){let i=this.left.eval(t,e);if(i.length!==1)return[];let n=this.right.name;return a(Qt(i[0],n))}},$r=class extends C{constructor(t,e){super("and",t,e)}eval(t,e){let i=v(this.left.eval(t,e),"boolean"),n=v(this.right.eval(t,e),"boolean");return i?.value===!0&&n?.value===!0?a(!0):i?.value===!1||n?.value===!1?a(!1):[]}},Hr=class extends C{constructor(t,e){super("or",t,e)}eval(t,e){let i=v(this.left.eval(t,e),"boolean"),n=v(this.right.eval(t,e),"boolean");return i?.value===!1&&n?.value===!1?a(!1):i?.value||n?.value?a(!0):[]}},jr=class extends C{constructor(t,e){super("xor",t,e)}eval(t,e){let i=v(this.left.eval(t,e),"boolean"),n=v(this.right.eval(t,e),"boolean");return!i||!n?[]:a(i.value!==n.value)}},qr=class extends C{constructor(t,e){super("implies",t,e)}eval(t,e){let i=v(this.left.eval(t,e),"boolean"),n=v(this.right.eval(t,e),"boolean");return n?.value===!0||i?.value===!1?a(!0):!i||!n?[]:a(!1)}},Wr=class{constructor(t,e){this.name=t,this.args=e}eval(t,e){let i=T[this.name];if(!i)throw new Error("Unrecognized function: "+this.name);return i(t,e,...this.args)}toString(){return`${this.name}(${this.args.map(t=>t.toString()).join(", ")})`}},Qr=class{constructor(t,e){this.left=t,this.expr=e}eval(t,e){let i=this.expr.eval(t,e);if(i.length!==1)return[];let n=i[0].value;if(typeof n!="number")throw new Error("Invalid indexer expression: should return integer}");let r=this.left.eval(t,e);return n in r?[r[n]]:[]}toString(){return`${this.left.toString()}[${this.expr.toString()}]`}};var ti=["!=","!~","<=",">=","{}","->"];var l={FunctionCall:0,Dot:1,Indexer:2,UnaryAdd:3,UnarySubtract:3,Multiply:4,Divide:4,IntegerDivide:4,Modulo:4,Add:5,Subtract:5,Ampersand:5,Is:6,As:6,Union:7,GreaterThan:8,GreaterThanOrEquals:8,LessThan:8,LessThanOrEquals:8,Equals:9,Equivalent:9,NotEquals:9,NotEquivalent:9,In:10,Contains:10,And:11,Xor:12,Or:12,Implies:13,Arrow:100,Semicolon:200},zr={parse(t){let e=t.consumeAndParse();if(!t.match(")"))throw new Error("Parse error: expected `)` got `"+t.peek()?.value+"`");return e}},Zr={parse(t,e){let i=t.consumeAndParse();if(!t.match("]"))throw new Error("Parse error: expected `]`");return new Qr(e,i)},precedence:l.Indexer},Xr={parse(t,e){if(!(e instanceof Se))throw new Error("Unexpected parentheses");let i=[];for(;!t.match(")");)i.push(t.consumeAndParse()),t.match(",");return new Wr(e.name,i)},precedence:l.FunctionCall};function Jr(t){let e=t.split(" "),i=parseFloat(e[0]),n=e[1];return n?.startsWith("'")&&n.endsWith("'")?n=n.substring(1,n.length-1):n="{"+n+"}",{value:i,unit:n}}function We(){return new Xn().registerPrefix("String",{parse:(t,e)=>new w({type:u.string,value:e.value})}).registerPrefix("DateTime",{parse:(t,e)=>new w({type:u.dateTime,value:Te(e.value)})}).registerPrefix("Quantity",{parse:(t,e)=>new w({type:u.Quantity,value:Jr(e.value)})}).registerPrefix("Number",{parse:(t,e)=>new w({type:e.value.includes(".")?u.decimal:u.integer,value:parseFloat(e.value)})}).registerPrefix("true",{parse:()=>new w({type:u.boolean,value:!0})}).registerPrefix("false",{parse:()=>new w({type:u.boolean,value:!1})}).registerPrefix("Symbol",{parse:(t,e)=>new Se(e.value)}).registerPrefix("{}",{parse:()=>new Pr}).registerPrefix("(",zr).registerInfix("[",Zr).registerInfix("(",Xr).prefix("+",l.UnaryAdd,(t,e)=>new br("+",e,i=>i)).prefix("-",l.UnarySubtract,(t,e)=>new g("-",e,e,(i,n)=>-n)).infixLeft(".",l.Dot,(t,e,i)=>new ei(t,i)).infixLeft("/",l.Divide,(t,e,i)=>new g("/",t,i,(n,r)=>n/r)).infixLeft("*",l.Multiply,(t,e,i)=>new g("*",t,i,(n,r)=>n*r)).infixLeft("+",l.Add,(t,e,i)=>new g("+",t,i,(n,r)=>n+r)).infixLeft("-",l.Subtract,(t,e,i)=>new g("-",t,i,(n,r)=>n-r)).infixLeft("|",l.Union,(t,e,i)=>new Mr(t,i)).infixLeft("=",l.Equals,(t,e,i)=>new kr(t,i)).infixLeft("!=",l.NotEquals,(t,e,i)=>new Br(t,i)).infixLeft("~",l.Equivalent,(t,e,i)=>new Fr(t,i)).infixLeft("!~",l.NotEquivalent,(t,e,i)=>new Gr(t,i)).infixLeft("<",l.LessThan,(t,e,i)=>new g("<",t,i,(n,r)=>n<r)).infixLeft("<=",l.LessThanOrEquals,(t,e,i)=>new g("<=",t,i,(n,r)=>n<=r)).infixLeft(">",l.GreaterThan,(t,e,i)=>new g(">",t,i,(n,r)=>n>r)).infixLeft(">=",l.GreaterThanOrEquals,(t,e,i)=>new g(">=",t,i,(n,r)=>n>=r)).infixLeft("&",l.Ampersand,(t,e,i)=>new Lr(t,i)).infixLeft("and",l.And,(t,e,i)=>new $r(t,i)).infixLeft("as",l.As,(t,e,i)=>new Ur(t,i)).infixLeft("contains",l.Contains,(t,e,i)=>new Vr(t,i)).infixLeft("div",l.Divide,(t,e,i)=>new g("div",t,i,(n,r)=>n/r|0)).infixLeft("in",l.In,(t,e,i)=>new wr(t,i)).infixLeft("is",l.Is,(t,e,i)=>new Yr(t,i)).infixLeft("mod",l.Modulo,(t,e,i)=>new g("mod",t,i,(n,r)=>n%r)).infixLeft("or",l.Or,(t,e,i)=>new Hr(t,i)).infixLeft("xor",l.Xor,(t,e,i)=>new jr(t,i)).infixLeft("implies",l.Implies,(t,e,i)=>new qr(t,i))}var xo=We();var Kr=(t=>(t.BOOLEAN="BOOLEAN",t.NUMBER="NUMBER",t.QUANTITY="QUANTITY",t.TEXT="TEXT",t.REFERENCE="REFERENCE",t.CANONICAL="CANONICAL",t.DATE="DATE",t.DATETIME="DATETIME",t.PERIOD="PERIOD",t.UUID="UUID",t))(Kr||{});var eo=(t=>(t.EQUALS="eq",t.NOT_EQUALS="ne",t.GREATER_THAN="gt",t.LESS_THAN="lt",t.GREATER_THAN_OR_EQUALS="ge",t.LESS_THAN_OR_EQUALS="le",t.STARTS_AFTER="sa",t.ENDS_BEFORE="eb",t.APPROXIMATELY="ap",t.CONTAINS="contains",t.STARTS_WITH="sw",t.EXACT="exact",t.TEXT="text",t.NOT="not",t.ABOVE="above",t.BELOW="below",t.IN="in",t.NOT_IN="not-in",t.OF_TYPE="of-type",t.MISSING="missing",t.PRESENT="present",t.IDENTIFIER="identifier",t.ITERATE="iterate",t))(eo||{});var to=(t=>(t.READ="read",t.VREAD="vread",t.UPDATE="update",t.PATCH="patch",t.DELETE="delete",t.HISTORY="history",t.HISTORY_INSTANCE="history-instance",t.HISTORY_TYPE="history-type",t.HISTORY_SYSTEM="history-system",t.CREATE="create",t.SEARCH="search",t.SEARCH_TYPE="search-type",t.SEARCH_SYSTEM="search-system",t.SEARCH_COMPARTMENT="search-compartment",t.CAPABILITIES="capabilities",t.TRANSACTION="transaction",t.BATCH="batch",t.OPERATION="operation",t))(to||{});function Ce(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}var io={CSS:"text/css",DICOM:"application/dicom",FAVICON:"image/vnd.microsoft.icon",FHIR_JSON:"application/fhir+json",FORM_URL_ENCODED:"application/x-www-form-urlencoded",HL7_V2:"x-application/hl7-v2+er7",HTML:"text/html",JAVASCRIPT:"text/javascript",JSON:"application/json",JSON_PATCH:"application/json-patch+json",PNG:"image/png",SCIM_JSON:"application/scim+json",SVG:"image/svg+xml",TEXT:"text/plain",TYPESCRIPT:"text/typescript",PING:"x-application/ping",XML:"text/xml",CDA_XML:"application/cda+xml"};var no;no=Symbol.toStringTag;var vo={Event:typeof globalThis.Event<"u"?globalThis.Event:void 0,ErrorEvent:void 0,CloseEvent:void 0};var Po={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0,startClosed:!1,debug:!1};var bo=io.FHIR_JSON+", */*; q=0.1";var ro=(t=>(t.ClientCredentials="client_credentials",t.AuthorizationCode="authorization_code",t.RefreshToken="refresh_token",t.JwtBearer="urn:ietf:params:oauth:grant-type:jwt-bearer",t.TokenExchange="urn:ietf:params:oauth:grant-type:token-exchange",t))(ro||{}),oo=(t=>(t.AccessToken="urn:ietf:params:oauth:token-type:access_token",t.RefreshToken="urn:ietf:params:oauth:token-type:refresh_token",t.IdToken="urn:ietf:params:oauth:token-type:id_token",t.Saml1Token="urn:ietf:params:oauth:token-type:saml1",t.Saml2Token="urn:ietf:params:oauth:token-type:saml2",t))(oo||{}),so=(t=>(t.ClientSecretBasic="client_secret_basic",t.ClientSecretPost="client_secret_post",t.ClientSecretJwt="client_secret_jwt",t.PrivateKeyJwt="private_key_jwt",t.None="none",t))(so||{}),ao=(t=>(t.JwtBearer="urn:ietf:params:oauth:client-assertion-type:jwt-bearer",t))(ao||{});var Uo=[...ti,"->","<<",">>","=="];var Lo=We().registerInfix("->",{precedence:l.Arrow}).registerInfix(";",{precedence:l.Semicolon});var Vo=" ".repeat(2);var wo=[...ti,"eq","ne","co"];var Mo=We();var co=(t=>(t[t.NONE=0]="NONE",t[t.ERROR=1]="ERROR",t[t.WARN=2]="WARN",t[t.INFO=3]="INFO",t[t.DEBUG=4]="DEBUG",t))(co||{});function ge(t){if(!t)return;let e=t.substring(0,4),i="01",n="01";return t.length>=8&&(i=t.substring(4,6),n=t.substring(6,8)),`${e}-${i}-${n}`}function f(t){if(!t)return;let e=t.substring(0,4),i="01",n="01",r="00",o="00",s="00",c="Z";return t.length>=8&&(i=t.substring(4,6),n=t.substring(6,8)),t.length>=12&&(r=t.substring(8,10),o=t.substring(10,12)),t.length>=14&&(s=t.substring(12,14)),t.length>14&&(c=t.substring(14),c==="+0000"&&(c="Z")),`${e}-${i}-${n}T${r}:${o}:${s}${c}`}function V(t){if(t)return t.substring(0,10).replace(/-/g,"")}function O(t){if(!t)return;let[e,i]=t.split("T"),n=e.replaceAll("-",""),r=(i??"").replaceAll(/\.\d+/g,"").replaceAll(/:/g,"").replaceAll(/Z/g,"+0000");return`${n}${r}`}var Ae="1.3.6.1.4.1.19376.1.5.3.1.3.1";var ii="2.16.840.1.113883.1.3";var ni="2.16.840.1.113883.2.20.5.1",ri="2.16.840.1.113883.3.26.1.1";var oi="2.16.840.1.113883.4.1",si="2.16.840.1.113883.4.3",ai="2.16.840.1.113883.4.6",ci="2.16.840.1.113883.4.9",ui="2.16.840.1.113883.5.1",Re="2.16.840.1.113883.5.4",Qe="2.16.840.1.113883.5.6",ze="2.16.840.1.113883.5.25",M="2.16.840.1.113883.6.1",li="2.16.840.1.113883.6.12",di="2.16.840.1.113883.6.24",pi="2.16.840.1.113883.6.69",hi="2.16.840.1.113883.6.88",k="2.16.840.1.113883.6.96",fi="2.16.840.1.113883.6.101",_i="2.16.840.1.113883.6.209",Ze="2.16.840.1.113883.6.238",mi="2.16.840.1.113883.6.345";var Ei="2.16.840.1.113883.10.20.15.3.8";var Xe="2.16.840.1.113883.10.20.22.1.1";var Je="2.16.840.1.113883.10.20.22.1.2";var Ne="2.16.840.1.113883.10.20.22.2.1.1";var z="2.16.840.1.113883.10.20.22.2.2",Z="2.16.840.1.113883.10.20.22.2.2.1";var Ke="2.16.840.1.113883.10.20.22.2.3.1";var Ii="2.16.840.1.113883.10.20.22.2.4.1";var De="2.16.840.1.113883.10.20.22.2.5.1";var xe="2.16.840.1.113883.10.20.22.2.6.1";var B="2.16.840.1.113883.10.20.22.2.7.1";var Ti="2.16.840.1.113883.10.20.22.2.8";var P="2.16.840.1.113883.10.20.22.2.10";var et="2.16.840.1.113883.10.20.22.2.17";var ve="2.16.840.1.113883.10.20.22.2.18";var Oi="2.16.840.1.113883.10.20.22.2.22.1";var Si="2.16.840.1.113883.10.20.22.2.23";var yi="2.16.840.1.113883.10.20.22.2.56";var Pe="2.16.840.1.113883.10.20.22.2.58";var X="2.16.840.1.113883.10.20.22.2.60";var be="2.16.840.1.113883.10.20.22.2.65";var Ue="2.16.840.1.113883.10.20.22.2.500",Ci="2.16.840.1.113883.10.20.22.4.1",gi="2.16.840.1.113883.10.20.22.4.1.2",Ai="2.16.840.1.113883.10.20.22.4.2",Ri="2.16.840.1.113883.10.20.22.4.2.2",tt="2.16.840.1.113883.10.20.22.4.3";var J="2.16.840.1.113883.10.20.22.4.4",Ni="2.16.840.1.113883.10.20.22.4.4.2";var it="2.16.840.1.113883.10.20.22.4.7";var nt="2.16.840.1.113883.10.20.22.4.8";var rt="2.16.840.1.113883.10.20.22.4.9";var K="2.16.840.1.113883.10.20.22.4.12";var Di="2.16.840.1.113883.10.20.22.4.13";var ot="2.16.840.1.113883.10.20.22.4.14";var st="2.16.840.1.113883.10.20.22.4.16";var xi="2.16.840.1.113883.10.20.22.4.20";var at="2.16.840.1.113883.10.20.22.4.23";var ee="2.16.840.1.113883.10.20.22.4.26",vi="2.16.840.1.113883.10.20.22.4.26.2",te="2.16.840.1.113883.10.20.22.4.27",Pi="2.16.840.1.113883.10.20.22.4.27.2";var ct="2.16.840.1.113883.10.20.22.4.30";var ut="2.16.840.1.113883.10.20.22.4.32";var bi="2.16.840.1.113883.10.20.22.4.38",Ui="2.16.840.1.113883.10.20.22.4.38.1";var Li="2.16.840.1.113883.10.20.22.4.44";var lt="2.16.840.1.113883.10.20.22.4.49";var dt="2.16.840.1.113883.10.20.22.4.52";var pt="2.16.840.1.113883.10.20.22.4.54";var Vi="2.16.840.1.113883.10.20.22.4.66";var wi="2.16.840.1.113883.10.20.22.4.67";var Mi="2.16.840.1.113883.10.20.22.4.69",ki="2.16.840.1.113883.10.20.22.4.70";var Bi="2.16.840.1.113883.10.20.22.4.74";var Fi="2.16.840.1.113883.10.20.22.4.75";var ie="2.16.840.1.113883.10.20.22.4.78",Gi="2.16.840.1.113883.10.20.22.4.78.2";var ne="2.16.840.1.113883.10.20.22.4.85";var Yi="2.16.840.1.113883.10.20.22.4.86";var $i="2.16.840.1.113883.10.20.22.4.114";var Hi="2.16.840.1.113883.10.20.22.4.119";var ji="2.16.840.1.113883.10.20.22.4.121";var qi="2.16.840.1.113883.10.20.22.4.130";var Wi="2.16.840.1.113883.10.20.22.4.133";var Le="2.16.840.1.113883.10.20.22.4.147",Qi="2.16.840.1.113883.10.20.22.4.200",zi="2.16.840.1.113883.10.20.22.4.201";var Zi="2.16.840.1.113883.10.20.22.4.244";var Xi="2.16.840.1.113883.10.20.22.4.250";var Ji="2.16.840.1.113883.10.20.22.4.406",Ki="2.16.840.1.113883.10.20.22.4.407";var en="2.16.840.1.113883.10.20.22.4.416";var ht="2.16.840.1.113883.10.20.22.4.500",tn="2.16.840.1.113883.10.20.22.4.501";var nn="2.16.840.1.113883.10.20.22.4.503",rn="2.16.840.1.113883.10.20.22.4.504";var on="2.16.840.1.113883.10.20.22.4.506",sn="2.16.840.1.113883.10.20.22.4.507",an="2.16.840.1.113883.10.20.22.4.508";var cn="2.16.840.1.113883.10.20.22.4.512";var ft="2.16.840.1.113883.12.292";var m=class{constructor(e,i,n,r){this.systemName=e,this.ccdaSystemOid=i,this.fhirSystemUrl=n,this.entries=r,this.ccdaToFhirMap={},this.fhirToCcdaMap={};for(let o of r)this.ccdaToFhirMap[o.ccdaValue]||(this.ccdaToFhirMap[o.ccdaValue]=o),this.fhirToCcdaMap[o.fhirValue]||(this.fhirToCcdaMap[o.fhirValue]=o)}getEntryByFhir(e){return this.fhirToCcdaMap[e]}getEntryByCcda(e){return this.ccdaToFhirMap[e]}mapCcdaToFhir(e){return this.ccdaToFhirMap[e]?.fhirValue}mapCcdaToFhirWithDefault(e,i){return e?this.mapCcdaToFhir(e)??i:i}mapFhirToCcdaWithDefault(e,i){return e?this.mapFhirToCcda(e)??i:i}mapCcdaToFhirCodeableConcept(e){let i=this.ccdaToFhirMap[e];if(i)return{coding:[{system:this.fhirSystemUrl,code:i.fhirValue,display:i.displayName}],text:i.displayName}}mapFhirToCcda(e){if(e)return this.fhirToCcdaMap[e]?.ccdaValue}mapFhirToCcdaCode(e){if(!e)return;let i=this.fhirToCcdaMap[e];if(i)return{"@_code":i.ccdaValue,"@_displayName":i.displayName,"@_codeSystem":this.ccdaSystemOid,"@_codeSystemName":ce.getEntryByCcda(this.ccdaSystemOid)?.displayName}}},b="http:",Ve=`${I}/CodeSystem/condition-clinical`,mt=`${I}/CodeSystem/condition-verification`,uo=`${I}/CodeSystem/v3-LanguageAbilityMode`,lo=`${I}/CodeSystem/v3-LanguageAbilityProficiency`,po=`${I}/CodeSystem/v3-Race`,Et=`${I}/CodeSystem/condition-category`,we=`${I}/CodeSystem/condition-ver-status`,re=`${I}/CodeSystem/allergyintolerance-clinical`,Me=`${I}/CodeSystem/allergyintolerance-verification`,It=`${I}/CodeSystem/v3-ActCode`,Tt=`${I}/CodeSystem/v3-ParticipationType`,Ot=`${I}/CodeSystem/diagnosis-role`,un=`${I}/CodeSystem/v3-Confidentiality`,ln=`${I}/CodeSystem/observation-category`,dn=`${_}/fhir/ValueSet/address-use`,pn=`${_}/fhir/ValueSet/name-use`,hn=`${_}/fhir/ValueSet/administrative-gender`,fn=`${_}/fhir/ValueSet/contactentity-use`,_n=`${_}/fhir/ValueSet/medicationrequest-status`,ho=`${_}/fhir/StructureDefinition/language-mode`,fo=`${_}/fhir/StructureDefinition/language-proficiency`,_o=`${_}/fhir/us/core/StructureDefinition/us-core-patient`,oe=`${_}/fhir/us/core/StructureDefinition/us-core-race`,se=`${_}/fhir/us/core/StructureDefinition/us-core-ethnicity`,St=`${_}/fhir/us/core/StructureDefinition/us-core-condition`,yt=`${_}/fhir/us/core/StructureDefinition/us-core-medicationrequest`,mo=`${_}/cda/template`,mn=`${b}//ncithesaurus-stage.nci.nih.gov`,En=`${_}/fhir/sid/us-ssn`,In=`${_}/fhir/sid/us-dln`,Tn=`${_}/fhir/sid/us-npi`,On=`${b}//fdasis.nlm.nih.gov`,Sn=`${b}//nucc.org/provider-taxonomy`,yn=`${b}//va.gov/terminology/medrt`,Cn=`${b}//hl7.org/fhir/ndfrt`,gn=`${b}//nucc.org/cvx`,An=`${_}/fhir/sid/cvx`,Ct=`${b}//www.w3.org/2001/XMLSchema-instance`,ae="https://medplum.com/fhir/StructureDefinition/ccda-narrative-reference",ce=new m("System","","",[{ccdaValue:ni,fhirValue:"https://fhir.infoway-inforoute.ca/CodeSystem/pCLOCD",displayName:"pan-Canadian LOINC Observation Code Database (pCLOCD)"},{ccdaValue:ri,fhirValue:mn,displayName:"NCI Thesaurus"},{ccdaValue:oi,fhirValue:En,displayName:"SSN"},{ccdaValue:si,fhirValue:In,displayName:"DLN"},{ccdaValue:ai,fhirValue:Tn,displayName:"NPI"},{ccdaValue:ci,fhirValue:On,displayName:"Unique Ingredient Identifier (UNII)"},{ccdaValue:M,fhirValue:ye,displayName:"LOINC"},{ccdaValue:li,fhirValue:$t,displayName:"Current Procedural Terminology (CPT)"},{ccdaValue:di,fhirValue:"urn:iso:std:iso:11073:10101",displayName:"Medical Device Communications (MDC)"},{ccdaValue:pi,fhirValue:Ht,displayName:"National Drug Code (NDC)"},{ccdaValue:hi,fhirValue:Yt,displayName:"RxNorm"},{ccdaValue:k,fhirValue:Ye,displayName:"SNOMED CT"},{ccdaValue:fi,fhirValue:Sn,displayName:"NUCC Health Care Provider Taxonomy"},{ccdaValue:mi,fhirValue:yn,displayName:"Medication Reference Terminology (MED-RT)"},{ccdaValue:_i,fhirValue:Cn,displayName:"National Drug File Reference Terminology (NDF-RT)"},{ccdaValue:ft,fhirValue:gn,displayName:"CVX"},{ccdaValue:ze,fhirValue:"Confidentiality",displayName:"Confidentiality"},{ccdaValue:ft,fhirValue:An,displayName:"Vaccine Administered Code Set (CVX)"}]);function F(t){if(t)return ce.mapCcdaToFhir(t)??`urn:oid:${t}`}function gt(t){if(t)return t.startsWith("urn:oid:")?t.replace("urn:oid:",""):ce.mapFhirToCcda(t)}function p(t){if(!t?.coding)return;let e=_t(t.coding[0]);if(t.coding.length>1){e.translation=[];for(let i=1;i<t.coding.length;i++)e.translation.push(_t(t.coding[i]))}return e}function _t(t){let e=t?.system?ce.getEntryByFhir(t.system):void 0,i=e?.ccdaValue,n=e?.displayName,r=t.system?.startsWith("urn:oid:")?t.system.replace("urn:oid:",""):void 0;return{"@_code":t.code,"@_displayName":t.display,"@_codeSystem":i??r,"@_codeSystemName":n}}function G(t){let e=p(t);if(e)return{"@_xsi:type":"CD",...e}}var At=new m("Confidentiality",ze,un,[{ccdaValue:"U",fhirValue:"U",displayName:"unrestricted"},{ccdaValue:"L",fhirValue:"L",displayName:"low"},{ccdaValue:"M",fhirValue:"M",displayName:"moderate"},{ccdaValue:"N",fhirValue:"N",displayName:"normal"},{ccdaValue:"R",fhirValue:"R",displayName:"restricted"},{ccdaValue:"V",fhirValue:"V",displayName:"very restricted"}]),ue=new m("HumanNameUse","",pn,[{ccdaValue:"C",fhirValue:"usual",displayName:"Common/Called by"},{ccdaValue:"L",fhirValue:"official",displayName:"Legal"},{ccdaValue:"TEMP",fhirValue:"temp",displayName:"Temporary"},{ccdaValue:"P",fhirValue:"nickname",displayName:"Nickname"},{ccdaValue:"ANON",fhirValue:"anonymous",displayName:"Anonymous"},{ccdaValue:"L",fhirValue:"maiden",displayName:"Maiden"},{ccdaValue:"L",fhirValue:"old",displayName:"Old"}]),Rt=new m("Gender","",hn,[{ccdaValue:"F",fhirValue:"female",displayName:"Female"},{ccdaValue:"M",fhirValue:"male",displayName:"Male"},{ccdaValue:"UN",fhirValue:"unknown",displayName:"Unknown"},{ccdaValue:"UN",fhirValue:"other",displayName:"Other"}]),le=new m("AddressUse","",dn,[{ccdaValue:"HP",fhirValue:"home",displayName:"Home"},{ccdaValue:"WP",fhirValue:"work",displayName:"Work"}]),de=new m("TelecomUse","",fn,[{ccdaValue:"WP",fhirValue:"work",displayName:"Work"},{ccdaValue:"HP",fhirValue:"home",displayName:"Home"}]),pe=new m("AllergyStatus","",Me,[{ccdaValue:"unconfirmed",fhirValue:"unconfirmed",displayName:"Unconfirmed"},{ccdaValue:"provisional",fhirValue:"provisional",displayName:"Provisional"},{ccdaValue:"differential",fhirValue:"differential",displayName:"Differential"},{ccdaValue:"confirmed",fhirValue:"confirmed",displayName:"Confirmed"},{ccdaValue:"refuted",fhirValue:"refuted",displayName:"Refuted"},{ccdaValue:"entered-in-error",fhirValue:"entered-in-error",displayName:"Entered in Error"},{ccdaValue:"unknown",fhirValue:"unknown",displayName:"Unknown"}]),Nt=new m("AllergyCategory",k,re,[{ccdaValue:"414285001",fhirValue:"food",displayName:"Allergy to food (finding)"},{ccdaValue:"419511003",fhirValue:"medication",displayName:"Propensity to adverse reactions to drug (finding)"},{ccdaValue:"426232007",fhirValue:"environment",displayName:"Environmental allergy (finding)"},{ccdaValue:"418038007",fhirValue:"biologic",displayName:"Propensity to adverse reactions to substance (finding)"}]),he=new m("AllergySeverity",Ye,re,[{ccdaValue:"255604002",fhirValue:"mild",displayName:"Mild"},{ccdaValue:"6736007",fhirValue:"moderate",displayName:"Moderate"},{ccdaValue:"24484000",fhirValue:"severe",displayName:"Severe"}]),fe=new m("ProblemStatus","",we,[{ccdaValue:"active",fhirValue:"active",displayName:"Active"},{ccdaValue:"inactive",fhirValue:"inactive",displayName:"Inactive"},{ccdaValue:"resolved",fhirValue:"inactive",displayName:"Resolved"},{ccdaValue:"remission",fhirValue:"inactive",displayName:"In Remission"},{ccdaValue:"relapse",fhirValue:"active",displayName:"Relapse"},{ccdaValue:"resolved relapse",fhirValue:"inactive",displayName:"Resolved Relapse"},{ccdaValue:"aborted",fhirValue:"aborted",displayName:"Aborted"}]),_e=new m("ImmunizationStatus","","",[{ccdaValue:"completed",fhirValue:"completed",displayName:"Completed"},{ccdaValue:"nullified",fhirValue:"entered-in-error",displayName:"Nullified"},{ccdaValue:"aborted",fhirValue:"not-done",displayName:"Aborted"},{ccdaValue:"cancelled",fhirValue:"not-done",displayName:"Cancelled"},{ccdaValue:"obsolete",fhirValue:"not-done",displayName:"Obsolete"}]),Dt=new m("EncounterStatus","","",[{ccdaValue:"active",fhirValue:"in-progress",displayName:"In Progress"},{ccdaValue:"completed",fhirValue:"finished",displayName:"Finished"},{ccdaValue:"aborted",fhirValue:"cancelled",displayName:"Cancelled"},{ccdaValue:"cancelled",fhirValue:"cancelled",displayName:"Cancelled"},{ccdaValue:"unknown",fhirValue:"unknown",displayName:"Unknown"}]),xt=new m("ProcedureStatus","","",[{ccdaValue:"completed",fhirValue:"completed",displayName:"Completed"},{ccdaValue:"aborted",fhirValue:"stopped",displayName:"Stopped"},{ccdaValue:"cancelled",fhirValue:"not-done",displayName:"Not Done"},{ccdaValue:"new",fhirValue:"not-done",displayName:"Draft"},{ccdaValue:"unknown",fhirValue:"unknown",displayName:"Unknown"}]),me=new m("MedicationStatus","",_n,[{ccdaValue:"active",fhirValue:"active",displayName:"Active"},{ccdaValue:"completed",fhirValue:"completed",displayName:"Completed"},{ccdaValue:"aborted",fhirValue:"stopped",displayName:"Stopped"},{ccdaValue:"cancelled",fhirValue:"cancelled",displayName:"Cancelled"},{ccdaValue:"aborted",fhirValue:"entered-in-error",displayName:"Entered in Error"},{ccdaValue:"active",fhirValue:"draft",displayName:"Draft"},{ccdaValue:"cancelled",fhirValue:"unknown",displayName:"Unknown"},{ccdaValue:"nullified",fhirValue:"cancelled",displayName:"Nullified"},{ccdaValue:"obsolete",fhirValue:"cancelled",displayName:"Obsolete"}]),Ee=new m("ObservationCategory","",ln,[{ccdaValue:bi,fhirValue:"social-history",displayName:"Social History"},{ccdaValue:Ui,fhirValue:"social-history",displayName:"Social History V2"},{ccdaValue:ie,fhirValue:"social-history",displayName:"Smoking Status"},{ccdaValue:Gi,fhirValue:"social-history",displayName:"Current Smoking Status"},{ccdaValue:ne,fhirValue:"social-history",displayName:"Tobacco Use"},{ccdaValue:nn,fhirValue:"social-history",displayName:"Basic Occupation"},{ccdaValue:rn,fhirValue:"social-history",displayName:"Basic Industry"},{ccdaValue:tn,fhirValue:"social-history",displayName:"Sexual Orientation"},{ccdaValue:sn,fhirValue:"social-history",displayName:"Sex Observation"},{ccdaValue:Qi,fhirValue:"social-history",displayName:"Gender Identity"},{ccdaValue:zi,fhirValue:"social-history",displayName:"Gender Identity V2"},{ccdaValue:Ei,fhirValue:"social-history",displayName:"Pregnancy Status"},{ccdaValue:on,fhirValue:"social-history",displayName:"Tribal Affiliation"},{ccdaValue:te,fhirValue:"vital-signs",displayName:"Vital Signs Observation"},{ccdaValue:Pi,fhirValue:"vital-signs",displayName:"Vital Signs Observation V2"},{ccdaValue:ee,fhirValue:"vital-signs",displayName:"Vital Signs Organizer"},{ccdaValue:vi,fhirValue:"vital-signs",displayName:"Vital Signs Organizer V2"},{ccdaValue:cn,fhirValue:"vital-signs",displayName:"Average Blood Pressure Organizer"},{ccdaValue:Ci,fhirValue:"laboratory",displayName:"Result Organizer"},{ccdaValue:gi,fhirValue:"laboratory",displayName:"Result Organizer V2"},{ccdaValue:Ai,fhirValue:"laboratory",displayName:"Result Observation"},{ccdaValue:Ri,fhirValue:"laboratory",displayName:"Result Observation V2"},{ccdaValue:Ji,fhirValue:"laboratory",displayName:"Laboratory Battery (ID)"},{ccdaValue:Ki,fhirValue:"laboratory",displayName:"Laboratory Observation (ID)"},{ccdaValue:en,fhirValue:"laboratory",displayName:"Laboratory Result Organizer (ID)"},{ccdaValue:Mi,fhirValue:"survey",displayName:"Assessment Scale Observation"},{ccdaValue:Yi,fhirValue:"survey",displayName:"Assessment Scale Supporting Observation"},{ccdaValue:Bi,fhirValue:"survey",displayName:"Cognitive Status Result Observation"},{ccdaValue:Fi,fhirValue:"survey",displayName:"Cognitive Status Result Organizer"},{ccdaValue:wi,fhirValue:"survey",displayName:"Functional Status Result Observation"},{ccdaValue:Vi,fhirValue:"survey",displayName:"Functional Status Result Organizer"},{ccdaValue:Di,fhirValue:"exam",displayName:"Procedure Activity Observation"},{ccdaValue:J,fhirValue:"exam",displayName:"Problem Observation"},{ccdaValue:Ni,fhirValue:"exam",displayName:"Problem Observation V2"},{ccdaValue:ki,fhirValue:"exam",displayName:"Pressure Ulcer Observation"},{ccdaValue:$i,fhirValue:"exam",displayName:"Wound Observation"},{ccdaValue:Wi,fhirValue:"exam",displayName:"Wound Measurements Observation"},{ccdaValue:B,fhirValue:"exam",displayName:"Procedure Section"},{ccdaValue:an,fhirValue:"therapy",displayName:"Medication Adherence"},{ccdaValue:qi,fhirValue:"therapy",displayName:"Nutrition Recommendations"},{ccdaValue:Zi,fhirValue:"therapy",displayName:"Diet Statement (Nutrition)"},{ccdaValue:Xi,fhirValue:"therapy",displayName:"Monitoring, Evaluation and Outcome (Nutrition)"}]);var Y=require("fast-xml-parser");var Eo=["ClinicalDocument.recordTarget",".id",".templateId",".name",".addr",".telecom",".streetAddressLine",".author",".effectiveTime","name.given","name.suffix","name.prefix","patient.raceCode","patient.ethnicGroupCode","patient.languageCommunication","component.structuredBody.component","component.structuredBody.component.section","component.section","component.observation","component.act","code.translation","section.entry","entry.act","entry.organizer","entry.substanceAdministration","entry.observation","entry.encounter","entry.procedure","encounter.performer","encounter.participant","encounter.entryRelationship","entryRelationship.observation","entryRelationship.substanceAdministration","entryRelationship.act","organizer.component","substanceAdministration.consumable.manufacturedProduct","substanceAdministration.entryRelationship","substanceAdministration.performer","act.entryRelationship","act.performer","observation.participant","observation.entryRelationship","observation.referenceRange","consumable.manufacturedProduct","manufacturedProduct.manufacturedMaterial","manufacturedProduct.manufacturerOrganization","manufacturedProduct.manufacturedLabeledDrug","manufacturedMaterial.code","manufacturedMaterial.lotNumberText"];function Io(t){return new Y.XMLParser({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1,isArray:(n,r,o,s)=>Eo.some(c=>r.endsWith(c))}).parse(t).ClinicalDocument}function To(t){return new Y.XMLBuilder({ignoreAttributes:!1,attributeNamePrefix:"@_",format:!0,suppressBooleanAttributes:!1,suppressEmptyNode:!0}).build({"?xml":{"@_version":"1.0","@_encoding":"UTF-8"},"?xml-stylesheet":{"@_type":"text/xsl","@_href":"CDA.xsl"},ClinicalDocument:{"@_xmlns":"urn:hl7-org:v3","@_xmlns:xsi":Ct,"@_xmlns:voc":"urn:hl7-org:v3/voc","@_xmlns:sdtc":"urn:hl7-org:sdtc",...t}})}function vt(t){return new Y.XMLParser({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1}).parse(t)}function Pt(t){return t?typeof t=="string"?t:new Y.XMLBuilder({ignoreAttributes:!1,attributeNamePrefix:"@_",format:!1,suppressBooleanAttributes:!1,suppressEmptyNode:!0}).build(t).split(`
2
- `).map(n=>n.trim()).join(""):""}function Oo(t){return new bt(t).convert()}var bt=class{constructor(e){this.resources=[];this.ccda=e}convert(){return this.processHeader(),{resourceType:"Bundle",type:"document",entry:[{resource:this.createComposition()},...this.patient?[{resource:this.patient}]:[],...this.resources.map(i=>({resource:i}))]}}processHeader(){let e=this.ccda.recordTarget?.[0]?.patientRole;e&&(this.patient=this.createPatient(e))}createPatient(e){let i=e.patient,n=[];return i.raceCode&&i.raceCode.length>0&&n.push({url:oe,extension:i.raceCode.map(r=>({url:"ombCategory",valueCoding:this.mapCodeToCoding(r)}))}),i.ethnicGroupCode&&i.ethnicGroupCode.length>0&&n.push({url:se,extension:i.ethnicGroupCode.map(r=>({url:"ombCategory",valueCoding:this.mapCodeToCoding(r)}))}),{resourceType:"Patient",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),name:this.mapCcdaNameArrayFhirHumanNameArray(i.name),gender:this.mapGenderCode(i.administrativeGenderCode?.["@_code"]),birthDate:ge(i.birthTime?.["@_value"]),address:this.mapAddresses(e.addr),telecom:this.mapTelecom(e.telecom),extension:n.length>0?n:void 0}}mapId(e){let i=e?.find(n=>!n["@_extension"]&&n["@_root"]&&je(n["@_root"]));return i?i["@_root"]:Ce()}mapIdentifiers(e){if(!e)return;let i=[];for(let n of e)!n["@_extension"]&&n["@_root"]&&je(n["@_root"])||i.push({system:F(n["@_root"]),value:n["@_extension"]});return i}mapCcdaNameArrayFhirHumanNameArray(e){return e?.map(i=>this.mapCcdaNameToFhirHumanName(i)).filter(Boolean)}mapCcdaNameToFhirHumanName(e){if(!e)return;let i={},n=e["@_use"]?ue.mapCcdaToFhir(e["@_use"]):void 0;return n&&(i.use=n),e.prefix&&(i.prefix=e.prefix.map(Ie)?.filter(Boolean)),e.family&&(i.family=Ie(e.family)),e.given&&(i.given=e.given.map(Ie)?.filter(Boolean)),e.suffix&&(i.suffix=e.suffix.map(Ie)?.filter(Boolean)),i}mapAddresses(e){if(!(!e||e.length===0||e.every(i=>i["@_nullFlavor"]==="UNK")))return e?.map(i=>({"@_use":i["@_use"]?le.mapCcdaToFhir(i["@_use"]):void 0,line:i.streetAddressLine,city:i.city,state:i.state,postalCode:i.postalCode,country:i.country}))}mapTelecom(e){if(!(!e||e.length===0||e.every(i=>i["@_nullFlavor"]==="UNK")))return e?.map(i=>({"@_use":i["@_use"]?de.mapCcdaToFhir(i["@_use"]):void 0,system:this.getTelecomSystem(i["@_value"]),value:this.getTelecomValue(i["@_value"])}))}createComposition(){let e=this.ccda.component?.structuredBody?.component||[],i=[];for(let n of e)for(let r of n.section){let o=this.processSection(r);i.push({title:r.title,code:this.mapCode(r.code),text:{status:"generated",div:`<div xmlns="http://www.w3.org/1999/xhtml">${Pt(r.text)}</div>`},entry:o.map(h)}),this.resources.push(...o)}return{resourceType:"Composition",id:this.mapId(this.ccda.id),language:this.ccda.languageCode?.["@_code"],status:"final",type:this.ccda.code?this.mapCode(this.ccda.code):{coding:[{system:ye,code:"34133-9"}]},confidentiality:this.ccda.confidentialityCode?.["@_code"],author:this.ccda.author?.[0]?[this.mapAuthorToReference(this.ccda.author?.[0])]:[{display:"Medplum"}],custodian:this.mapCustodianToReference(this.ccda.custodian),event:this.mapDocumentationOfToEvent(this.ccda.documentationOf),date:f(this.ccda.effectiveTime?.[0]?.["@_value"])??new Date().toISOString(),title:this.ccda.title??"Medical Summary",section:i}}processSection(e){let i=[];if(e.entry)for(let n of e.entry)this.processEntry(e,n,i);return i}processEntry(e,i,n){for(let r of i.act??[]){let o=this.processAct(e,r);o&&n.push(o)}for(let r of i.substanceAdministration??[]){let o=this.processSubstanceAdministration(e,r);o&&n.push(o)}for(let r of i.organizer??[])n.push(this.processOrganizer(e,r));for(let r of i.observation??[])n.push(this.processObservation(e,r));for(let r of i.encounter??[])n.push(this.processEncounter(e,r));for(let r of i.procedure??[])n.push(this.processProcedure(e,r))}processAct(e,i){let n=e.templateId[0]["@_root"];switch(n){case xe:return this.processAllergyIntoleranceAct(i);case De:return this.processConditionAct(i);case P:return this.processCarePlanAct(i);case Pe:return this.processConditionAct(i);case B:return this.processProcedureAct(i);case Ae:return;case be:return;case ve:return;default:throw new Error("Unhandled act templateId: "+n)}}processAllergyIntoleranceAct(e){let i=e.entryRelationship?.find(s=>s["@_typeCode"]==="SUBJ")?.observation?.[0];if(!i)return;let n={resourceType:"AllergyIntolerance",id:this.mapId(e.id),clinicalStatus:this.createClinicalStatus(e),verificationStatus:this.createVerificationStatus(),type:"allergy",category:["food"],patient:h(this.patient),recorder:this.mapAuthorToReference(e.author?.[0]),recordedDate:this.mapEffectiveTimeToDateTime(e.effectiveTime?.[0]),onsetDateTime:this.mapEffectiveTimeToDateTime(i.effectiveTime?.[0])};i.value?.["@_code"]==="414285001"&&(n.category=["food"]),n.extension=this.mapTextReference(i.text);let r=i.participant?.[0]?.participantRole?.playingEntity?.code;r&&(n.code=this.mapCode(r),n.code&&r.originalText?.reference?.["@_value"]&&(n.code.extension=this.mapTextReference(r.originalText)));let o=i.entryRelationship?.find(s=>s["@_typeCode"]==="MFST")?.observation;return o&&(n.reaction=o.map(s=>this.processReaction(s))),n.asserter=this.mapAuthorToReference(i.author?.[0]),n}processConditionAct(e){let i=e.entryRelationship?.find(r=>r["@_typeCode"]==="SUBJ")?.observation?.[0];if(!i)return;let n={resourceType:"Condition",id:this.mapId(e.id),identifier:this.concatArrays(this.mapIdentifiers(e.id),this.mapIdentifiers(i.id)),meta:{profile:[St]},clinicalStatus:{coding:[{system:Ve,code:fe.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active")}]},verificationStatus:{coding:[{system:mt,code:"confirmed"}]},category:[{coding:[{system:Et,code:"problem-list-item",display:"Problem List Item"}]}],code:this.mapCode(i.value),subject:h(this.patient),onsetDateTime:f(i.effectiveTime?.[0]?.low?.["@_value"]),abatementDateTime:f(i.effectiveTime?.[0]?.high?.["@_value"]),recordedDate:this.mapEffectiveTimeToDateTime(e.effectiveTime?.[0]),recorder:this.mapAuthorToReference(i.author?.[0]),asserter:this.mapAuthorToReference(i.author?.[0])};return n.extension=this.mapTextReference(i.text),n}processCarePlanAct(e){return{resourceType:"CarePlan",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"active",intent:"plan",title:"CARE PLAN",category:e.code?[this.mapCode(e.code)]:void 0,subject:h(this.patient),description:Ie(e.text)}}processProcedureAct(e){return{resourceType:"Procedure",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"completed",code:this.mapCode(e.code),subject:h(this.patient),performedDateTime:f(e.effectiveTime?.[0]?.["@_value"]),recorder:this.mapAuthorToReference(e.author?.[0]),asserter:this.mapAuthorToReference(e.author?.[0]),extension:this.mapTextReference(e.text)}}processSubstanceAdministration(e,i){let n=e.templateId[0]["@_root"];switch(n){case Ne:case P:return this.processMedicationSubstanceAdministration(i);case z:case Z:return this.processImmunizationSubstanceAdministration(i);default:throw new Error("Unhandled substance administration templateId: "+n)}}processMedicationSubstanceAdministration(e){let i=this.mapId(e.id),n=e.consumable?.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.code?.[0],r=e.routeCode,o=e.doseQuantity,s=e.consumable?.manufacturedProduct?.[0]?.manufacturerOrganization?.[0],c=e.entryRelationship?.find(E=>E.substanceAdministration?.[0]?.templateId?.[0]?.["@_root"]===Le)?.substanceAdministration?.[0],d,N;return s?d={resourceType:"Medication",id:"med-"+i,code:this.mapCode(n),extension:this.mapTextReference(n?.originalText),manufacturer:s?{identifier:{value:s.id?.[0]?.["@_root"]},display:s.name?.[0]}:void 0}:N={...this.mapCode(n),extension:this.mapTextReference(n?.originalText)},{resourceType:"MedicationRequest",id:i,contained:d?[d]:void 0,meta:{profile:[yt]},extension:this.mapTextReference(e.text),status:me.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active"),intent:"order",medicationReference:d?{reference:"#med-"+i}:void 0,medicationCodeableConcept:N,subject:h(this.patient),authoredOn:f(e.author?.[0]?.time?.["@_value"]),dispenseRequest:e.effectiveTime?.[0]?{validityPeriod:{start:f(e.effectiveTime?.[0]?.low?.["@_value"]),end:f(e.effectiveTime?.[0]?.high?.["@_value"])}}:void 0,dosageInstruction:[{text:typeof e.text=="string"?e.text:void 0,extension:this.mapTextReference(c?.text),route:r?this.mapCode(r):void 0,timing:{repeat:e.effectiveTime?.[1]?.period?{period:Number(e.effectiveTime?.[1]?.period["@_value"]),periodUnit:e.effectiveTime?.[1]?.period["@_unit"]}:void 0},doseAndRate:o?[{doseQuantity:{system:Ge,value:Number(o["@_value"]),code:"[IU]",unit:"[IU]"}}]:void 0}]}}processImmunizationSubstanceAdministration(e){let i=e.consumable;if(!i)return;let n={resourceType:"Immunization",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:_e.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"completed"),vaccineCode:this.mapCode(i.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.code?.[0]),patient:h(this.patient),occurrenceDateTime:f(e.effectiveTime?.[0]?.["@_value"]),lotNumber:i.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.lotNumberText?.[0]};return e.performer&&(n.performer=this.mapCcdaPerformerArrayToImmunizationPerformerArray(e.performer)),n.extension=this.mapTextReference(e.text),e.consumable?.manufacturedProduct?.[0]?.manufacturerOrganization?.[0]&&(n.manufacturer={display:e.consumable?.manufacturedProduct?.[0]?.manufacturerOrganization?.[0]?.name?.[0]}),n}processReaction(e){let i={id:this.mapId(e.id),manifestation:[this.mapCode(e.value)],onset:f(e.effectiveTime?.[0]?.low?.["@_value"])};return this.processSeverity(e,i),i.manifestation&&i.manifestation.length>0&&e.text?.reference?.["@_value"]&&(i.manifestation[0].extension=this.mapTextReference(e.text)),i}processSeverity(e,i){let n=e.entryRelationship?.find(o=>o["@_typeCode"]==="SUBJ")?.observation?.[0];if(!n)return;let r=n.value?.["@_code"];r&&(i.severity=he.mapCcdaToFhir(r)),i.extension=this.mapTextReference(n.text)}mapEffectiveTimeToDateTime(e){if(e?.["@_value"])return f(e["@_value"]);if(e?.low?.["@_value"])return f(e.low["@_value"])}mapEffectiveTimeToPeriod(e){if(!e?.["@_value"]&&(e?.low||e?.high))return{start:f(e?.low?.["@_value"]),end:f(e?.high?.["@_value"])}}mapGenderCode(e){return e?{F:"female",M:"male",UN:"unknown"}[e]:void 0}getTelecomSystem(e){if(e)return e.startsWith("tel:")?"phone":e.startsWith("mailto:")?"email":"other"}getTelecomValue(e){if(e)return e.replace(/^(tel:|mailto:)/,"")}mapCode(e){if(!e)return;let i={coding:[{system:F(e["@_codeSystem"]),code:e["@_code"],display:e["@_displayName"]}],text:e["@_displayName"]};if(e.translation)for(let n of e.translation)i.coding.push({system:F(n["@_codeSystem"]),code:n["@_code"],display:n["@_displayName"]});return i}mapCodeToCoding(e){if(e)return{system:F(e["@_codeSystem"]),code:e["@_code"],display:e["@_displayName"]}}createClinicalStatus(e){return{coding:[{system:re,code:pe.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active")}]}}createVerificationStatus(){return{coding:[{system:Me,code:"confirmed"}]}}mapAuthorToReference(e){if(!e)return;let i={resourceType:"Practitioner",id:this.mapId(e.assignedAuthor?.id),identifier:this.mapIdentifiers(e.assignedAuthor?.id),name:this.mapCcdaNameArrayFhirHumanNameArray(e.assignedAuthor?.assignedPerson?.name),address:this.mapAddresses(e.assignedAuthor?.addr),telecom:this.mapTelecom(e.assignedAuthor?.telecom),qualification:e.assignedAuthor?.code?[this.mapCode(e.assignedAuthor?.code)]:void 0};return this.resources.push(i),h(i)}mapAssignedEntityToReference(e){if(!e)return;let i=e.assignedPerson,n=e.representedOrganization,r={resourceType:"Practitioner",id:this.mapId(e?.id),identifier:this.mapIdentifiers(e?.id),name:this.mapCcdaNameArrayFhirHumanNameArray(i?.name),address:this.mapAddresses(e?.addr),telecom:this.mapTelecom(e?.telecom)};this.resources.push(r);let o={resourceType:"Organization",id:this.mapId(e?.id),identifier:this.mapIdentifiers(n?.id),name:n?.name?.[0],address:this.mapAddresses(n?.addr)};this.resources.push(o);let s={resourceType:"PractitionerRole",id:this.mapId(e?.id),practitioner:h(r),organization:h(o)};return this.resources.push(s),h(s)}mapCustodianToReference(e){if(!e)return;let i={resourceType:"Organization",id:this.mapId(e.assignedCustodian.representedCustodianOrganization.id),identifier:this.mapIdentifiers(e.assignedCustodian.representedCustodianOrganization.id),name:e.assignedCustodian.representedCustodianOrganization.name?.[0],address:this.mapAddresses(e.assignedCustodian.representedCustodianOrganization.addr),telecom:this.mapTelecom(e.assignedCustodian.representedCustodianOrganization.telecom)};return this.resources.push(i),h(i)}mapDocumentationOfToEvent(e){if(!e)return;let i=e.serviceEvent;if(i)return[{code:i.code?[this.mapCode(i.code)]:void 0,period:this.mapEffectiveTimeToPeriod(i.effectiveTime?.[0])}]}concatArrays(e,i){return e?i?[...e,...i]:e:i}mapCcdaPerformerArrayToImmunizationPerformerArray(e){let i=[];for(let n of e){let r=n.assignedEntity,o=this.mapAssignedEntityToReference(r);o&&i.push({actor:o})}return i}processOrganizer(e,i){return e.templateId[0]["@_root"]===Ue?this.processCareTeamOrganizer(i):this.processVitalsOrganizer(i)}processCareTeamOrganizer(e){let i=[];if(e.component)for(let r of e.component){let o=this.processCareTeamMember(r);o&&i.push(o)}return{resourceType:"CareTeam",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),participant:i.length>0?i:void 0}}processCareTeamMember(e){let i=e.act?.[0];if(!i)return;let n=i.performer?.[0];if(n)return{role:n.functionCode?[this.mapCode(n.functionCode)]:void 0,member:this.mapAssignedEntityToReference(n.assignedEntity),period:this.mapEffectiveTimeToPeriod(i.effectiveTime?.[0])}}processVitalsOrganizer(e){let i={resourceType:"Observation",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"final",category:this.mapObservationTemplateIdToObservationCategory(e.templateId),code:this.mapCode(e.code),subject:h(this.patient)};if(e.effectiveTime?.[0]?.["@_value"]&&(i.effectiveDateTime=f(e.effectiveTime?.[0]?.["@_value"])),e.component){let n=[];for(let r of e.component)n.push(...this.processVitalsComponent(r));n.length>0&&(i.hasMember=n)}return i}processVitalsComponent(e){let i=[];if(e.observation)for(let n of e.observation){let r=this.processVitalsObservation(n);i.push(h(r)),this.resources.push(r)}return i}processObservation(e,i){let n=i.templateId[0]["@_root"];if(n===X||n===ji)return this.processGoalObservation(i);switch(e.templateId[0]["@_root"]){case P:case X:return this.processGoalObservation(i);default:return this.processVitalsObservation(i)}}processGoalObservation(e){let i={resourceType:"Goal",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),lifecycleStatus:this.mapGoalLifecycleStatus(e),description:this.mapCode(e.code),subject:h(this.patient),startDate:ge(e.effectiveTime?.[0]?.["@_value"])};return i.target=e.entryRelationship?.map(n=>({measure:this.mapCode(n.act?.[0]?.code),detailCodeableConcept:this.mapCode(n.act?.[0]?.code),dueDate:f(n.act?.[0]?.effectiveTime?.[0]?.low?.["@_value"])})),i.extension=this.mapTextReference(e.text),i}mapGoalLifecycleStatus(e){return{active:"active",completed:"completed",cancelled:"cancelled",aborted:"cancelled"}[e.statusCode["@_code"]??"active"]}processVitalsObservation(e){let i={resourceType:"Observation",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"final",category:this.mapObservationTemplateIdToObservationCategory(e.templateId),code:this.mapCode(e.code),subject:h(this.patient),referenceRange:this.mapReferenceRangeArray(e.referenceRange),performer:e.author?.map(n=>this.mapAuthorToReference(n)).filter(Boolean)};if(e.value?.["@_xsi:type"])switch(e.value["@_xsi:type"]){case"PQ":case"CO":i.valueQuantity={value:e.value["@_value"]?parseFloat(e.value["@_value"]):void 0,unit:e.value["@_unit"],system:Ge,code:e.value["@_unit"]};break;case"CD":case"CE":i.valueCodeableConcept=this.mapCode(e.value);break;case"ST":i.valueString=e.value["#text"]??"";break;default:console.warn(`Unhandled observation value type: ${e.value["@_xsi:type"]}`)}return e.effectiveTime?.[0]?.["@_value"]&&(i.effectiveDateTime=f(e.effectiveTime?.[0]?.["@_value"])),i.extension=this.mapTextReference(e.text),i}mapObservationTemplateIdToObservationCategory(e){if(!e)return;let i=new Set,n=[];for(let r of e){let o=Ee.mapCcdaToFhirCodeableConcept(r["@_root"]);o?.coding?.[0]?.code&&!i.has(o.coding[0].code)&&(i.add(o.coding[0].code),n.push(o))}return Array.from(n.values())}mapReferenceRangeArray(e){if(!(!e||e.length===0))return e.map(i=>this.mapReferenceRange(i)).filter(Boolean)}mapReferenceRange(e){if(!e)return;let i=e.observationRange;if(!i)return;let n={};return n.extension=this.mapTextReference(i.text),n}processEncounter(e,i){let n={resourceType:"Encounter",id:this.mapId(i.id),identifier:this.mapIdentifiers(i.id),status:Dt.mapCcdaToFhirWithDefault(i.statusCode?.["@_code"],"unknown"),class:{system:It,code:i.code?.["@_code"]??"AMB",display:i.code?.["@_displayName"]??"Ambulatory"},type:i.code?[this.mapCode(i.code)]:void 0,subject:h(this.patient),period:this.mapEffectiveTimeToPeriod(i.effectiveTime?.[0])};if(i.performer&&(n.participant=i.performer.map(r=>({type:[{coding:[{system:Tt,code:r["@_typeCode"]??"PPRF",display:"Primary Performer"}]}],individual:this.mapAssignedEntityToReference(r.assignedEntity)}))),i.entryRelationship){let r=i.entryRelationship.filter(o=>o["@_typeCode"]==="RSON").map(o=>{let s=o.observation?.[0];if(!s)return;let c={resourceType:"Condition",id:this.mapId(s.id),identifier:this.mapIdentifiers(s.id),clinicalStatus:{coding:[{system:Ve,code:"active"}]},verificationStatus:{coding:[{system:we,code:"confirmed"}]},code:this.mapCode(s.value),subject:h(this.patient),onsetDateTime:f(s.effectiveTime?.[0]?.low?.["@_value"])};return this.resources.push(c),{condition:h(c),use:{coding:[{system:Ot,code:"AD",display:"Admission diagnosis"}]}}}).filter(Boolean);r.length>0&&(n.diagnosis=r)}return n.extension=this.mapTextReference(i.text),n}processProcedure(e,i){return{resourceType:"Procedure",id:this.mapId(i.id),identifier:this.mapIdentifiers(i.id),status:xt.mapCcdaToFhirWithDefault(i.statusCode?.["@_code"],"completed"),code:this.mapCode(i.code),subject:h(this.patient),performedPeriod:this.mapEffectiveTimeToPeriod(i.effectiveTime?.[0]),bodySite:i.targetSiteCode?[this.mapCode(i.targetSiteCode)]:void 0,extension:this.mapTextReference(i.text)}}mapTextReference(e){if(!(!e||typeof e!="object")&&e?.reference?.["@_value"])return[{url:ae,valueString:e.reference?.["@_value"]}]}};function Ie(t){if(t){if(typeof t=="string")return t;if(typeof t=="object"&&"#text"in t)return t["#text"]}}var Ut=[{"@_root":Xe,"@_extension":"2015-08-01"},{"@_root":Xe},{"@_root":Je,"@_extension":"2015-08-01"},{"@_root":Je}],Rn=[{"@_root":xe,"@_extension":"2015-08-01"}],Nn=[{"@_root":Ne,"@_extension":"2014-06-09"}],Dn=[{"@_root":De,"@_extension":"2015-08-01"}],ke=[{"@_root":z},{"@_root":z,"@_extension":"2015-08-01"},{"@_root":Z},{"@_root":Z,"@_extension":"2015-08-01"}],xn=[{"@_root":Ii,"@_extension":"2015-08-01"}],vn=[{"@_root":et},{"@_root":et,"@_extension":"2015-08-01"}],Pn=[{"@_root":B,"@_extension":"2014-06-09"}],So=[{"@_root":P,"@_extension":"2014-06-09"}],yo=[{"@_root":Ke,"@_extension":"2015-08-01"}],bn=[{"@_root":Ke,"@_extension":"2015-08-01"}],Co=[{"@_root":Si,"@_extension":"2015-08-01"}],Un=[{"@_root":Ti}],Ln=[{"@_root":P},{"@_root":P,"@_extension":"2014-06-09"}],Vn=[{"@_root":Oi,"@_extension":"2015-08-01"}],wn=[{"@_root":X}],Mn=[{"@_root":Pe,"@_extension":"2015-08-01"}],kn=[{"@_root":Ae,"@_extension":"2014-06-09"}],Bn=[{"@_root":yi,"@_extension":"2015-08-01"}],Fn=[{"@_root":be,"@_extension":"2016-11-01"}],Gn=[{"@_root":Ue,"@_extension":"2022-06-01"}],Yn=[{"@_root":ve,"@_extension":"2015-08-01"}],Lt={"48765-2":Rn,"10160-0":Nn,"11450-4":Dn,"11369-6":ke,"11348-0":ke,"9176-8":ke,"8716-3":xn,"29762-2":vn,"47519-4":Pn,"30954-2":bn,"51848-0":Un,"18776-5":Ln,"46240-8":Vn,"61146-7":wn,"75310-3":Mn,"42349-1":kn,"10190-7":Bn,"11488-4":Fn,"85847-2":Gn,"48768-6":Yn};function go(t){return new Vt(t).convert()}var Vt=class{constructor(e){this.bundle=e;let i=this.findResource("Composition");if(!i)throw new Error("Composition not found");let n=this.findResource("Patient");if(!n)throw new Error("Patient not found");this.composition=i,this.patient=n}convert(){let e=this.createSections();return{realmCode:{"@_code":"US"},typeId:{"@_root":ii,"@_extension":"POCD_HD000040"},templateId:Ut,id:this.mapIdentifiers(this.composition.id,void 0),code:{"@_code":"34133-9","@_displayName":"Summarization of Episode Note","@_codeSystem":M,"@_codeSystemName":"LOINC"},title:this.composition.title,effectiveTime:this.mapEffectiveTime(this.composition.date,void 0),confidentialityCode:this.composition.confidentiality?At.mapFhirToCcdaCode(this.composition.confidentiality):void 0,languageCode:{"@_code":this.composition.language??"en-US"},recordTarget:this.createRecordTarget(),author:this.mapAuthor(this.composition.author?.[0],this.composition.date),custodian:this.mapCustodian(this.composition.custodian),documentationOf:this.mapDocumentationOf(this.composition.event),component:e.length>0?{structuredBody:{component:e.map(i=>({section:[i]}))}}:void 0}}findResource(e){return this.bundle.entry?.find(i=>i.resource?.resourceType===e)?.resource}findResourceByReference(e){if(!e?.reference)return;let[i,n]=e.reference.split("/");if(!(!i||!n))return this.bundle.entry?.find(r=>r.resource?.resourceType===i&&r.resource?.id===n)?.resource}findResourcesByReferences(e){return e?e.map(i=>this.findResourceByReference(i)).filter(i=>!!i):[]}createRecordTarget(){if(!this.patient)throw new Error("Patient not found");return[{patientRole:{id:this.mapIdentifiers(this.patient.id,this.patient.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(this.patient.address),telecom:this.mapTelecom(this.patient.telecom),patient:this.mapPatient(this.patient)}}]}mapPatient(e){return{name:this.mapNames(e.name),administrativeGenderCode:this.mapGender(e.gender),birthTime:this.mapBirthDate(e.birthDate),raceCode:this.mapRace(e.extension),ethnicGroupCode:this.mapEthnicity(e.extension),languageCommunication:this.mapLanguageCommunication(e.communication)}}mapNames(e){return e?.map(i=>({"@_use":i.use?ue.mapFhirToCcdaWithDefault(i.use,"L"):void 0,prefix:i.prefix,family:i.family,given:i.given,suffix:i.suffix}))}mapGender(e){if(e)return{"@_code":Rt.mapFhirToCcda(e),"@_displayName":e?W(e):"Unknown","@_codeSystem":ui,"@_codeSystemName":"AdministrativeGender"}}mapBirthDate(e){if(e)return{"@_value":e.replace(/-/g,"")}}mapFhirAddressArrayToCcdaAddressArray(e){return!e||e.length===0?[{"@_nullFlavor":"UNK"}]:e.map(i=>this.mapFhirAddressToCcdaAddress(i)).filter(Boolean)}mapFhirAddressToCcdaAddress(e){return e?{"@_use":e.use?le.mapFhirToCcda(e.use):void 0,streetAddressLine:e.line||[],city:e.city,state:e.state,postalCode:e.postalCode,country:e.country}:void 0}mapRace(e){let n=e?.find(r=>r.url===oe)?.extension?.find(r=>r.url==="ombCategory")?.valueCoding;if(n)return[{"@_code":n.code,"@_displayName":n.display,"@_codeSystem":Ze,"@_codeSystemName":"CDC Race and Ethnicity"}]}mapEthnicity(e){let n=e?.find(r=>r.url===se)?.extension?.find(r=>r.url==="ombCategory")?.valueCoding;if(n)return[{"@_code":n.code,"@_displayName":n.display,"@_codeSystem":Ze,"@_codeSystemName":"CDC Race and Ethnicity"}]}mapLanguageCommunication(e){if(e?.length)return[{"@_languageCode":e[0].language?.coding?.[0]?.code}]}createSections(){let e=[];if(this.composition.section)for(let i of this.composition.section)e.push(this.createSection(i));return e}createSection(e){let i=e.code?.coding?.[0]?.code;if(!i)throw new Error(`Missing section code: ${JSON.stringify(e.code)}`);let n=Lt[i];if(!n)throw new Error(`Unknown section code: ${i}`);let r=this.findResourcesByReferences(e.entry);return{templateId:n,code:p(e.code),title:e.title,text:this.mapFhirTextDivToCcdaSectionText(e.text),entry:r.map(o=>this.createEntry(e,o)),"@_nullFlavor":r.length===0?"NI":void 0}}createEntry(e,i){switch(i.resourceType){case"AllergyIntolerance":return this.createAllergyEntry(i);case"CarePlan":return this.createPlanOfTreatmentCarePlanEntry(i);case"CareTeam":return this.createCareTeamEntry(i);case"Condition":return this.createProblemEntry(i);case"Encounter":return this.createEncounterEntry(i);case"Goal":return this.createPlanOfTreatmentGoalEntry(i);case"Immunization":return this.createImmunizationEntry(i);case"MedicationRequest":return this.createMedicationEntry(i);case"Procedure":return this.createHistoryOfProceduresEntry(i);case"Observation":return this.createObservationEntry(i);default:throw new Error(`Unknown resource type: ${i.resourceType}`)}}mapFhirTextDivToCcdaSectionText(e){if(!e)return;let i=vt(e.div)?.div;return i?.["@_xmlns"]&&delete i["@_xmlns"],i}createAllergyEntry(e){let i=e.reaction?.[0];return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":ct},{"@_root":ct,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"CONC","@_codeSystem":Qe},statusCode:{"@_code":pe.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:this.mapEffectivePeriod(e.recordedDate,void 0),author:this.mapAuthor(e.recorder,e.recordedDate),text:this.createTextFromExtensions(e.extension),entryRelationship:[{"@_typeCode":"SUBJ",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":it},{"@_root":it,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"ASSERTION","@_codeSystem":Re},statusCode:{"@_code":"completed"},author:this.mapAuthor(e.asserter,e.recordedDate),effectiveTime:this.mapEffectivePeriod(e.onsetPeriod?.start??e.onsetDateTime,e.onsetPeriod?.end,!0),value:this.mapAllergyCategory(e.category),text:this.createTextFromExtensions(e.extension),participant:[{"@_typeCode":"CSM",participantRole:{"@_classCode":"MANU",playingEntity:{"@_classCode":"MMAT",code:{...p(e.code),originalText:e.code?.extension?{reference:this.getNarrativeReference(e.code?.extension)}:void 0}}}}],entryRelationship:i?[{"@_typeCode":"MFST","@_inversionInd":"true",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":rt},{"@_root":rt,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(i.id,void 0),code:{"@_code":"ASSERTION","@_codeSystem":Re},statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveDate(e.onsetDateTime,e.onsetPeriod),value:G(i.manifestation?.[0]),text:this.createTextFromExtensions(i.manifestation?.[0]?.extension),entryRelationship:[{"@_typeCode":"SUBJ","@_inversionInd":"true",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":nt},{"@_root":nt,"@_extension":"2014-06-09"}],code:{"@_code":"SEV","@_codeSystem":Re,"@_codeSystemName":"ActCode"},statusCode:{"@_code":"completed"},value:{"@_xsi:type":"CD","@_code":he.mapFhirToCcdaWithDefault(i.severity,"M"),"@_displayName":i.severity?W(i.severity):void 0,"@_codeSystem":k,"@_codeSystemName":"SNOMED CT"},text:this.createTextFromExtensions(i.extension)}]}]}]}]:[]}]}]}]}}mapAllergyCategory(e){if(!e||e.length===0)return;let i=Nt.mapFhirToCcdaCode(e[0]);if(i)return{"@_xsi:type":"CD",...i}}mapAuthor(e,i){if(!e)return;let n=this.findResourceByReference(e);if(n?.resourceType==="Practitioner")return[{templateId:[{"@_root":Hi}],time:i?{"@_value":O(i)}:void 0,assignedAuthor:{id:this.mapIdentifiers(n.id,n.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(n.address),telecom:this.mapTelecom(n.telecom),code:p(n.qualification?.[0]),assignedPerson:{name:this.mapNames(n.name)}}}]}mapCustodian(e){if(!e)return;let i=this.findResourceByReference(e);if(i)return{assignedCustodian:{representedCustodianOrganization:{id:this.mapIdentifiers(i.id,i.identifier),name:i.name?[i.name]:void 0,telecom:this.mapTelecom(i.telecom),addr:this.mapFhirAddressArrayToCcdaAddressArray(i.address)}}}}mapDocumentationOf(e){if(!e||e.length===0)return;let i=e[0];if(!(!i||!i.code&&!i.period))return{serviceEvent:{"@_classCode":"PCPR",code:p(i.code?.[0]),effectiveTime:this.mapEffectiveDate(void 0,i.period)}}}createMedicationEntry(e){let i=e.contained?.find(s=>s.resourceType==="Medication"),n=i?.code||e.medicationCodeableConcept,r=i?.manufacturer,o=[];if(e.dispenseRequest?.validityPeriod){let s=this.mapEffectiveDate(void 0,e.dispenseRequest.validityPeriod);s&&o.push(...s)}return e.dosageInstruction?.[0]?.timing?.repeat?.period&&o.push({"@_xsi:type":"PIVL_TS","@_institutionSpecified":"true","@_operator":"A",period:{"@_value":e.dosageInstruction[0].timing.repeat.period.toString(),"@_unit":e.dosageInstruction[0].timing.repeat.periodUnit}}),{substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN",templateId:[{"@_root":st,"@_extension":"2014-06-09"},{"@_root":st}],id:[{"@_root":e.id||crypto.randomUUID()}],text:this.createTextFromExtensions(e.extension),statusCode:{"@_code":me.mapFhirToCcdaWithDefault(e.status,"active")},effectiveTime:o,routeCode:this.mapMedicationRoute(e.dosageInstruction?.[0]?.route),doseQuantity:this.mapDoseQuantity(e.dosageInstruction?.[0]?.doseAndRate?.[0]),consumable:{"@_typeCode":"CSM",manufacturedProduct:[{"@_classCode":"MANU",templateId:[{"@_root":at,"@_extension":"2014-06-09"},{"@_root":at}],manufacturedMaterial:[{code:[{...p(n),originalText:this.createTextFromExtensions(i?.extension)}]}],manufacturerOrganization:r?[{id:this.mapIdentifiers(r.id,r.identifier?[r.identifier]:void 0),name:[r.display]}]:void 0}]},entryRelationship:e.dosageInstruction?.filter(s=>!!s.extension)?.map(s=>({"@_typeCode":"COMP",substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN",templateId:[{"@_root":Le}],code:{"@_code":"76662-6","@_codeSystem":M,"@_codeSystemName":"LOINC","@_displayName":"Medication Instructions"},text:this.createTextFromExtensions(s.extension),consumable:{manufacturedProduct:[{manufacturedLabeledDrug:[{"@_nullFlavor":"NA"}]}]}}]}))}]}}mapMedicationRoute(e){if(e)return p(e)}mapDoseQuantity(e){if(e?.doseQuantity)return{"@_value":e.doseQuantity.value?.toString(),"@_unit":e.doseQuantity.unit}}mapTelecom(e){return!e||e.length===0?[{"@_nullFlavor":"UNK"}]:e?.map(i=>({"@_use":i.use?de.mapFhirToCcda(i.use):void 0,"@_value":`${this.mapTelecomSystemToPrefix(i.system)}${i.value}`}))}mapTelecomSystemToPrefix(e){return e==="email"?"mailto:":e==="phone"?"tel:":e==="fax"?"fax:":""}mapIdentifiers(e,i){let n=[];if(e&&n.push({"@_root":e}),i)for(let r of i){let o=gt(r.system);o&&n.push({"@_root":o,"@_extension":r.value})}return n}getNarrativeReference(e){let i=e?.find(n=>n.url===ae)?.valueString;return i?{"@_value":i}:void 0}createTextFromExtensions(e){let i=this.getNarrativeReference(e);return i?{reference:i}:void 0}createProblemEntry(e){return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":tt},{"@_root":tt,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,void 0),code:{"@_code":"CONC","@_codeSystem":Qe},statusCode:{"@_code":fe.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:this.mapEffectivePeriod(e.recordedDate,void 0),entryRelationship:[{"@_typeCode":"SUBJ",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":J},{"@_root":J,"@_extension":"2015-08-01"}],id:e.identifier?this.mapIdentifiers(void 0,e.identifier):[{"@_root":Ce()}],text:this.createTextFromExtensions(e.extension),code:{"@_code":"55607006","@_codeSystem":k,"@_codeSystemName":"SNOMED CT","@_displayName":"Problem",translation:[{"@_code":"75323-6","@_codeSystem":M,"@_codeSystemName":"LOINC","@_displayName":"Condition"}]},statusCode:{"@_code":"completed"},effectiveTime:[{low:e.onsetDateTime?{"@_value":V(e.onsetDateTime)}:void 0,high:e.abatementDateTime?{"@_value":O(e.abatementDateTime)}:void 0}],value:G(e.code),author:this.mapAuthor(e.asserter,e.recordedDate)}]}]}]}}createImmunizationEntry(e){let i=e?.manufacturer,n={substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN","@_negationInd":"false",templateId:[{"@_root":dt},{"@_root":dt,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),text:this.createTextFromExtensions(e.extension),statusCode:{"@_code":_e.mapFhirToCcdaWithDefault(e.status,"completed")},effectiveTime:[{"@_value":V(e.occurrenceDateTime)}],consumable:{manufacturedProduct:[{"@_classCode":"MANU",templateId:[{"@_root":pt},{"@_root":pt,"@_extension":"2014-06-09"}],manufacturedMaterial:[{code:[p(e.vaccineCode)],lotNumberText:e.lotNumber?[e.lotNumber]:void 0}],manufacturerOrganization:i?[{id:this.mapIdentifiers(i.id,i.identifier?[i.identifier]:void 0),name:[i.display]}]:void 0}]}}]};return e.performer&&(n.substanceAdministration[0].performer=e.performer.map(r=>this.mapImmunizationPerformerToCcdaPerformer(r)).filter(Boolean)),n}mapImmunizationPerformerToCcdaPerformer(e){if(!e)return;let i=this.findResourceByReference(e.actor);if(!i)return;let n,r;return i.resourceType==="PractitionerRole"?(n=this.findResourceByReference(i.practitioner),r=this.findResourceByReference(i.organization)):i.resourceType==="Practitioner"?n=i:i.resourceType==="Organization"&&(r=i),{assignedEntity:{id:this.mapIdentifiers(i.id,i.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(n?.address),telecom:this.mapTelecom(i.telecom),assignedPerson:n?{id:this.mapIdentifiers(n.id,n.identifier),name:this.mapNames(n.name)}:void 0,representedOrganization:r?{id:this.mapIdentifiers(r.id,r.identifier),name:r.name?[r.name]:void 0,addr:this.mapFhirAddressArrayToCcdaAddressArray(r.address),telecom:this.mapTelecom(r.telecom)}:void 0}}}createObservationEntry(e){return e.hasMember?{organizer:[this.createVitalSignsOrganizer(e)]}:{observation:[this.createVitalSignObservation(e)]}}createPlanOfTreatmentCarePlanEntry(e){return{act:[{"@_classCode":"ACT","@_moodCode":"INT",id:this.mapIdentifiers(e.id,e.identifier),code:G(e.category?.[0]),templateId:[{"@_root":xi}],statusCode:{"@_code":"completed"},text:e.description?{"#text":e.description}:this.createTextFromExtensions(e.extension)}]}}createPlanOfTreatmentGoalEntry(e){return{observation:[{"@_classCode":"OBS","@_moodCode":"GOL",templateId:[{"@_root":Li}],id:this.mapIdentifiers(e.id,e.identifier),code:p(e.description),statusCode:{"@_code":this.mapGoalStatus(e.lifecycleStatus)},effectiveTime:[{"@_value":O(e.startDate)}],text:this.createTextFromExtensions(e.extension),entryRelationship:e.target?.map(n=>({"@_typeCode":"RSON","@_inversionInd":"true",act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":K},{"@_root":K,"@_extension":"2014-06-09"}],code:p(n.measure),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":O(e.startDate)}]}]}))}]}}mapGoalStatus(e){switch(e){case"achieved":return"completed";case"cancelled":return"cancelled";default:return"active"}}createVitalSignsOrganizer(e){let i=[];if(e.hasMember)for(let r of e.hasMember){let o=this.findResourceByReference(r);if(!(!o||o.resourceType!=="Observation"))if(o.component)for(let s of o.component)i.push({observation:[this.createVitalSignComponentObservation(o,s)]});else i.push({observation:[this.createVitalSignObservation(o)]})}return{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":ee},{"@_root":ee,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":O(e.effectiveDateTime)}],component:i}}createVitalSignObservation(e){return{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":O(e.effectiveDateTime)}],value:this.mapObservationValue(e),referenceRange:this.mapReferenceRangeArray(e.referenceRange),text:this.createTextFromExtensions(e.extension),author:this.mapAuthor(e.performer?.[0],e.effectiveDateTime)}}createVitalSignComponentObservation(e,i){return{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:p(i.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":O(e.effectiveDateTime)}],value:this.mapObservationValue(i),referenceRange:this.mapReferenceRangeArray(i.referenceRange),text:this.createTextFromExtensions(i.extension),author:this.mapAuthor(e.performer?.[0],e.effectiveDateTime)}}mapObservationTemplateId(e){if(e.code?.coding?.[0]?.code==="72166-2")return[{"@_root":ie},{"@_root":ie,"@_extension":"2014-06-09"}];if(e.code?.coding?.[0]?.code==="11367-0")return[{"@_root":ne},{"@_root":ne,"@_extension":"2014-06-09"}];if(e.category?.[0]?.coding?.[0]?.code){let i=Ee.getEntryByFhir(e.category?.[0]?.coding?.[0]?.code);if(i)return[{"@_root":i.ccdaValue},{"@_root":i.ccdaValue,"@_extension":"2014-06-09"}]}return[{"@_root":te},{"@_root":te,"@_extension":"2014-06-09"}]}mapObservationValue(e){if(e.valueQuantity)return{"@_xsi:type":"PQ","@_unit":e.valueQuantity.unit,"@_value":e.valueQuantity.value?.toString()};if(e.valueCodeableConcept)return G(e.valueCodeableConcept)}mapReferenceRangeArray(e){if(!(!e||e.length===0))return e.map(i=>this.mapReferenceRange(i)).filter(Boolean)}mapReferenceRange(e){if(!e)return;let i=this.getNarrativeReference(e.extension);return i?{observationRange:{text:{reference:i},value:{"@_xsi:type":"ED",reference:i}}}:{observationRange:{text:this.createTextFromExtensions(e.extension)}}}createHistoryOfProceduresEntry(e){if(e.resourceType==="Procedure"){let i=["183948003","409063005","311331002","61310001","183945009","309814009","278373008","410606002","183933003","24642003","225338006","128939004"],n=e.code?.coding?.[0]?.code;return n&&i.includes(n)?{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":K},{"@_root":K,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.performedDateTime,e.performedPeriod),text:this.createTextFromExtensions(e.extension)}]}:{procedure:[{"@_classCode":"PROC","@_moodCode":"EVN",templateId:[{"@_root":ot},{"@_root":ot,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.performedDateTime,e.performedPeriod),text:this.createTextFromExtensions(e.extension),targetSiteCode:p(e.bodySite?.[0]),participant:[this.mapLocationToParticipant(e.location)].filter(Boolean)}]}}if(e.resourceType==="Observation")return{observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:p(e.code),value:this.mapObservationValue(e),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.effectiveDateTime,e.effectivePeriod),text:this.createTextFromExtensions(e.extension)}]};throw new Error(`Unknown history of procedures resource type: ${e.resourceType}`)}mapLocationToParticipant(e){if(!e)return;let i=this.findResourceByReference(e);if(i)return{"@_typeCode":"LOC",participantRole:{"@_classCode":"SDLOC",templateId:[{"@_root":ut}],id:this.mapIdentifiers(i.id,i.identifier),code:p(i.type?.[0]),addr:i.address?this.mapFhirAddressArrayToCcdaAddressArray([i.address]):void 0,telecom:this.mapTelecom(i.telecom),playingEntity:{"@_classCode":"PLC",name:i.name?[i.name]:void 0}}}}mapEffectiveTime(e,i){if(i)return[{low:{"@_value":O(i.start)},high:{"@_value":O(i.end)}}];if(e)return[{"@_value":O(e)}]}mapEffectiveDate(e,i){if(i)return[{"@_xsi:type":"IVL_TS",low:i.start?{"@_value":V(i.start)}:void 0,high:i.end?{"@_value":V(i.end)}:void 0}];if(e)return[{"@_value":V(e)}]}mapEffectivePeriod(e,i,n=!1){if(!e&&!i)return;let r={};return e?r.low={"@_value":O(e)}:n&&(r.low={"@_nullFlavor":"NI"}),i?r.high={"@_value":O(i)}:n&&(r.high={"@_nullFlavor":"NI"}),[r]}createEncounterEntry(e){return{encounter:[{"@_classCode":"ENC","@_moodCode":"EVN",templateId:[{"@_root":lt},{"@_root":lt,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:p(e.type?.[0]),text:this.createTextFromExtensions(e.extension),effectiveTime:this.mapEffectiveTime(void 0,e.period),entryRelationship:e.participant?.map(i=>({"@_typeCode":"LOC",participantRole:{"@_classCode":"SDLOC",templateId:[{"@_root":ut}],code:p(i.type?.[0])}}))}]}}createCareTeamEntry(e){return{organizer:[{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":ht,"@_extension":"2022-07-01"},{"@_root":ht,"@_extension":"2022-06-01"}],id:this.mapIdentifiers(e.id,e.identifier),component:e.participant?.map(i=>({"@_typeCode":"PRF",role:i.role}))}]}}};0&&(module.exports={ACT_CODE_SYSTEM,ADDRESS_USE_MAPPER,ADDRESS_USE_VALUE_SET,ADMINISTRATIVE_GENDER_VALUE_SET,ALLERGIES_SECTION_TEMPLATE_IDS,ALLERGY_CATEGORY_MAPPER,ALLERGY_CLINICAL_CODE_SYSTEM,ALLERGY_SEVERITY_MAPPER,ALLERGY_STATUS_MAPPER,ALLERGY_VERIFICATION_CODE_SYSTEM,ASSESSMENTS_SECTION_TEMPLATE_IDS,CARE_TEAM_SECTION_TEMPLATE_IDS,CCDA_NARRATIVE_REFERENCE_URL,CCDA_TEMPLATE_CODE_SYSTEM,CCDA_TEMPLATE_IDS,CLINICAL_CONDITION_CODE_SYSTEM,CLINICAL_NOTES_SECTION_TEMPLATE_IDS,CONDITION_CATEGORY_CODE_SYSTEM,CONDITION_VERIFICATION_CODE_SYSTEM,CONDITION_VER_STATUS_CODE_SYSTEM,CONFIDENTIALITY_CODE_SYSTEM,CONFIDENTIALITY_MAPPER,CONTACT_ENTITY_USE_VALUE_SET,CVX_URL,DEVICES_SECTION_TEMPLATE_IDS,DIAGNOSIS_ROLE_CODE_SYSTEM,ENCOUNTERS_SECTION_TEMPLATE_IDS,ENCOUNTER_STATUS_MAPPER,EnumMapper,FHIR_CVX_URL,GENDER_MAPPER,GOALS_SECTION_TEMPLATE_IDS,HEALTH_CONCERNS_SECTION_TEMPLATE_IDS,HTTP,HUMAN_NAME_USE_MAPPER,IMMUNIZATIONS_SECTION_TEMPLATE_IDS,IMMUNIZATION_STATUS_MAPPER,INSURANCE_SECTION_TEMPLATE_IDS,LAB_TESTS_SECTION_TEMPLATE_IDS,LANGUAGE_MODE_CODE_SYSTEM,LANGUAGE_MODE_URL,LANGUAGE_PROFICIENCY_CODE_SYSTEM,LANGUAGE_PROFICIENCY_URL,LOINC_TO_TEMPLATE_IDS,MEDICATIONS_SECTION_TEMPLATE_IDS,MEDICATION_REQUEST_STATUS_VALUE_SET,MEDICATION_STATUS_MAPPER,MENTAL_STATUS_SECTION_TEMPLATE_IDS,NAME_USE_VALUE_SET,NCI_THESAURUS_URL,NDFRT_URL,NUCC_TAXONOMY_URL,OBSERVATION_CATEGORY_CODE_SYSTEM,OBSERVATION_CATEGORY_MAPPER,PARTICIPATION_CODE_SYSTEM,PATIENT_NOTES_SECTION_TEMPLATE_IDS,PLAN_OF_TREATMENT_SECTION_TEMPLATE_IDS,PROBLEMS_SECTION_TEMPLATE_IDS,PROBLEM_STATUS_MAPPER,PROCEDURES_SECTION_TEMPLATE_IDS,PROCEDURE_STATUS_MAPPER,RACE_CODE_SYSTEM,REASON_FOR_REFERRAL_SECTION_TEMPLATE_IDS,RESULTS_SECTION_TEMPLATE_IDS,SOCIAL_HISTORY_SECTION_TEMPLATE_IDS,SYSTEM_MAPPER,TELECOM_USE_MAPPER,UNII_URL,US_CORE_CONDITION_URL,US_CORE_ETHNICITY_URL,US_CORE_MEDICATION_REQUEST_URL,US_CORE_PATIENT_URL,US_CORE_RACE_URL,US_DRIVER_LICENSE_URL,US_NPI_URL,US_SSN_URL,VA_MEDRT_URL,VITAL_SIGNS_SECTION_TEMPLATE_IDS,XSI_URL,convertCcdaToFhir,convertCcdaToXml,convertFhirToCcda,convertToCompactXml,convertXmlToCcda,mapCcdaSystemToFhir,mapCcdaToFhirDate,mapCcdaToFhirDateTime,mapCodeableConceptToCcdaCode,mapCodeableConceptToCcdaValue,mapCodingToCcdaCode,mapFhirSystemToCcda,mapFhirToCcdaDate,mapFhirToCcdaDateTime,parseXml});
1
+ "use strict";var Ye=Object.defineProperty;var Wn=Object.getOwnPropertyDescriptor;var Qn=Object.getOwnPropertyNames;var zn=Object.prototype.hasOwnProperty;var Zn=(i,e)=>{for(var t in e)Ye(i,t,{get:e[t],enumerable:!0})},Xn=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Qn(e))!zn.call(i,r)&&r!==t&&Ye(i,r,{get:()=>e[r],enumerable:!(n=Wn(e,r))||n.enumerable});return i};var Jn=i=>Xn(Ye({},"__esModule",{value:!0}),i);var No={};Zn(No,{ACT_CODE_SYSTEM:()=>yt,ADDRESS_USE_MAPPER:()=>fe,ADDRESS_USE_VALUE_SET:()=>hn,ADMINISTRATIVE_GENDER_VALUE_SET:()=>_n,ALLERGIES_SECTION_TEMPLATE_IDS:()=>Dn,ALLERGY_CATEGORY_MAPPER:()=>Pt,ALLERGY_CLINICAL_CODE_SYSTEM:()=>ce,ALLERGY_SEVERITY_MAPPER:()=>Ee,ALLERGY_STATUS_MAPPER:()=>me,ALLERGY_VERIFICATION_CODE_SYSTEM:()=>Fe,ASSESSMENTS_SECTION_TEMPLATE_IDS:()=>wn,CARE_TEAM_SECTION_TEMPLATE_IDS:()=>Hn,CCDA_NARRATIVE_REFERENCE_URL:()=>de,CCDA_TEMPLATE_CODE_SYSTEM:()=>To,CCDA_TEMPLATE_IDS:()=>kt,CLINICAL_CONDITION_CODE_SYSTEM:()=>ke,CLINICAL_NOTES_SECTION_TEMPLATE_IDS:()=>go,CONDITION_CATEGORY_CODE_SYSTEM:()=>St,CONDITION_VERIFICATION_CODE_SYSTEM:()=>Ot,CONDITION_VER_STATUS_CODE_SYSTEM:()=>Be,CONFIDENTIALITY_CODE_SYSTEM:()=>dn,CONFIDENTIALITY_MAPPER:()=>vt,CONTACT_ENTITY_USE_VALUE_SET:()=>mn,CVX_URL:()=>Rn,DEVICES_SECTION_TEMPLATE_IDS:()=>Vn,DIAGNOSIS_ROLE_CODE_SYSTEM:()=>gt,ENCOUNTERS_SECTION_TEMPLATE_IDS:()=>kn,ENCOUNTER_STATUS_MAPPER:()=>bt,EnumMapper:()=>m,FHIR_CVX_URL:()=>Nn,GENDER_MAPPER:()=>xt,GOALS_SECTION_TEMPLATE_IDS:()=>Bn,HEALTH_CONCERNS_SECTION_TEMPLATE_IDS:()=>Fn,HTTP:()=>b,HUMAN_NAME_USE_MAPPER:()=>he,IMMUNIZATIONS_SECTION_TEMPLATE_IDS:()=>Ge,IMMUNIZATION_STATUS_MAPPER:()=>Te,INSURANCE_SECTION_TEMPLATE_IDS:()=>jn,LAB_TESTS_SECTION_TEMPLATE_IDS:()=>Ao,LANGUAGE_MODE_CODE_SYSTEM:()=>ho,LANGUAGE_MODE_URL:()=>mo,LANGUAGE_PROFICIENCY_CODE_SYSTEM:()=>fo,LANGUAGE_PROFICIENCY_URL:()=>Eo,LOINC_TO_TEMPLATE_IDS:()=>Bt,MEDICATIONS_SECTION_TEMPLATE_IDS:()=>vn,MEDICATION_REQUEST_STATUS_VALUE_SET:()=>En,MEDICATION_STATUS_MAPPER:()=>Oe,MENTAL_STATUS_SECTION_TEMPLATE_IDS:()=>Yn,NAME_USE_VALUE_SET:()=>fn,NCI_THESAURUS_URL:()=>In,NDFRT_URL:()=>An,NUCC_TAXONOMY_URL:()=>Cn,OBSERVATION_CATEGORY_CODE_SYSTEM:()=>pn,OBSERVATION_CATEGORY_MAPPER:()=>Lt,PARTICIPATION_CODE_SYSTEM:()=>Ct,PATIENT_NOTES_SECTION_TEMPLATE_IDS:()=>$n,PLAN_OF_TREATMENT_SECTION_TEMPLATE_IDS:()=>Mn,PROBLEMS_SECTION_TEMPLATE_IDS:()=>xn,PROBLEM_STATUS_MAPPER:()=>Ie,PROCEDURES_SECTION_TEMPLATE_IDS:()=>Un,PROCEDURE_STATUS_MAPPER:()=>Ut,RACE_CODE_SYSTEM:()=>_o,REASON_FOR_REFERRAL_SECTION_TEMPLATE_IDS:()=>Gn,RESULTS_SECTION_TEMPLATE_IDS:()=>Ln,SOCIAL_HISTORY_SECTION_TEMPLATE_IDS:()=>bn,SYSTEM_MAPPER:()=>pe,TELECOM_USE_MAPPER:()=>_e,UNII_URL:()=>yn,US_CORE_CONDITION_URL:()=>At,US_CORE_ETHNICITY_URL:()=>le,US_CORE_MEDICATION_REQUEST_URL:()=>Rt,US_CORE_PATIENT_URL:()=>Io,US_CORE_RACE_URL:()=>ue,US_DRIVER_LICENSE_URL:()=>On,US_NPI_URL:()=>Sn,US_SSN_URL:()=>Tn,VA_MEDRT_URL:()=>gn,VITAL_SIGNS_SECTION_TEMPLATE_IDS:()=>Pn,XSI_URL:()=>Nt,convertCcdaToFhir:()=>Co,convertCcdaToXml:()=>yo,convertFhirToCcda:()=>Ro,convertToCompactXml:()=>wt,convertXmlToCcda:()=>So,mapCcdaSystemToFhir:()=>F,mapCcdaToFhirDate:()=>Ne,mapCcdaToFhirDateTime:()=>f,mapCodeableConceptToCcdaCode:()=>d,mapCodeableConceptToCcdaValue:()=>G,mapCodingToCcdaCode:()=>Tt,mapFhirSystemToCcda:()=>Dt,mapFhirToCcdaDate:()=>V,mapFhirToCcdaDateTime:()=>T,parseXml:()=>Vt});module.exports=Jn(No);var Kn=class{constructor(i,e){this.operator=i,this.child=e}toString(){return`${this.operator}(${this.child.toString()})`}},q=class{constructor(i,e,t){this.operator=i,this.left=e,this.right=t}toString(){return`${this.left.toString()} ${this.operator} ${this.right.toString()}`}},er=class{constructor(){this.prefixParselets={},this.infixParselets={}}registerInfix(i,e){return this.infixParselets[i]=e,this}registerPrefix(i,e){return this.prefixParselets[i]=e,this}prefix(i,e,t){return this.registerPrefix(i,{parse(n,r){let o=n.consumeAndParse(e);return t(r,o)}})}infixLeft(i,e,t){return this.registerInfix(i,{parse(n,r,o){let s=n.consumeAndParse(e);return t(r,o,s)},precedence:e})}construct(i){return new tr(i,this.prefixParselets,this.infixParselets)}},tr=class{constructor(i,e,t){this.tokens=i,this.prefixParselets=e,this.infixParselets=t}hasMore(){return this.tokens.length>0}match(i){return this.peek()?.id!==i?!1:(this.consume(),!0)}consumeAndParse(i=1/0){let e=this.consume(),t=this.prefixParselets[e.id];if(!t)throw Error(`Parse error at "${e.value}" (line ${e.line}, column ${e.column}). No matching prefix parselet.`);let n=t.parse(this,e);for(;i>this.getPrecedence();){let r=this.consume();n=this.getInfixParselet(r).parse(this,n,r)}return n}getPrecedence(){let i=this.peek();if(!i)return 1/0;let e=this.getInfixParselet(i);return e?e.precedence:1/0}consume(i,e){if(!this.tokens.length)throw Error("Cant consume unknown more tokens.");if(i&&this.peek()?.id!==i){let t=this.peek();throw Error(`Expected ${i} but got "${t.id}" (${t.value}) at line ${t.line} column ${t.column}.`)}if(e&&this.peek()?.value!==e){let t=this.peek();throw Error(`Expected "${e}" but got "${t.value}" at line ${t.line} column ${t.column}.`)}return this.tokens.shift()}peek(){return this.tokens.length>0?this.tokens[0]:void 0}removeComments(){this.tokens=this.tokens.filter(i=>i.id!=="Comment")}getInfixParselet(i){return this.infixParselets[i.id==="Symbol"?i.value:i.id]}},He="http://unitsofmeasure.org",Ae="http://loinc.org",je="http://snomed.info/sct",Wt="http://www.nlm.nih.gov/research/umls/rxnorm",Qt="http://www.ama-assn.org/go/cpt";var zt="http://hl7.org/fhir/sid/ndc",_="http://hl7.org",I="http://terminology.hl7.org";var ir="unauthorized";var Ce={resourceType:"OperationOutcome",id:ir,issue:[{severity:"error",code:"login",details:{text:"Unauthorized"}}]},vo={...Ce,issue:[...Ce.issue,{severity:"error",code:"expired",details:{text:"Token expired"}}]},xo={...Ce,issue:[...Ce.issue,{severity:"error",code:"invalid",details:{text:"Token not issued for this audience"}}]};function nr(i,e){let t=e.max&&e.max===Number.MAX_SAFE_INTEGER?Number.POSITIVE_INFINITY:e.max;return{path:i,description:"",type:e.type??[],min:e.min??0,max:t??1,isArray:!!t&&t>1,constraints:[]}}function rr(i){let e=Object.create(null);for(let[t,n]of Object.entries(i))e[t]={name:t,type:t,path:t,elements:Object.fromEntries(Object.entries(n.elements).map(([r,o])=>[r,nr(r,o)])),constraints:[],innerTypes:[]};return e}var or={Element:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]}}},BackboneElement:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]}}},Address:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},use:{type:[{code:"code"}]},type:{type:[{code:"code"}]},text:{type:[{code:"string"}]},line:{max:9007199254740991,type:[{code:"string"}]},city:{type:[{code:"string"}]},district:{type:[{code:"string"}]},state:{type:[{code:"string"}]},postalCode:{type:[{code:"string"}]},country:{type:[{code:"string"}]},period:{type:[{code:"Period"}]}}},Age:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Annotation:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},"author[x]":{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Organization"]},{code:"string"}]},time:{type:[{code:"dateTime"}]},text:{min:1,type:[{code:"markdown"}]}}},Attachment:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},contentType:{type:[{code:"code"}]},language:{type:[{code:"code"}]},data:{type:[{code:"base64Binary"}]},url:{type:[{code:"url"}]},size:{type:[{code:"unsignedInt"}]},hash:{type:[{code:"base64Binary"}]},title:{type:[{code:"string"}]},creation:{type:[{code:"dateTime"}]}}},CodeableConcept:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},coding:{max:9007199254740991,type:[{code:"Coding"}]},text:{type:[{code:"string"}]}}},Coding:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},system:{type:[{code:"uri"}]},version:{type:[{code:"string"}]},code:{type:[{code:"code"}]},display:{type:[{code:"string"}]},userSelected:{type:[{code:"boolean"}]}}},ContactDetail:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},name:{type:[{code:"string"}]},telecom:{max:9007199254740991,type:[{code:"ContactPoint"}]}}},ContactPoint:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},system:{type:[{code:"code"}]},value:{type:[{code:"string"}]},use:{type:[{code:"code"}]},rank:{type:[{code:"positiveInt"}]},period:{type:[{code:"Period"}]}}},Contributor:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},name:{min:1,type:[{code:"string"}]},contact:{max:9007199254740991,type:[{code:"ContactDetail"}]}}},Count:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},DataRequirement:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},profile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]},"subject[x]":{type:[{code:"CodeableConcept"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Group"]}]},mustSupport:{max:9007199254740991,type:[{code:"string"}]},codeFilter:{max:9007199254740991,type:[{code:"DataRequirementCodeFilter"}]},dateFilter:{max:9007199254740991,type:[{code:"DataRequirementDateFilter"}]},limit:{type:[{code:"positiveInt"}]},sort:{max:9007199254740991,type:[{code:"DataRequirementSort"}]}}},DataRequirementCodeFilter:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{type:[{code:"string"}]},searchParam:{type:[{code:"string"}]},valueSet:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/ValueSet"]}]},code:{max:9007199254740991,type:[{code:"Coding"}]}}},DataRequirementDateFilter:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{type:[{code:"string"}]},searchParam:{type:[{code:"string"}]},"value[x]":{type:[{code:"dateTime"},{code:"Period"},{code:"Duration"}]}}},DataRequirementSort:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},direction:{min:1,type:[{code:"code"}]}}},Distance:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Dosage:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},sequence:{type:[{code:"integer"}]},text:{type:[{code:"string"}]},additionalInstruction:{max:9007199254740991,type:[{code:"CodeableConcept"}]},patientInstruction:{type:[{code:"string"}]},timing:{type:[{code:"Timing"}]},"asNeeded[x]":{type:[{code:"boolean"},{code:"CodeableConcept"}]},site:{type:[{code:"CodeableConcept"}]},route:{type:[{code:"CodeableConcept"}]},method:{type:[{code:"CodeableConcept"}]},doseAndRate:{max:9007199254740991,type:[{code:"DosageDoseAndRate"}]},maxDosePerPeriod:{type:[{code:"Ratio"}]},maxDosePerAdministration:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},maxDosePerLifetime:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},DosageDoseAndRate:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{type:[{code:"CodeableConcept"}]},"dose[x]":{type:[{code:"Range"},{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},"rate[x]":{type:[{code:"Ratio"},{code:"Range"},{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},Duration:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},ElementDefinition:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},representation:{max:9007199254740991,type:[{code:"code"}]},sliceName:{type:[{code:"string"}]},sliceIsConstraining:{type:[{code:"boolean"}]},label:{type:[{code:"string"}]},code:{max:9007199254740991,type:[{code:"Coding"}]},slicing:{type:[{code:"ElementDefinitionSlicing"}]},short:{type:[{code:"string"}]},definition:{type:[{code:"markdown"}]},comment:{type:[{code:"markdown"}]},requirements:{type:[{code:"markdown"}]},alias:{max:9007199254740991,type:[{code:"string"}]},min:{type:[{code:"unsignedInt"}]},max:{type:[{code:"string"}]},base:{type:[{code:"ElementDefinitionBase"}]},contentReference:{type:[{code:"uri"}]},type:{max:9007199254740991,type:[{code:"ElementDefinitionType"}]},"defaultValue[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},meaningWhenMissing:{type:[{code:"markdown"}]},orderMeaning:{type:[{code:"string"}]},"fixed[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},"pattern[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},example:{max:9007199254740991,type:[{code:"ElementDefinitionExample"}]},"minValue[x]":{type:[{code:"date"},{code:"dateTime"},{code:"instant"},{code:"time"},{code:"decimal"},{code:"integer"},{code:"positiveInt"},{code:"unsignedInt"},{code:"Quantity"}]},"maxValue[x]":{type:[{code:"date"},{code:"dateTime"},{code:"instant"},{code:"time"},{code:"decimal"},{code:"integer"},{code:"positiveInt"},{code:"unsignedInt"},{code:"Quantity"}]},maxLength:{type:[{code:"integer"}]},condition:{max:9007199254740991,type:[{code:"id"}]},constraint:{max:9007199254740991,type:[{code:"ElementDefinitionConstraint"}]},mustSupport:{type:[{code:"boolean"}]},isModifier:{type:[{code:"boolean"}]},isModifierReason:{type:[{code:"string"}]},isSummary:{type:[{code:"boolean"}]},binding:{type:[{code:"ElementDefinitionBinding"}]},mapping:{max:9007199254740991,type:[{code:"ElementDefinitionMapping"}]}}},ElementDefinitionSlicingDiscriminator:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},path:{min:1,type:[{code:"string"}]}}},ElementDefinitionSlicing:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},discriminator:{max:9007199254740991,type:[{code:"ElementDefinitionSlicingDiscriminator"}]},description:{type:[{code:"string"}]},ordered:{type:[{code:"boolean"}]},rules:{min:1,type:[{code:"code"}]}}},ElementDefinitionBase:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},min:{min:1,type:[{code:"unsignedInt"}]},max:{min:1,type:[{code:"string"}]}}},ElementDefinitionType:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},code:{min:1,type:[{code:"uri"}]},profile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition","http://hl7.org/fhir/StructureDefinition/ImplementationGuide"]}]},targetProfile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition","http://hl7.org/fhir/StructureDefinition/ImplementationGuide"]}]},aggregation:{max:9007199254740991,type:[{code:"code"}]},versioning:{type:[{code:"code"}]}}},ElementDefinitionExample:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},label:{min:1,type:[{code:"string"}]},"value[x]":{min:1,type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]}}},ElementDefinitionConstraint:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},key:{min:1,type:[{code:"id"}]},requirements:{type:[{code:"string"}]},severity:{min:1,type:[{code:"code"}]},human:{min:1,type:[{code:"string"}]},expression:{type:[{code:"string"}]},xpath:{type:[{code:"string"}]},source:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]}}},ElementDefinitionBinding:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},strength:{min:1,type:[{code:"code"}]},description:{type:[{code:"string"}]},valueSet:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/ValueSet"]}]}}},ElementDefinitionMapping:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},identity:{min:1,type:[{code:"id"}]},language:{type:[{code:"code"}]},map:{min:1,type:[{code:"string"}]},comment:{type:[{code:"string"}]}}},Expression:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},description:{type:[{code:"string"}]},name:{type:[{code:"id"}]},language:{min:1,type:[{code:"code"}]},expression:{type:[{code:"string"}]},reference:{type:[{code:"uri"}]}}},Extension:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},url:{min:1,type:[{code:"uri"}]},"value[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]}}},HumanName:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},use:{type:[{code:"code"}]},text:{type:[{code:"string"}]},family:{type:[{code:"string"}]},given:{max:9007199254740991,type:[{code:"string"}]},prefix:{max:9007199254740991,type:[{code:"string"}]},suffix:{max:9007199254740991,type:[{code:"string"}]},period:{type:[{code:"Period"}]}}},Identifier:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},use:{type:[{code:"code"}]},type:{type:[{code:"CodeableConcept"}]},system:{type:[{code:"uri"}]},value:{type:[{code:"string"}]},period:{type:[{code:"Period"}]},assigner:{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Organization"]}]}}},MarketingStatus:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},country:{min:1,type:[{code:"CodeableConcept"}]},jurisdiction:{type:[{code:"CodeableConcept"}]},status:{min:1,type:[{code:"CodeableConcept"}]},dateRange:{min:1,type:[{code:"Period"}]},restoreDate:{type:[{code:"dateTime"}]}}},Meta:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},versionId:{type:[{code:"id"}]},lastUpdated:{type:[{code:"instant"}]},source:{type:[{code:"uri"}]},profile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]},security:{max:9007199254740991,type:[{code:"Coding"}]},tag:{max:9007199254740991,type:[{code:"Coding"}]},project:{type:[{code:"uri"}]},author:{type:[{code:"Reference"}]},onBehalfOf:{type:[{code:"Reference"}]},account:{type:[{code:"Reference"}]},accounts:{max:9007199254740991,type:[{code:"Reference"}]},compartment:{max:9007199254740991,type:[{code:"Reference"}]}}},Money:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},currency:{type:[{code:"code"}]}}},Narrative:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},status:{min:1,type:[{code:"code"}]},div:{min:1,type:[{code:"xhtml"}]}}},ParameterDefinition:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},name:{type:[{code:"code"}]},use:{min:1,type:[{code:"code"}]},min:{type:[{code:"integer"}]},max:{type:[{code:"string"}]},documentation:{type:[{code:"string"}]},type:{min:1,type:[{code:"code"}]},profile:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]}}},Period:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},start:{type:[{code:"dateTime"}]},end:{type:[{code:"dateTime"}]}}},Population:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},"age[x]":{type:[{code:"Range"},{code:"CodeableConcept"}]},gender:{type:[{code:"CodeableConcept"}]},race:{type:[{code:"CodeableConcept"}]},physiologicalCondition:{type:[{code:"CodeableConcept"}]}}},ProdCharacteristic:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},height:{type:[{code:"Quantity"}]},width:{type:[{code:"Quantity"}]},depth:{type:[{code:"Quantity"}]},weight:{type:[{code:"Quantity"}]},nominalVolume:{type:[{code:"Quantity"}]},externalDiameter:{type:[{code:"Quantity"}]},shape:{type:[{code:"string"}]},color:{max:9007199254740991,type:[{code:"string"}]},imprint:{max:9007199254740991,type:[{code:"string"}]},image:{max:9007199254740991,type:[{code:"Attachment"}]},scoring:{type:[{code:"CodeableConcept"}]}}},ProductShelfLife:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},identifier:{type:[{code:"Identifier"}]},type:{min:1,type:[{code:"CodeableConcept"}]},period:{min:1,type:[{code:"Quantity"}]},specialPrecautionsForStorage:{max:9007199254740991,type:[{code:"CodeableConcept"}]}}},Quantity:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Range:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},low:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},high:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},Ratio:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},numerator:{type:[{code:"Quantity"}]},denominator:{type:[{code:"Quantity"}]}}},Reference:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},reference:{type:[{code:"string"}]},type:{type:[{code:"uri"}]},identifier:{type:[{code:"Identifier"}]},display:{type:[{code:"string"}]}}},RelatedArtifact:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},label:{type:[{code:"string"}]},display:{type:[{code:"string"}]},citation:{type:[{code:"markdown"}]},url:{type:[{code:"url"}]},document:{type:[{code:"Attachment"}]},resource:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/Resource"]}]}}},SampledData:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},origin:{min:1,type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},period:{min:1,type:[{code:"decimal"}]},factor:{type:[{code:"decimal"}]},lowerLimit:{type:[{code:"decimal"}]},upperLimit:{type:[{code:"decimal"}]},dimensions:{min:1,type:[{code:"positiveInt"}]},data:{type:[{code:"string"}]}}},Signature:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,max:9007199254740991,type:[{code:"Coding"}]},when:{min:1,type:[{code:"instant"}]},who:{min:1,type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/PractitionerRole","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/Device","http://hl7.org/fhir/StructureDefinition/Organization"]}]},onBehalfOf:{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/PractitionerRole","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/Device","http://hl7.org/fhir/StructureDefinition/Organization"]}]},targetFormat:{type:[{code:"code"}]},sigFormat:{type:[{code:"code"}]},data:{type:[{code:"base64Binary"}]}}},SubstanceAmount:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},"amount[x]":{type:[{code:"Quantity"},{code:"Range"},{code:"string"}]},amountType:{type:[{code:"CodeableConcept"}]},amountText:{type:[{code:"string"}]},referenceRange:{type:[{code:"SubstanceAmountReferenceRange"}]}}},SubstanceAmountReferenceRange:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},lowLimit:{type:[{code:"Quantity"}]},highLimit:{type:[{code:"Quantity"}]}}},Timing:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},event:{max:9007199254740991,type:[{code:"dateTime"}]},repeat:{type:[{code:"TimingRepeat"}]},code:{type:[{code:"CodeableConcept"}]}}},TimingRepeat:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},"bounds[x]":{type:[{code:"Duration"},{code:"Range"},{code:"Period"}]},count:{type:[{code:"positiveInt"}]},countMax:{type:[{code:"positiveInt"}]},duration:{type:[{code:"decimal"}]},durationMax:{type:[{code:"decimal"}]},durationUnit:{type:[{code:"code"}]},frequency:{type:[{code:"positiveInt"}]},frequencyMax:{type:[{code:"positiveInt"}]},period:{type:[{code:"decimal"}]},periodMax:{type:[{code:"decimal"}]},periodUnit:{type:[{code:"code"}]},dayOfWeek:{max:9007199254740991,type:[{code:"code"}]},timeOfDay:{max:9007199254740991,type:[{code:"time"}]},when:{max:9007199254740991,type:[{code:"code"}]},offset:{type:[{code:"unsignedInt"}]}}},TriggerDefinition:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},name:{type:[{code:"string"}]},"timing[x]":{type:[{code:"Timing"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Schedule"]},{code:"date"},{code:"dateTime"}]},data:{max:9007199254740991,type:[{code:"DataRequirement"}]},condition:{type:[{code:"Expression"}]}}},UsageContext:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},code:{min:1,type:[{code:"Coding"}]},"value[x]":{min:1,type:[{code:"CodeableConcept"},{code:"Quantity"},{code:"Range"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/PlanDefinition","http://hl7.org/fhir/StructureDefinition/ResearchStudy","http://hl7.org/fhir/StructureDefinition/InsurancePlan","http://hl7.org/fhir/StructureDefinition/HealthcareService","http://hl7.org/fhir/StructureDefinition/Group","http://hl7.org/fhir/StructureDefinition/Location","http://hl7.org/fhir/StructureDefinition/Organization"]}]}}},MoneyQuantity:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},SimpleQuantity:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{max:0,type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},IdentityProvider:{elements:{authorizeUrl:{min:1,type:[{code:"string"}]},tokenUrl:{min:1,type:[{code:"string"}]},tokenAuthMethod:{type:[{code:"code"}]},userInfoUrl:{min:1,type:[{code:"string"}]},clientId:{min:1,type:[{code:"string"}]},clientSecret:{min:1,type:[{code:"string"}]},usePkce:{type:[{code:"boolean"}]},useSubject:{type:[{code:"boolean"}]}}}};var sr=rr(or);var Gt=Object.create(null);function ar(i){let e;return e=Gt[i],e||(e=Gt[i]=Object.create(null)),e}function cr(i,e){if(e){let t=ar(e)[i];if(t)return t}return sr[i]}var Zt={base64Binary:/^([A-Za-z\d+/]{4})*([A-Za-z\d+/]{2}==|[A-Za-z\d+/]{3}=)?$/,canonical:/^\S*$/,code:/^[^\s]+( [^\s]+)*$/,date:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1]))?)?$/,dateTime:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1])(T([01]\d|2[0-3])(:[0-5]\d:([0-5]\d|60)(\.\d{1,9})?)?)?)?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00)?)?)?$/,id:/^[A-Za-z0-9\-.]{1,64}$/,instant:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])T([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00))$/,markdown:/^[\r\n\t\u0020-\uFFFF]+$/,oid:/^urn:oid:[0-2](\.(0|[1-9]\d*))+$/,string:/^[\r\n\t\u0020-\uFFFF]+$/,time:/^([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?$/,uri:/^\S*$/,url:/^\S*$/,uuid:/^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,xhtml:/.*/};function a(i){return[{type:u.boolean,value:i}]}function L(i){return i==null?{type:"undefined",value:void 0}:Number.isSafeInteger(i)?{type:u.integer,value:i}:typeof i=="number"?{type:u.decimal,value:i}:typeof i=="boolean"?{type:u.boolean,value:i}:typeof i=="string"?{type:u.string,value:i}:y(i)?{type:u.Quantity,value:i}:Q(i)?{type:i.resourceType,value:i}:ni(i)?{type:u.CodeableConcept,value:i}:ii(i)?{type:u.Coding,value:i}:{type:u.BackboneElement,value:i}}function v(i){return i.length===0?!1:!!i[0].value}function x(i,e){if(i.length!==0){if(i.length===1&&(!e||i[0].type===e))return i[0];throw new Error(`Expected singleton of type ${e}, but found ${JSON.stringify(i)}`)}}function ur(i,e,t){if(!i.value)return;let n=br(i.type,e,t?.profileUrl);return n?lr(i,e,n):dr(i,e)}function lr(i,e,t){let n=i.value,r=t.type;if(!r||r.length===0)return;let o,s="undefined",c,p=t.path.lastIndexOf("."),N=t.path.substring(p+1);for(let E of r){let $=N.replace("[x]",W(E.code));if(o=n[$],c=n["_"+$],o!==void 0||c!==void 0){s=E.code;break}}if(c)if(Array.isArray(o)){o=o.slice();for(let E=0;E<Math.max(o.length,c.length);E++)o[E]=jt(o[E],c[E])}else o=jt(o,c);if(!j(o))return(s==="Element"||s==="BackboneElement")&&(s=t.type[0].code),Array.isArray(o)?o.map(E=>Yt(E,s)):Yt(o,s)}function Yt(i,e){return e==="Resource"&&Q(i)&&(e=i.resourceType),{type:e,value:i}}function dr(i,e){let t=i.value;if(!t||typeof t!="object")return;let n;if(e in t){let r=t[e];Array.isArray(r)?n=r.map(L):n=L(r)}else{let r=e.endsWith("[x]")?e.substring(0,e.length-3):e;for(let o of Object.values(u)){let s=r+W(o);if(s in t){let c=t[s];Array.isArray(c)?n=c.map(p=>({type:o,value:p})):n={type:o,value:c};break}}}if(Array.isArray(n)){if(n.length===0||j(n[0]))return}else if(j(n))return;return n}function Xt(i){let e=[];for(let t of i){let n=!1;for(let r of e)if(v(qe(t,r))){n=!0;break}n||e.push(t)}return e}function pr(i){return a(!v(i))}function hr(i,e){return i.length===0||e.length===0?[]:i.length!==e.length?a(!1):a(i.every((t,n)=>v(qe(t,e[n]))))}function fr(i,e){return i.length===0||e.length===0?[]:i.length!==e.length?a(!0):a(i.some((t,n)=>!v(qe(t,e[n]))))}function qe(i,e){let t=i.value?.valueOf(),n=e.value?.valueOf();return typeof t=="number"&&typeof n=="number"?a(Math.abs(t-n)<1e-8):y(t)&&y(n)?a(ei(t,n)):a(typeof t=="object"&&typeof n=="object"?We(i,e):t===n)}function Jt(i,e){return i.length===0&&e.length===0?a(!0):i.length!==e.length?a(!1):(i.sort($t),e.sort($t),a(i.every((t,n)=>v(_r(t,e[n])))))}function _r(i,e){let{type:t,value:n}=i,{type:r,value:o}=e,s=n?.valueOf(),c=o?.valueOf();return typeof s=="number"&&typeof c=="number"?a(Math.abs(s-c)<.01):y(s)&&y(c)?a(ei(s,c)):a(t==="Coding"&&r==="Coding"?typeof s!="object"||typeof c!="object"?!1:s.code===c.code&&s.system===c.system:typeof s=="object"&&typeof c=="object"?We({...s,id:void 0},{...c,id:void 0}):typeof s=="string"&&typeof c=="string"?s.toLowerCase()===c.toLowerCase():s===c)}function $t(i,e){let t=i.value?.valueOf(),n=e.value?.valueOf();return typeof t=="number"&&typeof n=="number"?t-n:typeof t=="string"&&typeof n=="string"?t.localeCompare(n):0}function Kt(i,e){let{value:t}=i;if(t==null)return!1;switch(e){case"Boolean":return typeof t=="boolean";case"Decimal":case"Integer":return typeof t=="number";case"Date":return mr(t);case"DateTime":return $e(t);case"Time":return typeof t=="string"&&!!/^T\d/.exec(t);case"Period":return Er(t);case"Quantity":return y(t);default:return i.type===e||typeof t=="object"&&t?.resourceType===e}}function mr(i){return typeof i=="string"&&!!Zt.date.exec(i)}function $e(i){return typeof i=="string"&&!!Zt.dateTime.exec(i)}function Er(i){return!!(i&&typeof i=="object"&&("start"in i&&$e(i.start)||"end"in i&&$e(i.end)))}function y(i){return!!(i&&typeof i=="object"&&"value"in i&&typeof i.value=="number")}function ei(i,e){return Math.abs(i.value-e.value)<.01&&(i.unit===e.unit||i.code===e.code||i.unit===e.code||i.code===e.unit)}function We(i,e){let t=Object.keys(i),n=Object.keys(e);if(t.length!==n.length)return!1;for(let r of t){let o=i[r],s=e[r];if(Ht(o)&&Ht(s)){if(!We(o,s))return!1}else if(o!==s)return!1}return!0}function Ht(i){return i!==null&&typeof i=="object"}function jt(i,e){if(e){if(typeof e!="object")throw new Error("Primitive extension must be an object");return Ir(i??{},e)}return i}function Ir(i,e){return delete e.__proto__,delete e.constructor,Object.assign(i,e)}function Tr(i,e){return Q(i,e)&&"id"in i&&typeof i.id=="string"}function h(i){let e=ti(i)??"undefined/undefined",t=yr(i);return t===e?{reference:e}:{reference:e,display:t}}function ti(i){if(ri(i))return i.reference;if(Tr(i))return`${i.resourceType}/${i.id}`}function Or(i){if(i)return ri(i)?i.reference.split("/")[1]:i.id}function Sr(i){return i.resourceType==="Patient"||i.resourceType==="Practitioner"||i.resourceType==="RelatedPerson"}function yr(i){if(Sr(i)){let e=Cr(i);if(e)return e}if(i.resourceType==="Device"){let e=gr(i);if(e)return e}if(i.resourceType==="MedicationRequest"&&i.medicationCodeableConcept)return qt(i.medicationCodeableConcept);if(i.resourceType==="Subscription"&&i.criteria)return i.criteria;if(i.resourceType==="User"&&i.email)return i.email;if("name"in i&&i.name&&typeof i.name=="string")return i.name;if("code"in i&&i.code){let e=i.code;if(Array.isArray(e)&&(e=e[0]),ni(e))return qt(e);if(Dr(e))return e.text}return ti(i)??""}function Cr(i){let e=i.name;if(e&&e.length>0)return xr(e[0])}function gr(i){let e=i.deviceName;if(e&&e.length>0)return e[0].name}function Ar(i,e){let t=new Date(i);t.setUTCHours(0,0,0,0);let n=e?new Date(e):new Date;n.setUTCHours(0,0,0,0);let r=t.getUTCFullYear(),o=t.getUTCMonth(),s=t.getUTCDate(),c=n.getUTCFullYear(),p=n.getUTCMonth(),N=n.getUTCDate(),E=c-r;(p<o||p===o&&N<s)&&E--;let $=c*12+p-(r*12+o);N<s&&$--;let qn=Math.floor((n.getTime()-t.getTime())/(1e3*60*60*24));return{years:E,months:$,days:qn}}function Rr(i,...e){let t=i;for(let n=0;n<e.length&&t;n++)t=t?.extension?.find(r=>r.url===e[n]);return t}function j(i){if(i==null)return!0;let e=typeof i;return e==="string"||e==="object"?!Nr(i):!1}function Nr(i){if(i==null)return!1;let e=typeof i;return e==="string"&&i!==""||e==="object"&&("length"in i&&i.length>0||Object.keys(i).length>0)}function Qe(i){return!!/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i.exec(i)}function ze(i){return i!==null&&typeof i=="object"}function ii(i){return ze(i)&&"code"in i&&typeof i.code=="string"}function ni(i){return ze(i)&&"coding"in i&&Array.isArray(i.coding)&&i.coding.every(ii)}function Dr(i){return ze(i)&&"text"in i&&typeof i.text=="string"}var vr=[];for(let i=0;i<256;i++)vr.push(i.toString(16).padStart(2,"0"));function W(i){return i?i.charAt(0).toUpperCase()+i.substring(1):""}function xr(i,e){let t=[];if(i.prefix&&e?.prefix!==!1&&t.push(...i.prefix),i.given&&t.push(...i.given),i.family&&t.push(i.family),i.suffix&&e?.suffix!==!1&&t.push(...i.suffix),i.use&&(e?.all||e?.use)&&t.push("["+i.use+"]"),t.length===0){let n=H(i.text);if(n)return n}return t.join(" ").trim()}function qt(i){return i?H(i.text)||(i.coding?i.coding.map(t=>Pr(t)).join(", "):""):""}function Pr(i,e){let t=H(i?.display);if(t){let n=e?H(i?.code):void 0;return`${t}${n?" ("+n+")":""}`}return H(i?.code)??""}function H(i){return typeof i=="string"?i:void 0}var u={Address:"Address",Age:"Age",Annotation:"Annotation",Attachment:"Attachment",BackboneElement:"BackboneElement",CodeableConcept:"CodeableConcept",Coding:"Coding",ContactDetail:"ContactDetail",ContactPoint:"ContactPoint",Contributor:"Contributor",Count:"Count",DataRequirement:"DataRequirement",Distance:"Distance",Dosage:"Dosage",Duration:"Duration",Expression:"Expression",Extension:"Extension",HumanName:"HumanName",Identifier:"Identifier",MarketingStatus:"MarketingStatus",Meta:"Meta",Money:"Money",Narrative:"Narrative",ParameterDefinition:"ParameterDefinition",Period:"Period",Population:"Population",ProdCharacteristic:"ProdCharacteristic",ProductShelfLife:"ProductShelfLife",Quantity:"Quantity",Range:"Range",Ratio:"Ratio",Reference:"Reference",RelatedArtifact:"RelatedArtifact",SampledData:"SampledData",Signature:"Signature",SubstanceAmount:"SubstanceAmount",SystemString:"http://hl7.org/fhirpath/System.String",Timing:"Timing",TriggerDefinition:"TriggerDefinition",UsageContext:"UsageContext",base64Binary:"base64Binary",boolean:"boolean",canonical:"canonical",code:"code",date:"date",dateTime:"dateTime",decimal:"decimal",id:"id",instant:"instant",integer:"integer",markdown:"markdown",oid:"oid",positiveInt:"positiveInt",string:"string",time:"time",unsignedInt:"unsignedInt",uri:"uri",url:"url",uuid:"uuid"};function br(i,e,t){let n=cr(i,t);if(n)return Ur(n.elements,e)}function Ur(i,e){let t=i[e]??i[e+"[x]"];if(t)return t;for(let n=0;n<e.length;n++){let r=e[n];if(r>="A"&&r<="Z"){let o=e.slice(0,n)+"[x]",s=i[o];if(s)return s}}}function Q(i,e){return!(!i||typeof i!="object"||!("resourceType"in i)||e&&i.resourceType!==e)}function ri(i){return!!(i&&typeof i=="object"&&"reference"in i&&typeof i.reference=="string")}function ye(i){if(i.startsWith("T"))return i+"T00:00:00.000Z".substring(i.length);if(i.length<=10)return i;try{return new Date(i).toISOString()}catch{return i}}var D=()=>[],O={empty:(i,e)=>a(e.length===0||e.every(t=>j(t.value))),hasValue:(i,e)=>a(e.length!==0),exists:(i,e,t)=>a(t?e.filter(n=>v(t.eval(i,[n]))).length>0:e.length>0&&e.every(n=>!j(n.value))),all:(i,e,t)=>a(e.every(n=>v(t.eval(i,[n])))),allTrue:(i,e)=>{for(let t of e)if(!t.value)return a(!1);return a(!0)},anyTrue:(i,e)=>{for(let t of e)if(t.value)return a(!0);return a(!1)},allFalse:(i,e)=>{for(let t of e)if(t.value)return a(!1);return a(!0)},anyFalse:(i,e)=>{for(let t of e)if(!t.value)return a(!0);return a(!1)},subsetOf:(i,e,t)=>{if(e.length===0)return a(!0);let n=t.eval(i,U(i));return n.length===0?a(!1):a(e.every(r=>n.some(o=>o.value===r.value)))},supersetOf:(i,e,t)=>{let n=t.eval(i,U(i));return n.length===0?a(!0):e.length===0?a(!1):a(n.every(r=>e.some(o=>o.value===r.value)))},count:(i,e)=>[{type:u.integer,value:e.length}],distinct:(i,e)=>{let t=[];for(let n of e)t.some(r=>r.value===n.value)||t.push(n);return t},isDistinct:(i,e)=>a(e.length===O.distinct(i,e).length),where:(i,e,t)=>e.filter(n=>v(t.eval(i,[n]))),select:(i,e,t)=>e.map(n=>t.eval({parent:i,variables:{$this:n}},[n])).flat(),repeat:D,ofType:(i,e,t)=>e.filter(n=>n.type===t.name),single:(i,e)=>{if(e.length>1)throw new Error("Expected input length one for single()");return e.length===0?[]:e.slice(0,1)},first:(i,e)=>e.length===0?[]:e.slice(0,1),last:(i,e)=>e.length===0?[]:e.slice(e.length-1,e.length),tail:(i,e)=>e.length===0?[]:e.slice(1,e.length),skip:(i,e,t)=>{let n=t.eval(i,e)[0]?.value;if(typeof n!="number")throw new Error("Expected a number for skip(num)");return n>=e.length?[]:n<=0?e:e.slice(n,e.length)},take:(i,e,t)=>{let n=t.eval(i,e)[0]?.value;if(typeof n!="number")throw new Error("Expected a number for take(num)");return n>=e.length?e:n<=0?[]:e.slice(0,n)},intersect:(i,e,t)=>{if(!t)return e;let n=t.eval(i,U(i)),r=[];for(let o of e)!r.some(s=>s.value===o.value)&&n.some(s=>s.value===o.value)&&r.push(o);return r},exclude:(i,e,t)=>{if(!t)return e;let n=t.eval(i,U(i)),r=[];for(let o of e)n.some(s=>s.value===o.value)||r.push(o);return r},union:(i,e,t)=>{if(!t)return e;let n=t.eval(i,U(i));return Xt([...e,...n])},combine:(i,e,t)=>{if(!t)return e;let n=t.eval(i,U(i));return[...e,...n]},htmlChecks:(i,e,t)=>[L(!0)],iif:(i,e,t,n,r)=>{let o=t.eval(i,e);if(o.length>1||o.length===1&&typeof o[0].value!="boolean")throw new Error("Expected criterion to evaluate to a Boolean");return v(o)?n.eval(i,e):r?r.eval(i,e):[]},toBoolean:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);if(typeof t=="boolean")return[{type:u.boolean,value:t}];if(typeof t=="number"&&(t===0||t===1))return a(!!t);if(typeof t=="string"){let n=t.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(n))return a(!0);if(["false","f","no","n","0","0.0"].includes(n))return a(!1)}return[]},convertsToBoolean:(i,e)=>e.length===0?[]:a(O.toBoolean(i,e).length===1),toInteger:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return typeof t=="number"?[{type:u.integer,value:t}]:typeof t=="string"&&/^[+-]?\d+$/.exec(t)?[{type:u.integer,value:parseInt(t,10)}]:typeof t=="boolean"?[{type:u.integer,value:t?1:0}]:[]},convertsToInteger:(i,e)=>e.length===0?[]:a(O.toInteger(i,e).length===1),toDate:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return typeof t=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(t)?[{type:u.date,value:ye(t)}]:[]},convertsToDate:(i,e)=>e.length===0?[]:a(O.toDate(i,e).length===1),toDateTime:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return typeof t=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(t)?[{type:u.dateTime,value:ye(t)}]:[]},convertsToDateTime:(i,e)=>e.length===0?[]:a(O.toDateTime(i,e).length===1),toDecimal:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return typeof t=="number"?[{type:u.decimal,value:t}]:typeof t=="string"&&/^-?\d{1,9}(\.\d{1,9})?$/.exec(t)?[{type:u.decimal,value:parseFloat(t)}]:typeof t=="boolean"?[{type:u.decimal,value:t?1:0}]:[]},convertsToDecimal:(i,e)=>e.length===0?[]:a(O.toDecimal(i,e).length===1),toQuantity:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return y(t)?[{type:u.Quantity,value:t}]:typeof t=="number"?[{type:u.Quantity,value:{value:t,unit:"1"}}]:typeof t=="string"&&/^-?\d{1,9}(\.\d{1,9})?/.exec(t)?[{type:u.Quantity,value:{value:parseFloat(t),unit:"1"}}]:typeof t=="boolean"?[{type:u.Quantity,value:{value:t?1:0,unit:"1"}}]:[]},convertsToQuantity:(i,e)=>e.length===0?[]:a(O.toQuantity(i,e).length===1),toString:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return t==null?[]:y(t)?[{type:u.string,value:`${t.value} '${t.unit}'`}]:[{type:u.string,value:t.toString()}]},convertsToString:(i,e)=>e.length===0?[]:a(O.toString(i,e).length===1),toTime:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);if(typeof t=="string"){let n=/^T?(\d{2}(:\d{2}(:\d{2})?)?)/.exec(t);if(n)return[{type:u.time,value:ye("T"+n[1])}]}return[]},convertsToTime:(i,e)=>e.length===0?[]:a(O.toTime(i,e).length===1),indexOf:(i,e,t)=>S((n,r)=>n.indexOf(r),i,e,t),substring:(i,e,t,n)=>S((r,o,s)=>{let c=o,p=s?c+s:r.length;return c<0||c>=r.length?void 0:r.substring(c,p)},i,e,t,n),startsWith:(i,e,t)=>S((n,r)=>n.startsWith(r),i,e,t),endsWith:(i,e,t)=>S((n,r)=>n.endsWith(r),i,e,t),contains:(i,e,t)=>S((n,r)=>n.includes(r),i,e,t),upper:(i,e)=>S(t=>t.toUpperCase(),i,e),lower:(i,e)=>S(t=>t.toLowerCase(),i,e),replace:(i,e,t,n)=>S((r,o,s)=>r.replaceAll(o,s),i,e,t,n),matches:(i,e,t)=>S((n,r)=>!!new RegExp(r).exec(n),i,e,t),replaceMatches:(i,e,t,n)=>S((r,o,s)=>r.replaceAll(o,s),i,e,t,n),length:(i,e)=>S(t=>t.length,i,e),toChars:(i,e)=>S(t=>t?t.split(""):void 0,i,e),encode:D,decode:D,escape:D,unescape:D,trim:D,split:D,join:(i,e,t)=>{let n=t?.eval(i,U(i))[0]?.value??"";if(typeof n!="string")throw new Error("Separator must be a string.");return[{type:u.string,value:e.map(r=>r.value?.toString()??"").join(n)}]},abs:(i,e)=>A(Math.abs,i,e),ceiling:(i,e)=>A(Math.ceil,i,e),exp:(i,e)=>A(Math.exp,i,e),floor:(i,e)=>A(Math.floor,i,e),ln:(i,e)=>A(Math.log,i,e),log:(i,e,t)=>A((n,r)=>Math.log(n)/Math.log(r),i,e,t),power:(i,e,t)=>A(Math.pow,i,e,t),round:(i,e)=>A(Math.round,i,e),sqrt:(i,e)=>A(Math.sqrt,i,e),truncate:(i,e)=>A(t=>t|0,i,e),children:D,descendants:D,trace:(i,e,t)=>e,now:()=>[{type:u.dateTime,value:new Date().toISOString()}],timeOfDay:()=>[{type:u.time,value:new Date().toISOString().substring(11)}],today:()=>[{type:u.date,value:new Date().toISOString().substring(0,10)}],between:(i,e,t,n,r)=>{let o=O.toDateTime(i,t.eval(i,e));if(o.length===0)throw new Error("Invalid start date");let s=O.toDateTime(i,n.eval(i,e));if(s.length===0)throw new Error("Invalid end date");let c=r.eval(i,e)[0]?.value;if(c!=="years"&&c!=="months"&&c!=="days")throw new Error("Invalid units");let p=Ar(o[0].value,s[0].value);return[{type:u.Quantity,value:{value:p[c],unit:c}}]},is:(i,e,t)=>{let n="";return t instanceof ge?n=t.name:t instanceof oi&&(n=t.left.name+"."+t.right.name),n?e.map(r=>({type:u.boolean,value:Kt(r,n)})):[]},not:(i,e)=>O.toBoolean(i,e).map(t=>({type:u.boolean,value:!t.value})),resolve:(i,e)=>e.map(t=>{let n=t.value,r;if(typeof n=="string")r=n;else if(typeof n=="object"){let o=n;if(o.resource)return L(o.resource);o.reference?r=o.reference:o.type&&o.identifier&&(r=`${o.type}?identifier=${o.identifier.system}|${o.identifier.value}`)}if(r?.includes("?")){let[o]=r.split("?");return{type:o,value:{resourceType:o}}}if(r?.includes("/")){let[o,s]=r.split("/");return{type:o,value:{resourceType:o,id:s}}}return{type:u.BackboneElement,value:void 0}}).filter(t=>!!t.value),as:(i,e)=>e,type:(i,e)=>e.map(({value:t})=>typeof t=="boolean"?{type:u.BackboneElement,value:{namespace:"System",name:"Boolean"}}:typeof t=="number"?{type:u.BackboneElement,value:{namespace:"System",name:"Integer"}}:Q(t)?{type:u.BackboneElement,value:{namespace:"FHIR",name:t.resourceType}}:{type:u.BackboneElement,value:null}),conformsTo:(i,e,t)=>{let n=t.eval(i,e)[0].value;if(!n.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");let r=n.replace("http://hl7.org/fhir/StructureDefinition/","");return e.map(o=>({type:u.boolean,value:o.value?.resourceType===r}))},getResourceKey:(i,e)=>{let t=e[0].value;return t?.id?[{type:u.id,value:t.id}]:[]},getReferenceKey:(i,e,t)=>{let n=e[0].value;if(!n?.reference)return[];let r="";return t instanceof ge&&(r=t.name),r&&!n.reference.startsWith(r+"/")?[]:[{type:u.id,value:Or(n)}]},extension:(i,e,t)=>{let n=t.eval(i,e)[0].value,r=e?.[0]?.value;if(r){let o=Rr(r,n);if(o)return[{type:u.Extension,value:o}]}return[]}};function S(i,e,t,...n){if(t.length===0)return[];let[{value:r}]=R(t,1);if(typeof r!="string")throw new Error("String function cannot be called with non-string");let o=i(r,...n.map(s=>s?.eval(e,t)[0]?.value));return o===void 0?[]:Array.isArray(o)?o.map(L):[L(o)]}function A(i,e,t,...n){if(t.length===0)return[];let[{value:r}]=R(t,1),o=y(r),s=o?r.value:r;if(typeof s!="number")throw new Error("Math function cannot be called with non-number");let c=i(s,...n.map(E=>E.eval(e,t)[0]?.value)),p=o?u.Quantity:t[0].type,N=o?{...r,value:c}:c;return[{type:p,value:N}]}function R(i,e){if(i.length!==e)throw new Error(`Expected ${e} arguments`);for(let t of i)if(t==null)throw new Error("Expected non-null argument");return i}function U(i){let e=i;for(;e.parent?.variables.$this;)e=e.parent;return[e.variables.$this]}var M=class{constructor(i){this.value=i}eval(){return[this.value]}toString(){let i=this.value.value;return typeof i=="string"?`'${i}'`:i.toString()}},ge=class{constructor(i){this.name=i}eval(i,e){if(this.name==="$this")return e;let t=this.getVariable(i);if(t)return[t];if(this.name.startsWith("%"))throw new Error(`Undefined variable ${this.name}`);return e.flatMap(n=>this.evalValue(n)).filter(n=>n?.value!==void 0)}getVariable(i){let e=i.variables[this.name];if(e!==void 0)return e;if(i.parent)return this.getVariable(i.parent)}evalValue(i){let e=i.value;if(!(!e||typeof e!="object"))return Q(e,this.name)?i:ur(i,this.name)}toString(){return this.name}},Lr=class{eval(){return[]}toString(){return"{}"}},Vr=class extends Kn{constructor(i,e,t){super(i,e),this.impl=t}eval(i,e){return this.impl(this.child.eval(i,e))}toString(){return this.operator+this.child.toString()}},wr=class extends q{constructor(i,e){super("as",i,e)}eval(i,e){return O.ofType(i,this.left.eval(i,e),this.right)}},C=class extends q{},g=class extends C{constructor(i,e,t,n){super(i,e,t),this.impl=n}eval(i,e){let t=this.left.eval(i,e);if(t.length!==1)return[];let n=this.right.eval(i,e);if(n.length!==1)return[];let r=t[0].value,o=n[0].value,s=y(r)?r.value:r,c=y(o)?o.value:o,p=this.impl(s,c);return typeof p=="boolean"?a(p):y(r)?[{type:u.Quantity,value:{...r,value:p}}]:[L(p)]}},Mr=class extends q{constructor(i,e){super("&",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e),r=[...t,...n];return r.length>0&&r.every(o=>typeof o.value=="string")?[{type:u.string,value:r.map(o=>o.value).join("")}]:r}},kr=class extends C{constructor(i,e){super("contains",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return a(t.some(r=>r.value===n[0].value))}},Br=class extends C{constructor(i,e){super("in",i,e)}eval(i,e){let t=x(this.left.eval(i,e)),n=this.right.eval(i,e);return t?a(n.some(r=>r.value===t.value)):[]}},oi=class extends q{constructor(i,e){super(".",i,e)}eval(i,e){return this.right.eval(i,this.left.eval(i,e))}toString(){return`${this.left.toString()}.${this.right.toString()}`}},Fr=class extends q{constructor(i,e){super("|",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return Xt([...t,...n])}},Gr=class extends C{constructor(i,e){super("=",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return hr(t,n)}},Yr=class extends C{constructor(i,e){super("!=",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return fr(t,n)}},$r=class extends C{constructor(i,e){super("~",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return Jt(t,n)}},Hr=class extends C{constructor(i,e){super("!~",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return pr(Jt(t,n))}},jr=class extends C{constructor(i,e){super("is",i,e)}eval(i,e){let t=this.left.eval(i,e);if(t.length!==1)return[];let n=this.right.name;return a(Kt(t[0],n))}},qr=class extends C{constructor(i,e){super("and",i,e)}eval(i,e){let t=x(this.left.eval(i,e),"boolean"),n=x(this.right.eval(i,e),"boolean");return t?.value===!0&&n?.value===!0?a(!0):t?.value===!1||n?.value===!1?a(!1):[]}},Wr=class extends C{constructor(i,e){super("or",i,e)}eval(i,e){let t=x(this.left.eval(i,e),"boolean"),n=x(this.right.eval(i,e),"boolean");return t?.value===!1&&n?.value===!1?a(!1):t?.value||n?.value?a(!0):[]}},Qr=class extends C{constructor(i,e){super("xor",i,e)}eval(i,e){let t=x(this.left.eval(i,e),"boolean"),n=x(this.right.eval(i,e),"boolean");return!t||!n?[]:a(t.value!==n.value)}},zr=class extends C{constructor(i,e){super("implies",i,e)}eval(i,e){let t=x(this.left.eval(i,e),"boolean"),n=x(this.right.eval(i,e),"boolean");return n?.value===!0||t?.value===!1?a(!0):!t||!n?[]:a(!1)}},Zr=class{constructor(i,e){this.name=i,this.args=e}eval(i,e){let t=O[this.name];if(!t)throw new Error("Unrecognized function: "+this.name);return t(i,e,...this.args)}toString(){return`${this.name}(${this.args.map(i=>i.toString()).join(", ")})`}},Xr=class{constructor(i,e){this.left=i,this.expr=e}eval(i,e){let t=this.expr.eval(i,e);if(t.length!==1)return[];let n=t[0].value;if(typeof n!="number")throw new Error("Invalid indexer expression: should return integer}");let r=this.left.eval(i,e);return n in r?[r[n]]:[]}toString(){return`${this.left.toString()}[${this.expr.toString()}]`}};var si=["!=","!~","<=",">=","{}","->"];var l={FunctionCall:0,Dot:1,Indexer:2,UnaryAdd:3,UnarySubtract:3,Multiply:4,Divide:4,IntegerDivide:4,Modulo:4,Add:5,Subtract:5,Ampersand:5,Is:6,As:6,Union:7,GreaterThan:8,GreaterThanOrEquals:8,LessThan:8,LessThanOrEquals:8,Equals:9,Equivalent:9,NotEquals:9,NotEquivalent:9,In:10,Contains:10,And:11,Xor:12,Or:12,Implies:13,Arrow:100,Semicolon:200},Jr={parse(i){let e=i.consumeAndParse();if(!i.match(")"))throw new Error("Parse error: expected `)` got `"+i.peek()?.value+"`");return e}},Kr={parse(i,e){let t=i.consumeAndParse();if(!i.match("]"))throw new Error("Parse error: expected `]`");return new Xr(e,t)},precedence:l.Indexer},eo={parse(i,e){if(!(e instanceof ge))throw new Error("Unexpected parentheses");let t=[];for(;!i.match(")");)t.push(i.consumeAndParse()),i.match(",");return new Zr(e.name,t)},precedence:l.FunctionCall};function to(i){let e=i.split(" "),t=parseFloat(e[0]),n=e[1];return n?.startsWith("'")&&n.endsWith("'")?n=n.substring(1,n.length-1):n="{"+n+"}",{value:t,unit:n}}function Ze(){return new er().registerPrefix("String",{parse:(i,e)=>new M({type:u.string,value:e.value})}).registerPrefix("DateTime",{parse:(i,e)=>new M({type:u.dateTime,value:ye(e.value)})}).registerPrefix("Quantity",{parse:(i,e)=>new M({type:u.Quantity,value:to(e.value)})}).registerPrefix("Number",{parse:(i,e)=>new M({type:e.value.includes(".")?u.decimal:u.integer,value:parseFloat(e.value)})}).registerPrefix("true",{parse:()=>new M({type:u.boolean,value:!0})}).registerPrefix("false",{parse:()=>new M({type:u.boolean,value:!1})}).registerPrefix("Symbol",{parse:(i,e)=>new ge(e.value)}).registerPrefix("{}",{parse:()=>new Lr}).registerPrefix("(",Jr).registerInfix("[",Kr).registerInfix("(",eo).prefix("+",l.UnaryAdd,(i,e)=>new Vr("+",e,t=>t)).prefix("-",l.UnarySubtract,(i,e)=>new g("-",e,e,(t,n)=>-n)).infixLeft(".",l.Dot,(i,e,t)=>new oi(i,t)).infixLeft("/",l.Divide,(i,e,t)=>new g("/",i,t,(n,r)=>n/r)).infixLeft("*",l.Multiply,(i,e,t)=>new g("*",i,t,(n,r)=>n*r)).infixLeft("+",l.Add,(i,e,t)=>new g("+",i,t,(n,r)=>n+r)).infixLeft("-",l.Subtract,(i,e,t)=>new g("-",i,t,(n,r)=>n-r)).infixLeft("|",l.Union,(i,e,t)=>new Fr(i,t)).infixLeft("=",l.Equals,(i,e,t)=>new Gr(i,t)).infixLeft("!=",l.NotEquals,(i,e,t)=>new Yr(i,t)).infixLeft("~",l.Equivalent,(i,e,t)=>new $r(i,t)).infixLeft("!~",l.NotEquivalent,(i,e,t)=>new Hr(i,t)).infixLeft("<",l.LessThan,(i,e,t)=>new g("<",i,t,(n,r)=>n<r)).infixLeft("<=",l.LessThanOrEquals,(i,e,t)=>new g("<=",i,t,(n,r)=>n<=r)).infixLeft(">",l.GreaterThan,(i,e,t)=>new g(">",i,t,(n,r)=>n>r)).infixLeft(">=",l.GreaterThanOrEquals,(i,e,t)=>new g(">=",i,t,(n,r)=>n>=r)).infixLeft("&",l.Ampersand,(i,e,t)=>new Mr(i,t)).infixLeft("and",l.And,(i,e,t)=>new qr(i,t)).infixLeft("as",l.As,(i,e,t)=>new wr(i,t)).infixLeft("contains",l.Contains,(i,e,t)=>new kr(i,t)).infixLeft("div",l.Divide,(i,e,t)=>new g("div",i,t,(n,r)=>n/r|0)).infixLeft("in",l.In,(i,e,t)=>new Br(i,t)).infixLeft("is",l.Is,(i,e,t)=>new jr(i,t)).infixLeft("mod",l.Modulo,(i,e,t)=>new g("mod",i,t,(n,r)=>n%r)).infixLeft("or",l.Or,(i,e,t)=>new Wr(i,t)).infixLeft("xor",l.Xor,(i,e,t)=>new Qr(i,t)).infixLeft("implies",l.Implies,(i,e,t)=>new zr(i,t))}var Po=Ze();var io=(i=>(i.BOOLEAN="BOOLEAN",i.NUMBER="NUMBER",i.QUANTITY="QUANTITY",i.TEXT="TEXT",i.REFERENCE="REFERENCE",i.CANONICAL="CANONICAL",i.DATE="DATE",i.DATETIME="DATETIME",i.PERIOD="PERIOD",i.UUID="UUID",i))(io||{});var no=(i=>(i.EQUALS="eq",i.NOT_EQUALS="ne",i.GREATER_THAN="gt",i.LESS_THAN="lt",i.GREATER_THAN_OR_EQUALS="ge",i.LESS_THAN_OR_EQUALS="le",i.STARTS_AFTER="sa",i.ENDS_BEFORE="eb",i.APPROXIMATELY="ap",i.CONTAINS="contains",i.STARTS_WITH="sw",i.EXACT="exact",i.TEXT="text",i.NOT="not",i.ABOVE="above",i.BELOW="below",i.IN="in",i.NOT_IN="not-in",i.OF_TYPE="of-type",i.MISSING="missing",i.PRESENT="present",i.IDENTIFIER="identifier",i.ITERATE="iterate",i))(no||{});var ro=(i=>(i.READ="read",i.VREAD="vread",i.UPDATE="update",i.PATCH="patch",i.DELETE="delete",i.HISTORY="history",i.HISTORY_INSTANCE="history-instance",i.HISTORY_TYPE="history-type",i.HISTORY_SYSTEM="history-system",i.CREATE="create",i.SEARCH="search",i.SEARCH_TYPE="search-type",i.SEARCH_SYSTEM="search-system",i.SEARCH_COMPARTMENT="search-compartment",i.CAPABILITIES="capabilities",i.TRANSACTION="transaction",i.BATCH="batch",i.OPERATION="operation",i))(ro||{});function Re(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,i=>{let e=Math.random()*16|0;return(i==="x"?e:e&3|8).toString(16)})}var oo={CSS:"text/css",DICOM:"application/dicom",FAVICON:"image/vnd.microsoft.icon",FHIR_JSON:"application/fhir+json",FORM_URL_ENCODED:"application/x-www-form-urlencoded",HL7_V2:"x-application/hl7-v2+er7",HTML:"text/html",JAVASCRIPT:"text/javascript",JSON:"application/json",JSON_PATCH:"application/json-patch+json",PNG:"image/png",SCIM_JSON:"application/scim+json",SVG:"image/svg+xml",TEXT:"text/plain",TYPESCRIPT:"text/typescript",PING:"x-application/ping",XML:"text/xml",CDA_XML:"application/cda+xml"};var so;so=Symbol.toStringTag;var bo={Event:typeof globalThis.Event<"u"?globalThis.Event:void 0,ErrorEvent:void 0,CloseEvent:void 0};var Uo={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0,startClosed:!1,debug:!1};var Lo=oo.FHIR_JSON+", */*; q=0.1";var ao=(i=>(i.ClientCredentials="client_credentials",i.AuthorizationCode="authorization_code",i.RefreshToken="refresh_token",i.JwtBearer="urn:ietf:params:oauth:grant-type:jwt-bearer",i.TokenExchange="urn:ietf:params:oauth:grant-type:token-exchange",i))(ao||{}),co=(i=>(i.AccessToken="urn:ietf:params:oauth:token-type:access_token",i.RefreshToken="urn:ietf:params:oauth:token-type:refresh_token",i.IdToken="urn:ietf:params:oauth:token-type:id_token",i.Saml1Token="urn:ietf:params:oauth:token-type:saml1",i.Saml2Token="urn:ietf:params:oauth:token-type:saml2",i))(co||{}),uo=(i=>(i.ClientSecretBasic="client_secret_basic",i.ClientSecretPost="client_secret_post",i.ClientSecretJwt="client_secret_jwt",i.PrivateKeyJwt="private_key_jwt",i.None="none",i))(uo||{}),lo=(i=>(i.JwtBearer="urn:ietf:params:oauth:client-assertion-type:jwt-bearer",i))(lo||{});var Vo=[...si,"->","<<",">>","=="];var wo=Ze().registerInfix("->",{precedence:l.Arrow}).registerInfix(";",{precedence:l.Semicolon});var Mo=" ".repeat(2);var ko=[...si,"eq","ne","co"];var Bo=Ze();var po=(i=>(i[i.NONE=0]="NONE",i[i.ERROR=1]="ERROR",i[i.WARN=2]="WARN",i[i.INFO=3]="INFO",i[i.DEBUG=4]="DEBUG",i))(po||{});function Ne(i){if(!i)return;let e=i.substring(0,4),t="01",n="01";return i.length>=8&&(t=i.substring(4,6),n=i.substring(6,8)),`${e}-${t}-${n}`}function f(i){if(!i)return;let e=i.substring(0,4),t="01",n="01",r="00",o="00",s="00",c="Z";return i.length>=8&&(t=i.substring(4,6),n=i.substring(6,8)),i.length>=12&&(r=i.substring(8,10),o=i.substring(10,12)),i.length>=14&&(s=i.substring(12,14)),i.length>14&&(c=i.substring(14),c==="+0000"&&(c="Z")),`${e}-${t}-${n}T${r}:${o}:${s}${c}`}function V(i){if(i)return i.substring(0,10).replace(/-/g,"")}function T(i){if(!i)return;let[e,t]=i.split("T"),n=e.replaceAll("-",""),r=(t??"").replaceAll(/\.\d+/g,"").replaceAll(/:/g,"").replaceAll(/Z/g,"+0000");return`${n}${r}`}var De="1.3.6.1.4.1.19376.1.5.3.1.3.1";var ai="2.16.840.1.113883.1.3";var ci="2.16.840.1.113883.2.20.5.1",ui="2.16.840.1.113883.3.26.1.1";var li="2.16.840.1.113883.4.1",di="2.16.840.1.113883.4.3",pi="2.16.840.1.113883.4.6",hi="2.16.840.1.113883.4.9",fi="2.16.840.1.113883.5.1",ve="2.16.840.1.113883.5.4",Xe="2.16.840.1.113883.5.6",Je="2.16.840.1.113883.5.25",k="2.16.840.1.113883.6.1",_i="2.16.840.1.113883.6.12",mi="2.16.840.1.113883.6.24",Ei="2.16.840.1.113883.6.69",Ii="2.16.840.1.113883.6.88",w="2.16.840.1.113883.6.96",Ti="2.16.840.1.113883.6.101",Oi="2.16.840.1.113883.6.209",Ke="2.16.840.1.113883.6.238",Si="2.16.840.1.113883.6.345";var yi="2.16.840.1.113883.10.20.15.3.8";var et="2.16.840.1.113883.10.20.22.1.1";var tt="2.16.840.1.113883.10.20.22.1.2";var xe="2.16.840.1.113883.10.20.22.2.1.1";var z="2.16.840.1.113883.10.20.22.2.2",Z="2.16.840.1.113883.10.20.22.2.2.1";var it="2.16.840.1.113883.10.20.22.2.3.1";var Ci="2.16.840.1.113883.10.20.22.2.4.1";var Pe="2.16.840.1.113883.10.20.22.2.5.1";var be="2.16.840.1.113883.10.20.22.2.6.1";var B="2.16.840.1.113883.10.20.22.2.7.1";var gi="2.16.840.1.113883.10.20.22.2.8";var P="2.16.840.1.113883.10.20.22.2.10";var nt="2.16.840.1.113883.10.20.22.2.17";var Ue="2.16.840.1.113883.10.20.22.2.18";var Ai="2.16.840.1.113883.10.20.22.2.22.1";var Ri="2.16.840.1.113883.10.20.22.2.23";var Ni="2.16.840.1.113883.10.20.22.2.56";var Le="2.16.840.1.113883.10.20.22.2.58";var X="2.16.840.1.113883.10.20.22.2.60";var Ve="2.16.840.1.113883.10.20.22.2.65";var we="2.16.840.1.113883.10.20.22.2.500",J="2.16.840.1.113883.10.20.22.4.1",Di="2.16.840.1.113883.10.20.22.4.1.2",K="2.16.840.1.113883.10.20.22.4.2",vi="2.16.840.1.113883.10.20.22.4.2.2",rt="2.16.840.1.113883.10.20.22.4.3";var ee="2.16.840.1.113883.10.20.22.4.4",xi="2.16.840.1.113883.10.20.22.4.4.2";var ot="2.16.840.1.113883.10.20.22.4.7";var st="2.16.840.1.113883.10.20.22.4.8";var at="2.16.840.1.113883.10.20.22.4.9";var te="2.16.840.1.113883.10.20.22.4.12";var ie="2.16.840.1.113883.10.20.22.4.13";var ne="2.16.840.1.113883.10.20.22.4.14";var ct="2.16.840.1.113883.10.20.22.4.16";var Pi="2.16.840.1.113883.10.20.22.4.20";var ut="2.16.840.1.113883.10.20.22.4.23";var re="2.16.840.1.113883.10.20.22.4.26",bi="2.16.840.1.113883.10.20.22.4.26.2",oe="2.16.840.1.113883.10.20.22.4.27",Ui="2.16.840.1.113883.10.20.22.4.27.2";var lt="2.16.840.1.113883.10.20.22.4.30";var dt="2.16.840.1.113883.10.20.22.4.32";var Li="2.16.840.1.113883.10.20.22.4.37",Vi="2.16.840.1.113883.10.20.22.4.38",wi="2.16.840.1.113883.10.20.22.4.38.1";var pt="2.16.840.1.113883.10.20.22.4.44";var ht="2.16.840.1.113883.10.20.22.4.49";var ft="2.16.840.1.113883.10.20.22.4.52";var _t="2.16.840.1.113883.10.20.22.4.54";var Mi="2.16.840.1.113883.10.20.22.4.66";var ki="2.16.840.1.113883.10.20.22.4.67";var Bi="2.16.840.1.113883.10.20.22.4.69",Fi="2.16.840.1.113883.10.20.22.4.70";var Gi="2.16.840.1.113883.10.20.22.4.74";var Yi="2.16.840.1.113883.10.20.22.4.75";var se="2.16.840.1.113883.10.20.22.4.78",$i="2.16.840.1.113883.10.20.22.4.78.2";var ae="2.16.840.1.113883.10.20.22.4.85";var Hi="2.16.840.1.113883.10.20.22.4.86";var ji="2.16.840.1.113883.10.20.22.4.114";var qi="2.16.840.1.113883.10.20.22.4.119";var Wi="2.16.840.1.113883.10.20.22.4.121";var Qi="2.16.840.1.113883.10.20.22.4.130";var zi="2.16.840.1.113883.10.20.22.4.133";var Me="2.16.840.1.113883.10.20.22.4.147",Zi="2.16.840.1.113883.10.20.22.4.200",Xi="2.16.840.1.113883.10.20.22.4.201";var Ji="2.16.840.1.113883.10.20.22.4.244";var Ki="2.16.840.1.113883.10.20.22.4.250";var en="2.16.840.1.113883.10.20.22.4.406",tn="2.16.840.1.113883.10.20.22.4.407";var nn="2.16.840.1.113883.10.20.22.4.416";var mt="2.16.840.1.113883.10.20.22.4.500",rn="2.16.840.1.113883.10.20.22.4.501";var on="2.16.840.1.113883.10.20.22.4.503",sn="2.16.840.1.113883.10.20.22.4.504";var an="2.16.840.1.113883.10.20.22.4.506",cn="2.16.840.1.113883.10.20.22.4.507",un="2.16.840.1.113883.10.20.22.4.508";var ln="2.16.840.1.113883.10.20.22.4.512";var Et="2.16.840.1.113883.12.292",It="2.16.840.1.113883.3.3719";var m=class{constructor(e,t,n,r){this.systemName=e,this.ccdaSystemOid=t,this.fhirSystemUrl=n,this.entries=r,this.ccdaToFhirMap={},this.fhirToCcdaMap={};for(let o of r)this.ccdaToFhirMap[o.ccdaValue]||(this.ccdaToFhirMap[o.ccdaValue]=o),this.fhirToCcdaMap[o.fhirValue]||(this.fhirToCcdaMap[o.fhirValue]=o)}getEntryByFhir(e){return this.fhirToCcdaMap[e]}getEntryByCcda(e){return this.ccdaToFhirMap[e]}mapCcdaToFhir(e){return this.ccdaToFhirMap[e]?.fhirValue}mapCcdaToFhirWithDefault(e,t){return e?this.mapCcdaToFhir(e)??t:t}mapFhirToCcdaWithDefault(e,t){return e?this.mapFhirToCcda(e)??t:t}mapCcdaToFhirCodeableConcept(e){let t=this.ccdaToFhirMap[e];if(t)return{coding:[{system:this.fhirSystemUrl,code:t.fhirValue,display:t.displayName}],text:t.displayName}}mapFhirToCcda(e){if(e)return this.fhirToCcdaMap[e]?.ccdaValue}mapFhirToCcdaCode(e){if(!e)return;let t=this.fhirToCcdaMap[e];if(t)return{"@_code":t.ccdaValue,"@_displayName":t.displayName,"@_codeSystem":this.ccdaSystemOid,"@_codeSystemName":pe.getEntryByCcda(this.ccdaSystemOid)?.displayName}}},b="http:",ke=`${I}/CodeSystem/condition-clinical`,Ot=`${I}/CodeSystem/condition-verification`,ho=`${I}/CodeSystem/v3-LanguageAbilityMode`,fo=`${I}/CodeSystem/v3-LanguageAbilityProficiency`,_o=`${I}/CodeSystem/v3-Race`,St=`${I}/CodeSystem/condition-category`,Be=`${I}/CodeSystem/condition-ver-status`,ce=`${I}/CodeSystem/allergyintolerance-clinical`,Fe=`${I}/CodeSystem/allergyintolerance-verification`,yt=`${I}/CodeSystem/v3-ActCode`,Ct=`${I}/CodeSystem/v3-ParticipationType`,gt=`${I}/CodeSystem/diagnosis-role`,dn=`${I}/CodeSystem/v3-Confidentiality`,pn=`${I}/CodeSystem/observation-category`,hn=`${_}/fhir/ValueSet/address-use`,fn=`${_}/fhir/ValueSet/name-use`,_n=`${_}/fhir/ValueSet/administrative-gender`,mn=`${_}/fhir/ValueSet/contactentity-use`,En=`${_}/fhir/ValueSet/medicationrequest-status`,mo=`${_}/fhir/StructureDefinition/language-mode`,Eo=`${_}/fhir/StructureDefinition/language-proficiency`,Io=`${_}/fhir/us/core/StructureDefinition/us-core-patient`,ue=`${_}/fhir/us/core/StructureDefinition/us-core-race`,le=`${_}/fhir/us/core/StructureDefinition/us-core-ethnicity`,At=`${_}/fhir/us/core/StructureDefinition/us-core-condition`,Rt=`${_}/fhir/us/core/StructureDefinition/us-core-medicationrequest`,To=`${_}/cda/template`,In=`${b}//ncithesaurus-stage.nci.nih.gov`,Tn=`${_}/fhir/sid/us-ssn`,On=`${_}/fhir/sid/us-dln`,Sn=`${_}/fhir/sid/us-npi`,yn=`${b}//fdasis.nlm.nih.gov`,Cn=`${b}//nucc.org/provider-taxonomy`,gn=`${b}//va.gov/terminology/medrt`,An=`${b}//hl7.org/fhir/ndfrt`,Rn=`${b}//nucc.org/cvx`,Nn=`${_}/fhir/sid/cvx`,Nt=`${b}//www.w3.org/2001/XMLSchema-instance`,de="https://medplum.com/fhir/StructureDefinition/ccda-narrative-reference",pe=new m("System","","",[{ccdaValue:ci,fhirValue:"https://fhir.infoway-inforoute.ca/CodeSystem/pCLOCD",displayName:"pan-Canadian LOINC Observation Code Database (pCLOCD)"},{ccdaValue:ui,fhirValue:In,displayName:"NCI Thesaurus"},{ccdaValue:li,fhirValue:Tn,displayName:"SSN"},{ccdaValue:di,fhirValue:On,displayName:"DLN"},{ccdaValue:pi,fhirValue:Sn,displayName:"NPI"},{ccdaValue:hi,fhirValue:yn,displayName:"Unique Ingredient Identifier (UNII)"},{ccdaValue:k,fhirValue:Ae,displayName:"LOINC"},{ccdaValue:_i,fhirValue:Qt,displayName:"Current Procedural Terminology (CPT)"},{ccdaValue:mi,fhirValue:"urn:iso:std:iso:11073:10101",displayName:"Medical Device Communications (MDC)"},{ccdaValue:Ei,fhirValue:zt,displayName:"National Drug Code (NDC)"},{ccdaValue:Ii,fhirValue:Wt,displayName:"RxNorm"},{ccdaValue:w,fhirValue:je,displayName:"SNOMED CT"},{ccdaValue:Ti,fhirValue:Cn,displayName:"NUCC Health Care Provider Taxonomy"},{ccdaValue:Si,fhirValue:gn,displayName:"Medication Reference Terminology (MED-RT)"},{ccdaValue:Oi,fhirValue:An,displayName:"National Drug File Reference Terminology (NDF-RT)"},{ccdaValue:Et,fhirValue:Rn,displayName:"CVX"},{ccdaValue:Je,fhirValue:"Confidentiality",displayName:"Confidentiality"},{ccdaValue:Et,fhirValue:Nn,displayName:"Vaccine Administered Code Set (CVX)"}]);function F(i){if(i)return pe.mapCcdaToFhir(i)??`urn:oid:${i}`}function Dt(i){if(i)return i.startsWith("urn:oid:")?i.replace("urn:oid:",""):pe.mapFhirToCcda(i)}function d(i){if(!i?.coding)return;let e=Tt(i.coding[0]);if(i.coding.length>1){e.translation=[];for(let t=1;t<i.coding.length;t++)e.translation.push(Tt(i.coding[t]))}return e}function Tt(i){let e=i?.system?pe.getEntryByFhir(i.system):void 0,t=e?.ccdaValue,n=e?.displayName,r=i.system?.startsWith("urn:oid:")?i.system.replace("urn:oid:",""):void 0;return{"@_code":i.code,"@_displayName":i.display,"@_codeSystem":t??r,"@_codeSystemName":n}}function G(i){let e=d(i);if(e)return{"@_xsi:type":"CD",...e}}var vt=new m("Confidentiality",Je,dn,[{ccdaValue:"U",fhirValue:"U",displayName:"unrestricted"},{ccdaValue:"L",fhirValue:"L",displayName:"low"},{ccdaValue:"M",fhirValue:"M",displayName:"moderate"},{ccdaValue:"N",fhirValue:"N",displayName:"normal"},{ccdaValue:"R",fhirValue:"R",displayName:"restricted"},{ccdaValue:"V",fhirValue:"V",displayName:"very restricted"}]),he=new m("HumanNameUse","",fn,[{ccdaValue:"C",fhirValue:"usual",displayName:"Common/Called by"},{ccdaValue:"L",fhirValue:"official",displayName:"Legal"},{ccdaValue:"TEMP",fhirValue:"temp",displayName:"Temporary"},{ccdaValue:"P",fhirValue:"nickname",displayName:"Nickname"},{ccdaValue:"ANON",fhirValue:"anonymous",displayName:"Anonymous"},{ccdaValue:"L",fhirValue:"maiden",displayName:"Maiden"},{ccdaValue:"L",fhirValue:"old",displayName:"Old"}]),xt=new m("Gender","",_n,[{ccdaValue:"F",fhirValue:"female",displayName:"Female"},{ccdaValue:"M",fhirValue:"male",displayName:"Male"},{ccdaValue:"UN",fhirValue:"unknown",displayName:"Unknown"},{ccdaValue:"UN",fhirValue:"other",displayName:"Other"}]),fe=new m("AddressUse","",hn,[{ccdaValue:"HP",fhirValue:"home",displayName:"Home"},{ccdaValue:"WP",fhirValue:"work",displayName:"Work"}]),_e=new m("TelecomUse","",mn,[{ccdaValue:"WP",fhirValue:"work",displayName:"Work"},{ccdaValue:"HP",fhirValue:"home",displayName:"Home"}]),me=new m("AllergyStatus","",Fe,[{ccdaValue:"unconfirmed",fhirValue:"unconfirmed",displayName:"Unconfirmed"},{ccdaValue:"provisional",fhirValue:"provisional",displayName:"Provisional"},{ccdaValue:"differential",fhirValue:"differential",displayName:"Differential"},{ccdaValue:"confirmed",fhirValue:"confirmed",displayName:"Confirmed"},{ccdaValue:"refuted",fhirValue:"refuted",displayName:"Refuted"},{ccdaValue:"entered-in-error",fhirValue:"entered-in-error",displayName:"Entered in Error"},{ccdaValue:"unknown",fhirValue:"unknown",displayName:"Unknown"}]),Pt=new m("AllergyCategory",w,ce,[{ccdaValue:"414285001",fhirValue:"food",displayName:"Allergy to food (finding)"},{ccdaValue:"419511003",fhirValue:"medication",displayName:"Propensity to adverse reactions to drug (finding)"},{ccdaValue:"426232007",fhirValue:"environment",displayName:"Environmental allergy (finding)"},{ccdaValue:"418038007",fhirValue:"biologic",displayName:"Propensity to adverse reactions to substance (finding)"}]),Ee=new m("AllergySeverity",je,ce,[{ccdaValue:"255604002",fhirValue:"mild",displayName:"Mild"},{ccdaValue:"6736007",fhirValue:"moderate",displayName:"Moderate"},{ccdaValue:"24484000",fhirValue:"severe",displayName:"Severe"}]),Ie=new m("ProblemStatus","",Be,[{ccdaValue:"active",fhirValue:"active",displayName:"Active"},{ccdaValue:"inactive",fhirValue:"inactive",displayName:"Inactive"},{ccdaValue:"resolved",fhirValue:"inactive",displayName:"Resolved"},{ccdaValue:"remission",fhirValue:"inactive",displayName:"In Remission"},{ccdaValue:"relapse",fhirValue:"active",displayName:"Relapse"},{ccdaValue:"resolved relapse",fhirValue:"inactive",displayName:"Resolved Relapse"},{ccdaValue:"aborted",fhirValue:"aborted",displayName:"Aborted"}]),Te=new m("ImmunizationStatus","","",[{ccdaValue:"completed",fhirValue:"completed",displayName:"Completed"},{ccdaValue:"nullified",fhirValue:"entered-in-error",displayName:"Nullified"},{ccdaValue:"aborted",fhirValue:"not-done",displayName:"Aborted"},{ccdaValue:"cancelled",fhirValue:"not-done",displayName:"Cancelled"},{ccdaValue:"obsolete",fhirValue:"not-done",displayName:"Obsolete"}]),bt=new m("EncounterStatus","","",[{ccdaValue:"active",fhirValue:"in-progress",displayName:"In Progress"},{ccdaValue:"completed",fhirValue:"finished",displayName:"Finished"},{ccdaValue:"aborted",fhirValue:"cancelled",displayName:"Cancelled"},{ccdaValue:"cancelled",fhirValue:"cancelled",displayName:"Cancelled"},{ccdaValue:"unknown",fhirValue:"unknown",displayName:"Unknown"}]),Ut=new m("ProcedureStatus","","",[{ccdaValue:"completed",fhirValue:"completed",displayName:"Completed"},{ccdaValue:"aborted",fhirValue:"stopped",displayName:"Stopped"},{ccdaValue:"cancelled",fhirValue:"not-done",displayName:"Not Done"},{ccdaValue:"new",fhirValue:"not-done",displayName:"Draft"},{ccdaValue:"unknown",fhirValue:"unknown",displayName:"Unknown"}]),Oe=new m("MedicationStatus","",En,[{ccdaValue:"active",fhirValue:"active",displayName:"Active"},{ccdaValue:"completed",fhirValue:"completed",displayName:"Completed"},{ccdaValue:"aborted",fhirValue:"stopped",displayName:"Stopped"},{ccdaValue:"cancelled",fhirValue:"cancelled",displayName:"Cancelled"},{ccdaValue:"aborted",fhirValue:"entered-in-error",displayName:"Entered in Error"},{ccdaValue:"active",fhirValue:"draft",displayName:"Draft"},{ccdaValue:"cancelled",fhirValue:"unknown",displayName:"Unknown"},{ccdaValue:"nullified",fhirValue:"cancelled",displayName:"Nullified"},{ccdaValue:"obsolete",fhirValue:"cancelled",displayName:"Obsolete"}]),Lt=new m("ObservationCategory","",pn,[{ccdaValue:Vi,fhirValue:"social-history",displayName:"Social History"},{ccdaValue:wi,fhirValue:"social-history",displayName:"Social History V2"},{ccdaValue:se,fhirValue:"social-history",displayName:"Smoking Status"},{ccdaValue:$i,fhirValue:"social-history",displayName:"Current Smoking Status"},{ccdaValue:ae,fhirValue:"social-history",displayName:"Tobacco Use"},{ccdaValue:on,fhirValue:"social-history",displayName:"Basic Occupation"},{ccdaValue:sn,fhirValue:"social-history",displayName:"Basic Industry"},{ccdaValue:rn,fhirValue:"social-history",displayName:"Sexual Orientation"},{ccdaValue:cn,fhirValue:"social-history",displayName:"Sex Observation"},{ccdaValue:Zi,fhirValue:"social-history",displayName:"Gender Identity"},{ccdaValue:Xi,fhirValue:"social-history",displayName:"Gender Identity V2"},{ccdaValue:yi,fhirValue:"social-history",displayName:"Pregnancy Status"},{ccdaValue:an,fhirValue:"social-history",displayName:"Tribal Affiliation"},{ccdaValue:oe,fhirValue:"vital-signs",displayName:"Vital Signs Observation"},{ccdaValue:Ui,fhirValue:"vital-signs",displayName:"Vital Signs Observation V2"},{ccdaValue:re,fhirValue:"vital-signs",displayName:"Vital Signs Organizer"},{ccdaValue:bi,fhirValue:"vital-signs",displayName:"Vital Signs Organizer V2"},{ccdaValue:ln,fhirValue:"vital-signs",displayName:"Average Blood Pressure Organizer"},{ccdaValue:K,fhirValue:"laboratory",displayName:"Result Observation"},{ccdaValue:vi,fhirValue:"laboratory",displayName:"Result Observation V2"},{ccdaValue:en,fhirValue:"laboratory",displayName:"Laboratory Battery (ID)"},{ccdaValue:tn,fhirValue:"laboratory",displayName:"Laboratory Observation (ID)"},{ccdaValue:nn,fhirValue:"laboratory",displayName:"Laboratory Result Organizer (ID)"},{ccdaValue:J,fhirValue:"laboratory",displayName:"Result Organizer"},{ccdaValue:Di,fhirValue:"laboratory",displayName:"Result Organizer V2"},{ccdaValue:Bi,fhirValue:"survey",displayName:"Assessment Scale Observation"},{ccdaValue:Hi,fhirValue:"survey",displayName:"Assessment Scale Supporting Observation"},{ccdaValue:Gi,fhirValue:"survey",displayName:"Cognitive Status Result Observation"},{ccdaValue:Yi,fhirValue:"survey",displayName:"Cognitive Status Result Organizer"},{ccdaValue:ki,fhirValue:"survey",displayName:"Functional Status Result Observation"},{ccdaValue:Mi,fhirValue:"survey",displayName:"Functional Status Result Organizer"},{ccdaValue:ie,fhirValue:"exam",displayName:"Procedure Activity Observation"},{ccdaValue:ee,fhirValue:"exam",displayName:"Problem Observation"},{ccdaValue:xi,fhirValue:"exam",displayName:"Problem Observation V2"},{ccdaValue:Fi,fhirValue:"exam",displayName:"Pressure Ulcer Observation"},{ccdaValue:ji,fhirValue:"exam",displayName:"Wound Observation"},{ccdaValue:zi,fhirValue:"exam",displayName:"Wound Measurements Observation"},{ccdaValue:B,fhirValue:"exam",displayName:"Procedure Section"},{ccdaValue:un,fhirValue:"therapy",displayName:"Medication Adherence"},{ccdaValue:Qi,fhirValue:"therapy",displayName:"Nutrition Recommendations"},{ccdaValue:Ji,fhirValue:"therapy",displayName:"Diet Statement (Nutrition)"},{ccdaValue:Ki,fhirValue:"therapy",displayName:"Monitoring, Evaluation and Outcome (Nutrition)"}]);var Y=require("fast-xml-parser");var Oo=["ClinicalDocument.recordTarget",".id",".templateId",".name",".addr",".telecom",".streetAddressLine",".author",".effectiveTime","name.given","name.suffix","name.prefix","patient.raceCode","patient.ethnicGroupCode","patient.languageCommunication","component.structuredBody.component","component.structuredBody.component.section","component.section","component.observation","component.act","code.translation","section.entry","entry.act","entry.organizer","entry.substanceAdministration","entry.observation","entry.encounter","entry.procedure","encounter.performer","encounter.participant","encounter.entryRelationship","entryRelationship.observation","entryRelationship.substanceAdministration","entryRelationship.act","organizer.component","substanceAdministration.consumable.manufacturedProduct","substanceAdministration.entryRelationship","substanceAdministration.performer","act.entryRelationship","act.performer","observation.participant","observation.entryRelationship","observation.referenceRange","consumable.manufacturedProduct","manufacturedProduct.manufacturedMaterial","manufacturedProduct.manufacturerOrganization","manufacturedProduct.manufacturedLabeledDrug","manufacturedMaterial.code","manufacturedMaterial.lotNumberText"];function So(i){return new Y.XMLParser({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1,isArray:(n,r,o,s)=>Oo.some(c=>r.endsWith(c))}).parse(i).ClinicalDocument}function yo(i){return new Y.XMLBuilder({ignoreAttributes:!1,attributeNamePrefix:"@_",format:!0,suppressBooleanAttributes:!1,suppressEmptyNode:!0}).build({"?xml":{"@_version":"1.0","@_encoding":"UTF-8"},"?xml-stylesheet":{"@_type":"text/xsl","@_href":"CDA.xsl"},ClinicalDocument:{"@_xmlns":"urn:hl7-org:v3","@_xmlns:xsi":Nt,"@_xmlns:voc":"urn:hl7-org:v3/voc","@_xmlns:sdtc":"urn:hl7-org:sdtc",...i}})}function Vt(i){return new Y.XMLParser({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1}).parse(i)}function wt(i){return i?typeof i=="string"?i:new Y.XMLBuilder({ignoreAttributes:!1,attributeNamePrefix:"@_",format:!1,suppressBooleanAttributes:!1,suppressEmptyNode:!0}).build(i).split(`
2
+ `).map(n=>n.trim()).join(""):""}function Co(i){return new Mt(i).convert()}var Mt=class{constructor(e){this.resources=[];this.ccda=e}convert(){return this.processHeader(),{resourceType:"Bundle",type:"document",entry:[{resource:this.createComposition()},...this.patient?[{resource:this.patient}]:[],...this.resources.map(t=>({resource:t}))]}}processHeader(){let e=this.ccda.recordTarget?.[0]?.patientRole;e&&(this.patient=this.createPatient(e))}createPatient(e){let t=e.patient,n=[];return t.raceCode&&t.raceCode.length>0&&n.push({url:ue,extension:t.raceCode.map(r=>({url:"ombCategory",valueCoding:this.mapCodeToCoding(r)}))}),t.ethnicGroupCode&&t.ethnicGroupCode.length>0&&n.push({url:le,extension:t.ethnicGroupCode.map(r=>({url:"ombCategory",valueCoding:this.mapCodeToCoding(r)}))}),{resourceType:"Patient",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),name:this.mapCcdaNameArrayFhirHumanNameArray(t.name),gender:this.mapGenderCode(t.administrativeGenderCode?.["@_code"]),birthDate:Ne(t.birthTime?.["@_value"]),address:this.mapAddresses(e.addr),telecom:this.mapTelecom(e.telecom),extension:n.length>0?n:void 0}}mapId(e){let t=e?.find(n=>!n["@_extension"]&&n["@_root"]&&Qe(n["@_root"]));return t?t["@_root"]:Re()}mapIdentifiers(e){if(!e)return;let t=[];for(let n of e)!n["@_extension"]&&n["@_root"]&&Qe(n["@_root"])||t.push({system:F(n["@_root"]),value:n["@_extension"]});return t}mapCcdaNameArrayFhirHumanNameArray(e){return e?.map(t=>this.mapCcdaNameToFhirHumanName(t)).filter(Boolean)}mapCcdaNameToFhirHumanName(e){if(!e)return;let t={},n=e["@_use"]?he.mapCcdaToFhir(e["@_use"]):void 0;return n&&(t.use=n),e.prefix&&(t.prefix=e.prefix.map(Se)?.filter(Boolean)),e.family&&(t.family=Se(e.family)),e.given&&(t.given=e.given.map(Se)?.filter(Boolean)),e.suffix&&(t.suffix=e.suffix.map(Se)?.filter(Boolean)),t}mapAddresses(e){if(!(!e||e.length===0||e.every(t=>t["@_nullFlavor"]==="UNK")))return e?.map(t=>({"@_use":t["@_use"]?fe.mapCcdaToFhir(t["@_use"]):void 0,line:t.streetAddressLine,city:t.city,state:t.state,postalCode:t.postalCode,country:t.country}))}mapTelecom(e){if(!(!e||e.length===0||e.every(t=>t["@_nullFlavor"]==="UNK")))return e?.map(t=>({"@_use":t["@_use"]?_e.mapCcdaToFhir(t["@_use"]):void 0,system:this.getTelecomSystem(t["@_value"]),value:this.getTelecomValue(t["@_value"])}))}createComposition(){let e=this.ccda.component?.structuredBody?.component||[],t=[];for(let n of e)for(let r of n.section){let o=this.processSection(r);t.push({title:r.title,code:this.mapCode(r.code),text:{status:"generated",div:`<div xmlns="http://www.w3.org/1999/xhtml">${wt(r.text)}</div>`},entry:o.map(h)}),this.resources.push(...o)}return{resourceType:"Composition",id:this.mapId(this.ccda.id),language:this.ccda.languageCode?.["@_code"],status:"final",type:this.ccda.code?this.mapCode(this.ccda.code):{coding:[{system:Ae,code:"34133-9"}]},confidentiality:this.ccda.confidentialityCode?.["@_code"],author:this.ccda.author?.[0]?[this.mapAuthorToReference(this.ccda.author?.[0])]:[{display:"Medplum"}],custodian:this.mapCustodianToReference(this.ccda.custodian),event:this.mapDocumentationOfToEvent(this.ccda.documentationOf),date:f(this.ccda.effectiveTime?.[0]?.["@_value"])??new Date().toISOString(),title:this.ccda.title??"Medical Summary",section:t}}processSection(e){let t=[];if(e.entry)for(let n of e.entry)this.processEntry(e,n,t);return t}processEntry(e,t,n){for(let r of t.act??[]){let o=this.processAct(e,r);o&&n.push(o)}for(let r of t.substanceAdministration??[]){let o=this.processSubstanceAdministration(e,r);o&&n.push(o)}for(let r of t.organizer??[])n.push(this.processOrganizer(e,r));for(let r of t.observation??[])n.push(this.processObservation(e,r));for(let r of t.encounter??[])n.push(this.processEncounter(e,r));for(let r of t.procedure??[])n.push(this.processProcedure(e,r))}processAct(e,t){let n=e.templateId[0]["@_root"];switch(n){case be:return this.processAllergyIntoleranceAct(t);case Pe:return this.processConditionAct(t);case P:return this.processCarePlanAct(t);case Le:return this.processConditionAct(t);case B:return this.processProcedureAct(t);case De:return;case Ve:return;case Ue:return;default:throw new Error("Unhandled act templateId: "+n)}}processAllergyIntoleranceAct(e){let t=e.entryRelationship?.find(s=>s["@_typeCode"]==="SUBJ")?.observation?.[0];if(!t)return;let n={resourceType:"AllergyIntolerance",id:this.mapId(e.id),clinicalStatus:this.createClinicalStatus(e),verificationStatus:this.createVerificationStatus(),type:"allergy",category:["food"],patient:h(this.patient),recorder:this.mapAuthorToReference(e.author?.[0]),recordedDate:this.mapEffectiveTimeToDateTime(e.effectiveTime?.[0]),onsetDateTime:this.mapEffectiveTimeToDateTime(t.effectiveTime?.[0])};t.value?.["@_code"]==="414285001"&&(n.category=["food"]),n.extension=this.mapTextReference(t.text);let r=t.participant?.[0]?.participantRole?.playingEntity?.code;r&&(n.code=this.mapCode(r),n.code&&r.originalText?.reference?.["@_value"]&&(n.code.extension=this.mapTextReference(r.originalText)));let o=t.entryRelationship?.find(s=>s["@_typeCode"]==="MFST")?.observation;return o&&(n.reaction=o.map(s=>this.processReaction(s))),n.asserter=this.mapAuthorToReference(t.author?.[0]),n}processConditionAct(e){let t=e.entryRelationship?.find(r=>r["@_typeCode"]==="SUBJ")?.observation?.[0];if(!t)return;let n={resourceType:"Condition",id:this.mapId(e.id),identifier:this.concatArrays(this.mapIdentifiers(e.id),this.mapIdentifiers(t.id)),meta:{profile:[At]},clinicalStatus:{coding:[{system:ke,code:Ie.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active")}]},verificationStatus:{coding:[{system:Ot,code:"confirmed"}]},category:[{coding:[{system:St,code:"problem-list-item",display:"Problem List Item"}]}],code:this.mapCode(t.value),subject:h(this.patient),onsetDateTime:f(t.effectiveTime?.[0]?.low?.["@_value"]),abatementDateTime:f(t.effectiveTime?.[0]?.high?.["@_value"]),recordedDate:this.mapEffectiveTimeToDateTime(e.effectiveTime?.[0]),recorder:this.mapAuthorToReference(t.author?.[0]),asserter:this.mapAuthorToReference(t.author?.[0])};return n.extension=this.mapTextReference(t.text),n}processCarePlanAct(e){return{resourceType:"CarePlan",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"active",intent:"plan",title:"CARE PLAN",category:e.code?[this.mapCode(e.code)]:void 0,subject:h(this.patient),description:Se(e.text)}}processProcedureAct(e){return{resourceType:"Procedure",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"completed",code:this.mapCode(e.code),subject:h(this.patient),performedDateTime:f(e.effectiveTime?.[0]?.["@_value"]),recorder:this.mapAuthorToReference(e.author?.[0]),asserter:this.mapAuthorToReference(e.author?.[0]),extension:this.mapTextReference(e.text)}}processSubstanceAdministration(e,t){let n=e.templateId[0]["@_root"];switch(n){case xe:case P:return this.processMedicationSubstanceAdministration(t);case z:case Z:return this.processImmunizationSubstanceAdministration(t);default:throw new Error("Unhandled substance administration templateId: "+n)}}processMedicationSubstanceAdministration(e){let t=this.mapId(e.id),n=e.consumable?.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.code?.[0],r=e.routeCode,o=e.doseQuantity,s=e.consumable?.manufacturedProduct?.[0]?.manufacturerOrganization?.[0],c=e.entryRelationship?.find(E=>E.substanceAdministration?.[0]?.templateId?.[0]?.["@_root"]===Me)?.substanceAdministration?.[0],p,N;return s?p={resourceType:"Medication",id:"med-"+t,code:this.mapCode(n),extension:this.mapTextReference(n?.originalText),manufacturer:s?{identifier:{value:s.id?.[0]?.["@_root"]},display:s.name?.[0]}:void 0}:N={...this.mapCode(n),extension:this.mapTextReference(n?.originalText)},{resourceType:"MedicationRequest",id:t,contained:p?[p]:void 0,meta:{profile:[Rt]},extension:this.mapTextReference(e.text),status:Oe.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active"),intent:"order",medicationReference:p?{reference:"#med-"+t}:void 0,medicationCodeableConcept:N,subject:h(this.patient),authoredOn:f(e.author?.[0]?.time?.["@_value"]),dispenseRequest:e.effectiveTime?.[0]?{validityPeriod:{start:f(e.effectiveTime?.[0]?.low?.["@_value"]),end:f(e.effectiveTime?.[0]?.high?.["@_value"])}}:void 0,dosageInstruction:[{text:typeof e.text=="string"?e.text:void 0,extension:this.mapTextReference(c?.text),route:r?this.mapCode(r):void 0,timing:{repeat:e.effectiveTime?.[1]?.period?{period:Number(e.effectiveTime?.[1]?.period["@_value"]),periodUnit:e.effectiveTime?.[1]?.period["@_unit"]}:void 0},doseAndRate:o?[{doseQuantity:{system:He,value:Number(o["@_value"]),code:"[IU]",unit:"[IU]"}}]:void 0}]}}processImmunizationSubstanceAdministration(e){let t=e.consumable;if(!t)return;let n={resourceType:"Immunization",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:Te.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"completed"),vaccineCode:this.mapCode(t.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.code?.[0]),patient:h(this.patient),occurrenceDateTime:f(e.effectiveTime?.[0]?.["@_value"]),lotNumber:t.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.lotNumberText?.[0]};return e.performer&&(n.performer=this.mapCcdaPerformerArrayToImmunizationPerformerArray(e.performer)),n.extension=this.mapTextReference(e.text),e.consumable?.manufacturedProduct?.[0]?.manufacturerOrganization?.[0]&&(n.manufacturer={display:e.consumable?.manufacturedProduct?.[0]?.manufacturerOrganization?.[0]?.name?.[0]}),n}processReaction(e){let t={id:this.mapId(e.id),manifestation:[this.mapCode(e.value)],onset:f(e.effectiveTime?.[0]?.low?.["@_value"])};return this.processSeverity(e,t),t.manifestation&&t.manifestation.length>0&&e.text?.reference?.["@_value"]&&(t.manifestation[0].extension=this.mapTextReference(e.text)),t}processSeverity(e,t){let n=e.entryRelationship?.find(o=>o["@_typeCode"]==="SUBJ")?.observation?.[0];if(!n)return;let r=n.value?.["@_code"];r&&(t.severity=Ee.mapCcdaToFhir(r)),t.extension=this.mapTextReference(n.text)}mapEffectiveTimeToDateTime(e){if(e?.["@_value"])return f(e["@_value"]);if(e?.low?.["@_value"])return f(e.low["@_value"])}mapEffectiveTimeToPeriod(e){if(!e?.["@_value"]&&(e?.low||e?.high))return{start:f(e?.low?.["@_value"]),end:f(e?.high?.["@_value"])}}mapGenderCode(e){return e?{F:"female",M:"male",UN:"unknown"}[e]:void 0}getTelecomSystem(e){if(e)return e.startsWith("tel:")?"phone":e.startsWith("mailto:")?"email":"other"}getTelecomValue(e){if(e)return e.replace(/^(tel:|mailto:)/,"")}mapCode(e){if(!e)return;let t={coding:[{system:F(e["@_codeSystem"]),code:e["@_code"],display:e["@_displayName"]}],text:e["@_displayName"]};if(e.translation)for(let n of e.translation)t.coding.push({system:F(n["@_codeSystem"]),code:n["@_code"],display:n["@_displayName"]});return t}mapCodeToCoding(e){if(e)return{system:F(e["@_codeSystem"]),code:e["@_code"],display:e["@_displayName"]}}createClinicalStatus(e){return{coding:[{system:ce,code:me.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active")}]}}createVerificationStatus(){return{coding:[{system:Fe,code:"confirmed"}]}}mapAuthorToReference(e){if(!e)return;let t={resourceType:"Practitioner",id:this.mapId(e.assignedAuthor?.id),identifier:this.mapIdentifiers(e.assignedAuthor?.id),name:this.mapCcdaNameArrayFhirHumanNameArray(e.assignedAuthor?.assignedPerson?.name),address:this.mapAddresses(e.assignedAuthor?.addr),telecom:this.mapTelecom(e.assignedAuthor?.telecom),qualification:e.assignedAuthor?.code?[this.mapCode(e.assignedAuthor?.code)]:void 0};return this.resources.push(t),h(t)}mapAssignedEntityToReference(e){if(!e)return;let t=e.assignedPerson,n=e.representedOrganization,r={resourceType:"Practitioner",id:this.mapId(e?.id),identifier:this.mapIdentifiers(e?.id),name:this.mapCcdaNameArrayFhirHumanNameArray(t?.name),address:this.mapAddresses(e?.addr),telecom:this.mapTelecom(e?.telecom)};this.resources.push(r);let o={resourceType:"Organization",id:this.mapId(e?.id),identifier:this.mapIdentifiers(n?.id),name:n?.name?.[0],address:this.mapAddresses(n?.addr)};this.resources.push(o);let s={resourceType:"PractitionerRole",id:this.mapId(e?.id),practitioner:h(r),organization:h(o)};return this.resources.push(s),h(s)}mapCustodianToReference(e){if(!e)return;let t={resourceType:"Organization",id:this.mapId(e.assignedCustodian.representedCustodianOrganization.id),identifier:this.mapIdentifiers(e.assignedCustodian.representedCustodianOrganization.id),name:e.assignedCustodian.representedCustodianOrganization.name?.[0],address:this.mapAddresses(e.assignedCustodian.representedCustodianOrganization.addr),telecom:this.mapTelecom(e.assignedCustodian.representedCustodianOrganization.telecom)};return this.resources.push(t),h(t)}mapDocumentationOfToEvent(e){if(!e)return;let t=e.serviceEvent;if(t)return[{code:t.code?[this.mapCode(t.code)]:void 0,period:this.mapEffectiveTimeToPeriod(t.effectiveTime?.[0])}]}concatArrays(e,t){return e?t?[...e,...t]:e:t}mapCcdaPerformerArrayToImmunizationPerformerArray(e){let t=[];for(let n of e){let r=n.assignedEntity,o=this.mapAssignedEntityToReference(r);o&&t.push({actor:o})}return t}processOrganizer(e,t){return e.templateId[0]["@_root"]===we?this.processCareTeamOrganizer(t):this.processVitalsOrganizer(t)}processCareTeamOrganizer(e){let t=[];if(e.component)for(let r of e.component){let o=this.processCareTeamMember(r);o&&t.push(o)}return{resourceType:"CareTeam",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),participant:t.length>0?t:void 0}}processCareTeamMember(e){let t=e.act?.[0];if(!t)return;let n=t.performer?.[0];if(n)return{role:n.functionCode?[this.mapCode(n.functionCode)]:void 0,member:this.mapAssignedEntityToReference(n.assignedEntity),period:this.mapEffectiveTimeToPeriod(t.effectiveTime?.[0])}}processVitalsOrganizer(e){let t={resourceType:"Observation",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"final",category:this.mapObservationTemplateIdToObservationCategory(e.templateId),code:this.mapCode(e.code),subject:h(this.patient)};if(e.effectiveTime?.[0]?.["@_value"]&&(t.effectiveDateTime=f(e.effectiveTime?.[0]?.["@_value"])),e.component){let n=[];for(let r of e.component)n.push(...this.processVitalsComponent(r));n.length>0&&(t.hasMember=n)}return t}processVitalsComponent(e){let t=[];if(e.observation)for(let n of e.observation){let r=this.processVitalsObservation(n);t.push(h(r)),this.resources.push(r)}return t}processObservation(e,t){let n=t.templateId[0]["@_root"];if(n===X||n===Wi)return this.processGoalObservation(t);switch(e.templateId[0]["@_root"]){case P:case X:return this.processGoalObservation(t);default:return this.processVitalsObservation(t)}}processGoalObservation(e){let t={resourceType:"Goal",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),lifecycleStatus:this.mapGoalLifecycleStatus(e),description:this.mapCode(e.code),subject:h(this.patient),startDate:Ne(e.effectiveTime?.[0]?.["@_value"])};return t.target=e.entryRelationship?.map(n=>({measure:this.mapCode(n.act?.[0]?.code),detailCodeableConcept:this.mapCode(n.act?.[0]?.code),dueDate:f(n.act?.[0]?.effectiveTime?.[0]?.low?.["@_value"])})),t.extension=this.mapTextReference(e.text),t}mapGoalLifecycleStatus(e){return{active:"active",completed:"completed",cancelled:"cancelled",aborted:"cancelled"}[e.statusCode["@_code"]??"active"]}processVitalsObservation(e){let t={resourceType:"Observation",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"final",category:this.mapObservationTemplateIdToObservationCategory(e.templateId),code:this.mapCode(e.code),subject:h(this.patient),referenceRange:this.mapReferenceRangeArray(e.referenceRange),performer:e.author?.map(n=>this.mapAuthorToReference(n)).filter(Boolean)};if(e.value?.["@_xsi:type"])switch(e.value["@_xsi:type"]){case"PQ":case"CO":t.valueQuantity={value:e.value["@_value"]?parseFloat(e.value["@_value"]):void 0,unit:e.value["@_unit"],system:He,code:e.value["@_unit"]};break;case"CD":case"CE":t.valueCodeableConcept=this.mapCode(e.value);break;case"ST":t.valueString=e.value["#text"]??"";break;default:console.warn(`Unhandled observation value type: ${e.value["@_xsi:type"]}`)}return e.effectiveTime?.[0]?.["@_value"]&&(t.effectiveDateTime=f(e.effectiveTime?.[0]?.["@_value"])),t.extension=this.mapTextReference(e.text),t}mapObservationTemplateIdToObservationCategory(e){if(!e)return;let t=new Set,n=[];for(let r of e){let o=Lt.mapCcdaToFhirCodeableConcept(r["@_root"]);o?.coding?.[0]?.code&&!t.has(o.coding[0].code)&&(t.add(o.coding[0].code),n.push(o))}return Array.from(n.values())}mapReferenceRangeArray(e){if(!(!e||e.length===0))return e.map(t=>this.mapReferenceRange(t)).filter(Boolean)}mapReferenceRange(e){if(!e)return;let t=e.observationRange;if(!t)return;let n={};return n.extension=this.mapTextReference(t.text),n}processEncounter(e,t){let n={resourceType:"Encounter",id:this.mapId(t.id),identifier:this.mapIdentifiers(t.id),status:bt.mapCcdaToFhirWithDefault(t.statusCode?.["@_code"],"unknown"),class:{system:yt,code:t.code?.["@_code"]??"AMB",display:t.code?.["@_displayName"]??"Ambulatory"},type:t.code?[this.mapCode(t.code)]:void 0,subject:h(this.patient),period:this.mapEffectiveTimeToPeriod(t.effectiveTime?.[0])};if(t.performer&&(n.participant=t.performer.map(r=>({type:[{coding:[{system:Ct,code:r["@_typeCode"]??"PPRF",display:"Primary Performer"}]}],individual:this.mapAssignedEntityToReference(r.assignedEntity)}))),t.entryRelationship){let r=t.entryRelationship.filter(o=>o["@_typeCode"]==="RSON").map(o=>{let s=o.observation?.[0];if(!s)return;let c={resourceType:"Condition",id:this.mapId(s.id),identifier:this.mapIdentifiers(s.id),clinicalStatus:{coding:[{system:ke,code:"active"}]},verificationStatus:{coding:[{system:Be,code:"confirmed"}]},code:this.mapCode(s.value),subject:h(this.patient),onsetDateTime:f(s.effectiveTime?.[0]?.low?.["@_value"])};return this.resources.push(c),{condition:h(c),use:{coding:[{system:gt,code:"AD",display:"Admission diagnosis"}]}}}).filter(Boolean);r.length>0&&(n.diagnosis=r)}return n.extension=this.mapTextReference(t.text),n}processProcedure(e,t){return{resourceType:"Procedure",id:this.mapId(t.id),identifier:this.mapIdentifiers(t.id),status:Ut.mapCcdaToFhirWithDefault(t.statusCode?.["@_code"],"completed"),code:this.mapCode(t.code),subject:h(this.patient),performedPeriod:this.mapEffectiveTimeToPeriod(t.effectiveTime?.[0]),bodySite:t.targetSiteCode?[this.mapCode(t.targetSiteCode)]:void 0,extension:this.mapTextReference(t.text)}}mapTextReference(e){if(!(!e||typeof e!="object")&&e?.reference?.["@_value"])return[{url:de,valueString:e.reference?.["@_value"]}]}};function Se(i){if(i){if(typeof i=="string")return i;if(typeof i=="object"&&"#text"in i)return i["#text"]}}var kt=[{"@_root":et,"@_extension":"2015-08-01"},{"@_root":et},{"@_root":tt,"@_extension":"2015-08-01"},{"@_root":tt}],Dn=[{"@_root":be,"@_extension":"2015-08-01"}],vn=[{"@_root":xe,"@_extension":"2014-06-09"}],xn=[{"@_root":Pe,"@_extension":"2015-08-01"}],Ge=[{"@_root":z},{"@_root":z,"@_extension":"2015-08-01"},{"@_root":Z},{"@_root":Z,"@_extension":"2015-08-01"}],Pn=[{"@_root":Ci,"@_extension":"2015-08-01"}],bn=[{"@_root":nt},{"@_root":nt,"@_extension":"2015-08-01"}],Un=[{"@_root":B,"@_extension":"2014-06-09"}],go=[{"@_root":P,"@_extension":"2014-06-09"}],Ao=[{"@_root":it,"@_extension":"2015-08-01"}],Ln=[{"@_root":it,"@_extension":"2015-08-01"}],Vn=[{"@_root":Ri,"@_extension":"2015-08-01"}],wn=[{"@_root":gi}],Mn=[{"@_root":P},{"@_root":P,"@_extension":"2014-06-09"}],kn=[{"@_root":Ai,"@_extension":"2015-08-01"}],Bn=[{"@_root":X}],Fn=[{"@_root":Le,"@_extension":"2015-08-01"}],Gn=[{"@_root":De,"@_extension":"2014-06-09"}],Yn=[{"@_root":Ni,"@_extension":"2015-08-01"}],$n=[{"@_root":Ve,"@_extension":"2016-11-01"}],Hn=[{"@_root":we,"@_extension":"2022-06-01"}],jn=[{"@_root":Ue,"@_extension":"2015-08-01"}],Bt={"48765-2":Dn,"10160-0":vn,"11450-4":xn,"11369-6":Ge,"11348-0":Ge,"9176-8":Ge,"8716-3":Pn,"29762-2":bn,"47519-4":Un,"30954-2":Ln,"51848-0":wn,"18776-5":Mn,"46240-8":kn,"61146-7":Bn,"75310-3":Fn,"42349-1":Gn,"10190-7":Yn,"11488-4":$n,"85847-2":Hn,"48768-6":jn,"46264-8":Vn};function Ro(i){return new Ft(i).convert()}var Ft=class{constructor(e){this.bundle=e;let t=this.findResource("Composition");if(!t)throw new Error("Composition not found");let n=this.findResource("Patient");if(!n)throw new Error("Patient not found");this.composition=t,this.patient=n}convert(){let e=this.createSections();return{realmCode:{"@_code":"US"},typeId:{"@_root":ai,"@_extension":"POCD_HD000040"},templateId:kt,id:this.mapIdentifiers(this.composition.id,void 0),code:{"@_code":"34133-9","@_displayName":"Summarization of Episode Note","@_codeSystem":k,"@_codeSystemName":"LOINC"},title:this.composition.title,effectiveTime:this.mapEffectiveTime(this.composition.date,void 0),confidentialityCode:this.composition.confidentiality?vt.mapFhirToCcdaCode(this.composition.confidentiality):void 0,languageCode:{"@_code":this.composition.language??"en-US"},recordTarget:this.createRecordTarget(),author:this.mapAuthor(this.composition.author?.[0],this.composition.date),custodian:this.mapCustodian(this.composition.custodian),documentationOf:this.mapDocumentationOf(this.composition.event),component:e.length>0?{structuredBody:{component:e.map(t=>({section:[t]}))}}:void 0}}findResource(e){return this.bundle.entry?.find(t=>t.resource?.resourceType===e)?.resource}findResourceByReference(e){if(!e?.reference)return;let[t,n]=e.reference.split("/");if(!(!t||!n))return this.bundle.entry?.find(r=>r.resource?.resourceType===t&&r.resource?.id===n)?.resource}findResourcesByReferences(e){return e?e.map(t=>this.findResourceByReference(t)).filter(t=>!!t):[]}createRecordTarget(){if(!this.patient)throw new Error("Patient not found");return[{patientRole:{id:this.mapIdentifiers(this.patient.id,this.patient.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(this.patient.address),telecom:this.mapTelecom(this.patient.telecom),patient:this.mapPatient(this.patient)}}]}mapPatient(e){return{name:this.mapNames(e.name),administrativeGenderCode:this.mapGender(e.gender),birthTime:this.mapBirthDate(e.birthDate),raceCode:this.mapRace(e.extension),ethnicGroupCode:this.mapEthnicity(e.extension),languageCommunication:this.mapLanguageCommunication(e.communication)}}mapNames(e){return e?.map(t=>({"@_use":t.use?he.mapFhirToCcdaWithDefault(t.use,"L"):void 0,prefix:t.prefix,family:t.family,given:t.given,suffix:t.suffix}))}mapGender(e){if(e)return{"@_code":xt.mapFhirToCcda(e),"@_displayName":e?W(e):"Unknown","@_codeSystem":fi,"@_codeSystemName":"AdministrativeGender"}}mapBirthDate(e){if(e)return{"@_value":e.replace(/-/g,"")}}mapFhirAddressArrayToCcdaAddressArray(e){return!e||e.length===0?[{"@_nullFlavor":"UNK"}]:e.map(t=>this.mapFhirAddressToCcdaAddress(t)).filter(Boolean)}mapFhirAddressToCcdaAddress(e){return e?{"@_use":e.use?fe.mapFhirToCcda(e.use):void 0,streetAddressLine:e.line||[],city:e.city,state:e.state,postalCode:e.postalCode,country:e.country}:void 0}mapRace(e){let n=e?.find(r=>r.url===ue)?.extension?.find(r=>r.url==="ombCategory")?.valueCoding;if(n)return[{"@_code":n.code,"@_displayName":n.display,"@_codeSystem":Ke,"@_codeSystemName":"CDC Race and Ethnicity"}]}mapEthnicity(e){let n=e?.find(r=>r.url===le)?.extension?.find(r=>r.url==="ombCategory")?.valueCoding;if(n)return[{"@_code":n.code,"@_displayName":n.display,"@_codeSystem":Ke,"@_codeSystemName":"CDC Race and Ethnicity"}]}mapLanguageCommunication(e){if(e?.length)return[{"@_languageCode":e[0].language?.coding?.[0]?.code}]}createSections(){let e=[];if(this.composition.section)for(let t of this.composition.section)e.push(this.createSection(t));return e}createSection(e){let t=e.code?.coding?.[0]?.code;if(!t)throw new Error(`Missing section code: ${JSON.stringify(e.code)}`);let n=Bt[t];if(!n)throw new Error(`Unknown section code: ${t}`);let r=this.findResourcesByReferences(e.entry);return{templateId:n,code:d(e.code),title:e.title,text:this.mapFhirTextDivToCcdaSectionText(e.text),entry:r.map(o=>this.createEntry(e,o)).filter(Boolean),"@_nullFlavor":r.length===0?"NI":void 0}}createEntry(e,t){switch(t.resourceType){case"AllergyIntolerance":return this.createAllergyEntry(t);case"CarePlan":return this.createPlanOfTreatmentCarePlanEntry(t);case"CareTeam":return this.createCareTeamEntry(t);case"Condition":return this.createProblemEntry(t);case"DeviceUseStatement":return this.createDeviceUseStatementEntry(t);case"DiagnosticReport":return this.createDiagnosticReportEntry(t);case"Encounter":return this.createEncounterEntry(t);case"Goal":return this.createPlanOfTreatmentGoalEntry(t);case"Immunization":return this.createImmunizationEntry(t);case"MedicationRequest":return this.createMedicationEntry(t);case"Procedure":return this.createHistoryOfProceduresEntry(t);case"Observation":return this.createObservationEntry(t);case"ServiceRequest":return this.createPlanOfTreatmentServiceRequestEntry(t);default:throw new Error(`Unknown resource type: ${t.resourceType}`)}}mapFhirTextDivToCcdaSectionText(e){if(!e)return;let t=Vt(e.div)?.div;return t?.["@_xmlns"]&&delete t["@_xmlns"],t}createAllergyEntry(e){let t=e.reaction?.[0];return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":lt},{"@_root":lt,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"CONC","@_codeSystem":Xe},statusCode:{"@_code":me.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:this.mapEffectivePeriod(e.recordedDate,void 0),author:this.mapAuthor(e.recorder,e.recordedDate),text:this.createTextFromExtensions(e.extension),entryRelationship:[{"@_typeCode":"SUBJ",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":ot},{"@_root":ot,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"ASSERTION","@_codeSystem":ve},statusCode:{"@_code":"completed"},author:this.mapAuthor(e.asserter,e.recordedDate),effectiveTime:this.mapEffectivePeriod(e.onsetPeriod?.start??e.onsetDateTime,e.onsetPeriod?.end,!0),value:this.mapAllergyCategory(e.category),text:this.createTextFromExtensions(e.extension),participant:[{"@_typeCode":"CSM",participantRole:{"@_classCode":"MANU",playingEntity:{"@_classCode":"MMAT",code:{...d(e.code),originalText:e.code?.extension?{reference:this.getNarrativeReference(e.code?.extension)}:void 0}}}}],entryRelationship:t?[{"@_typeCode":"MFST","@_inversionInd":"true",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":at},{"@_root":at,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(t.id,void 0),code:{"@_code":"ASSERTION","@_codeSystem":ve},statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveDate(e.onsetDateTime,e.onsetPeriod),value:G(t.manifestation?.[0]),text:this.createTextFromExtensions(t.manifestation?.[0]?.extension),entryRelationship:[{"@_typeCode":"SUBJ","@_inversionInd":"true",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":st},{"@_root":st,"@_extension":"2014-06-09"}],code:{"@_code":"SEV","@_codeSystem":ve,"@_codeSystemName":"ActCode"},statusCode:{"@_code":"completed"},value:{"@_xsi:type":"CD","@_code":Ee.mapFhirToCcdaWithDefault(t.severity,"M"),"@_displayName":t.severity?W(t.severity):void 0,"@_codeSystem":w,"@_codeSystemName":"SNOMED CT"},text:this.createTextFromExtensions(t.extension)}]}]}]}]:[]}]}]}]}}mapAllergyCategory(e){if(!e||e.length===0)return;let t=Pt.mapFhirToCcdaCode(e[0]);if(t)return{"@_xsi:type":"CD",...t}}mapAuthor(e,t){if(!e)return;let n=this.findResourceByReference(e);if(n?.resourceType==="Practitioner")return[{templateId:[{"@_root":qi}],time:t?{"@_value":T(t)}:void 0,assignedAuthor:{id:this.mapIdentifiers(n.id,n.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(n.address),telecom:this.mapTelecom(n.telecom),code:d(n.qualification?.[0]),assignedPerson:{name:this.mapNames(n.name)}}}]}mapCustodian(e){if(!e)return;let t=this.findResourceByReference(e);if(t)return{assignedCustodian:{representedCustodianOrganization:{id:this.mapIdentifiers(t.id,t.identifier),name:t.name?[t.name]:void 0,telecom:this.mapTelecom(t.telecom),addr:this.mapFhirAddressArrayToCcdaAddressArray(t.address)}}}}mapDocumentationOf(e){if(!e||e.length===0)return;let t=e[0];if(!(!t||!t.code&&!t.period))return{serviceEvent:{"@_classCode":"PCPR",code:d(t.code?.[0]),effectiveTime:this.mapEffectiveDate(void 0,t.period)}}}createMedicationEntry(e){let t=e.contained?.find(s=>s.resourceType==="Medication"),n=t?.code||e.medicationCodeableConcept,r=t?.manufacturer,o=[];if(e.dispenseRequest?.validityPeriod){let s=this.mapEffectiveDate(void 0,e.dispenseRequest.validityPeriod);s&&o.push(...s)}return e.dosageInstruction?.[0]?.timing?.repeat?.period&&o.push({"@_xsi:type":"PIVL_TS","@_institutionSpecified":"true","@_operator":"A",period:{"@_value":e.dosageInstruction[0].timing.repeat.period.toString(),"@_unit":e.dosageInstruction[0].timing.repeat.periodUnit}}),{substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN",templateId:[{"@_root":ct,"@_extension":"2014-06-09"},{"@_root":ct}],id:[{"@_root":e.id||crypto.randomUUID()}],text:this.createTextFromExtensions(e.extension),statusCode:{"@_code":Oe.mapFhirToCcdaWithDefault(e.status,"active")},effectiveTime:o,routeCode:this.mapMedicationRoute(e.dosageInstruction?.[0]?.route),doseQuantity:this.mapDoseQuantity(e.dosageInstruction?.[0]?.doseAndRate?.[0]),consumable:{"@_typeCode":"CSM",manufacturedProduct:[{"@_classCode":"MANU",templateId:[{"@_root":ut,"@_extension":"2014-06-09"},{"@_root":ut}],manufacturedMaterial:[{code:[{...d(n),originalText:this.createTextFromExtensions(t?.extension)}]}],manufacturerOrganization:r?[{id:this.mapIdentifiers(r.id,r.identifier?[r.identifier]:void 0),name:[r.display]}]:void 0}]},entryRelationship:e.dosageInstruction?.filter(s=>!!s.extension)?.map(s=>({"@_typeCode":"COMP",substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN",templateId:[{"@_root":Me}],code:{"@_code":"76662-6","@_codeSystem":k,"@_codeSystemName":"LOINC","@_displayName":"Medication Instructions"},text:this.createTextFromExtensions(s.extension),consumable:{manufacturedProduct:[{manufacturedLabeledDrug:[{"@_nullFlavor":"NA"}]}]}}]}))}]}}mapMedicationRoute(e){if(e)return d(e)}mapDoseQuantity(e){if(e?.doseQuantity)return{"@_value":e.doseQuantity.value?.toString(),"@_unit":e.doseQuantity.unit}}mapTelecom(e){return!e||e.length===0?[{"@_nullFlavor":"UNK"}]:e?.map(t=>({"@_use":t.use?_e.mapFhirToCcda(t.use):void 0,"@_value":`${this.mapTelecomSystemToPrefix(t.system)}${t.value}`}))}mapTelecomSystemToPrefix(e){return e==="email"?"mailto:":e==="phone"?"tel:":e==="fax"?"fax:":""}mapIdentifiers(e,t){let n=[];if(e&&n.push({"@_root":e}),t)for(let r of t){let o=Dt(r.system);o&&n.push({"@_root":o,"@_extension":r.value})}return n}getNarrativeReference(e){let t=e?.find(n=>n.url===de)?.valueString;return t?{"@_value":t}:void 0}createTextFromExtensions(e){let t=this.getNarrativeReference(e);return t?{reference:t}:void 0}createProblemEntry(e){return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":rt},{"@_root":rt,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,void 0),code:{"@_code":"CONC","@_codeSystem":Xe},statusCode:{"@_code":Ie.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:this.mapEffectivePeriod(e.recordedDate,void 0),entryRelationship:[{"@_typeCode":"SUBJ",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":ee},{"@_root":ee,"@_extension":"2015-08-01"}],id:e.identifier?this.mapIdentifiers(void 0,e.identifier):[{"@_root":Re()}],text:this.createTextFromExtensions(e.extension),code:{"@_code":"55607006","@_codeSystem":w,"@_codeSystemName":"SNOMED CT","@_displayName":"Problem",translation:[{"@_code":"75323-6","@_codeSystem":k,"@_codeSystemName":"LOINC","@_displayName":"Condition"}]},statusCode:{"@_code":"completed"},effectiveTime:[{low:e.onsetDateTime?{"@_value":V(e.onsetDateTime)}:void 0,high:e.abatementDateTime?{"@_value":T(e.abatementDateTime)}:void 0}],value:G(e.code),author:this.mapAuthor(e.asserter,e.recordedDate)}]}]}]}}createImmunizationEntry(e){let t=e?.manufacturer,n={substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN","@_negationInd":"false",templateId:[{"@_root":ft},{"@_root":ft,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),text:this.createTextFromExtensions(e.extension),statusCode:{"@_code":Te.mapFhirToCcdaWithDefault(e.status,"completed")},effectiveTime:[{"@_value":V(e.occurrenceDateTime)}],consumable:{manufacturedProduct:[{"@_classCode":"MANU",templateId:[{"@_root":_t},{"@_root":_t,"@_extension":"2014-06-09"}],manufacturedMaterial:[{code:[d(e.vaccineCode)],lotNumberText:e.lotNumber?[e.lotNumber]:void 0}],manufacturerOrganization:t?[{id:this.mapIdentifiers(t.id,t.identifier?[t.identifier]:void 0),name:[t.display]}]:void 0}]}}]};return e.performer&&(n.substanceAdministration[0].performer=e.performer.map(r=>this.mapImmunizationPerformerToCcdaPerformer(r)).filter(Boolean)),n}mapImmunizationPerformerToCcdaPerformer(e){if(!e)return;let t=this.findResourceByReference(e.actor);if(!t)return;let n,r;return t.resourceType==="PractitionerRole"?(n=this.findResourceByReference(t.practitioner),r=this.findResourceByReference(t.organization)):t.resourceType==="Practitioner"?n=t:t.resourceType==="Organization"&&(r=t),{assignedEntity:{id:this.mapIdentifiers(t.id,t.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(n?.address),telecom:this.mapTelecom(t.telecom),assignedPerson:n?{id:this.mapIdentifiers(n.id,n.identifier),name:this.mapNames(n.name)}:void 0,representedOrganization:r?{id:this.mapIdentifiers(r.id,r.identifier),name:r.name?[r.name]:void 0,addr:this.mapFhirAddressArrayToCcdaAddressArray(r.address),telecom:this.mapTelecom(r.telecom)}:void 0}}}createObservationEntry(e){return e.hasMember?{organizer:[this.createVitalSignsOrganizer(e)]}:{observation:[this.createVitalSignObservation(e)]}}createPlanOfTreatmentCarePlanEntry(e){return{act:[{"@_classCode":"ACT","@_moodCode":"INT",id:this.mapIdentifiers(e.id,e.identifier),code:G(e.category?.[0]),templateId:[{"@_root":Pi}],statusCode:{"@_code":"completed"},text:e.description?{"#text":e.description}:this.createTextFromExtensions(e.extension)}]}}createPlanOfTreatmentGoalEntry(e){return{observation:[{"@_classCode":"OBS","@_moodCode":"GOL",templateId:[{"@_root":pt}],id:this.mapIdentifiers(e.id,e.identifier),code:d(e.description),statusCode:{"@_code":this.mapPlanOfTreatmentStatus(e.lifecycleStatus)},effectiveTime:[{"@_value":T(e.startDate)}],text:this.createTextFromExtensions(e.extension),entryRelationship:e.target?.map(n=>({"@_typeCode":"RSON","@_inversionInd":"true",act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":te},{"@_root":te,"@_extension":"2014-06-09"}],code:d(n.measure),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":T(e.startDate)}]}]}))}]}}mapPlanOfTreatmentStatus(e){switch(e){case"achieved":return"completed";case"cancelled":return"cancelled";default:return"active"}}createVitalSignsOrganizer(e){let t=[];if(e.hasMember)for(let r of e.hasMember){let o=this.findResourceByReference(r);if(!(!o||o.resourceType!=="Observation"))if(o.component)for(let s of o.component)t.push({observation:[this.createVitalSignComponentObservation(o,s)]});else t.push({observation:[this.createVitalSignObservation(o)]})}return{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":re},{"@_root":re,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:d(e.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":T(e.effectiveDateTime)}],component:t}}createVitalSignObservation(e){return{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:d(e.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":T(e.effectiveDateTime)}],value:this.mapObservationValue(e),referenceRange:this.mapReferenceRangeArray(e.referenceRange),text:this.createTextFromExtensions(e.extension),author:this.mapAuthor(e.performer?.[0],e.effectiveDateTime)}}createVitalSignComponentObservation(e,t){return{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:d(t.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":T(e.effectiveDateTime)}],value:this.mapObservationValue(t),referenceRange:this.mapReferenceRangeArray(t.referenceRange),text:this.createTextFromExtensions(t.extension),author:this.mapAuthor(e.performer?.[0],e.effectiveDateTime)}}mapObservationTemplateId(e){let t=e.code?.coding?.[0]?.code,n=e.category?.[0]?.coding?.[0]?.code;return t==="72166-2"?[{"@_root":se},{"@_root":se,"@_extension":"2014-06-09"}]:t==="11367-0"?[{"@_root":ae},{"@_root":ae,"@_extension":"2014-06-09"}]:n==="exam"?[{"@_root":ie},{"@_root":ie,"@_extension":"2014-06-09"}]:n==="laboratory"?[{"@_root":K},{"@_root":K,"@_extension":"2015-08-01"}]:[{"@_root":oe},{"@_root":oe,"@_extension":"2014-06-09"}]}mapObservationValue(e){if(e.valueQuantity)return{"@_xsi:type":"PQ","@_unit":e.valueQuantity.unit,"@_value":e.valueQuantity.value?.toString()};if(e.valueCodeableConcept)return G(e.valueCodeableConcept);if(e.valueString)return{"@_xsi:type":"ST","#text":e.valueString}}mapReferenceRangeArray(e){if(!(!e||e.length===0))return e.map(t=>this.mapReferenceRange(t)).filter(Boolean)}mapReferenceRange(e){if(!e)return;let t=this.getNarrativeReference(e.extension);return t?{observationRange:{text:{reference:t},value:{"@_xsi:type":"ED",reference:t}}}:{observationRange:{text:this.createTextFromExtensions(e.extension)}}}createHistoryOfProceduresEntry(e){if(e.resourceType==="Procedure"){let t=["183948003","409063005","311331002","61310001","183945009","309814009","278373008","410606002","183933003","24642003","225338006","128939004"],n=e.code?.coding?.[0]?.code;return n&&t.includes(n)?{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":te},{"@_root":te,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:d(e.code),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.performedDateTime,e.performedPeriod),text:this.createTextFromExtensions(e.extension)}]}:{procedure:[{"@_classCode":"PROC","@_moodCode":"EVN",templateId:[{"@_root":ne},{"@_root":ne,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:d(e.code),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.performedDateTime,e.performedPeriod),text:this.createTextFromExtensions(e.extension),targetSiteCode:d(e.bodySite?.[0]),participant:[this.mapLocationToParticipant(e.location)].filter(Boolean)}]}}if(e.resourceType==="Observation")return{observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:d(e.code),value:this.mapObservationValue(e),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.effectiveDateTime,e.effectivePeriod),text:this.createTextFromExtensions(e.extension)}]};throw new Error(`Unknown history of procedures resource type: ${e.resourceType}`)}mapLocationToParticipant(e){if(!e)return;let t=this.findResourceByReference(e);if(t)return{"@_typeCode":"LOC",participantRole:{"@_classCode":"SDLOC",templateId:[{"@_root":dt}],id:this.mapIdentifiers(t.id,t.identifier),code:d(t.type?.[0]),addr:t.address?this.mapFhirAddressArrayToCcdaAddressArray([t.address]):void 0,telecom:this.mapTelecom(t.telecom),playingEntity:{"@_classCode":"PLC",name:t.name?[t.name]:void 0}}}}mapEffectiveTime(e,t){if(t)return[{low:{"@_value":T(t.start)},high:{"@_value":T(t.end)}}];if(e)return[{"@_value":T(e)}]}mapEffectiveDate(e,t){if(t)return[{"@_xsi:type":"IVL_TS",low:t.start?{"@_value":V(t.start)}:void 0,high:t.end?{"@_value":V(t.end)}:void 0}];if(e)return[{"@_value":V(e)}]}mapEffectivePeriod(e,t,n=!1){if(!e&&!t)return;let r={};return e?r.low={"@_value":T(e)}:n&&(r.low={"@_nullFlavor":"NI"}),t?r.high={"@_value":T(t)}:n&&(r.high={"@_nullFlavor":"NI"}),[r]}createEncounterEntry(e){return{encounter:[{"@_classCode":"ENC","@_moodCode":"EVN",templateId:[{"@_root":ht},{"@_root":ht,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:d(e.type?.[0]),text:this.createTextFromExtensions(e.extension),effectiveTime:this.mapEffectiveTime(void 0,e.period),entryRelationship:e.participant?.map(t=>({"@_typeCode":"LOC",participantRole:{"@_classCode":"SDLOC",templateId:[{"@_root":dt}],code:d(t.type?.[0])}}))}]}}createCareTeamEntry(e){return{organizer:[{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":mt,"@_extension":"2022-07-01"},{"@_root":mt,"@_extension":"2022-06-01"}],id:this.mapIdentifiers(e.id,e.identifier),component:e.participant?.map(t=>({"@_typeCode":"PRF",role:t.role}))}]}}createPlanOfTreatmentServiceRequestEntry(e){return{observation:[{"@_classCode":"OBS","@_moodCode":"RQO",templateId:[{"@_root":pt}],id:this.mapIdentifiers(e.id,e.identifier),code:d(e.code),statusCode:{"@_code":this.mapPlanOfTreatmentStatus(e.status)},effectiveTime:[{"@_value":T(e.occurrenceDateTime)}],text:this.createTextFromExtensions(e.extension)}]}}createDiagnosticReportEntry(e){let t=[];if(e.result)for(let n of e.result){let r=this.findResourceByReference(n);!r||r.resourceType!=="Observation"||t.push({observation:[this.createVitalSignObservation(r)]})}return{organizer:[{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":J},{"@_root":J,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:d(e.code),statusCode:{"@_code":"completed"},component:t}]}}createDeviceUseStatementEntry(e){let t=this.findResourceByReference(e.device);if(!t)return;let n=[],r=this.mapIdentifiers(t.id,t.identifier);return r&&n.push(...r),t.udiCarrier?.[0]?.deviceIdentifier&&n.push({"@_root":It,"@_extension":t.udiCarrier[0].carrierHRF,"@_assigningAuthorityName":"FDA"}),{procedure:[{"@_classCode":"PROC","@_moodCode":"EVN",templateId:[{"@_root":ne,"@_extension":"2014-06-09"},{"@_root":ne}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"360030002","@_codeSystem":w,"@_codeSystemName":"SNOMED CT","@_displayName":"Application of medical device"},statusCode:{"@_code":"completed"},participant:[{"@_typeCode":"DEV",participantRole:{"@_classCode":"MANU",templateId:[{"@_root":Li}],id:n,playingDevice:{"@_classCode":"DEV",code:d(t.type)},scopingEntity:{id:[{"@_root":It}]}}}]}]}}};0&&(module.exports={ACT_CODE_SYSTEM,ADDRESS_USE_MAPPER,ADDRESS_USE_VALUE_SET,ADMINISTRATIVE_GENDER_VALUE_SET,ALLERGIES_SECTION_TEMPLATE_IDS,ALLERGY_CATEGORY_MAPPER,ALLERGY_CLINICAL_CODE_SYSTEM,ALLERGY_SEVERITY_MAPPER,ALLERGY_STATUS_MAPPER,ALLERGY_VERIFICATION_CODE_SYSTEM,ASSESSMENTS_SECTION_TEMPLATE_IDS,CARE_TEAM_SECTION_TEMPLATE_IDS,CCDA_NARRATIVE_REFERENCE_URL,CCDA_TEMPLATE_CODE_SYSTEM,CCDA_TEMPLATE_IDS,CLINICAL_CONDITION_CODE_SYSTEM,CLINICAL_NOTES_SECTION_TEMPLATE_IDS,CONDITION_CATEGORY_CODE_SYSTEM,CONDITION_VERIFICATION_CODE_SYSTEM,CONDITION_VER_STATUS_CODE_SYSTEM,CONFIDENTIALITY_CODE_SYSTEM,CONFIDENTIALITY_MAPPER,CONTACT_ENTITY_USE_VALUE_SET,CVX_URL,DEVICES_SECTION_TEMPLATE_IDS,DIAGNOSIS_ROLE_CODE_SYSTEM,ENCOUNTERS_SECTION_TEMPLATE_IDS,ENCOUNTER_STATUS_MAPPER,EnumMapper,FHIR_CVX_URL,GENDER_MAPPER,GOALS_SECTION_TEMPLATE_IDS,HEALTH_CONCERNS_SECTION_TEMPLATE_IDS,HTTP,HUMAN_NAME_USE_MAPPER,IMMUNIZATIONS_SECTION_TEMPLATE_IDS,IMMUNIZATION_STATUS_MAPPER,INSURANCE_SECTION_TEMPLATE_IDS,LAB_TESTS_SECTION_TEMPLATE_IDS,LANGUAGE_MODE_CODE_SYSTEM,LANGUAGE_MODE_URL,LANGUAGE_PROFICIENCY_CODE_SYSTEM,LANGUAGE_PROFICIENCY_URL,LOINC_TO_TEMPLATE_IDS,MEDICATIONS_SECTION_TEMPLATE_IDS,MEDICATION_REQUEST_STATUS_VALUE_SET,MEDICATION_STATUS_MAPPER,MENTAL_STATUS_SECTION_TEMPLATE_IDS,NAME_USE_VALUE_SET,NCI_THESAURUS_URL,NDFRT_URL,NUCC_TAXONOMY_URL,OBSERVATION_CATEGORY_CODE_SYSTEM,OBSERVATION_CATEGORY_MAPPER,PARTICIPATION_CODE_SYSTEM,PATIENT_NOTES_SECTION_TEMPLATE_IDS,PLAN_OF_TREATMENT_SECTION_TEMPLATE_IDS,PROBLEMS_SECTION_TEMPLATE_IDS,PROBLEM_STATUS_MAPPER,PROCEDURES_SECTION_TEMPLATE_IDS,PROCEDURE_STATUS_MAPPER,RACE_CODE_SYSTEM,REASON_FOR_REFERRAL_SECTION_TEMPLATE_IDS,RESULTS_SECTION_TEMPLATE_IDS,SOCIAL_HISTORY_SECTION_TEMPLATE_IDS,SYSTEM_MAPPER,TELECOM_USE_MAPPER,UNII_URL,US_CORE_CONDITION_URL,US_CORE_ETHNICITY_URL,US_CORE_MEDICATION_REQUEST_URL,US_CORE_PATIENT_URL,US_CORE_RACE_URL,US_DRIVER_LICENSE_URL,US_NPI_URL,US_SSN_URL,VA_MEDRT_URL,VITAL_SIGNS_SECTION_TEMPLATE_IDS,XSI_URL,convertCcdaToFhir,convertCcdaToXml,convertFhirToCcda,convertToCompactXml,convertXmlToCcda,mapCcdaSystemToFhir,mapCcdaToFhirDate,mapCcdaToFhirDateTime,mapCodeableConceptToCcdaCode,mapCodeableConceptToCcdaValue,mapCodingToCcdaCode,mapFhirSystemToCcda,mapFhirToCcdaDate,mapFhirToCcdaDateTime,parseXml});
3
3
  /*!
4
4
  * Reconnecting WebSocket
5
5
  * by Pedro Ladaria <pedro.ladaria@gmail.com>