@medplum/ccda 5.0.12 → 5.0.14

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