@medplum/ccda 5.1.38 → 5.1.40

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