@medplum/ccda 5.1.2 → 5.1.4

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,4 +1,4 @@
1
- "use strict";var it=Object.defineProperty;var zo=Object.getOwnPropertyDescriptor;var Zo=Object.getOwnPropertyNames;var Xo=Object.prototype.hasOwnProperty;var Jo=(t,e,i)=>e in t?it(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var Ko=(t,e)=>{for(var i in e)it(t,i,{get:e[i],enumerable:!0})},es=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Zo(e))!Xo.call(t,r)&&r!==i&&it(t,r,{get:()=>e[r],enumerable:!(n=zo(e,r))||n.enumerable});return t};var ts=t=>es(it({},"__esModule",{value:!0}),t);var D=(t,e,i)=>Jo(t,typeof e!="symbol"?e+"":e,i);var Wa={};Ko(Wa,{ACT_CODE_SYSTEM:()=>wt,ADDRESS_USE_MAPPER:()=>ze,ADDRESS_USE_VALUE_SET:()=>zr,ADMINISTRATIVE_GENDER_CODE_SYSTEM:()=>jr,ADMINISTRATIVE_GENDER_VALUE_SET:()=>Xr,ALLERGIES_SECTION_TEMPLATE_IDS:()=>lo,ALLERGY_CATEGORY_MAPPER:()=>sn,ALLERGY_CLINICAL_CODE_SYSTEM:()=>ke,ALLERGY_SEVERITY_MAPPER:()=>Je,ALLERGY_STATUS_MAPPER:()=>Xe,ALLERGY_VERIFICATION_CODE_SYSTEM:()=>Vt,ASSESSMENTS_SECTION_TEMPLATE_IDS:()=>Oo,CARE_TEAM_SECTION_TEMPLATE_IDS:()=>Do,CCDA_NARRATIVE_REFERENCE_URL:()=>Ye,CCDA_TEMPLATE_CODE_SYSTEM:()=>ma,CCDA_TEMPLATE_IDS:()=>fn,CLINICAL_CONDITION_CODE_SYSTEM:()=>Ut,CLINICAL_NOTES_SECTION_TEMPLATE_IDS:()=>ya,CONDITION_CATEGORY_CODE_SYSTEM:()=>yi,CONDITION_VERIFICATION_CODE_SYSTEM:()=>Si,CONDITION_VER_STATUS_CODE_SYSTEM:()=>Mt,CONFIDENTIALITY_CODE_SYSTEM:()=>qr,CONFIDENTIALITY_MAPPER:()=>rn,CONTACT_ENTITY_USE_VALUE_SET:()=>Jr,CVX_URL:()=>ao,DEVICES_SECTION_TEMPLATE_IDS:()=>To,DIAGNOSIS_ROLE_CODE_SYSTEM:()=>gi,ENCOUNTERS_SECTION_TEMPLATE_IDS:()=>yo,ENCOUNTER_STATUS_MAPPER:()=>an,EnumMapper:()=>g,FHIR_CVX_URL:()=>co,FHIR_ICF_URL:()=>uo,FUNCTIONAL_STATUS_TEMPLATE_IDS:()=>xo,FhirToCcdaConverter:()=>Bt,GENDER_MAPPER:()=>on,GOALS_SECTION_TEMPLATE_IDS:()=>Co,HEALTH_CONCERNS_SECTION_TEMPLATE_IDS:()=>go,HTTP:()=>Z,HUMAN_NAME_USE_MAPPER:()=>Qe,IMMUNIZATIONS_SECTION_TEMPLATE_IDS:()=>fo,IMMUNIZATION_STATUS_MAPPER:()=>Ke,INSURANCE_COVERAGE_TYPE_MAPPER:()=>un,INSURANCE_SECTION_TEMPLATE_IDS:()=>vo,LAB_TESTS_SECTION_TEMPLATE_IDS:()=>Ca,LANGUAGE_MODE_CODE_SYSTEM:()=>ca,LANGUAGE_MODE_URL:()=>pa,LANGUAGE_PROFICIENCY_CODE_SYSTEM:()=>da,LANGUAGE_PROFICIENCY_URL:()=>ha,LOINC_ADMINISTRATIVE_SEX:()=>qi,LOINC_ALLERGIES_SECTION:()=>Di,LOINC_ASSESSMENTS_SECTION:()=>$e,LOINC_BIRTH_SEX:()=>Wi,LOINC_CARE_TEAM_SECTION:()=>ki,LOINC_CLINICAL_FINDING:()=>zi,LOINC_CONDITION:()=>Gi,LOINC_DEVICES_SECTION:()=>Mi,LOINC_DISABILITY_STATUS:()=>Xi,LOINC_ENCOUNTERS_SECTION:()=>Vi,LOINC_FUNCTIONAL_STATUS_ASSESSMENT_NOTE:()=>Ji,LOINC_FUNCTIONAL_STATUS_SECTION:()=>Zi,LOINC_GOALS_SECTION:()=>ce,LOINC_HEALTH_CONCERNS_SECTION:()=>de,LOINC_HISTORY_OF_OCCUPATION:()=>Ki,LOINC_HISTORY_OF_OCCUPATION_INDUSTRY:()=>en,LOINC_HISTORY_OF_SOCIAL_FUNCTION:()=>Qi,LOINC_HISTORY_OF_TOBACCO_USE:()=>ji,LOINC_IMMUNIZATIONS_SECTION:()=>vi,LOINC_INSURANCE_SECTION:()=>Bi,LOINC_MEDICATIONS_SECTION:()=>xi,LOINC_MEDICATION_INSTRUCTIONS:()=>Yi,LOINC_MENTAL_STATUS_SECTION:()=>Fi,LOINC_NOTES_SECTION:()=>je,LOINC_NOTE_DOCUMENT:()=>_a,LOINC_OVERALL_GOAL:()=>Hi,LOINC_PATIENT_SUMMARY_DOCUMENT:()=>Ea,LOINC_PLAN_OF_TREATMENT_SECTION:()=>He,LOINC_PREGNANCY_STATUS:()=>Ft,LOINC_PROBLEMS_SECTION:()=>Ge,LOINC_PROCEDURES_SECTION:()=>Ui,LOINC_REASON_FOR_REFERRAL_SECTION:()=>ue,LOINC_REFERRAL_NOTE:()=>wi,LOINC_RESULTS_SECTION:()=>Pi,LOINC_SOCIAL_HISTORY_SECTION:()=>bi,LOINC_SUMMARY_OF_EPISODE_NOTE:()=>qe,LOINC_TOBACCO_SMOKING_STATUS:()=>$i,LOINC_TO_TEMPLATE_IDS:()=>_n,LOINC_TRIBAL_AFFILIATION:()=>tn,LOINC_VITAL_SIGNS_SECTION:()=>Li,MEDICATIONS_SECTION_TEMPLATE_IDS:()=>po,MEDICATION_REQUEST_STATUS_VALUE_SET:()=>la,MEDICATION_STATUS_MAPPER:()=>et,MENTAL_STATUS_SECTION_TEMPLATE_IDS:()=>No,NAME_USE_VALUE_SET:()=>Zr,NCI_THESAURUS_URL:()=>Kr,NDFRT_URL:()=>so,NUCC_TAXONOMY_URL:()=>ro,OBSERVATION_CATEGORY_CODE_SYSTEM:()=>Wr,OBSERVATION_CATEGORY_MAPPER:()=>dn,PARTICIPATION_CODE_SYSTEM:()=>Ci,PATIENT_NOTES_SECTION_TEMPLATE_IDS:()=>Ro,PLAN_OF_TREATMENT_SECTION_TEMPLATE_IDS:()=>So,PROBLEMS_SECTION_TEMPLATE_IDS:()=>ho,PROBLEM_STATUS_MAPPER:()=>le,PROCEDURES_SECTION_TEMPLATE_IDS:()=>Eo,PROCEDURE_STATUS_MAPPER:()=>cn,RACE_CODE_SYSTEM:()=>ua,REASON_FOR_REFERRAL_SECTION_TEMPLATE_IDS:()=>Ao,REFERRAL_TEMPLATE_IDS:()=>mn,RESULTS_SECTION_TEMPLATE_IDS:()=>Io,ROLE_CODE_CODE_SYSTEM:()=>Qr,SOCIAL_HISTORY_SECTION_TEMPLATE_IDS:()=>_o,SYSTEM_MAPPER:()=>We,TELECOM_USE_MAPPER:()=>Ze,UNII_URL:()=>no,US_CORE_CONDITION_URL:()=>Ai,US_CORE_ETHNICITY_URL:()=>Be,US_CORE_MEDICATION_REQUEST_URL:()=>Ni,US_CORE_PATIENT_URL:()=>fa,US_CORE_RACE_URL:()=>ae,US_DRIVER_LICENSE_URL:()=>to,US_NPI_URL:()=>io,US_SSN_URL:()=>eo,VA_MEDRT_URL:()=>oo,VITAL_SIGNS_SECTION_TEMPLATE_IDS:()=>mo,XSI_URL:()=>Ri,convertCcdaToFhir:()=>Sa,convertCcdaToXml:()=>Oa,convertFhirToCcda:()=>qa,convertToCompactXml:()=>pn,convertXmlToCcda:()=>Ta,mapCcdaCodeToCodeableConcept:()=>kt,mapCcdaSystemToFhir:()=>z,mapCcdaToFhirDate:()=>pt,mapCcdaToFhirDateTime:()=>C,mapCodeableConceptToCcdaCode:()=>p,mapCodeableConceptToCcdaValue:()=>b,mapCodingToCcdaCode:()=>Oi,mapFhirPeriodOrDateTimeToCcda:()=>Xt,mapFhirSystemToCcda:()=>nn,mapFhirToCcdaDate:()=>L,mapFhirToCcdaDateTime:()=>T,parseXml:()=>ln});module.exports=ts(Wa);var is=Object.defineProperty,ns=(t,e,i)=>e in t?is(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,S=(t,e,i)=>ns(t,typeof e!="symbol"?e+"":e,i),$t=class{constructor(t=10){S(this,"max"),S(this,"cache"),this.max=t,this.cache=new Map}clear(){this.cache.clear()}get(t){let e=this.cache.get(t);return e&&(this.cache.delete(t),this.cache.set(t,e)),e}set(t,e){this.cache.has(t)?this.cache.delete(t):this.cache.size>=this.max&&this.cache.delete(this.first()),this.cache.set(t,e)}delete(t){this.cache.delete(t)}keys(){return this.cache.keys()}first(){return this.cache.keys().next().value}},rs=class{constructor(t,e){S(this,"operator"),S(this,"child"),this.operator=t,this.child=e}toString(){return`${this.operator}(${this.child.toString()})`}},Ie=class{constructor(t,e,i){S(this,"operator"),S(this,"left"),S(this,"right"),this.operator=t,this.left=e,this.right=i}toString(){return`(${this.left.toString()} ${this.operator} ${this.right.toString()})`}},os=class{constructor(){S(this,"prefixParselets",{}),S(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 ss(t,this.prefixParselets,this.infixParselets)}},ss=class{constructor(t,e,i){S(this,"tokens"),S(this,"prefixParselets"),S(this,"infixParselets"),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 new 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 new Error("Cant consume unknown more tokens.");if(t&&this.peek()?.id!==t){let i=this.peek();throw new 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 new 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]}},Te="http://unitsofmeasure.org",at="http://loinc.org",ct="http://snomed.info/sct",gn="http://www.nlm.nih.gov/research/umls/rxnorm",An="http://www.ama-assn.org/go/cpt";var Nn="http://hl7.org/fhir/sid/ndc",O="http://hl7.org",R="http://terminology.hl7.org";var as="unauthorized";var ot={resourceType:"OperationOutcome",id:as,issue:[{severity:"error",code:"login",details:{text:"Unauthorized"}}]},za={...ot,issue:[...ot.issue,{severity:"error",code:"expired",details:{text:"Token expired"}}]},Za={...ot,issue:[...ot.issue,{severity:"error",code:"invalid",details:{text:"Token not issued for this audience"}}]};function cs(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 ds(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,cs(r,o)])),constraints:[],innerTypes:[]};return e}var us={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 ls=ds(us);var Tn=Object.create(null);function ps(t){let e;return e=Tn[t],e||(e=Tn[t]=Object.create(null)),e}function hs(t,e){if(e){let i=ps(e)[t];if(i)return i}return ls[t]}function fs(t,e,i){let n=t.path;return ms(_s(t,e,i),n,e)}function ms(t,e,i){let n=e?e+".":"";return t===void 0?{type:"undefined",value:void 0,path:`${n}${i}`}:Array.isArray(t)?t.map((r,o)=>({...r,path:`${n}${i}[${o}]`})):{...t,path:`${n}${i}`}}var Xa=new $t(1e3);var Rn={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 c(t){return[{type:u.boolean,value:t}]}function j(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}:V(t)?{type:u.Quantity,value:t}:Oe(t)?{type:t.resourceType,value:t}:Un(t)?{type:u.CodeableConcept,value:t}:Ln(t)?{type:u.Coding,value:t}:{type:u.BackboneElement,value:t}}function $(t){return t.length===0?!1:!!t[0].value}function q(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 _s(t,e,i){if(!t.value)return;let n=Vs(t.type,e,i?.profileUrl);return n?Es(t,e,n):jt(t,e)}function Es(t,e,i){let n=t.value,r=i.type;if(!r||r.length===0)return;let o,s="undefined",a,l=i.path.lastIndexOf("."),E=i.path.substring(l+1),N=E,me=!1;E.endsWith("[x]")&&(N=E.substring(0,E.length-3),me=!0);for(let A of r){let Yt=N;if(me&&(Yt+=ie(A.code)),o=n[Yt],a=n["_"+Yt],o!==void 0||a!==void 0){s=A.code;break}}if(a)if(Array.isArray(o)){o=o.slice();for(let A=0;A<Math.max(o.length,a.length);A++)o[A]=Gt(o[A],a[A])}else if(!o&&Array.isArray(a)){o=a.slice();for(let A=0;A<a.length;A++)o[A]=Gt(void 0,a[A])}else o=Gt(o,a);if(!Ee(o))return(s==="Element"||s==="BackboneElement")&&(s=i.type[0].code),Array.isArray(o)?o.map(A=>On(A,s)):On(o,s)}function On(t,e){return e==="Resource"&&Oe(t)&&(e=t.resourceType),{type:e,value:t}}function jt(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(j):n=j(r)}else{let r=e.endsWith("[x]")?e.substring(0,e.length-3):e;for(let o of Object.values(u)){let s=r+ie(o);if(s in i){let a=i[s];Array.isArray(a)?n=a.map(l=>({type:o,value:l})):n={type:o,value:a};break}}}if(Array.isArray(n)){if(n.length===0||Ee(n[0]))return}else if(Ee(n))return;return n}function Dn(t){let e=[];for(let i of t){let n=!1;for(let r of e)if($(dt(i,r))){n=!0;break}n||e.push(i)}return e}function Is(t){return c(!$(t))}function Ts(t,e){return t.length===0||e.length===0?[]:t.length!==e.length?c(!1):c(t.every((i,n)=>$(dt(i,e[n]))))}function Os(t,e){return t.length===0||e.length===0?[]:t.length!==e.length?c(!0):c(t.some((i,n)=>!$(dt(i,e[n]))))}function dt(t,e){let i=t.value?.valueOf(),n=e.value?.valueOf();return typeof i=="number"&&typeof n=="number"?c(Math.abs(i-n)<1e-8):V(i)&&V(n)?c(Pn(i,n)):c(typeof i=="object"&&typeof n=="object"?qt(t,e):i===n)}function vn(t,e){return t.length===0&&e.length===0?c(!0):t.length!==e.length?c(!1):(t.sort(Sn),e.sort(Sn),c(t.every((i,n)=>$(Ss(i,e[n])))))}function Ss(t,e){let{type:i,value:n}=t,{type:r,value:o}=e,s=n?.valueOf(),a=o?.valueOf();return typeof s=="number"&&typeof a=="number"?c(Math.abs(s-a)<.01):V(s)&&V(a)?c(Pn(s,a)):c(i==="Coding"&&r==="Coding"?typeof s!="object"||typeof a!="object"?!1:s.code===a.code&&s.system===a.system:typeof s=="object"&&typeof a=="object"?qt({...s,id:void 0},{...a,id:void 0}):typeof s=="string"&&typeof a=="string"?s.toLowerCase()===a.toLowerCase():s===a)}function Sn(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 xn(t,e){let{value:i}=t;if(i==null)return!1;let n=e;switch(n.startsWith("System.")&&(n=n.substring(7)),n.startsWith("FHIR.")&&(n=n.substring(5)),n){case"Boolean":return typeof i=="boolean";case"Decimal":case"Integer":return typeof i=="number";case"Date":return ys(i);case"DateTime":return Ht(i);case"Time":return typeof i=="string"&&!!/^T\d/.exec(i);case"Period":return Cs(i);case"Quantity":return V(i);default:return t.type===n||typeof i=="object"&&i?.resourceType===n}}function ys(t){return typeof t=="string"&&!!Rn.date.exec(t)}function Ht(t){return typeof t=="string"&&!!Rn.dateTime.exec(t)}function Cs(t){return!!(t&&typeof t=="object"&&("start"in t&&Ht(t.start)||"end"in t&&Ht(t.end)))}function V(t){return!!(t&&typeof t=="object"&&"value"in t&&typeof t.value=="number")}function Pn(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 qt(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(yn(o)&&yn(s)){if(!qt(o,s))return!1}else if(o!==s)return!1}return!0}function yn(t){return t!==null&&typeof t=="object"}function Gt(t,e){if(e){if(typeof e!="object")throw new Error("Primitive extension must be an object");return gs(t??{},e)}return t}function gs(t,e){return delete e.__proto__,delete e.constructor,Object.assign(t,e)}function As(t,e){return Oe(t,e)&&"id"in t&&typeof t.id=="string"}function I(t){let e=bn(t)??"undefined/undefined",i=Ds(t);return i===e?{reference:e}:{reference:e,display:i}}function bn(t){if(Vn(t))return t.reference;if(As(t))return`${t.resourceType}/${t.id}`}function Ns(t){if(t)return Vn(t)?t.reference.split("/")[1]:t.id}function Rs(t){return t.resourceType==="Patient"||t.resourceType==="Practitioner"||t.resourceType==="RelatedPerson"}function Ds(t){if(Rs(t)){let e=vs(t);if(e)return e}if(t.resourceType==="Device"){let e=xs(t);if(e)return e}if(t.resourceType==="MedicationRequest"&&t.medicationCodeableConcept)return Cn(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]),Un(e))return Cn(e);if(bs(e))return e.text}return bn(t)??""}function vs(t){let e=t.name;if(e&&e.length>0)return Us(e[0])}function xs(t){let e=t.deviceName;if(e&&e.length>0)return e[0].name}function Ps(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(),a=n.getUTCFullYear(),l=n.getUTCMonth(),E=n.getUTCDate(),N=a-r;(l<o||l===o&&E<s)&&N--;let me=a*12+l-(r*12+o);E<s&&me--;let A=Math.floor((n.getTime()-i.getTime())/(1e3*60*60*24));return{years:N,months:me,days:A}}function ut(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 Ee(t){if(t==null)return!0;let e=typeof t;return e==="string"||e==="object"?!Wt(t):!1}function Wt(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 Qt(t){return/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i.test(t)}function zt(t){return t!==null&&typeof t=="object"}function Ln(t){return zt(t)&&"code"in t&&typeof t.code=="string"}function Un(t){return zt(t)&&"coding"in t&&Array.isArray(t.coding)&&t.coding.every(Ln)}function bs(t){return zt(t)&&"text"in t&&typeof t.text=="string"}var Ls=[];for(let t=0;t<256;t++)Ls.push(t.toString(16).padStart(2,"0"));function ie(t){return t?t.charAt(0).toUpperCase()+t.substring(1):""}function Mn(t,e){return t?(t.push(e),t):[e]}var f=Object.freeze([]);function Us(t,e){if(!t)return"";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=_e(t.text);if(n)return n}return i.join(" ").trim()}function Cn(t){return t?_e(t.text)||(t.coding?t.coding.map(i=>Ms(i)).join(", "):""):""}function Ms(t,e){let i=_e(t?.display);if(i){let n=e?_e(t?.code):void 0;return`${i}${n?" ("+n+")":""}`}return _e(t?.code)??""}function _e(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",Element:"Element",ElementDefinition:"ElementDefinition",Expression:"Expression",Extension:"Extension",HumanName:"HumanName",Identifier:"Identifier",MarketingStatus:"MarketingStatus",Meta:"Meta",Money:"Money",MoneyQuantity:"MoneyQuantity",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",SimpleQuantity:"SimpleQuantity",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",xhtml:"xhtml"};function Vs(t,e,i){let n=hs(t,i);if(n)return ws(n.elements,e)}function ws(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 Oe(t,e){return!(!t||typeof t!="object"||!("resourceType"in t)||e&&t.resourceType!==e)}function Vn(t,e){return t&&typeof t=="object"&&"reference"in t&&typeof t.reference=="string"?e?t.reference.match(new RegExp(`^${e}(/|\\?)`))!==null:!0:!1}function rt(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 H=()=>[],x={empty:(t,e)=>c(e.every(i=>Ee(i.value))),hasValue:(t,e)=>c(e.length!==0),exists:(t,e,i)=>c(i?e.some(n=>$(i.eval(t,[n]))):e.length>0&&e.every(n=>!Ee(n.value))),all:(t,e,i)=>c(e.every(n=>$(i.eval(t,[n])))),allTrue:(t,e)=>{for(let i of e)if(!i.value)return c(!1);return c(!0)},anyTrue:(t,e)=>{for(let i of e)if(i.value)return c(!0);return c(!1)},allFalse:(t,e)=>{for(let i of e)if(i.value)return c(!1);return c(!0)},anyFalse:(t,e)=>{for(let i of e)if(!i.value)return c(!0);return c(!1)},subsetOf:(t,e,i)=>{if(e.length===0)return c(!0);let n=i.eval(t,J(t));return n.length===0?c(!1):c(e.every(r=>n.some(o=>o.value===r.value)))},supersetOf:(t,e,i)=>{let n=i.eval(t,J(t));return n.length===0?c(!0):e.length===0?c(!1):c(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)=>c(e.length===x.distinct(t,e).length),where:(t,e,i)=>e.filter(n=>$(i.eval(t,[n]))),select:(t,e,i)=>e.flatMap(n=>i.eval({parent:t,variables:{$this:n}},[n])),repeat:H,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(-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 TypeError("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 TypeError("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,J(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,J(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,J(t));return Dn([...e,...n])},combine:(t,e,i)=>{if(!i)return e;let n=i.eval(t,J(t));return[...e,...n]},htmlChecks:(t,e,i)=>[j(!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 $(o)?n.eval(t,e):r?r.eval(t,e):[]},toBoolean:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(e,1);if(typeof i=="boolean")return[{type:u.boolean,value:i}];if(typeof i=="number"&&(i===0||i===1))return c(!!i);if(typeof i=="string"){let n=i.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(n))return c(!0);if(["false","f","no","n","0","0.0"].includes(n))return c(!1)}return[]},convertsToBoolean:(t,e)=>e.length===0?[]:c(x.toBoolean(t,e).length===1),toInteger:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(e,1);return typeof i=="number"?[{type:u.integer,value:i}]:typeof i=="string"&&/^[+-]?\d+$/.exec(i)?[{type:u.integer,value:Number.parseInt(i,10)}]:typeof i=="boolean"?[{type:u.integer,value:i?1:0}]:[]},convertsToInteger:(t,e)=>e.length===0?[]:c(x.toInteger(t,e).length===1),toDate:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(e,1);return typeof i=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(i)?[{type:u.date,value:rt(i)}]:[]},convertsToDate:(t,e)=>e.length===0?[]:c(x.toDate(t,e).length===1),toDateTime:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(e,1);return typeof i=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(i)?[{type:u.dateTime,value:rt(i)}]:[]},convertsToDateTime:(t,e)=>e.length===0?[]:c(x.toDateTime(t,e).length===1),toDecimal:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(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:Number.parseFloat(i)}]:typeof i=="boolean"?[{type:u.decimal,value:i?1:0}]:[]},convertsToDecimal:(t,e)=>e.length===0?[]:c(x.toDecimal(t,e).length===1),toQuantity:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(e,1);return V(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:Number.parseFloat(i),unit:"1"}}]:typeof i=="boolean"?[{type:u.Quantity,value:{value:i?1:0,unit:"1"}}]:[]},convertsToQuantity:(t,e)=>e.length===0?[]:c(x.toQuantity(t,e).length===1),toString:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(e,1);return i==null?[]:V(i)?[{type:u.string,value:`${i.value} '${i.unit}'`}]:[{type:u.string,value:i.toString()}]},convertsToString:(t,e)=>e.length===0?[]:c(x.toString(t,e).length===1),toTime:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(e,1);if(typeof i=="string"){let n=/^T?(\d{2}(:\d{2}(:\d{2})?)?)/.exec(i);if(n)return[{type:u.time,value:rt("T"+n[1])}]}return[]},convertsToTime:(t,e)=>e.length===0?[]:c(x.toTime(t,e).length===1),indexOf:(t,e,i)=>M((n,r)=>n.indexOf(r),t,e,i),substring:(t,e,i,n)=>M((r,o,s)=>{let a=o,l=s?a+s:r.length;return a<0||a>=r.length?void 0:r.substring(a,l)},t,e,i,n),startsWith:(t,e,i)=>M((n,r)=>n.startsWith(r),t,e,i),endsWith:(t,e,i)=>M((n,r)=>n.endsWith(r),t,e,i),contains:(t,e,i)=>M((n,r)=>n.includes(r),t,e,i),upper:(t,e)=>M(i=>i.toUpperCase(),t,e),lower:(t,e)=>M(i=>i.toLowerCase(),t,e),replace:(t,e,i,n)=>M((r,o,s)=>r.replaceAll(o,s),t,e,i,n),matches:(t,e,i)=>M((n,r)=>!!new RegExp(r).exec(n),t,e,i),replaceMatches:(t,e,i,n)=>M((r,o,s)=>r.replaceAll(new RegExp(o,"g"),s.replaceAll(/\$\{(\w+)\}/g,"$<$1>")),t,e,i,n),length:(t,e)=>M(i=>i.length,t,e),toChars:(t,e)=>M(i=>i?i.split(""):void 0,t,e),encode:H,decode:H,escape:H,unescape:H,trim:H,split:H,join:(t,e,i)=>{let n=i?.eval(t,J(t))[0]?.value??"";if(typeof n!="string")throw new TypeError("Separator must be a string.");return[{type:u.string,value:e.map(r=>r.value?.toString()??"").join(n)}]},abs:(t,e)=>k(Math.abs,t,e),ceiling:(t,e)=>k(Math.ceil,t,e),exp:(t,e)=>k(Math.exp,t,e),floor:(t,e)=>k(Math.floor,t,e),ln:(t,e)=>k(Math.log,t,e),log:(t,e,i)=>k((n,r)=>Math.log(n)/Math.log(r),t,e,i),power:(t,e,i)=>k(Math.pow,t,e,i),round:(t,e,...i)=>k((n,r=0)=>{if(typeof r!="number"||r<0)throw new Error("Invalid precision provided to round()");let o=Math.pow(10,r);return Math.round(n*o)/o},t,e,...i),sqrt:(t,e)=>k(Math.sqrt,t,e),truncate:(t,e)=>k(i=>Math.trunc(i),t,e),children:H,descendants:H,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=x.toDateTime(t,i.eval(t,e));if(o.length===0)throw new Error("Invalid start date");let s=x.toDateTime(t,n.eval(t,e));if(s.length===0)throw new Error("Invalid end date");let a=r.eval(t,e)[0]?.value;if(a!=="years"&&a!=="months"&&a!=="days")throw new Error("Invalid units");let l=Ps(o[0].value,s[0].value);return[{type:u.Quantity,value:{value:l[a],unit:a}}]},is:(t,e,i)=>{let n="";return i instanceof st?n=i.name:i instanceof wn&&(n=i.left.name+"."+i.right.name),n?e.map(r=>({type:u.boolean,value:xn(r,n)})):[]},not:(t,e)=>x.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 j(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"}}:Oe(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 st&&(r=i.name),r&&!n.reference.startsWith(r+"/")?[]:[{type:u.id,value:Ns(n)}]},extension:(t,e,i)=>{let n=i.eval(t,e)[0].value,r=e?.[0]?.value;if(r){let o=ut(r,n);if(o)return[{type:u.Extension,value:o}]}return[]}};function M(t,e,i,...n){if(i.length===0)return[];let[{value:r}]=B(i,1);if(typeof r!="string")throw new TypeError("String function cannot be called with non-string");let o=n.map(a=>a?.eval(e,i)[0]?.value),s=t(r,...o);return s===void 0?[]:Array.isArray(s)?s.map(j):[j(s)]}function k(t,e,i,...n){if(i.length===0)return[];let[{value:r}]=B(i,1),o=V(r),s=o?r.value:r;if(typeof s!="number")throw new TypeError("Math function cannot be called with non-number");let a=t(s,...n.map(N=>N.eval(e,i)[0]?.value)),l=o?u.Quantity:i[0].type,E=o?{...r,value:a}:a;return[{type:l,value:E}]}function B(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 J(t){let e=t;for(;e.parent?.variables.$this;)e=e.parent;return[e.variables.$this]}var te=class{constructor(t){S(this,"value"),this.value=t}eval(){return[this.value]}toString(){let t=this.value.value;return typeof t=="string"?`'${t}'`:t.toString()}},st=class{constructor(t){S(this,"name"),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 Oe(e,this.name)?t:fs(t,this.name)}toString(){return this.name}},Fs=class{eval(){return[]}toString(){return"{}"}},ks=class extends rs{constructor(t,e,i){super(t,e),S(this,"impl"),this.impl=i}eval(t,e){return this.impl(this.child.eval(t,e))}toString(){return this.operator+this.child.toString()}},Bs=class extends Ie{constructor(t,e){super("as",t,e)}eval(t,e){return x.ofType(t,this.left.eval(t,e),this.right)}},w=class extends Ie{},F=class extends w{constructor(t,e,i,n){super(t,e,i),S(this,"impl"),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=V(r)?r.value:r,a=V(o)?o.value:o,l=this.impl(s,a);return typeof l=="boolean"?c(l):V(r)?[{type:u.Quantity,value:{...r,value:l}}]:[j(l)]}},Ys=class extends Ie{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}},Gs=class extends w{constructor(t,e){super("contains",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return c(i.some(r=>r.value===n[0].value))}},Hs=class extends w{constructor(t,e){super("in",t,e)}eval(t,e){let i=q(this.left.eval(t,e)),n=this.right.eval(t,e);return i?c(n.some(r=>dt(i,r)[0].value)):[]}},wn=class extends Ie{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()}`}},$s=class extends Ie{constructor(t,e){super("|",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return Dn([...i,...n])}},js=class extends w{constructor(t,e){super("=",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return Ts(i,n)}},qs=class extends w{constructor(t,e){super("!=",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return Os(i,n)}},Ws=class extends w{constructor(t,e){super("~",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return vn(i,n)}},Qs=class extends w{constructor(t,e){super("!~",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return Is(vn(i,n))}},zs=class extends w{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 c(xn(i[0],n))}},Zs=class extends w{constructor(t,e){super("and",t,e)}eval(t,e){let i=q(this.left.eval(t,e),"boolean"),n=q(this.right.eval(t,e),"boolean");return i?.value===!0&&n?.value===!0?c(!0):i?.value===!1||n?.value===!1?c(!1):[]}},Xs=class extends w{constructor(t,e){super("or",t,e)}eval(t,e){let i=q(this.left.eval(t,e),"boolean"),n=q(this.right.eval(t,e),"boolean");return i?.value===!1&&n?.value===!1?c(!1):i?.value||n?.value?c(!0):[]}},Js=class extends w{constructor(t,e){super("xor",t,e)}eval(t,e){let i=q(this.left.eval(t,e),"boolean"),n=q(this.right.eval(t,e),"boolean");return!i||!n?[]:c(i.value!==n.value)}},Ks=class extends w{constructor(t,e){super("implies",t,e)}eval(t,e){let i=q(this.left.eval(t,e),"boolean"),n=q(this.right.eval(t,e),"boolean");return n?.value===!0||i?.value===!1?c(!0):!i||!n?[]:c(!1)}},ea=class{constructor(t,e){S(this,"name"),S(this,"args"),this.name=t,this.args=e}eval(t,e){let i=x[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(", ")})`}},ta=class{constructor(t,e){S(this,"left"),S(this,"expr"),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 Fn=["!=","!~","<=",">=","{}","->"];var _={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},ia={parse(t){let e=t.consumeAndParse();if(!t.match(")"))throw new Error("Parse error: expected `)` got `"+t.peek()?.value+"`");return e}},na={parse(t,e){let i=t.consumeAndParse();if(!t.match("]"))throw new Error("Parse error: expected `]`");return new ta(e,i)},precedence:_.Indexer},ra={parse(t,e){if(!(e instanceof st))throw new Error("Unexpected parentheses");let i=[];for(;!t.match(")");)i.push(t.consumeAndParse()),t.match(",");return new ea(e.name,i)},precedence:_.FunctionCall};function oa(t){let e=t.split(" "),i=Number.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 Zt(){return new os().registerPrefix("String",{parse:(t,e)=>new te({type:u.string,value:e.value})}).registerPrefix("DateTime",{parse:(t,e)=>new te({type:u.dateTime,value:rt(e.value)})}).registerPrefix("Quantity",{parse:(t,e)=>new te({type:u.Quantity,value:oa(e.value)})}).registerPrefix("Number",{parse:(t,e)=>new te({type:e.value.includes(".")?u.decimal:u.integer,value:Number.parseFloat(e.value)})}).registerPrefix("true",{parse:()=>new te({type:u.boolean,value:!0})}).registerPrefix("false",{parse:()=>new te({type:u.boolean,value:!1})}).registerPrefix("Symbol",{parse:(t,e)=>new st(e.value)}).registerPrefix("{}",{parse:()=>new Fs}).registerPrefix("(",ia).registerInfix("[",na).registerInfix("(",ra).prefix("+",_.UnaryAdd,(t,e)=>new ks("+",e,i=>i)).prefix("-",_.UnarySubtract,(t,e)=>new F("-",e,e,(i,n)=>-n)).infixLeft(".",_.Dot,(t,e,i)=>new wn(t,i)).infixLeft("/",_.Divide,(t,e,i)=>new F("/",t,i,(n,r)=>n/r)).infixLeft("*",_.Multiply,(t,e,i)=>new F("*",t,i,(n,r)=>n*r)).infixLeft("+",_.Add,(t,e,i)=>new F("+",t,i,(n,r)=>n+r)).infixLeft("-",_.Subtract,(t,e,i)=>new F("-",t,i,(n,r)=>n-r)).infixLeft("|",_.Union,(t,e,i)=>new $s(t,i)).infixLeft("=",_.Equals,(t,e,i)=>new js(t,i)).infixLeft("!=",_.NotEquals,(t,e,i)=>new qs(t,i)).infixLeft("~",_.Equivalent,(t,e,i)=>new Ws(t,i)).infixLeft("!~",_.NotEquivalent,(t,e,i)=>new Qs(t,i)).infixLeft("<",_.LessThan,(t,e,i)=>new F("<",t,i,(n,r)=>n<r)).infixLeft("<=",_.LessThanOrEquals,(t,e,i)=>new F("<=",t,i,(n,r)=>n<=r)).infixLeft(">",_.GreaterThan,(t,e,i)=>new F(">",t,i,(n,r)=>n>r)).infixLeft(">=",_.GreaterThanOrEquals,(t,e,i)=>new F(">=",t,i,(n,r)=>n>=r)).infixLeft("&",_.Ampersand,(t,e,i)=>new Ys(t,i)).infixLeft("and",_.And,(t,e,i)=>new Zs(t,i)).infixLeft("as",_.As,(t,e,i)=>new Bs(t,i)).infixLeft("contains",_.Contains,(t,e,i)=>new Gs(t,i)).infixLeft("div",_.Divide,(t,e,i)=>new F("div",t,i,(n,r)=>Math.trunc(n/r))).infixLeft("in",_.In,(t,e,i)=>new Hs(t,i)).infixLeft("is",_.Is,(t,e,i)=>new zs(t,i)).infixLeft("mod",_.Modulo,(t,e,i)=>new F("mod",t,i,(n,r)=>n%r)).infixLeft("or",_.Or,(t,e,i)=>new Xs(t,i)).infixLeft("xor",_.Xor,(t,e,i)=>new Js(t,i)).infixLeft("implies",_.Implies,(t,e,i)=>new Ks(t,i))}var Ja=Zt();var h={EQUALS:"eq",NOT_EQUALS:"ne",GREATER_THAN:"gt",LESS_THAN:"lt",GREATER_THAN_OR_EQUALS:"ge",LESS_THAN_OR_EQUALS:"le",STARTS_AFTER:"sa",ENDS_BEFORE:"eb",APPROXIMATELY:"ap",CONTAINS:"contains",STARTS_WITH:"sw",EXACT:"exact",TEXT:"text",NOT:"not",ABOVE:"above",BELOW:"below",IN:"in",NOT_IN:"not-in",OF_TYPE:"of-type",MISSING:"missing",PRESENT:"present",IDENTIFIER:"identifier",ITERATE:"iterate"},Ka={contains:h.CONTAINS,exact:h.EXACT,above:h.ABOVE,below:h.BELOW,text:h.TEXT,not:h.NOT,in:h.IN,"not-in":h.NOT_IN,"of-type":h.OF_TYPE,missing:h.MISSING,identifier:h.IDENTIFIER,iterate:h.ITERATE},ec={eq:h.EQUALS,ne:h.NOT_EQUALS,lt:h.LESS_THAN,le:h.LESS_THAN_OR_EQUALS,gt:h.GREATER_THAN,ge:h.GREATER_THAN_OR_EQUALS,sa:h.STARTS_AFTER,eb:h.ENDS_BEFORE,ap:h.APPROXIMATELY,sw:h.STARTS_WITH};var tc=[h.MISSING,h.PRESENT];var ic=new $t(1e3);var nt={READ:"read",VREAD:"vread",UPDATE:"update",DELETE:"delete",HISTORY:"history",CREATE:"create",SEARCH:"search"},nc=[nt.READ,nt.VREAD,nt.HISTORY,nt.SEARCH];function lt(){return typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replaceAll(/[xy]/g,t=>{let e=Math.trunc(Math.random()*16);return(t==="x"?e:e&3|8).toString(16)})}var sa={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",JWT:"application/jwt",MULTIPART_FORM_DATA:"multipart/form-data",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",OCTET_STREAM:"application/octet-stream"};var aa;aa=Symbol.toStringTag;var rc={Event:typeof globalThis.Event<"u"?globalThis.Event:void 0,ErrorEvent:void 0,CloseEvent:void 0};var oc={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 sc=[WebSocket.CLOSING,WebSocket.CLOSED];var ac=new $t(1e3);var cc=sa.FHIR_JSON+", */*; q=0.1";var dc=[...Fn,"->","<<",">>","=="];var uc=Zt().registerInfix("->",{precedence:_.Arrow}).registerInfix(";",{precedence:_.Semicolon});var lc=" ".repeat(2);var pc=[...Fn,"eq","ne","co"];var hc={eq:h.EXACT,ne:h.NOT_EQUALS,co:h.CONTAINS,sw:h.STARTS_WITH,ew:void 0,gt:h.GREATER_THAN,lt:h.LESS_THAN,ge:h.GREATER_THAN_OR_EQUALS,le:h.LESS_THAN_OR_EQUALS,ap:h.APPROXIMATELY,sa:h.STARTS_AFTER,eb:h.ENDS_BEFORE,pr:h.PRESENT,po:void 0,ss:void 0,sb:void 0,in:h.IN,ni:h.NOT_IN,re:h.EQUALS,identifier:h.IDENTIFIER};var fc=Zt();var mc=`${O}/fhir/StructureDefinition/patient-preferredPharmacy`;function pt(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 C(t){if(!t)return;let e=/^[+-]\d{4}$/,i=t.substring(0,4),n="01",r="01",o="00",s="00",a="00",l="Z";t.length>=8&&(n=t.substring(4,6),r=t.substring(6,8)),t.length>=12&&(o=t.substring(8,10),s=t.substring(10,12));let E=t.charAt(12);t.length>=14&&E!=="+"&&E!=="-"&&(a=t.substring(12,14));let N=E==="+"||E==="-"?12:14;return t.length>N&&(l=t.substring(N),l==="+0000"||l==="-0000"?l="Z":e.test(l)&&(l=`${l.substring(0,3)}:${l.substring(3)}`)),`${i}-${n}-${r}T${o}:${s}:${a}${l}`}function L(t){if(t)return t.substring(0,10).replaceAll("-","")}function T(t){if(!t)return;let[e,i]=t.split("T"),n=e.replaceAll("-",""),r=(i??"").replaceAll(/\.\d+/g,"").replaceAll(":","").replaceAll("Z","+0000");return`${n}${r}`}function Xt(t,e){if(t?.start||t?.end){let i={};return t.start&&(i.low={"@_value":T(t.start)??""}),t.end&&(i.high={"@_value":T(t.end)??""}),i}return e?{"@_value":T(e)??""}:{}}var K="1.3.6.1.4.1.19376.1.5.3.1.3.1";var kn="2.16.840.1.113883.1.3";var Bn="2.16.840.1.113883.2.20.5.1",Yn="2.16.840.1.113883.3.26.1.1";var Gn="2.16.840.1.113883.3.221.5",Hn="2.16.840.1.113883.4.1",$n="2.16.840.1.113883.4.3",jn="2.16.840.1.113883.4.6",qn="2.16.840.1.113883.4.9",ht="2.16.840.1.113883.5.1",ft="2.16.840.1.113883.5.4",mt="2.16.840.1.113883.5.6",Jt="2.16.840.1.113883.5.25",Wn="2.16.840.1.113883.5.111",y="2.16.840.1.113883.6.1",Qn="2.16.840.1.113883.6.12",zn="2.16.840.1.113883.6.24",Zn="2.16.840.1.113883.6.69",Xn="2.16.840.1.113883.6.88",P="2.16.840.1.113883.6.96",Jn="2.16.840.1.113883.6.101",Kn="2.16.840.1.113883.6.209",_t="2.16.840.1.113883.6.238",er="2.16.840.1.113883.6.254",tr="2.16.840.1.113883.6.345";var Et="2.16.840.1.113883.10.20.15.3.8";var Se="2.16.840.1.113883.10.20.22.1.1";var Kt="2.16.840.1.113883.10.20.22.1.2";var ei="2.16.840.1.113883.10.20.22.1.14";var It="2.16.840.1.113883.10.20.22.2.1.1";var ye="2.16.840.1.113883.10.20.22.2.2",Ce="2.16.840.1.113883.10.20.22.2.2.1";var ti="2.16.840.1.113883.10.20.22.2.3.1";var ir="2.16.840.1.113883.10.20.22.2.4.1";var nr="2.16.840.1.113883.10.20.22.2.5",ge="2.16.840.1.113883.10.20.22.2.5.1",rr="2.16.840.1.113883.10.20.22.2.5.1 .2",or="2.16.840.1.113883.10.20.22.2.5.2",sr="2.16.840.1.113883.10.20.22.2.6",Ae="2.16.840.1.113883.10.20.22.2.6.1",ar="2.16.840.1.113883.10.20.22.2.6.1.2",cr="2.16.840.1.113883.10.20.22.2.6.2";var ne="2.16.840.1.113883.10.20.22.2.7.1";var Tt="2.16.840.1.113883.10.20.22.2.8";var Q="2.16.840.1.113883.10.20.22.2.10";var ii="2.16.840.1.113883.10.20.22.2.14";var ni="2.16.840.1.113883.10.20.22.2.17";var Ne="2.16.840.1.113883.10.20.22.2.18";var dr="2.16.840.1.113883.10.20.22.2.22.1";var ur="2.16.840.1.113883.10.20.22.2.23";var lr="2.16.840.1.113883.10.20.22.2.56";var Ot="2.16.840.1.113883.10.20.22.2.58";var Re="2.16.840.1.113883.10.20.22.2.60";var St="2.16.840.1.113883.10.20.22.2.65";var yt="2.16.840.1.113883.10.20.22.2.500",De="2.16.840.1.113883.10.20.22.4.1",pr="2.16.840.1.113883.10.20.22.4.1.2",ve="2.16.840.1.113883.10.20.22.4.2",hr="2.16.840.1.113883.10.20.22.4.2.2",ri="2.16.840.1.113883.10.20.22.4.3";var Y="2.16.840.1.113883.10.20.22.4.4",fr="2.16.840.1.113883.10.20.22.4.4.2";var oi="2.16.840.1.113883.10.20.22.4.7";var si="2.16.840.1.113883.10.20.22.4.8";var ai="2.16.840.1.113883.10.20.22.4.9";var re="2.16.840.1.113883.10.20.22.4.12";var xe="2.16.840.1.113883.10.20.22.4.13";var oe="2.16.840.1.113883.10.20.22.4.14";var ci="2.16.840.1.113883.10.20.22.4.16";var mr="2.16.840.1.113883.10.20.22.4.20";var di="2.16.840.1.113883.10.20.22.4.23";var Pe="2.16.840.1.113883.10.20.22.4.26",_r="2.16.840.1.113883.10.20.22.4.26.2",be="2.16.840.1.113883.10.20.22.4.27",Er="2.16.840.1.113883.10.20.22.4.27.2";var ui="2.16.840.1.113883.10.20.22.4.30";var Ct="2.16.840.1.113883.10.20.22.4.32";var Ir="2.16.840.1.113883.10.20.22.4.37",Tr="2.16.840.1.113883.10.20.22.4.38",Or="2.16.840.1.113883.10.20.22.4.38.1";var gt="2.16.840.1.113883.10.20.22.4.41";var At="2.16.840.1.113883.10.20.22.4.44";var Le="2.16.840.1.113883.10.20.22.4.49";var li="2.16.840.1.113883.10.20.22.4.52";var pi="2.16.840.1.113883.10.20.22.4.54",hi="2.16.840.1.113883.10.20.22.4.60";var fi="2.16.840.1.113883.10.20.22.4.61";var Ue="2.16.840.1.113883.10.20.22.4.66";var Me="2.16.840.1.113883.10.20.22.4.67";var Nt="2.16.840.1.113883.10.20.22.4.69",Sr="2.16.840.1.113883.10.20.22.4.70";var yr="2.16.840.1.113883.10.20.22.4.74";var Cr="2.16.840.1.113883.10.20.22.4.75";var Ve="2.16.840.1.113883.10.20.22.4.78",gr="2.16.840.1.113883.10.20.22.4.78.2";var we="2.16.840.1.113883.10.20.22.4.85";var Rt="2.16.840.1.113883.10.20.22.4.86",Ar="2.16.840.1.113883.10.20.22.4.87";var Nr="2.16.840.1.113883.10.20.22.4.89",Rr="2.16.840.1.113883.10.20.22.4.90";var Dr="2.16.840.1.113883.10.20.22.4.114";var vr="2.16.840.1.113883.10.20.22.4.119";var se="2.16.840.1.113883.10.20.22.4.121";var xr="2.16.840.1.113883.10.20.22.4.128";var Pr="2.16.840.1.113883.10.20.22.4.130";var mi="2.16.840.1.113883.10.20.22.4.132",br="2.16.840.1.113883.10.20.22.4.133";var Lr="2.16.840.1.113883.10.20.22.4.140";var Dt="2.16.840.1.113883.10.20.22.4.147",Fe="2.16.840.1.113883.10.20.22.4.200",Ur="2.16.840.1.113883.10.20.22.4.201",Mr="2.16.840.1.113883.10.20.22.4.202";var Vr="2.16.840.1.113883.10.20.22.4.244";var wr="2.16.840.1.113883.10.20.22.4.250";var Fr="2.16.840.1.113883.10.20.22.4.406",kr="2.16.840.1.113883.10.20.22.4.407";var Br="2.16.840.1.113883.10.20.22.4.416";var _i="2.16.840.1.113883.10.20.22.4.500",Yr="2.16.840.1.113883.10.20.22.4.501";var vt="2.16.840.1.113883.10.20.22.4.503",xt="2.16.840.1.113883.10.20.22.4.504",Ei="2.16.840.1.113883.10.20.22.4.505",Pt="2.16.840.1.113883.10.20.22.4.506",bt="2.16.840.1.113883.10.20.22.4.507",Gr="2.16.840.1.113883.10.20.22.4.508";var Hr="2.16.840.1.113883.10.20.22.4.512";var $r="2.16.840.1.113883.10.20.22.5.8";var Ii="2.16.840.1.113883.12.292",Ti="2.16.840.1.113883.3.3719";function Lt(t){if(t==null)return t;if(Array.isArray(t))return t.map(e=>Lt(e)).filter(e=>e!==void 0);if(typeof t=="object"){let e=Object.keys(t).filter(n=>n!=="@_nullFlavor");if(e.length===0)return;let i={};for(let n of e){let r=Lt(t[n]);r!==void 0&&(i[n]=r)}return Object.keys(i).length===0?void 0:i}return t}var g=class{constructor(e,i){D(this,"details");D(this,"entries");D(this,"ccdaToFhirMap");D(this,"fhirToCcdaMap");this.details=e,this.entries=i,this.ccdaToFhirMap={},this.fhirToCcdaMap={};for(let n of i)this.ccdaToFhirMap[n.ccdaValue]||(this.ccdaToFhirMap[n.ccdaValue]=n),this.fhirToCcdaMap[n.fhirValue]||(this.fhirToCcdaMap[n.fhirValue]=n)}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.details.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.details.ccdaSystemOid,"@_codeSystemName":this.details.ccdaSystemOid?We.getEntryByCcda(this.details.ccdaSystemOid)?.displayName:void 0}}},Z="http:",jr=`${O}/fhir/administrative-gender`,Ut=`${R}/CodeSystem/condition-clinical`,Si=`${R}/CodeSystem/condition-verification`,ca=`${R}/CodeSystem/v3-LanguageAbilityMode`,da=`${R}/CodeSystem/v3-LanguageAbilityProficiency`,ua=`${R}/CodeSystem/v3-Race`,yi=`${R}/CodeSystem/condition-category`,Mt=`${R}/CodeSystem/condition-ver-status`,ke=`${R}/CodeSystem/allergyintolerance-clinical`,Vt=`${R}/CodeSystem/allergyintolerance-verification`,wt=`${R}/CodeSystem/v3-ActCode`,Ci=`${R}/CodeSystem/v3-ParticipationType`,gi=`${R}/CodeSystem/diagnosis-role`,qr=`${R}/CodeSystem/v3-Confidentiality`,Wr=`${R}/CodeSystem/observation-category`,Qr=`${R}/CodeSystem/v3-RoleCode`,zr=`${O}/fhir/ValueSet/address-use`,Zr=`${O}/fhir/ValueSet/name-use`,Xr=`${O}/fhir/ValueSet/administrative-gender`,Jr=`${O}/fhir/ValueSet/contactentity-use`,la=`${O}/fhir/ValueSet/medicationrequest-status`,pa=`${O}/fhir/StructureDefinition/language-mode`,ha=`${O}/fhir/StructureDefinition/language-proficiency`,fa=`${O}/fhir/us/core/StructureDefinition/us-core-patient`,ae=`${O}/fhir/us/core/StructureDefinition/us-core-race`,Be=`${O}/fhir/us/core/StructureDefinition/us-core-ethnicity`,Ai=`${O}/fhir/us/core/StructureDefinition/us-core-condition`,Ni=`${O}/fhir/us/core/StructureDefinition/us-core-medicationrequest`,ma=`${O}/cda/template`,Kr=`${Z}//ncithesaurus-stage.nci.nih.gov`,eo=`${O}/fhir/sid/us-ssn`,to=`${O}/fhir/sid/us-dln`,io=`${O}/fhir/sid/us-npi`,no=`${Z}//fdasis.nlm.nih.gov`,ro=`${Z}//nucc.org/provider-taxonomy`,oo=`${Z}//va.gov/terminology/medrt`,so=`${Z}//hl7.org/fhir/ndfrt`,ao=`${Z}//nucc.org/cvx`,co=`${O}/fhir/sid/cvx`,uo=`${O}/fhir/sid/icf`,Ri=`${Z}//www.w3.org/2001/XMLSchema-instance`,Ye="https://medplum.com/fhir/StructureDefinition/ccda-narrative-reference",Di="48765-2",vi="11369-6",xi="10160-0",Ge="11450-4",Pi="30954-2",bi="29762-2",Li="8716-3",Ui="47519-4",He="18776-5",$e="51848-0",Mi="46264-8",ce="61146-7",de="75310-3",Vi="46240-8",ue="42349-1",wi="57133-1",Fi="10190-7",ki="85847-2",Bi="48768-6",je="11488-4",_a="34109-9",Ea="60591-5",qe="34133-9",Yi="76662-6",Gi="75323-6",Hi="58144-7",$i="72166-2",ji="11367-0",qi="46098-0",Wi="76689-9",Qi="8689-2",zi="75321-0",Zi="47420-5",Xi="89571-4",Ji="47420-5",Ki="11341-5",en="86188-0",Ft="82810-3",tn="95370-3",We=new g({},[{ccdaValue:Bn,fhirValue:"https://fhir.infoway-inforoute.ca/CodeSystem/pCLOCD",displayName:"pan-Canadian LOINC Observation Code Database (pCLOCD)"},{ccdaValue:Yn,fhirValue:Kr,displayName:"NCI Thesaurus"},{ccdaValue:Hn,fhirValue:eo,displayName:"SSN"},{ccdaValue:$n,fhirValue:to,displayName:"DLN"},{ccdaValue:jn,fhirValue:io,displayName:"NPI"},{ccdaValue:qn,fhirValue:no,displayName:"Unique Ingredient Identifier (UNII)"},{ccdaValue:y,fhirValue:at,displayName:"LOINC"},{ccdaValue:Qn,fhirValue:An,displayName:"Current Procedural Terminology (CPT)"},{ccdaValue:zn,fhirValue:"urn:iso:std:iso:11073:10101",displayName:"Medical Device Communications (MDC)"},{ccdaValue:Zn,fhirValue:Nn,displayName:"National Drug Code (NDC)"},{ccdaValue:Xn,fhirValue:gn,displayName:"RxNorm"},{ccdaValue:P,fhirValue:ct,displayName:"SNOMED CT"},{ccdaValue:Jn,fhirValue:ro,displayName:"NUCC Health Care Provider Taxonomy"},{ccdaValue:tr,fhirValue:oo,displayName:"Medication Reference Terminology (MED-RT)"},{ccdaValue:Kn,fhirValue:so,displayName:"National Drug File Reference Terminology (NDF-RT)"},{ccdaValue:Ii,fhirValue:ao,displayName:"CVX"},{ccdaValue:Jt,fhirValue:"Confidentiality",displayName:"Confidentiality"},{ccdaValue:ht,fhirValue:jr,displayName:"Administrative Sex"},{ccdaValue:Wn,fhirValue:Qr,displayName:"Role Code"},{ccdaValue:Gn,fhirValue:"",displayName:"Insurance Type Code"},{ccdaValue:Ii,fhirValue:co,displayName:"Vaccine Administered Code Set (CVX)"},{ccdaValue:er,fhirValue:uo,displayName:"International Classification of Functioning, Disability and Health (ICF)"}]);function z(t){if(t)return We.mapCcdaToFhir(t)??`urn:oid:${t}`}function kt(t){if(!t)return;let e=[],i=z(t["@_codeSystem"]),n=t["@_code"],r=t["@_displayName"];(i||n||r)&&e.push({...i&&{system:i},...n&&{code:n},...r&&{display:r}});for(let s of t.translation??f){let a=z(s["@_codeSystem"]),l=s["@_code"],E=s["@_displayName"];(a||l||E)&&e.push({...a&&{system:a},...l&&{code:l},...E&&{display:E}})}let o=t["@_displayName"];return e.length===0?o?{text:o}:void 0:{coding:e,...o&&{text:o}}}function nn(t){if(t)return t.startsWith("urn:oid:")?t.replace("urn:oid:",""):We.mapFhirToCcda(t)}function p(t){if(!t?.coding?.[0])return;let e=Oi(t.coding[0]);if(t.coding.length>1){e.translation=[];for(let i=1;i<t.coding.length;i++)e.translation.push(Oi(t.coding[i]))}return e}function Oi(t){let e=t?.system?We.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 b(t){let e=p(t);if(e)return{"@_xsi:type":"CD",...e}}var rn=new g({ccdaSystemOid:Jt,fhirSystemUrl:qr},[{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"}]),Qe=new g({fhirSystemUrl:Zr},[{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"}]),on=new g({fhirSystemUrl:Xr},[{ccdaValue:"F",fhirValue:"female",displayName:"Female"},{ccdaValue:"M",fhirValue:"male",displayName:"Male"},{ccdaValue:"UN",fhirValue:"unknown",displayName:"Unknown"},{ccdaValue:"UN",fhirValue:"other",displayName:"Other"}]),ze=new g({fhirSystemUrl:zr},[{ccdaValue:"HP",fhirValue:"home",displayName:"Home"},{ccdaValue:"WP",fhirValue:"work",displayName:"Work"}]),Ze=new g({fhirSystemUrl:Jr},[{ccdaValue:"WP",fhirValue:"work",displayName:"Work"},{ccdaValue:"HP",fhirValue:"home",displayName:"Home"},{ccdaValue:"MC",fhirValue:"mobile",displayName:"Mobile"}]),Xe=new g({fhirSystemUrl:Vt},[{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"}]),sn=new g({ccdaSystemOid:P,fhirSystemUrl:ke},[{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)"}]),Je=new g({ccdaSystemOid:P,fhirSystemUrl:ke},[{ccdaValue:"255604002",fhirValue:"mild",displayName:"Mild"},{ccdaValue:"6736007",fhirValue:"moderate",displayName:"Moderate"},{ccdaValue:"24484000",fhirValue:"severe",displayName:"Severe"}]),le=new g({fhirSystemUrl:Mt},[{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"}]),Ke=new g({},[{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"}]),an=new g({},[{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"}]),cn=new g({},[{ccdaValue:"completed",fhirValue:"completed",displayName:"Completed"},{ccdaValue:"active",fhirValue:"active",displayName:"Active"},{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"}]),et=new g({},[{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"}]),dn=new g({fhirSystemUrl:Wr},[{ccdaValue:Tr,fhirValue:"social-history",displayName:"Social History"},{ccdaValue:Or,fhirValue:"social-history",displayName:"Social History V2"},{ccdaValue:Ve,fhirValue:"social-history",displayName:"Smoking Status"},{ccdaValue:gr,fhirValue:"social-history",displayName:"Current Smoking Status"},{ccdaValue:we,fhirValue:"social-history",displayName:"Tobacco Use"},{ccdaValue:vt,fhirValue:"social-history",displayName:"Basic Occupation"},{ccdaValue:xt,fhirValue:"social-history",displayName:"Basic Industry"},{ccdaValue:Yr,fhirValue:"social-history",displayName:"Sexual Orientation"},{ccdaValue:bt,fhirValue:"social-history",displayName:"Sex Observation"},{ccdaValue:Fe,fhirValue:"social-history",displayName:"Gender Identity"},{ccdaValue:Ur,fhirValue:"social-history",displayName:"Gender Identity V2"},{ccdaValue:Et,fhirValue:"social-history",displayName:"Pregnancy Status"},{ccdaValue:Pt,fhirValue:"social-history",displayName:"Tribal Affiliation"},{ccdaValue:be,fhirValue:"vital-signs",displayName:"Vital Signs Observation"},{ccdaValue:Er,fhirValue:"vital-signs",displayName:"Vital Signs Observation V2"},{ccdaValue:Pe,fhirValue:"vital-signs",displayName:"Vital Signs Organizer"},{ccdaValue:_r,fhirValue:"vital-signs",displayName:"Vital Signs Organizer V2"},{ccdaValue:Hr,fhirValue:"vital-signs",displayName:"Average Blood Pressure Organizer"},{ccdaValue:ve,fhirValue:"laboratory",displayName:"Result Observation"},{ccdaValue:hr,fhirValue:"laboratory",displayName:"Result Observation V2"},{ccdaValue:Fr,fhirValue:"laboratory",displayName:"Laboratory Battery (ID)"},{ccdaValue:kr,fhirValue:"laboratory",displayName:"Laboratory Observation (ID)"},{ccdaValue:Br,fhirValue:"laboratory",displayName:"Laboratory Result Organizer (ID)"},{ccdaValue:De,fhirValue:"laboratory",displayName:"Result Organizer"},{ccdaValue:pr,fhirValue:"laboratory",displayName:"Result Organizer V2"},{ccdaValue:Nt,fhirValue:"survey",displayName:"Assessment Scale Observation"},{ccdaValue:Rt,fhirValue:"survey",displayName:"Assessment Scale Supporting Observation"},{ccdaValue:yr,fhirValue:"survey",displayName:"Cognitive Status Result Observation"},{ccdaValue:Cr,fhirValue:"survey",displayName:"Cognitive Status Result Organizer"},{ccdaValue:Me,fhirValue:"survey",displayName:"Functional Status Result Observation"},{ccdaValue:Ue,fhirValue:"survey",displayName:"Functional Status Result Organizer"},{ccdaValue:xe,fhirValue:"exam",displayName:"Procedure Activity Observation"},{ccdaValue:Y,fhirValue:"exam",displayName:"Problem Observation"},{ccdaValue:fr,fhirValue:"exam",displayName:"Problem Observation V2"},{ccdaValue:Sr,fhirValue:"exam",displayName:"Pressure Ulcer Observation"},{ccdaValue:Dr,fhirValue:"exam",displayName:"Wound Observation"},{ccdaValue:br,fhirValue:"exam",displayName:"Wound Measurements Observation"},{ccdaValue:ne,fhirValue:"exam",displayName:"Procedure Section"},{ccdaValue:Gr,fhirValue:"therapy",displayName:"Medication Adherence"},{ccdaValue:Pr,fhirValue:"therapy",displayName:"Nutrition Recommendations"},{ccdaValue:Vr,fhirValue:"therapy",displayName:"Diet Statement (Nutrition)"},{ccdaValue:wr,fhirValue:"therapy",displayName:"Monitoring, Evaluation and Outcome (Nutrition)"}]),un=new g({fhirSystemUrl:wt},[{ccdaValue:"71",fhirValue:"HMO",displayName:"Health Maintenance Organization"},{ccdaValue:"72",fhirValue:"PPO",displayName:"Preferred Provider Organization"},{ccdaValue:"73",fhirValue:"POS",displayName:"Point of Service"},{ccdaValue:"79",fhirValue:"MCPOL",displayName:"Managed Care Policy"},{ccdaValue:"81",fhirValue:"pay",displayName:"Self Pay"},{ccdaValue:"9999",fhirValue:"",displayName:"Unknown"}]);var pe=require("fast-xml-parser");var Ia=["ClinicalDocument.participant","ClinicalDocument.recordTarget",".id",".templateId",".name",".addr",".telecom",".streetAddressLine",".author",".effectiveTime","name.given","name.suffix","name.prefix","patient.raceCode","patient.sdtc:raceCode","patient.ethnicGroupCode","patient.languageCommunication","component.structuredBody.component","component.structuredBody.component.section","component.section","component.observation","component.act","code.translation","value.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 Ta(t){return new pe.XMLParser({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1,isArray:(n,r,o,s)=>Ia.some(a=>r.endsWith(a))}).parse(t).ClinicalDocument}function Oa(t){return new pe.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":Ri,"@_xmlns:voc":"urn:hl7-org:v3/voc","@_xmlns:sdtc":"urn:hl7-org:sdtc",...t}})}function ln(t){return new pe.XMLParser({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1}).parse(t)}function pn(t){return t?typeof t=="string"?t:new pe.XMLBuilder({ignoreAttributes:!1,attributeNamePrefix:"@_",format:!1,suppressBooleanAttributes:!1,suppressEmptyNode:!0}).build(t).split(`
1
+ "use strict";var it=Object.defineProperty;var zo=Object.getOwnPropertyDescriptor;var Zo=Object.getOwnPropertyNames;var Xo=Object.prototype.hasOwnProperty;var Jo=(t,e,i)=>e in t?it(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var Ko=(t,e)=>{for(var i in e)it(t,i,{get:e[i],enumerable:!0})},es=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Zo(e))!Xo.call(t,r)&&r!==i&&it(t,r,{get:()=>e[r],enumerable:!(n=zo(e,r))||n.enumerable});return t};var ts=t=>es(it({},"__esModule",{value:!0}),t);var D=(t,e,i)=>Jo(t,typeof e!="symbol"?e+"":e,i);var Wa={};Ko(Wa,{ACT_CODE_SYSTEM:()=>wt,ADDRESS_USE_MAPPER:()=>ze,ADDRESS_USE_VALUE_SET:()=>zr,ADMINISTRATIVE_GENDER_CODE_SYSTEM:()=>jr,ADMINISTRATIVE_GENDER_VALUE_SET:()=>Xr,ALLERGIES_SECTION_TEMPLATE_IDS:()=>lo,ALLERGY_CATEGORY_MAPPER:()=>sn,ALLERGY_CLINICAL_CODE_SYSTEM:()=>ke,ALLERGY_SEVERITY_MAPPER:()=>Je,ALLERGY_STATUS_MAPPER:()=>Xe,ALLERGY_VERIFICATION_CODE_SYSTEM:()=>Vt,ASSESSMENTS_SECTION_TEMPLATE_IDS:()=>Oo,CARE_TEAM_SECTION_TEMPLATE_IDS:()=>Do,CCDA_NARRATIVE_REFERENCE_URL:()=>Ye,CCDA_TEMPLATE_CODE_SYSTEM:()=>ma,CCDA_TEMPLATE_IDS:()=>fn,CLINICAL_CONDITION_CODE_SYSTEM:()=>Ut,CLINICAL_NOTES_SECTION_TEMPLATE_IDS:()=>ya,CONDITION_CATEGORY_CODE_SYSTEM:()=>yi,CONDITION_VERIFICATION_CODE_SYSTEM:()=>Si,CONDITION_VER_STATUS_CODE_SYSTEM:()=>Mt,CONFIDENTIALITY_CODE_SYSTEM:()=>qr,CONFIDENTIALITY_MAPPER:()=>rn,CONTACT_ENTITY_USE_VALUE_SET:()=>Jr,CVX_URL:()=>ao,DEVICES_SECTION_TEMPLATE_IDS:()=>To,DIAGNOSIS_ROLE_CODE_SYSTEM:()=>gi,ENCOUNTERS_SECTION_TEMPLATE_IDS:()=>yo,ENCOUNTER_STATUS_MAPPER:()=>an,EnumMapper:()=>g,FHIR_CVX_URL:()=>co,FHIR_ICF_URL:()=>uo,FUNCTIONAL_STATUS_TEMPLATE_IDS:()=>xo,FhirToCcdaConverter:()=>Bt,GENDER_MAPPER:()=>on,GOALS_SECTION_TEMPLATE_IDS:()=>Co,HEALTH_CONCERNS_SECTION_TEMPLATE_IDS:()=>go,HTTP:()=>Z,HUMAN_NAME_USE_MAPPER:()=>Qe,IMMUNIZATIONS_SECTION_TEMPLATE_IDS:()=>fo,IMMUNIZATION_STATUS_MAPPER:()=>Ke,INSURANCE_COVERAGE_TYPE_MAPPER:()=>un,INSURANCE_SECTION_TEMPLATE_IDS:()=>vo,LAB_TESTS_SECTION_TEMPLATE_IDS:()=>Ca,LANGUAGE_MODE_CODE_SYSTEM:()=>ca,LANGUAGE_MODE_URL:()=>pa,LANGUAGE_PROFICIENCY_CODE_SYSTEM:()=>da,LANGUAGE_PROFICIENCY_URL:()=>ha,LOINC_ADMINISTRATIVE_SEX:()=>qi,LOINC_ALLERGIES_SECTION:()=>Di,LOINC_ASSESSMENTS_SECTION:()=>$e,LOINC_BIRTH_SEX:()=>Wi,LOINC_CARE_TEAM_SECTION:()=>ki,LOINC_CLINICAL_FINDING:()=>zi,LOINC_CONDITION:()=>Gi,LOINC_DEVICES_SECTION:()=>Mi,LOINC_DISABILITY_STATUS:()=>Xi,LOINC_ENCOUNTERS_SECTION:()=>Vi,LOINC_FUNCTIONAL_STATUS_ASSESSMENT_NOTE:()=>Ji,LOINC_FUNCTIONAL_STATUS_SECTION:()=>Zi,LOINC_GOALS_SECTION:()=>ce,LOINC_HEALTH_CONCERNS_SECTION:()=>de,LOINC_HISTORY_OF_OCCUPATION:()=>Ki,LOINC_HISTORY_OF_OCCUPATION_INDUSTRY:()=>en,LOINC_HISTORY_OF_SOCIAL_FUNCTION:()=>Qi,LOINC_HISTORY_OF_TOBACCO_USE:()=>ji,LOINC_IMMUNIZATIONS_SECTION:()=>vi,LOINC_INSURANCE_SECTION:()=>Bi,LOINC_MEDICATIONS_SECTION:()=>xi,LOINC_MEDICATION_INSTRUCTIONS:()=>Yi,LOINC_MENTAL_STATUS_SECTION:()=>Fi,LOINC_NOTES_SECTION:()=>je,LOINC_NOTE_DOCUMENT:()=>_a,LOINC_OVERALL_GOAL:()=>Hi,LOINC_PATIENT_SUMMARY_DOCUMENT:()=>Ea,LOINC_PLAN_OF_TREATMENT_SECTION:()=>He,LOINC_PREGNANCY_STATUS:()=>Ft,LOINC_PROBLEMS_SECTION:()=>Ge,LOINC_PROCEDURES_SECTION:()=>Ui,LOINC_REASON_FOR_REFERRAL_SECTION:()=>ue,LOINC_REFERRAL_NOTE:()=>wi,LOINC_RESULTS_SECTION:()=>Pi,LOINC_SOCIAL_HISTORY_SECTION:()=>bi,LOINC_SUMMARY_OF_EPISODE_NOTE:()=>qe,LOINC_TOBACCO_SMOKING_STATUS:()=>$i,LOINC_TO_TEMPLATE_IDS:()=>_n,LOINC_TRIBAL_AFFILIATION:()=>tn,LOINC_VITAL_SIGNS_SECTION:()=>Li,MEDICATIONS_SECTION_TEMPLATE_IDS:()=>po,MEDICATION_REQUEST_STATUS_VALUE_SET:()=>la,MEDICATION_STATUS_MAPPER:()=>et,MENTAL_STATUS_SECTION_TEMPLATE_IDS:()=>No,NAME_USE_VALUE_SET:()=>Zr,NCI_THESAURUS_URL:()=>Kr,NDFRT_URL:()=>so,NUCC_TAXONOMY_URL:()=>ro,OBSERVATION_CATEGORY_CODE_SYSTEM:()=>Wr,OBSERVATION_CATEGORY_MAPPER:()=>dn,PARTICIPATION_CODE_SYSTEM:()=>Ci,PATIENT_NOTES_SECTION_TEMPLATE_IDS:()=>Ro,PLAN_OF_TREATMENT_SECTION_TEMPLATE_IDS:()=>So,PROBLEMS_SECTION_TEMPLATE_IDS:()=>ho,PROBLEM_STATUS_MAPPER:()=>le,PROCEDURES_SECTION_TEMPLATE_IDS:()=>Eo,PROCEDURE_STATUS_MAPPER:()=>cn,RACE_CODE_SYSTEM:()=>ua,REASON_FOR_REFERRAL_SECTION_TEMPLATE_IDS:()=>Ao,REFERRAL_TEMPLATE_IDS:()=>mn,RESULTS_SECTION_TEMPLATE_IDS:()=>Io,ROLE_CODE_CODE_SYSTEM:()=>Qr,SOCIAL_HISTORY_SECTION_TEMPLATE_IDS:()=>_o,SYSTEM_MAPPER:()=>We,TELECOM_USE_MAPPER:()=>Ze,UNII_URL:()=>no,US_CORE_CONDITION_URL:()=>Ai,US_CORE_ETHNICITY_URL:()=>Be,US_CORE_MEDICATION_REQUEST_URL:()=>Ni,US_CORE_PATIENT_URL:()=>fa,US_CORE_RACE_URL:()=>ae,US_DRIVER_LICENSE_URL:()=>to,US_NPI_URL:()=>io,US_SSN_URL:()=>eo,VA_MEDRT_URL:()=>oo,VITAL_SIGNS_SECTION_TEMPLATE_IDS:()=>mo,XSI_URL:()=>Ri,convertCcdaToFhir:()=>Sa,convertCcdaToXml:()=>Oa,convertFhirToCcda:()=>qa,convertToCompactXml:()=>pn,convertXmlToCcda:()=>Ta,mapCcdaCodeToCodeableConcept:()=>kt,mapCcdaSystemToFhir:()=>z,mapCcdaToFhirDate:()=>pt,mapCcdaToFhirDateTime:()=>C,mapCodeableConceptToCcdaCode:()=>p,mapCodeableConceptToCcdaValue:()=>b,mapCodingToCcdaCode:()=>Oi,mapFhirPeriodOrDateTimeToCcda:()=>Xt,mapFhirSystemToCcda:()=>nn,mapFhirToCcdaDate:()=>L,mapFhirToCcdaDateTime:()=>T,parseXml:()=>ln});module.exports=ts(Wa);var is=Object.defineProperty,ns=(t,e,i)=>e in t?is(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,S=(t,e,i)=>ns(t,typeof e!="symbol"?e+"":e,i),$t=class{constructor(t=10){S(this,"max"),S(this,"cache"),this.max=t,this.cache=new Map}clear(){this.cache.clear()}get(t){let e=this.cache.get(t);return e&&(this.cache.delete(t),this.cache.set(t,e)),e}set(t,e){this.cache.has(t)?this.cache.delete(t):this.cache.size>=this.max&&this.cache.delete(this.first()),this.cache.set(t,e)}delete(t){this.cache.delete(t)}keys(){return this.cache.keys()}first(){return this.cache.keys().next().value}},rs=class{constructor(t,e){S(this,"operator"),S(this,"child"),this.operator=t,this.child=e}toString(){return`${this.operator}(${this.child.toString()})`}},Ie=class{constructor(t,e,i){S(this,"operator"),S(this,"left"),S(this,"right"),this.operator=t,this.left=e,this.right=i}toString(){return`(${this.left.toString()} ${this.operator} ${this.right.toString()})`}},os=class{constructor(){S(this,"prefixParselets",{}),S(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 ss(t,this.prefixParselets,this.infixParselets)}},ss=class{constructor(t,e,i){S(this,"tokens"),S(this,"prefixParselets"),S(this,"infixParselets"),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 new 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 new Error("Cant consume unknown more tokens.");if(t&&this.peek()?.id!==t){let i=this.peek();throw new 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 new 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]}},Te="http://unitsofmeasure.org",at="http://loinc.org",ct="http://snomed.info/sct",gn="http://www.nlm.nih.gov/research/umls/rxnorm",An="http://www.ama-assn.org/go/cpt";var Nn="http://hl7.org/fhir/sid/ndc",O="http://hl7.org",R="http://terminology.hl7.org";var as="unauthorized";var ot={resourceType:"OperationOutcome",id:as,issue:[{severity:"error",code:"login",details:{text:"Unauthorized"}}]},za={...ot,issue:[...ot.issue,{severity:"error",code:"expired",details:{text:"Token expired"}}]},Za={...ot,issue:[...ot.issue,{severity:"error",code:"invalid",details:{text:"Token not issued for this audience"}}]};function cs(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 ds(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,cs(r,o)])),constraints:[],innerTypes:[]};return e}var us={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 ls=ds(us);var Tn=Object.create(null);function ps(t){let e;return e=Tn[t],e||(e=Tn[t]=Object.create(null)),e}function hs(t,e){if(e){let i=ps(e)[t];if(i)return i}return ls[t]}function fs(t,e,i){let n=t.path;return ms(_s(t,e,i),n,e)}function ms(t,e,i){let n=e?e+".":"";return t===void 0?{type:"undefined",value:void 0,path:`${n}${i}`}:Array.isArray(t)?t.map((r,o)=>({...r,path:`${n}${i}[${o}]`})):{...t,path:`${n}${i}`}}var Xa=new $t(1e3);var Rn={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 c(t){return[{type:u.boolean,value:t}]}function j(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}:V(t)?{type:u.Quantity,value:t}:Oe(t)?{type:t.resourceType,value:t}:Un(t)?{type:u.CodeableConcept,value:t}:Ln(t)?{type:u.Coding,value:t}:{type:u.BackboneElement,value:t}}function $(t){return t.length===0?!1:!!t[0].value}function q(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 _s(t,e,i){if(!t.value)return;let n=Vs(t.type,e,i?.profileUrl);return n?Es(t,e,n):jt(t,e)}function Es(t,e,i){let n=t.value,r=i.type;if(!r||r.length===0)return;let o,s="undefined",a,l=i.path.lastIndexOf("."),E=i.path.substring(l+1),N=E,me=!1;E.endsWith("[x]")&&(N=E.substring(0,E.length-3),me=!0);for(let A of r){let Yt=N;if(me&&(Yt+=ie(A.code)),o=n[Yt],a=n["_"+Yt],o!==void 0||a!==void 0){s=A.code;break}}if(a)if(Array.isArray(o)){o=o.slice();for(let A=0;A<Math.max(o.length,a.length);A++)o[A]=Gt(o[A],a[A])}else if(!o&&Array.isArray(a)){o=a.slice();for(let A=0;A<a.length;A++)o[A]=Gt(void 0,a[A])}else o=Gt(o,a);if(!Ee(o))return(s==="Element"||s==="BackboneElement")&&(s=i.type[0].code),Array.isArray(o)?o.map(A=>On(A,s)):On(o,s)}function On(t,e){return e==="Resource"&&Oe(t)&&(e=t.resourceType),{type:e,value:t}}function jt(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(j):n=j(r)}else{let r=e.endsWith("[x]")?e.substring(0,e.length-3):e;for(let o of Object.values(u)){let s=r+ie(o);if(s in i){let a=i[s];Array.isArray(a)?n=a.map(l=>({type:o,value:l})):n={type:o,value:a};break}}}if(Array.isArray(n)){if(n.length===0||Ee(n[0]))return}else if(Ee(n))return;return n}function Dn(t){let e=[];for(let i of t){let n=!1;for(let r of e)if($(dt(i,r))){n=!0;break}n||e.push(i)}return e}function Is(t){return c(!$(t))}function Ts(t,e){return t.length===0||e.length===0?[]:t.length!==e.length?c(!1):c(t.every((i,n)=>$(dt(i,e[n]))))}function Os(t,e){return t.length===0||e.length===0?[]:t.length!==e.length?c(!0):c(t.some((i,n)=>!$(dt(i,e[n]))))}function dt(t,e){let i=t.value?.valueOf(),n=e.value?.valueOf();return typeof i=="number"&&typeof n=="number"?c(Math.abs(i-n)<1e-8):V(i)&&V(n)?c(Pn(i,n)):c(typeof i=="object"&&typeof n=="object"?qt(t,e):i===n)}function vn(t,e){return t.length===0&&e.length===0?c(!0):t.length!==e.length?c(!1):(t.sort(Sn),e.sort(Sn),c(t.every((i,n)=>$(Ss(i,e[n])))))}function Ss(t,e){let{type:i,value:n}=t,{type:r,value:o}=e,s=n?.valueOf(),a=o?.valueOf();return typeof s=="number"&&typeof a=="number"?c(Math.abs(s-a)<.01):V(s)&&V(a)?c(Pn(s,a)):c(i==="Coding"&&r==="Coding"?typeof s!="object"||typeof a!="object"?!1:s.code===a.code&&s.system===a.system:typeof s=="object"&&typeof a=="object"?qt({...s,id:void 0},{...a,id:void 0}):typeof s=="string"&&typeof a=="string"?s.toLowerCase()===a.toLowerCase():s===a)}function Sn(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 xn(t,e){let{value:i}=t;if(i==null)return!1;let n=e;switch(n.startsWith("System.")&&(n=n.substring(7)),n.startsWith("FHIR.")&&(n=n.substring(5)),n){case"Boolean":return typeof i=="boolean";case"Decimal":case"Integer":return typeof i=="number";case"Date":return ys(i);case"DateTime":return Ht(i);case"Time":return typeof i=="string"&&!!/^T\d/.exec(i);case"Period":return Cs(i);case"Quantity":return V(i);default:return t.type===n||typeof i=="object"&&i?.resourceType===n}}function ys(t){return typeof t=="string"&&!!Rn.date.exec(t)}function Ht(t){return typeof t=="string"&&!!Rn.dateTime.exec(t)}function Cs(t){return!!(t&&typeof t=="object"&&("start"in t&&Ht(t.start)||"end"in t&&Ht(t.end)))}function V(t){return!!(t&&typeof t=="object"&&"value"in t&&typeof t.value=="number")}function Pn(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 qt(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(yn(o)&&yn(s)){if(!qt(o,s))return!1}else if(o!==s)return!1}return!0}function yn(t){return t!==null&&typeof t=="object"}function Gt(t,e){if(e){if(typeof e!="object")throw new Error("Primitive extension must be an object");return gs(t??{},e)}return t}function gs(t,e){return delete e.__proto__,delete e.constructor,Object.assign(t,e)}function As(t,e){return Oe(t,e)&&"id"in t&&typeof t.id=="string"}function I(t){let e=bn(t)??"undefined/undefined",i=Ds(t);return i===e?{reference:e}:{reference:e,display:i}}function bn(t){if(Vn(t))return t.reference;if(As(t))return`${t.resourceType}/${t.id}`}function Ns(t){if(t)return Vn(t)?t.reference.split("/")[1]:t.id}function Rs(t){return t.resourceType==="Patient"||t.resourceType==="Practitioner"||t.resourceType==="RelatedPerson"}function Ds(t){if(Rs(t)){let e=vs(t);if(e)return e}if(t.resourceType==="Device"){let e=xs(t);if(e)return e}if(t.resourceType==="MedicationRequest"&&t.medicationCodeableConcept)return Cn(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]),Un(e))return Cn(e);if(bs(e))return e.text}return bn(t)??""}function vs(t){let e=t.name;if(e&&e.length>0)return Us(e[0])}function xs(t){let e=t.deviceName;if(e&&e.length>0)return e[0].name}function Ps(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(),a=n.getUTCFullYear(),l=n.getUTCMonth(),E=n.getUTCDate(),N=a-r;(l<o||l===o&&E<s)&&N--;let me=a*12+l-(r*12+o);E<s&&me--;let A=Math.floor((n.getTime()-i.getTime())/(1e3*60*60*24));return{years:N,months:me,days:A}}function ut(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 Ee(t){if(t==null)return!0;let e=typeof t;return e==="string"||e==="object"?!Wt(t):!1}function Wt(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 Qt(t){return/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i.test(t)}function zt(t){return t!==null&&typeof t=="object"}function Ln(t){return zt(t)&&"code"in t&&typeof t.code=="string"}function Un(t){return zt(t)&&"coding"in t&&Array.isArray(t.coding)&&t.coding.every(Ln)}function bs(t){return zt(t)&&"text"in t&&typeof t.text=="string"}var Ls=[];for(let t=0;t<256;t++)Ls.push(t.toString(16).padStart(2,"0"));function ie(t){return t?t.charAt(0).toUpperCase()+t.substring(1):""}function Mn(t,e){return t?(t.push(e),t):[e]}var f=Object.freeze([]);function Us(t,e){if(!t)return"";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=_e(t.text);if(n)return n}return i.join(" ").trim()}function Cn(t){return t?_e(t.text)||(t.coding?t.coding.map(i=>Ms(i)).join(", "):""):""}function Ms(t,e){let i=_e(t?.display);if(i){let n=e?_e(t?.code):void 0;return`${i}${n?" ("+n+")":""}`}return _e(t?.code)??""}function _e(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",Element:"Element",ElementDefinition:"ElementDefinition",Expression:"Expression",Extension:"Extension",HumanName:"HumanName",Identifier:"Identifier",MarketingStatus:"MarketingStatus",Meta:"Meta",Money:"Money",MoneyQuantity:"MoneyQuantity",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",SimpleQuantity:"SimpleQuantity",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",xhtml:"xhtml"};function Vs(t,e,i){let n=hs(t,i);if(n)return ws(n.elements,e)}function ws(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 Oe(t,e){return!(!t||typeof t!="object"||!("resourceType"in t)||e&&t.resourceType!==e)}function Vn(t,e){return t&&typeof t=="object"&&"reference"in t&&typeof t.reference=="string"?e?t.reference.match(new RegExp(`^${e}(/|\\?)`))!==null:!0:!1}function rt(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 H=()=>[],x={empty:(t,e)=>c(e.every(i=>Ee(i.value))),hasValue:(t,e)=>c(e.length!==0),exists:(t,e,i)=>c(i?e.some(n=>$(i.eval(t,[n]))):e.length>0&&e.every(n=>!Ee(n.value))),all:(t,e,i)=>c(e.every(n=>$(i.eval(t,[n])))),allTrue:(t,e)=>{for(let i of e)if(!i.value)return c(!1);return c(!0)},anyTrue:(t,e)=>{for(let i of e)if(i.value)return c(!0);return c(!1)},allFalse:(t,e)=>{for(let i of e)if(i.value)return c(!1);return c(!0)},anyFalse:(t,e)=>{for(let i of e)if(!i.value)return c(!0);return c(!1)},subsetOf:(t,e,i)=>{if(e.length===0)return c(!0);let n=i.eval(t,J(t));return n.length===0?c(!1):c(e.every(r=>n.some(o=>o.value===r.value)))},supersetOf:(t,e,i)=>{let n=i.eval(t,J(t));return n.length===0?c(!0):e.length===0?c(!1):c(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)=>c(e.length===x.distinct(t,e).length),where:(t,e,i)=>e.filter(n=>$(i.eval(t,[n]))),select:(t,e,i)=>e.flatMap(n=>i.eval({parent:t,variables:{$this:n}},[n])),repeat:H,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(-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 TypeError("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 TypeError("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,J(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,J(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,J(t));return Dn([...e,...n])},combine:(t,e,i)=>{if(!i)return e;let n=i.eval(t,J(t));return[...e,...n]},htmlChecks:(t,e,i)=>[j(!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 $(o)?n.eval(t,e):r?r.eval(t,e):[]},toBoolean:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(e,1);if(typeof i=="boolean")return[{type:u.boolean,value:i}];if(typeof i=="number"&&(i===0||i===1))return c(!!i);if(typeof i=="string"){let n=i.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(n))return c(!0);if(["false","f","no","n","0","0.0"].includes(n))return c(!1)}return[]},convertsToBoolean:(t,e)=>e.length===0?[]:c(x.toBoolean(t,e).length===1),toInteger:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(e,1);return typeof i=="number"?[{type:u.integer,value:i}]:typeof i=="string"&&/^[+-]?\d+$/.exec(i)?[{type:u.integer,value:Number.parseInt(i,10)}]:typeof i=="boolean"?[{type:u.integer,value:i?1:0}]:[]},convertsToInteger:(t,e)=>e.length===0?[]:c(x.toInteger(t,e).length===1),toDate:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(e,1);return typeof i=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(i)?[{type:u.date,value:rt(i)}]:[]},convertsToDate:(t,e)=>e.length===0?[]:c(x.toDate(t,e).length===1),toDateTime:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(e,1);return typeof i=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(i)?[{type:u.dateTime,value:rt(i)}]:[]},convertsToDateTime:(t,e)=>e.length===0?[]:c(x.toDateTime(t,e).length===1),toDecimal:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(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:Number.parseFloat(i)}]:typeof i=="boolean"?[{type:u.decimal,value:i?1:0}]:[]},convertsToDecimal:(t,e)=>e.length===0?[]:c(x.toDecimal(t,e).length===1),toQuantity:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(e,1);return V(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:Number.parseFloat(i),unit:"1"}}]:typeof i=="boolean"?[{type:u.Quantity,value:{value:i?1:0,unit:"1"}}]:[]},convertsToQuantity:(t,e)=>e.length===0?[]:c(x.toQuantity(t,e).length===1),toString:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(e,1);return i==null?[]:V(i)?[{type:u.string,value:`${i.value} '${i.unit}'`}]:[{type:u.string,value:i.toString()}]},convertsToString:(t,e)=>e.length===0?[]:c(x.toString(t,e).length===1),toTime:(t,e)=>{if(e.length===0)return[];let[{value:i}]=B(e,1);if(typeof i=="string"){let n=/^T?(\d{2}(:\d{2}(:\d{2})?)?)/.exec(i);if(n)return[{type:u.time,value:rt("T"+n[1])}]}return[]},convertsToTime:(t,e)=>e.length===0?[]:c(x.toTime(t,e).length===1),indexOf:(t,e,i)=>M((n,r)=>n.indexOf(r),t,e,i),substring:(t,e,i,n)=>M((r,o,s)=>{let a=o,l=s?a+s:r.length;return a<0||a>=r.length?void 0:r.substring(a,l)},t,e,i,n),startsWith:(t,e,i)=>M((n,r)=>n.startsWith(r),t,e,i),endsWith:(t,e,i)=>M((n,r)=>n.endsWith(r),t,e,i),contains:(t,e,i)=>M((n,r)=>n.includes(r),t,e,i),upper:(t,e)=>M(i=>i.toUpperCase(),t,e),lower:(t,e)=>M(i=>i.toLowerCase(),t,e),replace:(t,e,i,n)=>M((r,o,s)=>r.replaceAll(o,s),t,e,i,n),matches:(t,e,i)=>M((n,r)=>!!new RegExp(r).exec(n),t,e,i),replaceMatches:(t,e,i,n)=>M((r,o,s)=>r.replaceAll(new RegExp(o,"g"),s.replaceAll(/\$\{(\w+)\}/g,"$<$1>")),t,e,i,n),length:(t,e)=>M(i=>i.length,t,e),toChars:(t,e)=>M(i=>i?i.split(""):void 0,t,e),encode:H,decode:H,escape:H,unescape:H,trim:H,split:H,join:(t,e,i)=>{let n=i?.eval(t,J(t))[0]?.value??"";if(typeof n!="string")throw new TypeError("Separator must be a string.");return[{type:u.string,value:e.map(r=>r.value?.toString()??"").join(n)}]},abs:(t,e)=>k(Math.abs,t,e),ceiling:(t,e)=>k(Math.ceil,t,e),exp:(t,e)=>k(Math.exp,t,e),floor:(t,e)=>k(Math.floor,t,e),ln:(t,e)=>k(Math.log,t,e),log:(t,e,i)=>k((n,r)=>Math.log(n)/Math.log(r),t,e,i),power:(t,e,i)=>k(Math.pow,t,e,i),round:(t,e,...i)=>k((n,r=0)=>{if(typeof r!="number"||r<0)throw new Error("Invalid precision provided to round()");let o=Math.pow(10,r);return Math.round(n*o)/o},t,e,...i),sqrt:(t,e)=>k(Math.sqrt,t,e),truncate:(t,e)=>k(i=>Math.trunc(i),t,e),children:H,descendants:H,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=x.toDateTime(t,i.eval(t,e));if(o.length===0)throw new Error("Invalid start date");let s=x.toDateTime(t,n.eval(t,e));if(s.length===0)throw new Error("Invalid end date");let a=r.eval(t,e)[0]?.value;if(a!=="years"&&a!=="months"&&a!=="days")throw new Error("Invalid units");let l=Ps(o[0].value,s[0].value);return[{type:u.Quantity,value:{value:l[a],unit:a}}]},is:(t,e,i)=>{let n="";return i instanceof st?n=i.name:i instanceof wn&&(n=i.left.name+"."+i.right.name),n?e.map(r=>({type:u.boolean,value:xn(r,n)})):[]},not:(t,e)=>x.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 j(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"}}:Oe(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 st&&(r=i.name),r&&!n.reference.startsWith(r+"/")?[]:[{type:u.id,value:Ns(n)}]},extension:(t,e,i)=>{let n=i.eval(t,e)[0].value,r=e?.[0]?.value;if(r){let o=ut(r,n);if(o)return[{type:u.Extension,value:o}]}return[]}};function M(t,e,i,...n){if(i.length===0)return[];let[{value:r}]=B(i,1);if(typeof r!="string")throw new TypeError("String function cannot be called with non-string");let o=n.map(a=>a?.eval(e,i)[0]?.value),s=t(r,...o);return s===void 0?[]:Array.isArray(s)?s.map(j):[j(s)]}function k(t,e,i,...n){if(i.length===0)return[];let[{value:r}]=B(i,1),o=V(r),s=o?r.value:r;if(typeof s!="number")throw new TypeError("Math function cannot be called with non-number");let a=t(s,...n.map(N=>N.eval(e,i)[0]?.value)),l=o?u.Quantity:i[0].type,E=o?{...r,value:a}:a;return[{type:l,value:E}]}function B(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 J(t){let e=t;for(;e.parent?.variables.$this;)e=e.parent;return[e.variables.$this]}var te=class{constructor(t){S(this,"value"),this.value=t}eval(){return[this.value]}toString(){let t=this.value.value;return typeof t=="string"?`'${t}'`:t.toString()}},st=class{constructor(t){S(this,"name"),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 Oe(e,this.name)?t:fs(t,this.name)}toString(){return this.name}},Fs=class{eval(){return[]}toString(){return"{}"}},ks=class extends rs{constructor(t,e,i){super(t,e),S(this,"impl"),this.impl=i}eval(t,e){return this.impl(this.child.eval(t,e))}toString(){return this.operator+this.child.toString()}},Bs=class extends Ie{constructor(t,e){super("as",t,e)}eval(t,e){return x.ofType(t,this.left.eval(t,e),this.right)}},w=class extends Ie{},F=class extends w{constructor(t,e,i,n){super(t,e,i),S(this,"impl"),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=V(r)?r.value:r,a=V(o)?o.value:o,l=this.impl(s,a);return typeof l=="boolean"?c(l):V(r)?[{type:u.Quantity,value:{...r,value:l}}]:[j(l)]}},Ys=class extends Ie{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}},Gs=class extends w{constructor(t,e){super("contains",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return c(i.some(r=>r.value===n[0].value))}},Hs=class extends w{constructor(t,e){super("in",t,e)}eval(t,e){let i=q(this.left.eval(t,e)),n=this.right.eval(t,e);return i?c(n.some(r=>dt(i,r)[0].value)):[]}},wn=class extends Ie{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()}`}},$s=class extends Ie{constructor(t,e){super("|",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return Dn([...i,...n])}},js=class extends w{constructor(t,e){super("=",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return Ts(i,n)}},qs=class extends w{constructor(t,e){super("!=",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return Os(i,n)}},Ws=class extends w{constructor(t,e){super("~",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return vn(i,n)}},Qs=class extends w{constructor(t,e){super("!~",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return Is(vn(i,n))}},zs=class extends w{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 c(xn(i[0],n))}},Zs=class extends w{constructor(t,e){super("and",t,e)}eval(t,e){let i=q(this.left.eval(t,e),"boolean"),n=q(this.right.eval(t,e),"boolean");return i?.value===!0&&n?.value===!0?c(!0):i?.value===!1||n?.value===!1?c(!1):[]}},Xs=class extends w{constructor(t,e){super("or",t,e)}eval(t,e){let i=q(this.left.eval(t,e),"boolean"),n=q(this.right.eval(t,e),"boolean");return i?.value===!1&&n?.value===!1?c(!1):i?.value||n?.value?c(!0):[]}},Js=class extends w{constructor(t,e){super("xor",t,e)}eval(t,e){let i=q(this.left.eval(t,e),"boolean"),n=q(this.right.eval(t,e),"boolean");return!i||!n?[]:c(i.value!==n.value)}},Ks=class extends w{constructor(t,e){super("implies",t,e)}eval(t,e){let i=q(this.left.eval(t,e),"boolean"),n=q(this.right.eval(t,e),"boolean");return n?.value===!0||i?.value===!1?c(!0):!i||!n?[]:c(!1)}},ea=class{constructor(t,e){S(this,"name"),S(this,"args"),this.name=t,this.args=e}eval(t,e){let i=x[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(", ")})`}},ta=class{constructor(t,e){S(this,"left"),S(this,"expr"),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 Fn=["!=","!~","<=",">=","{}","->"];var _={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},ia={parse(t){let e=t.consumeAndParse();if(!t.match(")"))throw new Error("Parse error: expected `)` got `"+t.peek()?.value+"`");return e}},na={parse(t,e){let i=t.consumeAndParse();if(!t.match("]"))throw new Error("Parse error: expected `]`");return new ta(e,i)},precedence:_.Indexer},ra={parse(t,e){if(!(e instanceof st))throw new Error("Unexpected parentheses");let i=[];for(;!t.match(")");)i.push(t.consumeAndParse()),t.match(",");return new ea(e.name,i)},precedence:_.FunctionCall};function oa(t){let e=t.split(" "),i=Number.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 Zt(){return new os().registerPrefix("String",{parse:(t,e)=>new te({type:u.string,value:e.value})}).registerPrefix("DateTime",{parse:(t,e)=>new te({type:u.dateTime,value:rt(e.value)})}).registerPrefix("Quantity",{parse:(t,e)=>new te({type:u.Quantity,value:oa(e.value)})}).registerPrefix("Number",{parse:(t,e)=>new te({type:e.value.includes(".")?u.decimal:u.integer,value:Number.parseFloat(e.value)})}).registerPrefix("true",{parse:()=>new te({type:u.boolean,value:!0})}).registerPrefix("false",{parse:()=>new te({type:u.boolean,value:!1})}).registerPrefix("Symbol",{parse:(t,e)=>new st(e.value)}).registerPrefix("{}",{parse:()=>new Fs}).registerPrefix("(",ia).registerInfix("[",na).registerInfix("(",ra).prefix("+",_.UnaryAdd,(t,e)=>new ks("+",e,i=>i)).prefix("-",_.UnarySubtract,(t,e)=>new F("-",e,e,(i,n)=>-n)).infixLeft(".",_.Dot,(t,e,i)=>new wn(t,i)).infixLeft("/",_.Divide,(t,e,i)=>new F("/",t,i,(n,r)=>n/r)).infixLeft("*",_.Multiply,(t,e,i)=>new F("*",t,i,(n,r)=>n*r)).infixLeft("+",_.Add,(t,e,i)=>new F("+",t,i,(n,r)=>n+r)).infixLeft("-",_.Subtract,(t,e,i)=>new F("-",t,i,(n,r)=>n-r)).infixLeft("|",_.Union,(t,e,i)=>new $s(t,i)).infixLeft("=",_.Equals,(t,e,i)=>new js(t,i)).infixLeft("!=",_.NotEquals,(t,e,i)=>new qs(t,i)).infixLeft("~",_.Equivalent,(t,e,i)=>new Ws(t,i)).infixLeft("!~",_.NotEquivalent,(t,e,i)=>new Qs(t,i)).infixLeft("<",_.LessThan,(t,e,i)=>new F("<",t,i,(n,r)=>n<r)).infixLeft("<=",_.LessThanOrEquals,(t,e,i)=>new F("<=",t,i,(n,r)=>n<=r)).infixLeft(">",_.GreaterThan,(t,e,i)=>new F(">",t,i,(n,r)=>n>r)).infixLeft(">=",_.GreaterThanOrEquals,(t,e,i)=>new F(">=",t,i,(n,r)=>n>=r)).infixLeft("&",_.Ampersand,(t,e,i)=>new Ys(t,i)).infixLeft("and",_.And,(t,e,i)=>new Zs(t,i)).infixLeft("as",_.As,(t,e,i)=>new Bs(t,i)).infixLeft("contains",_.Contains,(t,e,i)=>new Gs(t,i)).infixLeft("div",_.Divide,(t,e,i)=>new F("div",t,i,(n,r)=>Math.trunc(n/r))).infixLeft("in",_.In,(t,e,i)=>new Hs(t,i)).infixLeft("is",_.Is,(t,e,i)=>new zs(t,i)).infixLeft("mod",_.Modulo,(t,e,i)=>new F("mod",t,i,(n,r)=>n%r)).infixLeft("or",_.Or,(t,e,i)=>new Xs(t,i)).infixLeft("xor",_.Xor,(t,e,i)=>new Js(t,i)).infixLeft("implies",_.Implies,(t,e,i)=>new Ks(t,i))}var Ja=Zt();var h={EQUALS:"eq",NOT_EQUALS:"ne",GREATER_THAN:"gt",LESS_THAN:"lt",GREATER_THAN_OR_EQUALS:"ge",LESS_THAN_OR_EQUALS:"le",STARTS_AFTER:"sa",ENDS_BEFORE:"eb",APPROXIMATELY:"ap",CONTAINS:"contains",STARTS_WITH:"sw",EXACT:"exact",TEXT:"text",NOT:"not",ABOVE:"above",BELOW:"below",IN:"in",NOT_IN:"not-in",OF_TYPE:"of-type",MISSING:"missing",PRESENT:"present",IDENTIFIER:"identifier",ITERATE:"iterate"},Ka={contains:h.CONTAINS,exact:h.EXACT,above:h.ABOVE,below:h.BELOW,text:h.TEXT,not:h.NOT,in:h.IN,"not-in":h.NOT_IN,"of-type":h.OF_TYPE,missing:h.MISSING,identifier:h.IDENTIFIER,iterate:h.ITERATE},ec={eq:h.EQUALS,ne:h.NOT_EQUALS,lt:h.LESS_THAN,le:h.LESS_THAN_OR_EQUALS,gt:h.GREATER_THAN,ge:h.GREATER_THAN_OR_EQUALS,sa:h.STARTS_AFTER,eb:h.ENDS_BEFORE,ap:h.APPROXIMATELY,sw:h.STARTS_WITH};var tc=[h.MISSING,h.PRESENT];var ic=new $t(1e3);var nt={READ:"read",VREAD:"vread",UPDATE:"update",DELETE:"delete",HISTORY:"history",CREATE:"create",SEARCH:"search"},nc=[nt.READ,nt.VREAD,nt.HISTORY,nt.SEARCH];function lt(){return typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replaceAll(/[xy]/g,t=>{let e=Math.trunc(Math.random()*16);return(t==="x"?e:e&3|8).toString(16)})}var sa={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",JWT:"application/jwt",MULTIPART_FORM_DATA:"multipart/form-data",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",OCTET_STREAM:"application/octet-stream"};var aa;aa=Symbol.toStringTag;var rc={Event:typeof globalThis.Event<"u"?globalThis.Event:void 0,ErrorEvent:void 0,CloseEvent:void 0};var oc={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 sc=[WebSocket.CLOSING,WebSocket.CLOSED];var ac=new $t(1e3);var cc=sa.FHIR_JSON+", */*; q=0.1";var dc=[...Fn,"->","<<",">>","=="];var uc=Zt().registerInfix("->",{precedence:_.Arrow}).registerInfix(";",{precedence:_.Semicolon});var lc=" ".repeat(2);var pc=[...Fn,"eq","ne","co"];var hc={eq:h.EXACT,ne:h.NOT_EQUALS,co:h.CONTAINS,sw:h.STARTS_WITH,ew:void 0,gt:h.GREATER_THAN,lt:h.LESS_THAN,ge:h.GREATER_THAN_OR_EQUALS,le:h.LESS_THAN_OR_EQUALS,ap:h.APPROXIMATELY,sa:h.STARTS_AFTER,eb:h.ENDS_BEFORE,pr:h.PRESENT,po:void 0,ss:void 0,sb:void 0,in:h.IN,ni:h.NOT_IN,re:h.EQUALS,identifier:h.IDENTIFIER};var fc=Zt();var mc=`${O}/fhir/StructureDefinition/patient-preferredPharmacy`;function pt(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 C(t){if(!t)return;let e=/^[+-]\d{4}$/,i=t.substring(0,4),n="01",r="01",o="00",s="00",a="00",l="Z";t.length>=8&&(n=t.substring(4,6),r=t.substring(6,8)),t.length>=12&&(o=t.substring(8,10),s=t.substring(10,12));let E=t.charAt(12);t.length>=14&&E!=="+"&&E!=="-"&&(a=t.substring(12,14));let N=E==="+"||E==="-"?12:14;return t.length>N&&(l=t.substring(N),l==="+0000"||l==="-0000"?l="Z":e.test(l)&&(l=`${l.substring(0,3)}:${l.substring(3)}`)),`${i}-${n}-${r}T${o}:${s}:${a}${l}`}function L(t){if(t)return t.substring(0,10).replaceAll("-","")}function T(t){if(!t)return;let[e,i]=t.split("T"),n=e.replaceAll("-",""),r=(i??"").replaceAll(/\.\d+/g,"").replaceAll(":","").replaceAll("Z","+0000");return`${n}${r}`}function Xt(t,e){if(t?.start||t?.end){let i={};return t.start&&(i.low={"@_value":T(t.start)??""}),t.end&&(i.high={"@_value":T(t.end)??""}),i}return e?{"@_value":T(e)??""}:{}}var K="1.3.6.1.4.1.19376.1.5.3.1.3.1";var kn="2.16.840.1.113883.1.3";var Bn="2.16.840.1.113883.2.20.5.1",Yn="2.16.840.1.113883.3.26.1.1";var Gn="2.16.840.1.113883.3.221.5",Hn="2.16.840.1.113883.4.1",$n="2.16.840.1.113883.4.3",jn="2.16.840.1.113883.4.6",qn="2.16.840.1.113883.4.9",ht="2.16.840.1.113883.5.1",ft="2.16.840.1.113883.5.4",mt="2.16.840.1.113883.5.6",Jt="2.16.840.1.113883.5.25",Wn="2.16.840.1.113883.5.111",y="2.16.840.1.113883.6.1",Qn="2.16.840.1.113883.6.12",zn="2.16.840.1.113883.6.24",Zn="2.16.840.1.113883.6.69",Xn="2.16.840.1.113883.6.88",P="2.16.840.1.113883.6.96",Jn="2.16.840.1.113883.6.101",Kn="2.16.840.1.113883.6.209",_t="2.16.840.1.113883.6.238",er="2.16.840.1.113883.6.254",tr="2.16.840.1.113883.6.345";var Et="2.16.840.1.113883.10.20.15.3.8";var Se="2.16.840.1.113883.10.20.22.1.1";var Kt="2.16.840.1.113883.10.20.22.1.2";var ei="2.16.840.1.113883.10.20.22.1.14";var It="2.16.840.1.113883.10.20.22.2.1.1";var ye="2.16.840.1.113883.10.20.22.2.2",Ce="2.16.840.1.113883.10.20.22.2.2.1";var ti="2.16.840.1.113883.10.20.22.2.3.1";var ir="2.16.840.1.113883.10.20.22.2.4.1";var nr="2.16.840.1.113883.10.20.22.2.5",ge="2.16.840.1.113883.10.20.22.2.5.1",rr="2.16.840.1.113883.10.20.22.2.5.1 .2",or="2.16.840.1.113883.10.20.22.2.5.2",sr="2.16.840.1.113883.10.20.22.2.6",Ae="2.16.840.1.113883.10.20.22.2.6.1",ar="2.16.840.1.113883.10.20.22.2.6.1.2",cr="2.16.840.1.113883.10.20.22.2.6.2";var ne="2.16.840.1.113883.10.20.22.2.7.1";var Tt="2.16.840.1.113883.10.20.22.2.8";var Q="2.16.840.1.113883.10.20.22.2.10";var ii="2.16.840.1.113883.10.20.22.2.14";var ni="2.16.840.1.113883.10.20.22.2.17";var Ne="2.16.840.1.113883.10.20.22.2.18";var dr="2.16.840.1.113883.10.20.22.2.22.1";var ur="2.16.840.1.113883.10.20.22.2.23";var lr="2.16.840.1.113883.10.20.22.2.56";var Ot="2.16.840.1.113883.10.20.22.2.58";var Re="2.16.840.1.113883.10.20.22.2.60";var St="2.16.840.1.113883.10.20.22.2.65";var yt="2.16.840.1.113883.10.20.22.2.500",De="2.16.840.1.113883.10.20.22.4.1",pr="2.16.840.1.113883.10.20.22.4.1.2",ve="2.16.840.1.113883.10.20.22.4.2",hr="2.16.840.1.113883.10.20.22.4.2.2",ri="2.16.840.1.113883.10.20.22.4.3";var Y="2.16.840.1.113883.10.20.22.4.4",fr="2.16.840.1.113883.10.20.22.4.4.2";var oi="2.16.840.1.113883.10.20.22.4.7";var si="2.16.840.1.113883.10.20.22.4.8";var ai="2.16.840.1.113883.10.20.22.4.9";var re="2.16.840.1.113883.10.20.22.4.12";var xe="2.16.840.1.113883.10.20.22.4.13";var oe="2.16.840.1.113883.10.20.22.4.14";var ci="2.16.840.1.113883.10.20.22.4.16";var mr="2.16.840.1.113883.10.20.22.4.20";var di="2.16.840.1.113883.10.20.22.4.23";var Pe="2.16.840.1.113883.10.20.22.4.26",_r="2.16.840.1.113883.10.20.22.4.26.2",be="2.16.840.1.113883.10.20.22.4.27",Er="2.16.840.1.113883.10.20.22.4.27.2";var ui="2.16.840.1.113883.10.20.22.4.30";var Ct="2.16.840.1.113883.10.20.22.4.32";var Ir="2.16.840.1.113883.10.20.22.4.37",Tr="2.16.840.1.113883.10.20.22.4.38",Or="2.16.840.1.113883.10.20.22.4.38.1";var gt="2.16.840.1.113883.10.20.22.4.41";var At="2.16.840.1.113883.10.20.22.4.44";var Le="2.16.840.1.113883.10.20.22.4.49";var li="2.16.840.1.113883.10.20.22.4.52";var pi="2.16.840.1.113883.10.20.22.4.54",hi="2.16.840.1.113883.10.20.22.4.60";var fi="2.16.840.1.113883.10.20.22.4.61";var Ue="2.16.840.1.113883.10.20.22.4.66";var Me="2.16.840.1.113883.10.20.22.4.67";var Nt="2.16.840.1.113883.10.20.22.4.69",Sr="2.16.840.1.113883.10.20.22.4.70";var yr="2.16.840.1.113883.10.20.22.4.74";var Cr="2.16.840.1.113883.10.20.22.4.75";var Ve="2.16.840.1.113883.10.20.22.4.78",gr="2.16.840.1.113883.10.20.22.4.78.2";var we="2.16.840.1.113883.10.20.22.4.85";var Rt="2.16.840.1.113883.10.20.22.4.86",Ar="2.16.840.1.113883.10.20.22.4.87";var Nr="2.16.840.1.113883.10.20.22.4.89",Rr="2.16.840.1.113883.10.20.22.4.90";var Dr="2.16.840.1.113883.10.20.22.4.114";var vr="2.16.840.1.113883.10.20.22.4.119";var se="2.16.840.1.113883.10.20.22.4.121";var xr="2.16.840.1.113883.10.20.22.4.128";var Pr="2.16.840.1.113883.10.20.22.4.130";var mi="2.16.840.1.113883.10.20.22.4.132",br="2.16.840.1.113883.10.20.22.4.133";var Lr="2.16.840.1.113883.10.20.22.4.140";var Dt="2.16.840.1.113883.10.20.22.4.147",Fe="2.16.840.1.113883.10.20.22.4.200",Ur="2.16.840.1.113883.10.20.22.4.201",Mr="2.16.840.1.113883.10.20.22.4.202";var Vr="2.16.840.1.113883.10.20.22.4.244";var wr="2.16.840.1.113883.10.20.22.4.250";var Fr="2.16.840.1.113883.10.20.22.4.406",kr="2.16.840.1.113883.10.20.22.4.407";var Br="2.16.840.1.113883.10.20.22.4.416";var _i="2.16.840.1.113883.10.20.22.4.500",Yr="2.16.840.1.113883.10.20.22.4.501";var vt="2.16.840.1.113883.10.20.22.4.503",xt="2.16.840.1.113883.10.20.22.4.504",Ei="2.16.840.1.113883.10.20.22.4.505",Pt="2.16.840.1.113883.10.20.22.4.506",bt="2.16.840.1.113883.10.20.22.4.507",Gr="2.16.840.1.113883.10.20.22.4.508";var Hr="2.16.840.1.113883.10.20.22.4.512";var $r="2.16.840.1.113883.10.20.22.5.8";var Ii="2.16.840.1.113883.12.292",Ti="2.16.840.1.113883.3.3719";function Lt(t){if(t==null)return t;if(Array.isArray(t))return t.map(e=>Lt(e)).filter(e=>e!==void 0);if(typeof t=="object"){let e=Object.keys(t).filter(n=>n!=="@_nullFlavor");if(e.length===0)return;let i={};for(let n of e){let r=Lt(t[n]);r!==void 0&&(i[n]=r)}return Object.keys(i).length===0?void 0:i}return t}var g=class{constructor(e,i){D(this,"details");D(this,"entries");D(this,"ccdaToFhirMap");D(this,"fhirToCcdaMap");this.details=e,this.entries=i,this.ccdaToFhirMap={},this.fhirToCcdaMap={};for(let n of i)this.ccdaToFhirMap[n.ccdaValue]||(this.ccdaToFhirMap[n.ccdaValue]=n),this.fhirToCcdaMap[n.fhirValue]||(this.fhirToCcdaMap[n.fhirValue]=n)}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.details.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.details.ccdaSystemOid,"@_codeSystemName":this.details.ccdaSystemOid?We.getEntryByCcda(this.details.ccdaSystemOid)?.displayName:void 0}}},Z="http:",jr=`${O}/fhir/administrative-gender`,Ut=`${R}/CodeSystem/condition-clinical`,Si=`${R}/CodeSystem/condition-verification`,ca=`${R}/CodeSystem/v3-LanguageAbilityMode`,da=`${R}/CodeSystem/v3-LanguageAbilityProficiency`,ua=`${R}/CodeSystem/v3-Race`,yi=`${R}/CodeSystem/condition-category`,Mt=`${R}/CodeSystem/condition-ver-status`,ke=`${R}/CodeSystem/allergyintolerance-clinical`,Vt=`${R}/CodeSystem/allergyintolerance-verification`,wt=`${R}/CodeSystem/v3-ActCode`,Ci=`${R}/CodeSystem/v3-ParticipationType`,gi=`${R}/CodeSystem/diagnosis-role`,qr=`${R}/CodeSystem/v3-Confidentiality`,Wr=`${R}/CodeSystem/observation-category`,Qr=`${R}/CodeSystem/v3-RoleCode`,zr=`${O}/fhir/ValueSet/address-use`,Zr=`${O}/fhir/ValueSet/name-use`,Xr=`${O}/fhir/ValueSet/administrative-gender`,Jr=`${O}/fhir/ValueSet/contactentity-use`,la=`${O}/fhir/ValueSet/medicationrequest-status`,pa=`${O}/fhir/StructureDefinition/language-mode`,ha=`${O}/fhir/StructureDefinition/language-proficiency`,fa=`${O}/fhir/us/core/StructureDefinition/us-core-patient`,ae=`${O}/fhir/us/core/StructureDefinition/us-core-race`,Be=`${O}/fhir/us/core/StructureDefinition/us-core-ethnicity`,Ai=`${O}/fhir/us/core/StructureDefinition/us-core-condition`,Ni=`${O}/fhir/us/core/StructureDefinition/us-core-medicationrequest`,ma=`${O}/cda/template`,Kr=`${Z}//ncithesaurus-stage.nci.nih.gov`,eo=`${O}/fhir/sid/us-ssn`,to=`${O}/fhir/sid/us-dln`,io=`${O}/fhir/sid/us-npi`,no=`${Z}//fdasis.nlm.nih.gov`,ro=`${Z}//nucc.org/provider-taxonomy`,oo=`${Z}//va.gov/terminology/medrt`,so=`${Z}//hl7.org/fhir/ndfrt`,ao=`${Z}//nucc.org/cvx`,co=`${O}/fhir/sid/cvx`,uo=`${O}/fhir/sid/icf`,Ri=`${Z}//www.w3.org/2001/XMLSchema-instance`,Ye="https://medplum.com/fhir/StructureDefinition/ccda-narrative-reference",Di="48765-2",vi="11369-6",xi="10160-0",Ge="11450-4",Pi="30954-2",bi="29762-2",Li="8716-3",Ui="47519-4",He="18776-5",$e="51848-0",Mi="46264-8",ce="61146-7",de="75310-3",Vi="46240-8",ue="42349-1",wi="57133-1",Fi="10190-7",ki="85847-2",Bi="48768-6",je="11488-4",_a="34109-9",Ea="60591-5",qe="34133-9",Yi="76662-6",Gi="75323-6",Hi="58144-7",$i="72166-2",ji="11367-0",qi="46098-0",Wi="76689-9",Qi="8689-2",zi="75321-0",Zi="47420-5",Xi="89571-4",Ji="47420-5",Ki="11341-5",en="86188-0",Ft="82810-3",tn="95370-3",We=new g({},[{ccdaValue:Bn,fhirValue:"https://fhir.infoway-inforoute.ca/CodeSystem/pCLOCD",displayName:"pan-Canadian LOINC Observation Code Database (pCLOCD)"},{ccdaValue:Yn,fhirValue:Kr,displayName:"NCI Thesaurus"},{ccdaValue:Hn,fhirValue:eo,displayName:"SSN"},{ccdaValue:$n,fhirValue:to,displayName:"DLN"},{ccdaValue:jn,fhirValue:io,displayName:"NPI"},{ccdaValue:qn,fhirValue:no,displayName:"Unique Ingredient Identifier (UNII)"},{ccdaValue:y,fhirValue:at,displayName:"LOINC"},{ccdaValue:Qn,fhirValue:An,displayName:"Current Procedural Terminology (CPT)"},{ccdaValue:zn,fhirValue:"urn:iso:std:iso:11073:10101",displayName:"Medical Device Communications (MDC)"},{ccdaValue:Zn,fhirValue:Nn,displayName:"National Drug Code (NDC)"},{ccdaValue:Xn,fhirValue:gn,displayName:"RxNorm"},{ccdaValue:P,fhirValue:ct,displayName:"SNOMED CT"},{ccdaValue:Jn,fhirValue:ro,displayName:"NUCC Health Care Provider Taxonomy"},{ccdaValue:tr,fhirValue:oo,displayName:"Medication Reference Terminology (MED-RT)"},{ccdaValue:Kn,fhirValue:so,displayName:"National Drug File Reference Terminology (NDF-RT)"},{ccdaValue:Ii,fhirValue:ao,displayName:"CVX"},{ccdaValue:Jt,fhirValue:"Confidentiality",displayName:"Confidentiality"},{ccdaValue:ht,fhirValue:jr,displayName:"Administrative Sex"},{ccdaValue:Wn,fhirValue:Qr,displayName:"Role Code"},{ccdaValue:Gn,fhirValue:"",displayName:"Insurance Type Code"},{ccdaValue:Ii,fhirValue:co,displayName:"Vaccine Administered Code Set (CVX)"},{ccdaValue:er,fhirValue:uo,displayName:"International Classification of Functioning, Disability and Health (ICF)"}]);function z(t){if(t)return We.mapCcdaToFhir(t)??`urn:oid:${t}`}function kt(t){if(!t)return;let e=[],i=z(t["@_codeSystem"]),n=t["@_code"],r=t["@_displayName"];(i||n||r)&&e.push({...i&&{system:i},...n&&{code:n},...r&&{display:r}});for(let s of t.translation??f){let a=z(s["@_codeSystem"]),l=s["@_code"],E=s["@_displayName"];(a||l||E)&&e.push({...a&&{system:a},...l&&{code:l},...E&&{display:E}})}let o=t["@_displayName"];return e.length===0?o?{text:o}:void 0:{coding:e,...o&&{text:o}}}function nn(t){if(t)return t.startsWith("urn:oid:")?t.replace("urn:oid:",""):We.mapFhirToCcda(t)}function p(t){if(!t?.coding?.[0])return;let e=Oi(t.coding[0]);if(t.coding.length>1){e.translation=[];for(let i=1;i<t.coding.length;i++)e.translation.push(Oi(t.coding[i]))}return e}function Oi(t){let e=t?.system?We.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 b(t){let e=p(t);if(e)return{"@_xsi:type":"CD",...e}}var rn=new g({ccdaSystemOid:Jt,fhirSystemUrl:qr},[{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"}]),Qe=new g({fhirSystemUrl:Zr},[{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"}]),on=new g({fhirSystemUrl:Xr},[{ccdaValue:"F",fhirValue:"female",displayName:"Female"},{ccdaValue:"M",fhirValue:"male",displayName:"Male"},{ccdaValue:"UN",fhirValue:"unknown",displayName:"Unknown"},{ccdaValue:"UN",fhirValue:"other",displayName:"Other"}]),ze=new g({fhirSystemUrl:zr},[{ccdaValue:"HP",fhirValue:"home",displayName:"Home"},{ccdaValue:"WP",fhirValue:"work",displayName:"Work"}]),Ze=new g({fhirSystemUrl:Jr},[{ccdaValue:"WP",fhirValue:"work",displayName:"Work"},{ccdaValue:"HP",fhirValue:"home",displayName:"Home"},{ccdaValue:"MC",fhirValue:"mobile",displayName:"Mobile"}]),Xe=new g({fhirSystemUrl:Vt},[{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"}]),sn=new g({ccdaSystemOid:P,fhirSystemUrl:ke},[{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)"}]),Je=new g({ccdaSystemOid:P,fhirSystemUrl:ke},[{ccdaValue:"255604002",fhirValue:"mild",displayName:"Mild"},{ccdaValue:"6736007",fhirValue:"moderate",displayName:"Moderate"},{ccdaValue:"24484000",fhirValue:"severe",displayName:"Severe"}]),le=new g({fhirSystemUrl:Mt},[{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"}]),Ke=new g({},[{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"}]),an=new g({},[{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"}]),cn=new g({},[{ccdaValue:"completed",fhirValue:"completed",displayName:"Completed"},{ccdaValue:"active",fhirValue:"active",displayName:"Active"},{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"}]),et=new g({},[{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"}]),dn=new g({fhirSystemUrl:Wr},[{ccdaValue:Tr,fhirValue:"social-history",displayName:"Social History"},{ccdaValue:Or,fhirValue:"social-history",displayName:"Social History V2"},{ccdaValue:Ve,fhirValue:"social-history",displayName:"Smoking Status"},{ccdaValue:gr,fhirValue:"social-history",displayName:"Current Smoking Status"},{ccdaValue:we,fhirValue:"social-history",displayName:"Tobacco Use"},{ccdaValue:vt,fhirValue:"social-history",displayName:"Basic Occupation"},{ccdaValue:xt,fhirValue:"social-history",displayName:"Basic Industry"},{ccdaValue:Yr,fhirValue:"social-history",displayName:"Sexual Orientation"},{ccdaValue:bt,fhirValue:"social-history",displayName:"Sex Observation"},{ccdaValue:Fe,fhirValue:"social-history",displayName:"Gender Identity"},{ccdaValue:Ur,fhirValue:"social-history",displayName:"Gender Identity V2"},{ccdaValue:Et,fhirValue:"social-history",displayName:"Pregnancy Status"},{ccdaValue:Pt,fhirValue:"social-history",displayName:"Tribal Affiliation"},{ccdaValue:be,fhirValue:"vital-signs",displayName:"Vital Signs Observation"},{ccdaValue:Er,fhirValue:"vital-signs",displayName:"Vital Signs Observation V2"},{ccdaValue:Pe,fhirValue:"vital-signs",displayName:"Vital Signs Organizer"},{ccdaValue:_r,fhirValue:"vital-signs",displayName:"Vital Signs Organizer V2"},{ccdaValue:Hr,fhirValue:"vital-signs",displayName:"Average Blood Pressure Organizer"},{ccdaValue:ve,fhirValue:"laboratory",displayName:"Result Observation"},{ccdaValue:hr,fhirValue:"laboratory",displayName:"Result Observation V2"},{ccdaValue:Fr,fhirValue:"laboratory",displayName:"Laboratory Battery (ID)"},{ccdaValue:kr,fhirValue:"laboratory",displayName:"Laboratory Observation (ID)"},{ccdaValue:Br,fhirValue:"laboratory",displayName:"Laboratory Result Organizer (ID)"},{ccdaValue:De,fhirValue:"laboratory",displayName:"Result Organizer"},{ccdaValue:pr,fhirValue:"laboratory",displayName:"Result Organizer V2"},{ccdaValue:Nt,fhirValue:"survey",displayName:"Assessment Scale Observation"},{ccdaValue:Rt,fhirValue:"survey",displayName:"Assessment Scale Supporting Observation"},{ccdaValue:yr,fhirValue:"survey",displayName:"Cognitive Status Result Observation"},{ccdaValue:Cr,fhirValue:"survey",displayName:"Cognitive Status Result Organizer"},{ccdaValue:Me,fhirValue:"survey",displayName:"Functional Status Result Observation"},{ccdaValue:Ue,fhirValue:"survey",displayName:"Functional Status Result Organizer"},{ccdaValue:xe,fhirValue:"exam",displayName:"Procedure Activity Observation"},{ccdaValue:Y,fhirValue:"exam",displayName:"Problem Observation"},{ccdaValue:fr,fhirValue:"exam",displayName:"Problem Observation V2"},{ccdaValue:Sr,fhirValue:"exam",displayName:"Pressure Ulcer Observation"},{ccdaValue:Dr,fhirValue:"exam",displayName:"Wound Observation"},{ccdaValue:br,fhirValue:"exam",displayName:"Wound Measurements Observation"},{ccdaValue:ne,fhirValue:"exam",displayName:"Procedure Section"},{ccdaValue:Gr,fhirValue:"therapy",displayName:"Medication Adherence"},{ccdaValue:Pr,fhirValue:"therapy",displayName:"Nutrition Recommendations"},{ccdaValue:Vr,fhirValue:"therapy",displayName:"Diet Statement (Nutrition)"},{ccdaValue:wr,fhirValue:"therapy",displayName:"Monitoring, Evaluation and Outcome (Nutrition)"}]),un=new g({fhirSystemUrl:wt},[{ccdaValue:"71",fhirValue:"HMO",displayName:"Health Maintenance Organization"},{ccdaValue:"72",fhirValue:"PPO",displayName:"Preferred Provider Organization"},{ccdaValue:"73",fhirValue:"POS",displayName:"Point of Service"},{ccdaValue:"79",fhirValue:"MCPOL",displayName:"Managed Care Policy"},{ccdaValue:"81",fhirValue:"pay",displayName:"Self Pay"},{ccdaValue:"9999",fhirValue:"",displayName:"Unknown"}]);var pe=require("fast-xml-parser");var Ia=["ClinicalDocument.participant","ClinicalDocument.recordTarget",".id",".templateId",".name",".addr",".telecom",".streetAddressLine",".author",".effectiveTime","name.given","name.suffix","name.prefix","patient.raceCode","patient.sdtc:raceCode","patient.ethnicGroupCode","patient.languageCommunication","component.structuredBody.component","component.structuredBody.component.section","component.section","component.observation","component.act","code.translation","value.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 Ta(t){return new pe.XMLParser({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1,jPath:!0,isArray:(n,r,o,s)=>Ia.some(a=>r.endsWith(a))}).parse(t).ClinicalDocument}function Oa(t){return new pe.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":Ri,"@_xmlns:voc":"urn:hl7-org:v3/voc","@_xmlns:sdtc":"urn:hl7-org:sdtc",...t}})}function ln(t){return new pe.XMLParser({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1}).parse(t)}function pn(t){return t?typeof t=="string"?t:new pe.XMLBuilder({ignoreAttributes:!1,attributeNamePrefix:"@_",format:!1,suppressBooleanAttributes:!1,suppressEmptyNode:!0}).build(t).split(`
2
2
  `).map(n=>n.trim()).join(""):""}function Sa(t,e){return new hn(Lt(t),e).convert()}var hn=class{constructor(e,i){D(this,"ccda");D(this,"options");D(this,"resources",[]);D(this,"patient");this.ccda=e,this.options=i}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),this.createRelatedPersons())}createPatient(e){let i=e.patient,n=[];return i.raceCode&&i.raceCode.length>0&&n.push({url:ae,extension:i.raceCode.map(r=>({url:"ombCategory",valueCoding:this.mapCodeToCoding(r)}))}),i.ethnicGroupCode&&i.ethnicGroupCode.length>0&&n.push({url:Be,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:pt(i.birthTime?.["@_value"]),address:this.mapAddresses(e.addr),telecom:this.mapTelecom(e.telecom),extension:n.length>0?n:void 0}}createRelatedPersons(){let e=this.ccda.participant;for(let i of e??f){let n=this.mapParticipantToRelatedPerson(i);n&&this.resources.push(n)}}mapParticipantToRelatedPerson(e){let i=this.patient;if(!i)return;let n=e.associatedEntity;if(!n)return;let r=kt(n.code);return{resourceType:"RelatedPerson",id:this.mapId(n.id),patient:I(i),relationship:r?[r]:void 0,identifier:this.mapIdentifiers(n.id),name:this.mapCcdaNameArrayFhirHumanNameArray(n.associatedPerson?.name),address:this.mapAddresses(n.addr),telecom:this.mapTelecom(n.telecom)}}mapId(e){let i=e?.find(n=>!n["@_extension"]&&n["@_root"]&&Qt(n["@_root"]));return i?i["@_root"]:lt()}mapIdentifiers(e){let i;for(let n of e??f)!n["@_extension"]&&n["@_root"]&&Qt(n["@_root"])||(i=Mn(i,{system:z(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"]?Qe.mapCcdaToFhir(e["@_use"]):void 0;return n&&(i.use=n),e.prefix&&(i.prefix=e.prefix.map(he)?.filter(Boolean)),e.family&&(i.family=he(e.family)),e.given&&(i.given=e.given.map(he)?.filter(Boolean)),e.suffix&&(i.suffix=e.suffix.map(he)?.filter(Boolean)),i}mapAddresses(e){if(!(!e||e.length===0))return e?.map(i=>({use:i["@_use"]?ze.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))return e?.map(i=>({use:i["@_use"]?Ze.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">${pn(r.text)}</div>`},entry:o.map(I)}),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:at,code:qe}]},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:C(this.ccda.effectiveTime?.[0]?.["@_value"])??new Date().toISOString(),title:this.ccda.title??"Medical Summary",section:i}}processSection(e){let i=[];for(let n of e.entry??f)this.processEntry(e,n,i);return i}processEntry(e,i,n){for(let r of i.act??f){let o=this.processAct(e,r);o&&n.push(o)}for(let r of i.substanceAdministration??f){let o=this.processSubstanceAdministration(e,r);o&&n.push(o)}for(let r of i.organizer??f)n.push(this.processOrganizer(e,r));for(let r of i.observation??f){let o=this.processObservation(e,r);o&&n.push(o)}for(let r of i.encounter??f)n.push(this.processEncounter(e,r));for(let r of i.procedure??f)n.push(this.processProcedure(e,r))}processAct(e,i){let n=e.templateId[0]["@_root"];switch(n){case Ae:case sr:case ar:case cr:return this.processAllergyIntoleranceAct(i);case ge:case nr:case rr:case or:return this.processConditionAct(i);case Q:return this.processCarePlanAct(i);case Ot:return this.processConditionAct(i);case ne:return this.processProcedureAct(i);case K:return;case St:return;case Ne:return;default:if(this.options?.ignoreUnsupportedSections)return;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:I(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:[Ai]},clinicalStatus:{coding:[{system:Ut,code:le.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active")}]},verificationStatus:{coding:[{system:Si,code:"confirmed"}]},category:[{coding:[{system:yi,code:"problem-list-item",display:"Problem List Item"}]}],code:this.mapCode(i.value),subject:I(this.patient),onsetDateTime:C(i.effectiveTime?.[0]?.low?.["@_value"]),abatementDateTime:C(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:"completed",intent:"plan",title:"CARE PLAN",category:e.code?[this.mapCode(e.code)]:void 0,subject:I(this.patient),description:he(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:I(this.patient),performedDateTime:C(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 It:case Q:return this.processMedicationSubstanceAdministration(i);case ye:case Ce:return this.processImmunizationSubstanceAdministration(i);default:if(this.options?.ignoreUnsupportedSections)return;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],a=e.entryRelationship?.find(N=>N.substanceAdministration?.[0]?.templateId?.[0]?.["@_root"]===Dt)?.substanceAdministration?.[0],l,E;return s?l={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}:E={...this.mapCode(n),extension:this.mapTextReference(n?.originalText)},{resourceType:"MedicationRequest",id:i,contained:l?[l]:void 0,meta:{profile:[Ni]},extension:this.mapTextReference(e.text),status:et.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active"),intent:"order",medicationReference:l?{reference:"#med-"+i}:void 0,medicationCodeableConcept:E,subject:I(this.patient),authoredOn:C(e.author?.[0]?.time?.["@_value"]),dispenseRequest:e.effectiveTime?.[0]?{validityPeriod:{start:C(e.effectiveTime?.[0]?.low?.["@_value"]),end:C(e.effectiveTime?.[0]?.high?.["@_value"])}}:void 0,dosageInstruction:[{text:typeof e.text=="string"?e.text:void 0,extension:this.mapTextReference(a?.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:Te,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:Ke.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"completed"),vaccineCode:this.mapCode(i.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.code?.[0]),patient:I(this.patient),occurrenceDateTime:C(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:C(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=Je.mapCcdaToFhir(r)),i.extension=this.mapTextReference(n.text)}mapEffectiveTimeToDateTime(e){if(e?.["@_value"])return C(e["@_value"]);if(e?.low?.["@_value"])return C(e.low["@_value"])}mapEffectiveTimeToPeriod(e){if(!e?.["@_value"]&&(e?.low||e?.high))return{start:C(e?.low?.["@_value"]),end:C(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=[],n=z(e["@_codeSystem"]),r=e["@_code"],o=e["@_displayName"];(n||r||o)&&i.push({...n&&{system:n},...r&&{code:r},...o&&{display:o}});for(let a of e.translation??f){let l=z(a["@_codeSystem"]),E=a["@_code"],N=a["@_displayName"];(l||E||N)&&i.push({...l&&{system:l},...E&&{code:E},...N&&{display:N}})}let s=e["@_displayName"]||e.originalText?.reference?.["@_value"]||he(e.originalText);return i.length===0?s?{text:s}:void 0:{coding:i,...s&&{text:s}}}mapCodeToCoding(e){if(e)return{system:z(e["@_codeSystem"]),code:e["@_code"],display:e["@_displayName"]}}mapQualification(e){let i=this.mapCode(e);if(i)return[{code:i}]}createClinicalStatus(e){return{coding:[{system:ke,code:Xe.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active")}]}}createVerificationStatus(){return{coding:[{system:Vt,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:this.mapQualification(e.assignedAuthor?.code)};return this.resources.push(i),I(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:I(r),organization:I(o)};return this.resources.push(s),I(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),I(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"]===yt?this.processCareTeamOrganizer(i):this.processVitalsOrganizer(i)}processCareTeamOrganizer(e){let i=[];for(let r of e.component??f){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:I(this.patient)};e.effectiveTime?.[0]?.["@_value"]&&(i.effectiveDateTime=C(e.effectiveTime?.[0]?.["@_value"]));let n=[];for(let r of e.component??f)n.push(...this.processVitalsComponent(r));return n.length>0&&(i.hasMember=n),i}processVitalsComponent(e){let i=[];for(let n of e.observation??f){let r=this.processVitalsObservation(n);r&&(i.push(I(r)),this.resources.push(r))}return i}processObservation(e,i){let n=i.templateId[0]["@_root"];if(n===Re||n===se)return this.processGoalObservation(i);switch(e.templateId[0]["@_root"]){case Q:case Re:return this.processGoalObservation(i);default:return this.processVitalsObservation(i)}}processGoalObservation(e){let i=[];e.code&&i.push(this.mapCode(e.code));let n=[],r,o=e.value;if(o){let a=o["@_xsi:type"];a==="CD"?r=kt(o):a==="ST"&&(r={text:o["#text"]??""})}for(let a of e.entryRelationship??f)n.push({measure:this.mapCode(a.act?.[0]?.code),detailCodeableConcept:this.mapCode(a.act?.[0]?.code),dueDate:C(a.act?.[0]?.effectiveTime?.[0]?.low?.["@_value"])});return{resourceType:"Goal",id:this.mapId(e.id),extension:this.mapTextReference(e.text),identifier:this.mapIdentifiers(e.id),lifecycleStatus:this.mapGoalLifecycleStatus(e),category:i,description:r??{text:"Unknown goal"},subject:I(this.patient),startDate:pt(e.effectiveTime?.[0]?.["@_value"]),target:n}}mapGoalLifecycleStatus(e){return{active:"active",completed:"completed",cancelled:"cancelled",aborted:"cancelled"}[e.statusCode["@_code"]??"active"]}processVitalsObservation(e){let i=this.mapCode(e.code);if(!i)return;let n={resourceType:"Observation",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"final",category:this.mapObservationTemplateIdToObservationCategory(e.templateId),code:i,subject:I(this.patient),referenceRange:this.mapReferenceRangeArray(e.referenceRange),performer:e.author?.map(o=>this.mapAuthorToReference(o)).filter(Boolean)};if(e.value?.["@_xsi:type"])switch(e.value["@_xsi:type"]){case"PQ":case"CO":n.valueQuantity={value:e.value["@_value"]?Number.parseFloat(e.value["@_value"]):void 0,unit:e.value["@_unit"],system:Te,code:e.value["@_unit"]};break;case"CD":case"CE":n.valueCodeableConcept=this.mapCode(e.value);break;case"ST":n.valueString=e.value["#text"]??"";break;case"INT":n.valueInteger=e.value["@_value"]?Number.parseInt(e.value["@_value"],10):void 0;break;default:console.warn(`Unhandled observation value type: ${e.value["@_xsi:type"]}`)}e.effectiveTime?.[0]?.["@_value"]&&(n.effectiveDateTime=C(e.effectiveTime?.[0]?.["@_value"])),n.extension=this.mapTextReference(e.text);let r=e.entryRelationship;for(let o of r??f){let s=o.observation;for(let a of s??f){let l=this.processVitalsObservation(a);l&&(this.resources.push(l),n.hasMember||(n.hasMember=[]),n.hasMember.push(I(l)))}}return n}mapObservationTemplateIdToObservationCategory(e){if(!e)return;let i=new Set,n=[];for(let r of e){let o=dn.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={};n.extension=this.mapTextReference(i.text);let r=i.value;if(r?.low&&(n.low={value:r.low["@_value"]?Number.parseFloat(r.low["@_value"]):void 0,unit:r.low["@_unit"],system:Te,code:r.low["@_unit"]}),r?.high&&(n.high={value:r.high["@_value"]?Number.parseFloat(r.high["@_value"]):void 0,unit:r.high["@_unit"],system:Te,code:r.high["@_unit"]}),!(!n.extension&&!n.low&&!n.high))return n}processEncounter(e,i){let n={resourceType:"Encounter",id:this.mapId(i.id),identifier:this.mapIdentifiers(i.id),status:an.mapCcdaToFhirWithDefault(i.statusCode?.["@_code"],"unknown"),class:{system:wt,code:i.code?.["@_code"]??"AMB",display:i.code?.["@_displayName"]??"Ambulatory"},type:i.code?[this.mapCode(i.code)]:void 0,subject:I(this.patient),period:this.mapEffectiveTimeToPeriod(i.effectiveTime?.[0])};if(i.performer&&(n.participant=i.performer.map(r=>({type:[{coding:[{system:Ci,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 a={resourceType:"Condition",id:this.mapId(s.id),identifier:this.mapIdentifiers(s.id),clinicalStatus:{coding:[{system:Ut,code:"active"}]},verificationStatus:{coding:[{system:Mt,code:"confirmed"}]},code:this.mapCode(s.value),subject:I(this.patient),onsetDateTime:C(s.effectiveTime?.[0]?.low?.["@_value"])};return this.resources.push(a),{condition:I(a),use:{coding:[{system:gi,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:cn.mapCcdaToFhirWithDefault(i.statusCode?.["@_code"],"completed"),code:this.mapCode(i.code),subject:I(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:Ye,valueString:e.reference?.["@_value"]}]}};function he(t){if(t){if(typeof t=="string")return t;if(typeof t=="object"&&"#text"in t)return t["#text"]}}var fn=[{"@_root":Se,"@_extension":"2015-08-01"},{"@_root":Se},{"@_root":Kt,"@_extension":"2015-08-01"},{"@_root":Kt}],mn=[{"@_root":Se,"@_extension":"2015-08-01"},{"@_root":Se},{"@_root":ei,"@_extension":"2015-08-01"},{"@_root":ei}],lo=[{"@_root":Ae,"@_extension":"2015-08-01"},{"@_root":Ae}],po=[{"@_root":It,"@_extension":"2014-06-09"}],ho=[{"@_root":ge,"@_extension":"2015-08-01"},{"@_root":ge}],fo=[{"@_root":ye},{"@_root":ye,"@_extension":"2015-08-01"},{"@_root":Ce},{"@_root":Ce,"@_extension":"2015-08-01"}],mo=[{"@_root":ir,"@_extension":"2015-08-01"}],_o=[{"@_root":ni},{"@_root":ni,"@_extension":"2015-08-01"}],Eo=[{"@_root":ne,"@_extension":"2014-06-09"}],ya=[{"@_root":Q,"@_extension":"2014-06-09"}],Ca=[{"@_root":ti,"@_extension":"2015-08-01"}],Io=[{"@_root":ti,"@_extension":"2015-08-01"}],To=[{"@_root":ur,"@_extension":"2015-08-01"}],Oo=[{"@_root":Tt}],So=[{"@_root":Q},{"@_root":Q,"@_extension":"2014-06-09"}],yo=[{"@_root":dr,"@_extension":"2015-08-01"}],Co=[{"@_root":Re}],go=[{"@_root":Ot,"@_extension":"2015-08-01"}],Ao=[{"@_root":K,"@_extension":"2014-06-09"}],No=[{"@_root":lr,"@_extension":"2015-08-01"}],Ro=[{"@_root":St,"@_extension":"2016-11-01"}],Do=[{"@_root":yt,"@_extension":"2022-06-01"}],vo=[{"@_root":Ne,"@_extension":"2015-08-01"},{"@_root":Ne}],xo=[{"@_root":ii,"@_extension":"2014-06-09"},{"@_root":ii}],_n=Object.fromEntries([[Di,lo],[xi,po],[Ge,ho],[vi,fo],[Li,mo],[bi,_o],[Ui,Eo],[Pi,Io],[$e,Oo],[He,So],[Vi,yo],[ce,Co],[de,go],[ue,Ao],[Fi,No],[je,Ro],[ki,Do],[Bi,vo],[Mi,To],[Zi,xo]]);function Po(t){return{name:G(t.name),administrativeGenderCode:ga(t.gender),birthTime:Aa(t.birthDate),raceCode:Da(t),"sdtc:raceCode":va(t),ethnicGroupCode:xa(t.extension),languageCommunication:Pa(t.communication)}}function G(t){return t?.map(e=>({"@_use":e.use?Qe.mapFhirToCcdaWithDefault(e.use,"L"):void 0,prefix:e.prefix,family:e.family,given:e.given,suffix:e.suffix}))}function ga(t){if(t)return{"@_code":on.mapFhirToCcda(t),"@_displayName":t?ie(t):"Unknown","@_codeSystem":ht,"@_codeSystemName":"AdministrativeGender"}}function Aa(t){if(t)return{"@_value":t.replaceAll("-","")}}function U(t){return!t||t.length===0?[{"@_nullFlavor":"UNK"}]:t?.map(e=>({"@_use":e.use?Ze.mapFhirToCcda(e.use):void 0,"@_value":`${Na(e.system)}${e.value}`}))}function Na(t){return t==="email"?"mailto:":t==="phone"?"tel:":t==="fax"?"fax:":""}function v(t){return!t||t.length===0?[{"@_nullFlavor":"UNK"}]:t.map(e=>Ra(e)).filter(Boolean)}function Ra(t){return t?{"@_use":t.use?ze.mapFhirToCcda(t.use):void 0,streetAddressLine:t.line||[],city:t.city,state:t.state,postalCode:t.postalCode,country:t.country}:void 0}function Da(t){let e=ut(t,ae,"ombCategory")?.valueCoding;return e?[{"@_code":e.code,"@_displayName":e.display,"@_codeSystem":_t,"@_codeSystemName":"CDC Race and Ethnicity"}]:[{"@_nullFlavor":"UNK"}]}function va(t){let e=ut(t,ae,"detailed")?.valueCoding;if(e)return[{"@_code":e.code,"@_displayName":e.display,"@_codeSystem":_t,"@_codeSystemName":"CDC Race and Ethnicity"}]}function xa(t){let i=t?.find(n=>n.url===Be)?.extension?.find(n=>n.url==="ombCategory")?.valueCoding;return i?[{"@_code":i.code,"@_displayName":i.display,"@_codeSystem":_t,"@_codeSystemName":"CDC Race and Ethnicity"}]:[{"@_nullFlavor":"UNK"}]}function Pa(t){if(t?.length)return[{languageCode:{"@_code":t[0].language?.coding?.[0]?.code}}]}function d(t,e){let i=[];t&&i.push({"@_root":t});for(let n of e??f){let r=nn(n.system);r&&i.push({"@_root":r,"@_extension":n.value})}return i}function X(t,e){if(e)return[{low:{"@_value":T(e.start)},high:{"@_value":T(e.end)}}];if(t)return[{"@_value":T(t)}]}function fe(t,e){if(e)return[{"@_xsi:type":"IVL_TS",low:e.start?{"@_value":L(e.start)}:void 0,high:e.end?{"@_value":L(e.end)}:void 0}];if(t)return[{"@_value":L(t)}]}function W(t,e,i=!1){if(!t&&!e)return;let n={};return t?n.low={"@_value":T(t)}:i&&(n.low={"@_nullFlavor":"NI"}),e?n.high={"@_value":T(e)}:i&&(n.high={"@_nullFlavor":"NI"}),[n]}function tt(t){let e=t?.find(i=>i.url===Ye)?.valueString;return e?{"@_value":e}:void 0}function m(t){let e=tt(t);return e?{reference:e}:void 0}function bo(t){if(!t)return;let e=ln(t.div)?.div;return e?.["@_xmlns"]&&delete e["@_xmlns"],e}function Lo(t,e){let i=e.reaction?.[0];return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":ui},{"@_root":ui,"@_extension":"2015-08-01"}],id:d(e.id,e.identifier),code:{"@_code":"CONC","@_codeSystem":mt},statusCode:{"@_code":Xe.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:W(e.recordedDate,void 0),author:t.mapAuthor(e.recorder,e.recordedDate),text:m(e.extension),entryRelationship:[{"@_typeCode":"SUBJ",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":oi},{"@_root":oi,"@_extension":"2014-06-09"}],id:d(e.id,e.identifier),code:{"@_code":"ASSERTION","@_codeSystem":ft},text:m(e.extension),statusCode:{"@_code":"completed"},effectiveTime:W(e.onsetPeriod?.start??e.onsetDateTime,e.onsetPeriod?.end,!0),value:ba(e.category),author:t.mapAuthor(e.asserter,e.recordedDate),participant:[{"@_typeCode":"CSM",participantRole:{"@_classCode":"MANU",playingEntity:{"@_classCode":"MMAT",code:e.code?.coding?.[0]?.code==="716186003"?{"@_nullFlavor":"NA"}:{...p(e.code),originalText:e.code?.extension?{reference:tt(e.code?.extension)}:void 0}}}}],entryRelationship:i?[{"@_typeCode":"MFST","@_inversionInd":"true",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":ai},{"@_root":ai,"@_extension":"2014-06-09"}],id:d(i.id,void 0),code:{"@_code":"ASSERTION","@_codeSystem":ft},statusCode:{"@_code":"completed"},effectiveTime:fe(e.onsetDateTime,e.onsetPeriod),value:b(i.manifestation?.[0]),text:m(i.manifestation?.[0]?.extension),entryRelationship:[{"@_typeCode":"SUBJ","@_inversionInd":"true",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":si},{"@_root":si,"@_extension":"2014-06-09"}],code:{"@_code":"SEV","@_codeSystem":ft,"@_codeSystemName":"ActCode"},statusCode:{"@_code":"completed"},value:{"@_xsi:type":"CD","@_code":Je.mapFhirToCcdaWithDefault(i.severity,"M"),"@_displayName":i.severity?ie(i.severity):void 0,"@_codeSystem":P,"@_codeSystemName":"SNOMED CT"},text:m(i.extension)}]}]}]}]:[]}]}]}]}}function ba(t){return{"@_xsi:type":"CD",...sn.mapFhirToCcdaCode(t?.[0])??{"@_code":"419199007","@_displayName":"Allergy to substance (disorder)","@_codeSystem":P,"@_codeSystemName":"SNOMED CT"}}}function Uo(t,e){if(e.status==="completed")return{act:[{"@_classCode":"ACT","@_moodCode":"INT",templateId:[{"@_root":mr}],id:d(e.id,e.identifier),code:b(e.category?.[0]),text:e.description?{"#text":e.description}:m(e.extension),statusCode:{"@_code":e.status}}]}}function Mo(t,e){return{organizer:[{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":_i,"@_extension":"2022-07-01"},{"@_root":_i,"@_extension":"2022-06-01"}],id:d(e.id,e.identifier),component:e.participant?.map(i=>({"@_typeCode":"PRF",role:i.role}))}]}}function Vo(t,e){return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":Mr,"@_extension":"2016-11-01"}],id:d(e.id,e.identifier),code:p(e.code)??{"@_code":je,"@_codeSystem":y,"@_codeSystemName":"LOINC","@_displayName":"Note"},text:e.summary?{"#text":e.summary}:m(e.extension),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":L(e.date)}],author:t.mapAuthor(e.assessor,e.date)}]}}function wo(t,e,i){let n=e.code?.coding?.[0]?.code;if(n===Ge)return La(t,i);if(n===de)return Ua(t,i)}function La(t,e){return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":ri},{"@_root":ri,"@_extension":"2015-08-01"}],id:d(e.id,void 0),code:{"@_code":"CONC","@_codeSystem":mt},statusCode:{"@_code":le.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:W(e.recordedDate,void 0),entryRelationship:[{"@_typeCode":"SUBJ",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":Y},{"@_root":Y,"@_extension":"2015-08-01"}],id:e.identifier?d(void 0,e.identifier):[{"@_root":lt()}],text:m(e.extension),code:{"@_code":"55607006","@_codeSystem":P,"@_codeSystemName":"SNOMED CT","@_displayName":"Problem",translation:[{"@_code":Gi,"@_codeSystem":y,"@_codeSystemName":"LOINC","@_displayName":"Condition"}]},statusCode:{"@_code":"completed"},effectiveTime:[{low:e.onsetDateTime?{"@_value":L(e.onsetDateTime)}:void 0,high:e.abatementDateTime?{"@_value":T(e.abatementDateTime)}:void 0}],value:b(e.code),author:t.mapAuthor(e.asserter,e.recordedDate)}]}]}]}}function Ua(t,e){let i=[];for(let n of e.evidence??f)for(let r of n.detail??f){let o=t.findResourceByReference(r);o?.resourceType==="Observation"&&i.push({"@_typeCode":"REFR",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":Y},{"@_root":Y,"@_extension":"2015-08-01"}],id:d(o.id,o.identifier),text:m(o.extension),code:{"@_code":"404684003","@_codeSystem":P,"@_codeSystemName":"SNOMED CT","@_displayName":"Clinical finding (finding)",translation:[{"@_code":zi,"@_codeSystem":y,"@_codeSystemName":"LOINC","@_displayName":"Clinical finding"}]},statusCode:{"@_code":"completed"},effectiveTime:W(o.effectivePeriod?.start,o.effectivePeriod?.end,!0),value:b(o.valueCodeableConcept),author:t.mapAuthor(o.performer?.[0],o.effectiveDateTime)}]})}return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":mi,"@_extension":"2015-08-01"},{"@_root":mi,"@_extension":"2022-06-01"}],id:d(e.id,void 0),code:{"@_code":de,"@_codeSystem":y,"@_codeSystemName":"LOINC","@_displayName":"Health Concern"},statusCode:{"@_code":le.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:W(e.recordedDate,void 0),entryRelationship:i}]}}function Fo(t,e){let i=t.findResourceByReference(e.device);if(!i)return;let n=[],r=d(i.id,i.identifier);return r&&n.push(...r),i.udiCarrier?.[0]?.deviceIdentifier&&n.push({"@_root":Ti,"@_extension":i.udiCarrier[0].carrierHRF,"@_assigningAuthorityName":"FDA"}),{procedure:[{"@_classCode":"PROC","@_moodCode":"EVN",templateId:[{"@_root":oe,"@_extension":"2014-06-09"},{"@_root":oe}],id:d(e.id,e.identifier),code:{"@_code":"360030002","@_codeSystem":P,"@_codeSystemName":"SNOMED CT","@_displayName":"Application of medical device"},statusCode:{"@_code":"completed"},participant:[{"@_typeCode":"DEV",participantRole:{"@_classCode":"MANU",templateId:[{"@_root":Ir}],id:n,playingDevice:{"@_classCode":"DEV",code:p(i.type)},scopingEntity:{id:[{"@_root":Ti}]}}}]}]}}function ko(t,e){let i=jt(j(e),"value");return(e.component||e.hasMember)&&!Wt(i)?{organizer:[Ma(t,e)]}:{observation:[ee(t,e)]}}function Ma(t,e){let i=[];for(let r of e.component??f)i.push({observation:[ee(t,e,r)]});for(let r of e.hasMember??f){let o=t.findResourceByReference(r);if(o?.resourceType==="Observation")if(o.component)for(let s of o.component)i.push({observation:[ee(t,o,s)]});else i.push({observation:[ee(t,o)]})}return{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:Va(e),id:d(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":T(e.effectiveDateTime)}],component:i}}function ee(t,e,i){let n=p(i?.code??e.code);n?.["@_code"]===Ft&&(n={"@_code":"ASSERTION","@_codeSystem":"2.16.840.1.113883.5.4"});let r=[];for(let s of e.hasMember??f){let a=t.findResourceByReference(s);a?.resourceType==="Observation"&&r.push({"@_typeCode":"COMP",observation:[ee(t,a)]})}return{"@_classCode":"OBS","@_moodCode":"EVN",templateId:En(e,i),id:d(e.id,e.identifier),code:n,statusCode:{"@_code":"completed"},effectiveTime:[Xt(e.effectivePeriod,e.effectiveDateTime)],value:In(i??e),referenceRange:wa(i?.referenceRange??e.referenceRange),text:m(i?.extension??e.extension),author:t.mapAuthor(e.performer?.[0],e.effectiveDateTime),entryRelationship:r}}function Va(t){return t.code?.coding?.[0]?.code==="d5"?[{"@_root":Ue,"@_extension":"2014-06-09"},{"@_root":Ue}]:[{"@_root":Pe},{"@_root":Pe,"@_extension":"2015-08-01"}]}function En(t,e){let i=t.code?.coding?.[0]?.code,n=t.category?.[0]?.coding?.[0]?.code;return i===$i?[{"@_root":Ve},{"@_root":Ve,"@_extension":"2014-06-09"}]:i===ji?[{"@_root":we},{"@_root":we,"@_extension":"2014-06-09"}]:i===qi?[{"@_root":bt,"@_extension":"2023-06-28"}]:i===Wi?[{"@_root":Fe},{"@_root":Fe,"@_extension":"2016-06-01"}]:i===Xi?[{"@_root":Ei},{"@_root":Ei,"@_extension":"2023-05-01"}]:i===Ki?[{"@_root":vt,"@_extension":"2023-05-01"}]:i===en?[{"@_root":xt,"@_extension":"2023-05-01"}]:i===Ft?[{"@_root":Et}]:i===tn?[{"@_root":Pt,"@_extension":"2023-05-01"}]:i==="d5"?e?.code?.coding?.[0]?.code===Ji?[{"@_root":xr}]:[{"@_root":Me,"@_extension":"2014-06-09"},{"@_root":Me}]:n==="exam"?[{"@_root":xe},{"@_root":xe,"@_extension":"2014-06-09"}]:n==="laboratory"?[{"@_root":ve},{"@_root":ve,"@_extension":"2015-08-01"}]:n==="survey"?t.hasMember?[{"@_root":Nt,"@_extension":"2022-06-01"}]:[{"@_root":Rt}]:[{"@_root":be},{"@_root":be,"@_extension":"2014-06-09"}]}function In(t){if(t.valueQuantity)return{"@_xsi:type":"PQ","@_unit":t.valueQuantity.unit,"@_value":t.valueQuantity.value?.toString()};if(t.valueCodeableConcept)return b(t.valueCodeableConcept);if(t.valueString!==void 0)return{"@_xsi:type":"ST","#text":t.valueString};if(t.valueInteger!==void 0)return{"@_xsi:type":"INT","@_value":t.valueInteger.toString()}}function wa(t){if(!(!t||t.length===0))return t.map(e=>Fa(e)).filter(Boolean)}function Fa(t){if(!t)return;let e=tt(t.extension);return e?{observationRange:{text:{reference:e},value:{"@_xsi:type":"ED",reference:e}}}:t.low||t.high?{observationRange:{value:{"@_xsi:type":"IVL_PQ",low:t.low?{"@_value":t.low.value?.toString(),"@_unit":t.low.unit}:void 0,high:t.high?{"@_value":t.high.value?.toString(),"@_unit":t.high.unit}:void 0}}}:{observationRange:{text:m(t.extension)}}}function Bo(t,e){let i=[];for(let n of e.result??f){let r=t.findResourceByReference(n);r?.resourceType==="Observation"&&i.push({observation:[ee(t,r)]})}return{organizer:[{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":De},{"@_root":De,"@_extension":"2015-08-01"}],id:d(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":"completed"},component:i}]}}function Yo(t,e){return{encounter:[{"@_classCode":"ENC","@_moodCode":"EVN",templateId:[{"@_root":Le},{"@_root":Le,"@_extension":"2015-08-01"}],id:d(e.id,e.identifier),code:p(e.type?.[0]),text:m(e.extension),effectiveTime:X(void 0,e.period),participant:e.participant?.map(i=>({"@_typeCode":"LOC",participantRole:{"@_classCode":"SDLOC",templateId:[{"@_root":Ct}],code:p(i.type?.[0])}})),entryRelationship:e.diagnosis?.map(i=>ka(t,i)).filter(Boolean)}]}}function ka(t,e){let i=t.findResourceByReference(e.condition);if(i?.resourceType==="Condition")return{"@_typeCode":"REFR",act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":Le,"@_extension":"2015-08-01"},{"@_root":Le}],code:{"@_code":"29308-4","@_displayName":"Diagnosis","@_codeSystem":y,"@_codeSystemName":"LOINC"},entryRelationship:[{"@_typeCode":"SUBJ",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":Y,"@_extension":"2015-08-01"},{"@_root":Y}],id:d(i.id,i.identifier),code:{"@_code":"282291009","@_displayName":"Diagnosis interpretation","@_codeSystem":P,"@_codeSystemName":"SNOMED CT",translation:[{"@_code":"29308-4","@_displayName":"Diagnosis","@_codeSystem":y,"@_codeSystemName":"LOINC"}]},statusCode:{"@_code":"completed"},effectiveTime:W(i.onsetDateTime,i.abatementDateTime),value:b(i.code)}]}]}]}}function Go(t,e){let i=t.code?.coding?.[0]?.code,n;if(e.category?.[0])n=p(e.category[0]);else if(i===ce)n={"@_code":Hi,"@_codeSystem":y,"@_codeSystemName":"LOINC","@_displayName":"Resident's overall goal established during assessment process"};else if(e.description)n=p(e.description);else return;let r;if(i===He)r=[{"@_root":At}];else if(n?.["@_code"]===Qi)r=[{"@_root":se},{"@_root":se,"@_extension":"2022-06-01"}];else if(i===ce)r=[{"@_root":se}];else return;let o;return e.description.coding?.[0]?.code?o=b(e.description):e.description.text&&(o={"@_xsi:type":"ST","#text":e.description.text}),{observation:[{"@_classCode":"OBS","@_moodCode":"GOL",templateId:r,id:d(e.id,e.identifier),code:n,statusCode:{"@_code":Ba(e.lifecycleStatus)},effectiveTime:[{"@_value":T(e.startDate)}],value:o,text:m(e.extension),entryRelationship:e.target?.map(s=>({"@_typeCode":"RSON","@_inversionInd":"true",act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":re},{"@_root":re,"@_extension":"2014-06-09"}],code:p(s.measure),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":T(e.startDate)}]}]}))}]}}function Ba(t){switch(t){case"completed":return"completed";case"cancelled":return"cancelled";default:return"active"}}function Ho(t,e){let i=e?.manufacturer,n={substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN","@_negationInd":"false",templateId:[{"@_root":li},{"@_root":li,"@_extension":"2015-08-01"}],id:d(e.id,e.identifier),text:m(e.extension),statusCode:{"@_code":Ke.mapFhirToCcdaWithDefault(e.status,"completed")},effectiveTime:[{"@_value":L(e.occurrenceDateTime)}],consumable:{manufacturedProduct:[{"@_classCode":"MANU",templateId:[{"@_root":pi},{"@_root":pi,"@_extension":"2014-06-09"}],manufacturedMaterial:[{code:[p(e.vaccineCode)],lotNumberText:e.lotNumber?[e.lotNumber]:void 0}],manufacturerOrganization:i?[{id:d(i.id,i.identifier?[i.identifier]:void 0),name:[i.display]}]:void 0}]}}]};return e.performer&&(n.substanceAdministration[0].performer=e.performer.map(r=>Ya(t,r)).filter(Boolean)),n}function Ya(t,e){if(!e)return;let i=t.findResourceByReference(e.actor);if(!i)return;let n,r;return i.resourceType==="PractitionerRole"?(n=t.findResourceByReference(i.practitioner),r=t.findResourceByReference(i.organization)):i.resourceType==="Practitioner"?n=i:i.resourceType==="Organization"&&(r=i),{assignedEntity:{id:d(i.id,i.identifier),addr:v(n?.address),telecom:U(i.telecom),assignedPerson:n?{id:d(n.id,n.identifier),name:G(n.name)}:void 0,representedOrganization:r?{id:d(r.id,r.identifier),name:r.name?[r.name]:void 0,addr:v(r.address),telecom:U(r.telecom)}:void 0}}}function $o(t,e){let i=[];for(let n of e.coverage??f){let r=t.findResourceByReference(n.coverage);if(r?.resourceType!=="Coverage")continue;let o=r.class?.find(l=>l.type?.coding?.[0]?.code==="plan"),s=t.findResourceByReference(r.payor?.[0]),a=t.findResourceByReference(r.policyHolder);i.push({"@_typeCode":"COMP",sequenceNumber:{"@_xsi:type":"INT","@_value":i.length.toString()},act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":fi,"@_extension":"2015-08-01"},{"@_root":fi}],id:d(r.id,r.identifier),code:{"@_code":un.mapFhirToCcdaWithDefault(r.type?.coding?.[0]?.code,"9999"),"@_displayName":r.type?.coding?.[0]?.display||"Unknown","@_codeSystemName":"Source of Payment Typology (PHDSC)","@_codeSystem":"2.16.840.1.113883.3.221.5"},statusCode:{"@_code":"completed"},text:m(r.extension),performer:[{"@_typeCode":"PRF",templateId:[{"@_root":Ar}],assignedEntity:{id:[{"@_root":"2.16.840.1.113883.6.300","@_extension":"999999"}],code:{"@_code":"PAYOR","@_codeSystem":"2.16.840.1.113883.5.110","@_codeSystemName":"HL7 RoleCode","@_displayName":"invoice payor"},addr:v(s?.address),telecom:U(s?.telecom),representedOrganization:{name:s?.name?[s.name]:void 0,telecom:U(s?.telecom),addr:v(s?.address)}}}],participant:[{"@_typeCode":"COV",templateId:[{"@_root":Nr}],participantRole:{"@_classCode":"PAT",id:[{"@_root":"2.16.840.1.113883.6.300","@_extension":a?.identifier?.[0]?.value||"88800933502"}],code:{"@_code":"FAMDEP","@_codeSystem":"2.16.840.1.113883.5.111","@_displayName":a?"self":"dependent"},addr:v(a?.address),playingEntity:{"@_classCode":"PSN",name:G(a?.name),"sdtc:birthTime":a?.birthDate?{"@_value":L(a.birthDate)}:void 0}}},a?{"@_typeCode":"HLD",templateId:[{"@_root":Rr}],participantRole:{id:[{"@_root":"2.16.840.1.113883.6.300","@_extension":a.identifier?.[0]?.value||"888009335"}],addr:v(a.address),playingEntity:{name:G(a.name)}}}:void 0].filter(Boolean),entryRelationship:[{"@_typeCode":"REFR",act:[{"@_classCode":"ACT","@_moodCode":"DEF",id:d(r.id,r.identifier),code:{"@_code":"PAYOR","@_codeSystem":"2.16.840.1.113883.5.110","@_codeSystemName":"HL7 RoleCode","@_displayName":"invoice payor"},text:o?.value?{"#text":o.value}:void 0}]}]}]})}return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":hi,"@_extension":"2015-08-01"},{"@_root":hi}],id:d(e.id,e.identifier),code:{"@_code":"48768-6","@_codeSystem":y,"@_codeSystemName":"LOINC","@_displayName":"Payment Sources"},statusCode:{"@_code":"completed"},entryRelationship:i}]}}function jo(t,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=fe(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":ci,"@_extension":"2014-06-09"},{"@_root":ci}],id:[{"@_root":e.id||crypto.randomUUID()}],text:m(e.extension),statusCode:{"@_code":et.mapFhirToCcdaWithDefault(e.status,"active")},effectiveTime:o,routeCode:Ga(e.dosageInstruction?.[0]?.route),doseQuantity:Ha(e.dosageInstruction?.[0]?.doseAndRate?.[0]),consumable:{"@_typeCode":"CSM",manufacturedProduct:[{"@_classCode":"MANU",templateId:[{"@_root":di,"@_extension":"2014-06-09"},{"@_root":di}],manufacturedMaterial:[{code:[{...p(n),originalText:m(i?.extension)}]}],manufacturerOrganization:r?[{id:d(r.id,r.identifier?[r.identifier]:void 0),name:[r.display]}]:void 0}]},author:t.mapAuthor(e.requester,e.authoredOn),entryRelationship:e.dosageInstruction?.filter(s=>!!s.extension)?.map(s=>({"@_typeCode":"COMP",substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN",templateId:[{"@_root":Dt}],code:{"@_code":Yi,"@_codeSystem":y,"@_codeSystemName":"LOINC","@_displayName":"Medication Instructions"},text:m(s.extension),consumable:{manufacturedProduct:[{manufacturedLabeledDrug:[{"@_nullFlavor":"NA"}]}]}}]}))}]}}function Ga(t){if(t)return p(t)}function Ha(t){if(t?.doseQuantity)return{"@_value":t.doseQuantity.value?.toString(),"@_unit":t.doseQuantity.unit}}function qo(t,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":re},{"@_root":re,"@_extension":"2014-06-09"}],id:d(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":"completed"},effectiveTime:X(e.performedDateTime,e.performedPeriod),text:m(e.extension)}]}:{procedure:[{"@_classCode":"PROC","@_moodCode":"EVN",templateId:[{"@_root":oe},{"@_root":oe,"@_extension":"2014-06-09"}],id:d(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":"completed"},effectiveTime:X(e.performedDateTime,e.performedPeriod),text:m(e.extension),targetSiteCode:p(e.bodySite?.[0]),participant:[$a(t,e.location)].filter(Boolean)}]}}if(e.resourceType==="Observation")return{observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:En(e),id:d(e.id,e.identifier),code:p(e.code),value:In(e),statusCode:{"@_code":"completed"},effectiveTime:X(e.effectiveDateTime,e.effectivePeriod),text:m(e.extension)}]};throw new Error(`Unknown history of procedures resource type: ${e.resourceType}`)}function $a(t,e){if(!e)return;let i=t.findResourceByReference(e);if(i)return{"@_typeCode":"LOC",participantRole:{"@_classCode":"SDLOC",templateId:[{"@_root":Ct}],id:d(i.id,i.identifier),code:p(i.type?.[0]),addr:i.address?v([i.address]):void 0,telecom:U(i.telecom),playingEntity:{"@_classCode":"PLC",name:i.name?[i.name]:void 0}}}}function Wo(t,e){return e.code?.coding?.[0]?.system===ct?{procedure:[{"@_classCode":"PROC","@_moodCode":"RQO",templateId:[{"@_root":gt},{"@_root":gt,"@_extension":"2014-06-09"},{"@_root":gt,"@_extension":"2022-06-01"}],id:d(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":"active"},effectiveTime:[{"@_value":T(e.authoredOn)}],text:m(e.extension)}]}:{observation:[{"@_classCode":"OBS","@_moodCode":"RQO",templateId:[{"@_root":At}],id:d(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":ja(e.status)},effectiveTime:[{"@_value":T(e.occurrenceDateTime)}],text:m(e.extension)}]}}function ja(t){switch(t){case"completed":return"completed";case"entered-in-error":return"cancelled";default:return"active"}}function Qo(t){if(!t||t.length===0)return;let e=t[0];if(!(!e||!e.code&&!e.period))return{serviceEvent:{"@_classCode":"PCPR",code:p(e.code?.[0]),effectiveTime:fe(void 0,e.period)}}}function qa(t,e){return new Bt(t,e).convert()}var Bt=class{constructor(e,i){D(this,"bundle");D(this,"options");D(this,"composition");D(this,"patient");this.bundle=e,this.options=i;let n=this.findResource("Composition");if(!n)throw new Error("Composition not found");let r=this.findResource("Patient");if(!r)throw new Error("Patient not found");this.composition=n,this.patient=r}convert(){let e=this.createSections(),i=this.composition.section?.find(o=>o.code?.coding?.[0]?.code===ue)?.entry?.find(o=>o.reference?.startsWith("ServiceRequest/")),n,r;return this.options?.type==="referral"?(n=mn,r={"@_code":wi,"@_displayName":"Referral Note","@_codeSystem":y,"@_codeSystemName":"LOINC"}):(n=fn,r={"@_code":qe,"@_displayName":"Summarization of Episode Note","@_codeSystem":y,"@_codeSystemName":"LOINC"}),{realmCode:{"@_code":"US"},typeId:{"@_root":kn,"@_extension":"POCD_HD000040"},templateId:n,id:d(this.composition.id,void 0),code:r,title:this.composition.title,effectiveTime:X(this.composition.date,void 0),confidentialityCode:this.composition.confidentiality?rn.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,!0),custodian:this.mapCustodian(this.composition.custodian),informationRecipient:this.mapRecipient(i),participant:this.createParticipants(),documentationOf:Qo(this.composition.event),component:e.length>0?{structuredBody:{component:e.map(o=>({section:[o]}))}}: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:d(this.patient.id,this.patient.identifier),addr:v(this.patient.address),telecom:U(this.patient.telecom),patient:Po(this.patient)}}]}createSections(){let e=[];for(let i of this.composition.section??f)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=_n[i];if(!n)throw new Error(`Unknown section code: ${i}`);let r=this.findResourcesByReferences(e.entry);return i===$e&&r.length===1&&r[0].resourceType==="ClinicalImpression"?this.createClinicalImpressionSection(e,r[0]):i===ue&&r.length===1&&r[0].resourceType==="ServiceRequest"?this.createReasonForReferralSection(e,r[0]):{templateId:n,code:p(e.code),title:e.title,text:bo(e.text),entry:r.map(o=>this.createEntry(e,o)).filter(Boolean),"@_nullFlavor":r.length===0?"NI":void 0}}createEntry(e,i){switch(i.resourceType){case"Account":return $o(this,i);case"AllergyIntolerance":return Lo(this,i);case"CarePlan":return Uo(this,i);case"CareTeam":return Mo(this,i);case"ClinicalImpression":return Vo(this,i);case"Condition":return wo(this,e,i);case"DeviceUseStatement":return Fo(this,i);case"DiagnosticReport":return Bo(this,i);case"Encounter":return Yo(this,i);case"Goal":return Go(e,i);case"Immunization":return Ho(this,i);case"MedicationRequest":return jo(this,i);case"Procedure":return qo(this,i);case"Observation":return ko(this,i);case"ServiceRequest":return Wo(this,i);default:return}}mapAuthor(e,i,n){if(!e)return;let r=this.findResourceByReference(e);if(!r)return;let o;if(r.resourceType==="Organization"?o=r:r.resourceType==="PractitionerRole"&&(o=this.findResourceByReference(r.organization),r=this.findResourceByReference(r.practitioner)),!r)return;let s;"address"in r&&(s=r.address);let a;"telecom"in r&&(a=r.telecom);let l;"qualification"in r&&(l=r.qualification?.[0]?.code);let E;return["Patient","Practitioner","RelatedPerson"].includes(r.resourceType)&&(E=r.name),[{templateId:[{"@_root":vr}],time:i?{"@_value":T(i)}:void 0,assignedAuthor:{id:d(r.id,r.identifier),addr:v(s),telecom:U(a),code:p(l),assignedPerson:E?{name:G(E)}:void 0,assignedAuthoringDevice:!E&&n?{manufacturerModelName:"Medplum",softwareName:"Medplum"}:void 0,representedOrganization:o?.name?{name:[o.name]}:void 0}}]}mapCustodian(e){if(!e)return;let i=this.findResourceByReference(e);if(i)return{assignedCustodian:{representedCustodianOrganization:{id:d(i.id,i.identifier),name:i.name?[i.name]:void 0,telecom:U(i.telecom),addr:v(i.address)}}}}mapRecipient(e){if(!e)return;let i=this.findResourceByReference(e);if(!i)return;let n=i.performer;if(!n||n.length===0)return;let r=this.findResourceByReference(n[0]);if(r?.resourceType==="Practitioner")return{intendedRecipient:{informationRecipient:{name:G(r.name)}}}}createParticipants(){let e=this.bundle.entry?.filter(i=>i.resource?.resourceType==="RelatedPerson").map(i=>i.resource);if(!(!e||e.length===0))return e.map(i=>({"@_typeCode":"IND",templateId:[{"@_root":$r,"@_extension":"2023-05-01"}],associatedEntity:{"@_classCode":"PRS",id:d(i.id,i.identifier),code:p(i.relationship?.[0]),addr:v(i.address),telecom:U(i.telecom),associatedPerson:{name:G(i.name)}}}))}createClinicalImpressionSection(e,i){return{templateId:[{"@_root":Tt}],code:p(e.code),title:e.title,text:i.summary,author:this.mapAuthor(i.assessor,i.date)}}createReasonForReferralSection(e,i){return{templateId:[{"@_root":K,"@_extension":"2014-06-09"},{"@_root":K}],code:p(e.code),title:e.title,text:i.note?.[0]?.text,entry:[{act:[{"@_classCode":"PCPR","@_moodCode":"INT",templateId:[{"@_root":Lr}],id:d(i.id,i.identifier),code:p(i.code),statusCode:{"@_code":"active"},effectiveTime:[{"@_value":T(i.occurrenceDateTime)}],priorityCode:{"@_code":"A","@_codeSystem":"2.16.840.1.113883.5.7","@_codeSystemName":"ActPriority","@_displayName":"ASAP"},author:this.mapAuthor(i.requester,i.occurrenceDateTime)}]}]}}};0&&(module.exports={ACT_CODE_SYSTEM,ADDRESS_USE_MAPPER,ADDRESS_USE_VALUE_SET,ADMINISTRATIVE_GENDER_CODE_SYSTEM,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,FHIR_ICF_URL,FUNCTIONAL_STATUS_TEMPLATE_IDS,FhirToCcdaConverter,GENDER_MAPPER,GOALS_SECTION_TEMPLATE_IDS,HEALTH_CONCERNS_SECTION_TEMPLATE_IDS,HTTP,HUMAN_NAME_USE_MAPPER,IMMUNIZATIONS_SECTION_TEMPLATE_IDS,IMMUNIZATION_STATUS_MAPPER,INSURANCE_COVERAGE_TYPE_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_ADMINISTRATIVE_SEX,LOINC_ALLERGIES_SECTION,LOINC_ASSESSMENTS_SECTION,LOINC_BIRTH_SEX,LOINC_CARE_TEAM_SECTION,LOINC_CLINICAL_FINDING,LOINC_CONDITION,LOINC_DEVICES_SECTION,LOINC_DISABILITY_STATUS,LOINC_ENCOUNTERS_SECTION,LOINC_FUNCTIONAL_STATUS_ASSESSMENT_NOTE,LOINC_FUNCTIONAL_STATUS_SECTION,LOINC_GOALS_SECTION,LOINC_HEALTH_CONCERNS_SECTION,LOINC_HISTORY_OF_OCCUPATION,LOINC_HISTORY_OF_OCCUPATION_INDUSTRY,LOINC_HISTORY_OF_SOCIAL_FUNCTION,LOINC_HISTORY_OF_TOBACCO_USE,LOINC_IMMUNIZATIONS_SECTION,LOINC_INSURANCE_SECTION,LOINC_MEDICATIONS_SECTION,LOINC_MEDICATION_INSTRUCTIONS,LOINC_MENTAL_STATUS_SECTION,LOINC_NOTES_SECTION,LOINC_NOTE_DOCUMENT,LOINC_OVERALL_GOAL,LOINC_PATIENT_SUMMARY_DOCUMENT,LOINC_PLAN_OF_TREATMENT_SECTION,LOINC_PREGNANCY_STATUS,LOINC_PROBLEMS_SECTION,LOINC_PROCEDURES_SECTION,LOINC_REASON_FOR_REFERRAL_SECTION,LOINC_REFERRAL_NOTE,LOINC_RESULTS_SECTION,LOINC_SOCIAL_HISTORY_SECTION,LOINC_SUMMARY_OF_EPISODE_NOTE,LOINC_TOBACCO_SMOKING_STATUS,LOINC_TO_TEMPLATE_IDS,LOINC_TRIBAL_AFFILIATION,LOINC_VITAL_SIGNS_SECTION,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,REFERRAL_TEMPLATE_IDS,RESULTS_SECTION_TEMPLATE_IDS,ROLE_CODE_CODE_SYSTEM,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,mapCcdaCodeToCodeableConcept,mapCcdaSystemToFhir,mapCcdaToFhirDate,mapCcdaToFhirDateTime,mapCodeableConceptToCcdaCode,mapCodeableConceptToCcdaValue,mapCodingToCcdaCode,mapFhirPeriodOrDateTimeToCcda,mapFhirSystemToCcda,mapFhirToCcdaDate,mapFhirToCcdaDateTime,parseXml});
3
3
  /*!
4
4
  * Reconnecting WebSocket