@medplum/ccda 4.0.2 → 4.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.cjs.map +3 -3
- package/dist/cjs/index.d.ts +76 -4
- package/dist/esm/index.d.ts +76 -4
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/index.mjs.map +3 -3
- package/package.json +5 -5
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var Ye=Object.defineProperty;var Wn=Object.getOwnPropertyDescriptor;var Qn=Object.getOwnPropertyNames;var zn=Object.prototype.hasOwnProperty;var Zn=(i,e)=>{for(var t in e)Ye(i,t,{get:e[t],enumerable:!0})},Xn=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Qn(e))!zn.call(i,r)&&r!==t&&Ye(i,r,{get:()=>e[r],enumerable:!(n=Wn(e,r))||n.enumerable});return i};var Jn=i=>Xn(Ye({},"__esModule",{value:!0}),i);var No={};Zn(No,{ACT_CODE_SYSTEM:()=>yt,ADDRESS_USE_MAPPER:()=>fe,ADDRESS_USE_VALUE_SET:()=>hn,ADMINISTRATIVE_GENDER_VALUE_SET:()=>_n,ALLERGIES_SECTION_TEMPLATE_IDS:()=>Dn,ALLERGY_CATEGORY_MAPPER:()=>Pt,ALLERGY_CLINICAL_CODE_SYSTEM:()=>ce,ALLERGY_SEVERITY_MAPPER:()=>Ee,ALLERGY_STATUS_MAPPER:()=>me,ALLERGY_VERIFICATION_CODE_SYSTEM:()=>Fe,ASSESSMENTS_SECTION_TEMPLATE_IDS:()=>wn,CARE_TEAM_SECTION_TEMPLATE_IDS:()=>Hn,CCDA_NARRATIVE_REFERENCE_URL:()=>de,CCDA_TEMPLATE_CODE_SYSTEM:()=>To,CCDA_TEMPLATE_IDS:()=>kt,CLINICAL_CONDITION_CODE_SYSTEM:()=>ke,CLINICAL_NOTES_SECTION_TEMPLATE_IDS:()=>go,CONDITION_CATEGORY_CODE_SYSTEM:()=>St,CONDITION_VERIFICATION_CODE_SYSTEM:()=>Ot,CONDITION_VER_STATUS_CODE_SYSTEM:()=>Be,CONFIDENTIALITY_CODE_SYSTEM:()=>dn,CONFIDENTIALITY_MAPPER:()=>vt,CONTACT_ENTITY_USE_VALUE_SET:()=>mn,CVX_URL:()=>Rn,DEVICES_SECTION_TEMPLATE_IDS:()=>Vn,DIAGNOSIS_ROLE_CODE_SYSTEM:()=>gt,ENCOUNTERS_SECTION_TEMPLATE_IDS:()=>kn,ENCOUNTER_STATUS_MAPPER:()=>bt,EnumMapper:()=>m,FHIR_CVX_URL:()=>Nn,GENDER_MAPPER:()=>xt,GOALS_SECTION_TEMPLATE_IDS:()=>Bn,HEALTH_CONCERNS_SECTION_TEMPLATE_IDS:()=>Fn,HTTP:()=>b,HUMAN_NAME_USE_MAPPER:()=>he,IMMUNIZATIONS_SECTION_TEMPLATE_IDS:()=>Ge,IMMUNIZATION_STATUS_MAPPER:()=>Te,INSURANCE_SECTION_TEMPLATE_IDS:()=>jn,LAB_TESTS_SECTION_TEMPLATE_IDS:()=>Ao,LANGUAGE_MODE_CODE_SYSTEM:()=>ho,LANGUAGE_MODE_URL:()=>mo,LANGUAGE_PROFICIENCY_CODE_SYSTEM:()=>fo,LANGUAGE_PROFICIENCY_URL:()=>Eo,LOINC_TO_TEMPLATE_IDS:()=>Bt,MEDICATIONS_SECTION_TEMPLATE_IDS:()=>vn,MEDICATION_REQUEST_STATUS_VALUE_SET:()=>En,MEDICATION_STATUS_MAPPER:()=>Oe,MENTAL_STATUS_SECTION_TEMPLATE_IDS:()=>Yn,NAME_USE_VALUE_SET:()=>fn,NCI_THESAURUS_URL:()=>In,NDFRT_URL:()=>An,NUCC_TAXONOMY_URL:()=>Cn,OBSERVATION_CATEGORY_CODE_SYSTEM:()=>pn,OBSERVATION_CATEGORY_MAPPER:()=>Lt,PARTICIPATION_CODE_SYSTEM:()=>Ct,PATIENT_NOTES_SECTION_TEMPLATE_IDS:()=>$n,PLAN_OF_TREATMENT_SECTION_TEMPLATE_IDS:()=>Mn,PROBLEMS_SECTION_TEMPLATE_IDS:()=>xn,PROBLEM_STATUS_MAPPER:()=>Ie,PROCEDURES_SECTION_TEMPLATE_IDS:()=>Un,PROCEDURE_STATUS_MAPPER:()=>Ut,RACE_CODE_SYSTEM:()=>_o,REASON_FOR_REFERRAL_SECTION_TEMPLATE_IDS:()=>Gn,RESULTS_SECTION_TEMPLATE_IDS:()=>Ln,SOCIAL_HISTORY_SECTION_TEMPLATE_IDS:()=>bn,SYSTEM_MAPPER:()=>pe,TELECOM_USE_MAPPER:()=>_e,UNII_URL:()=>yn,US_CORE_CONDITION_URL:()=>At,US_CORE_ETHNICITY_URL:()=>le,US_CORE_MEDICATION_REQUEST_URL:()=>Rt,US_CORE_PATIENT_URL:()=>Io,US_CORE_RACE_URL:()=>ue,US_DRIVER_LICENSE_URL:()=>On,US_NPI_URL:()=>Sn,US_SSN_URL:()=>Tn,VA_MEDRT_URL:()=>gn,VITAL_SIGNS_SECTION_TEMPLATE_IDS:()=>Pn,XSI_URL:()=>Nt,convertCcdaToFhir:()=>Co,convertCcdaToXml:()=>yo,convertFhirToCcda:()=>Ro,convertToCompactXml:()=>wt,convertXmlToCcda:()=>So,mapCcdaSystemToFhir:()=>F,mapCcdaToFhirDate:()=>Ne,mapCcdaToFhirDateTime:()=>f,mapCodeableConceptToCcdaCode:()=>d,mapCodeableConceptToCcdaValue:()=>G,mapCodingToCcdaCode:()=>Tt,mapFhirSystemToCcda:()=>Dt,mapFhirToCcdaDate:()=>V,mapFhirToCcdaDateTime:()=>T,parseXml:()=>Vt});module.exports=Jn(No);var Kn=class{constructor(i,e){this.operator=i,this.child=e}toString(){return`${this.operator}(${this.child.toString()})`}},q=class{constructor(i,e,t){this.operator=i,this.left=e,this.right=t}toString(){return`${this.left.toString()} ${this.operator} ${this.right.toString()}`}},er=class{constructor(){this.prefixParselets={},this.infixParselets={}}registerInfix(i,e){return this.infixParselets[i]=e,this}registerPrefix(i,e){return this.prefixParselets[i]=e,this}prefix(i,e,t){return this.registerPrefix(i,{parse(n,r){let o=n.consumeAndParse(e);return t(r,o)}})}infixLeft(i,e,t){return this.registerInfix(i,{parse(n,r,o){let s=n.consumeAndParse(e);return t(r,o,s)},precedence:e})}construct(i){return new tr(i,this.prefixParselets,this.infixParselets)}},tr=class{constructor(i,e,t){this.tokens=i,this.prefixParselets=e,this.infixParselets=t}hasMore(){return this.tokens.length>0}match(i){return this.peek()?.id!==i?!1:(this.consume(),!0)}consumeAndParse(i=1/0){let e=this.consume(),t=this.prefixParselets[e.id];if(!t)throw Error(`Parse error at "${e.value}" (line ${e.line}, column ${e.column}). No matching prefix parselet.`);let n=t.parse(this,e);for(;i>this.getPrecedence();){let r=this.consume();n=this.getInfixParselet(r).parse(this,n,r)}return n}getPrecedence(){let i=this.peek();if(!i)return 1/0;let e=this.getInfixParselet(i);return e?e.precedence:1/0}consume(i,e){if(!this.tokens.length)throw Error("Cant consume unknown more tokens.");if(i&&this.peek()?.id!==i){let t=this.peek();throw Error(`Expected ${i} but got "${t.id}" (${t.value}) at line ${t.line} column ${t.column}.`)}if(e&&this.peek()?.value!==e){let t=this.peek();throw Error(`Expected "${e}" but got "${t.value}" at line ${t.line} column ${t.column}.`)}return this.tokens.shift()}peek(){return this.tokens.length>0?this.tokens[0]:void 0}removeComments(){this.tokens=this.tokens.filter(i=>i.id!=="Comment")}getInfixParselet(i){return this.infixParselets[i.id==="Symbol"?i.value:i.id]}},He="http://unitsofmeasure.org",Ae="http://loinc.org",je="http://snomed.info/sct",Wt="http://www.nlm.nih.gov/research/umls/rxnorm",Qt="http://www.ama-assn.org/go/cpt";var zt="http://hl7.org/fhir/sid/ndc",_="http://hl7.org",I="http://terminology.hl7.org";var ir="unauthorized";var Ce={resourceType:"OperationOutcome",id:ir,issue:[{severity:"error",code:"login",details:{text:"Unauthorized"}}]},vo={...Ce,issue:[...Ce.issue,{severity:"error",code:"expired",details:{text:"Token expired"}}]},xo={...Ce,issue:[...Ce.issue,{severity:"error",code:"invalid",details:{text:"Token not issued for this audience"}}]};function nr(i,e){let t=e.max&&e.max===Number.MAX_SAFE_INTEGER?Number.POSITIVE_INFINITY:e.max;return{path:i,description:"",type:e.type??[],min:e.min??0,max:t??1,isArray:!!t&&t>1,constraints:[]}}function rr(i){let e=Object.create(null);for(let[t,n]of Object.entries(i))e[t]={name:t,type:t,path:t,elements:Object.fromEntries(Object.entries(n.elements).map(([r,o])=>[r,nr(r,o)])),constraints:[],innerTypes:[]};return e}var or={Element:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]}}},BackboneElement:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]}}},Address:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},use:{type:[{code:"code"}]},type:{type:[{code:"code"}]},text:{type:[{code:"string"}]},line:{max:9007199254740991,type:[{code:"string"}]},city:{type:[{code:"string"}]},district:{type:[{code:"string"}]},state:{type:[{code:"string"}]},postalCode:{type:[{code:"string"}]},country:{type:[{code:"string"}]},period:{type:[{code:"Period"}]}}},Age:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Annotation:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},"author[x]":{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Organization"]},{code:"string"}]},time:{type:[{code:"dateTime"}]},text:{min:1,type:[{code:"markdown"}]}}},Attachment:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},contentType:{type:[{code:"code"}]},language:{type:[{code:"code"}]},data:{type:[{code:"base64Binary"}]},url:{type:[{code:"url"}]},size:{type:[{code:"unsignedInt"}]},hash:{type:[{code:"base64Binary"}]},title:{type:[{code:"string"}]},creation:{type:[{code:"dateTime"}]}}},CodeableConcept:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},coding:{max:9007199254740991,type:[{code:"Coding"}]},text:{type:[{code:"string"}]}}},Coding:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},system:{type:[{code:"uri"}]},version:{type:[{code:"string"}]},code:{type:[{code:"code"}]},display:{type:[{code:"string"}]},userSelected:{type:[{code:"boolean"}]}}},ContactDetail:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},name:{type:[{code:"string"}]},telecom:{max:9007199254740991,type:[{code:"ContactPoint"}]}}},ContactPoint:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},system:{type:[{code:"code"}]},value:{type:[{code:"string"}]},use:{type:[{code:"code"}]},rank:{type:[{code:"positiveInt"}]},period:{type:[{code:"Period"}]}}},Contributor:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},name:{min:1,type:[{code:"string"}]},contact:{max:9007199254740991,type:[{code:"ContactDetail"}]}}},Count:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},DataRequirement:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},profile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]},"subject[x]":{type:[{code:"CodeableConcept"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Group"]}]},mustSupport:{max:9007199254740991,type:[{code:"string"}]},codeFilter:{max:9007199254740991,type:[{code:"DataRequirementCodeFilter"}]},dateFilter:{max:9007199254740991,type:[{code:"DataRequirementDateFilter"}]},limit:{type:[{code:"positiveInt"}]},sort:{max:9007199254740991,type:[{code:"DataRequirementSort"}]}}},DataRequirementCodeFilter:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{type:[{code:"string"}]},searchParam:{type:[{code:"string"}]},valueSet:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/ValueSet"]}]},code:{max:9007199254740991,type:[{code:"Coding"}]}}},DataRequirementDateFilter:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{type:[{code:"string"}]},searchParam:{type:[{code:"string"}]},"value[x]":{type:[{code:"dateTime"},{code:"Period"},{code:"Duration"}]}}},DataRequirementSort:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},direction:{min:1,type:[{code:"code"}]}}},Distance:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Dosage:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},sequence:{type:[{code:"integer"}]},text:{type:[{code:"string"}]},additionalInstruction:{max:9007199254740991,type:[{code:"CodeableConcept"}]},patientInstruction:{type:[{code:"string"}]},timing:{type:[{code:"Timing"}]},"asNeeded[x]":{type:[{code:"boolean"},{code:"CodeableConcept"}]},site:{type:[{code:"CodeableConcept"}]},route:{type:[{code:"CodeableConcept"}]},method:{type:[{code:"CodeableConcept"}]},doseAndRate:{max:9007199254740991,type:[{code:"DosageDoseAndRate"}]},maxDosePerPeriod:{type:[{code:"Ratio"}]},maxDosePerAdministration:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},maxDosePerLifetime:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},DosageDoseAndRate:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{type:[{code:"CodeableConcept"}]},"dose[x]":{type:[{code:"Range"},{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},"rate[x]":{type:[{code:"Ratio"},{code:"Range"},{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},Duration:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},ElementDefinition:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},representation:{max:9007199254740991,type:[{code:"code"}]},sliceName:{type:[{code:"string"}]},sliceIsConstraining:{type:[{code:"boolean"}]},label:{type:[{code:"string"}]},code:{max:9007199254740991,type:[{code:"Coding"}]},slicing:{type:[{code:"ElementDefinitionSlicing"}]},short:{type:[{code:"string"}]},definition:{type:[{code:"markdown"}]},comment:{type:[{code:"markdown"}]},requirements:{type:[{code:"markdown"}]},alias:{max:9007199254740991,type:[{code:"string"}]},min:{type:[{code:"unsignedInt"}]},max:{type:[{code:"string"}]},base:{type:[{code:"ElementDefinitionBase"}]},contentReference:{type:[{code:"uri"}]},type:{max:9007199254740991,type:[{code:"ElementDefinitionType"}]},"defaultValue[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},meaningWhenMissing:{type:[{code:"markdown"}]},orderMeaning:{type:[{code:"string"}]},"fixed[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},"pattern[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},example:{max:9007199254740991,type:[{code:"ElementDefinitionExample"}]},"minValue[x]":{type:[{code:"date"},{code:"dateTime"},{code:"instant"},{code:"time"},{code:"decimal"},{code:"integer"},{code:"positiveInt"},{code:"unsignedInt"},{code:"Quantity"}]},"maxValue[x]":{type:[{code:"date"},{code:"dateTime"},{code:"instant"},{code:"time"},{code:"decimal"},{code:"integer"},{code:"positiveInt"},{code:"unsignedInt"},{code:"Quantity"}]},maxLength:{type:[{code:"integer"}]},condition:{max:9007199254740991,type:[{code:"id"}]},constraint:{max:9007199254740991,type:[{code:"ElementDefinitionConstraint"}]},mustSupport:{type:[{code:"boolean"}]},isModifier:{type:[{code:"boolean"}]},isModifierReason:{type:[{code:"string"}]},isSummary:{type:[{code:"boolean"}]},binding:{type:[{code:"ElementDefinitionBinding"}]},mapping:{max:9007199254740991,type:[{code:"ElementDefinitionMapping"}]}}},ElementDefinitionSlicingDiscriminator:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},path:{min:1,type:[{code:"string"}]}}},ElementDefinitionSlicing:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},discriminator:{max:9007199254740991,type:[{code:"ElementDefinitionSlicingDiscriminator"}]},description:{type:[{code:"string"}]},ordered:{type:[{code:"boolean"}]},rules:{min:1,type:[{code:"code"}]}}},ElementDefinitionBase:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},min:{min:1,type:[{code:"unsignedInt"}]},max:{min:1,type:[{code:"string"}]}}},ElementDefinitionType:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},code:{min:1,type:[{code:"uri"}]},profile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition","http://hl7.org/fhir/StructureDefinition/ImplementationGuide"]}]},targetProfile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition","http://hl7.org/fhir/StructureDefinition/ImplementationGuide"]}]},aggregation:{max:9007199254740991,type:[{code:"code"}]},versioning:{type:[{code:"code"}]}}},ElementDefinitionExample:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},label:{min:1,type:[{code:"string"}]},"value[x]":{min:1,type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]}}},ElementDefinitionConstraint:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},key:{min:1,type:[{code:"id"}]},requirements:{type:[{code:"string"}]},severity:{min:1,type:[{code:"code"}]},human:{min:1,type:[{code:"string"}]},expression:{type:[{code:"string"}]},xpath:{type:[{code:"string"}]},source:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]}}},ElementDefinitionBinding:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},strength:{min:1,type:[{code:"code"}]},description:{type:[{code:"string"}]},valueSet:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/ValueSet"]}]}}},ElementDefinitionMapping:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},identity:{min:1,type:[{code:"id"}]},language:{type:[{code:"code"}]},map:{min:1,type:[{code:"string"}]},comment:{type:[{code:"string"}]}}},Expression:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},description:{type:[{code:"string"}]},name:{type:[{code:"id"}]},language:{min:1,type:[{code:"code"}]},expression:{type:[{code:"string"}]},reference:{type:[{code:"uri"}]}}},Extension:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},url:{min:1,type:[{code:"uri"}]},"value[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]}}},HumanName:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},use:{type:[{code:"code"}]},text:{type:[{code:"string"}]},family:{type:[{code:"string"}]},given:{max:9007199254740991,type:[{code:"string"}]},prefix:{max:9007199254740991,type:[{code:"string"}]},suffix:{max:9007199254740991,type:[{code:"string"}]},period:{type:[{code:"Period"}]}}},Identifier:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},use:{type:[{code:"code"}]},type:{type:[{code:"CodeableConcept"}]},system:{type:[{code:"uri"}]},value:{type:[{code:"string"}]},period:{type:[{code:"Period"}]},assigner:{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Organization"]}]}}},MarketingStatus:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},country:{min:1,type:[{code:"CodeableConcept"}]},jurisdiction:{type:[{code:"CodeableConcept"}]},status:{min:1,type:[{code:"CodeableConcept"}]},dateRange:{min:1,type:[{code:"Period"}]},restoreDate:{type:[{code:"dateTime"}]}}},Meta:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},versionId:{type:[{code:"id"}]},lastUpdated:{type:[{code:"instant"}]},source:{type:[{code:"uri"}]},profile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]},security:{max:9007199254740991,type:[{code:"Coding"}]},tag:{max:9007199254740991,type:[{code:"Coding"}]},project:{type:[{code:"uri"}]},author:{type:[{code:"Reference"}]},onBehalfOf:{type:[{code:"Reference"}]},account:{type:[{code:"Reference"}]},accounts:{max:9007199254740991,type:[{code:"Reference"}]},compartment:{max:9007199254740991,type:[{code:"Reference"}]}}},Money:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},currency:{type:[{code:"code"}]}}},Narrative:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},status:{min:1,type:[{code:"code"}]},div:{min:1,type:[{code:"xhtml"}]}}},ParameterDefinition:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},name:{type:[{code:"code"}]},use:{min:1,type:[{code:"code"}]},min:{type:[{code:"integer"}]},max:{type:[{code:"string"}]},documentation:{type:[{code:"string"}]},type:{min:1,type:[{code:"code"}]},profile:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]}}},Period:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},start:{type:[{code:"dateTime"}]},end:{type:[{code:"dateTime"}]}}},Population:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},"age[x]":{type:[{code:"Range"},{code:"CodeableConcept"}]},gender:{type:[{code:"CodeableConcept"}]},race:{type:[{code:"CodeableConcept"}]},physiologicalCondition:{type:[{code:"CodeableConcept"}]}}},ProdCharacteristic:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},height:{type:[{code:"Quantity"}]},width:{type:[{code:"Quantity"}]},depth:{type:[{code:"Quantity"}]},weight:{type:[{code:"Quantity"}]},nominalVolume:{type:[{code:"Quantity"}]},externalDiameter:{type:[{code:"Quantity"}]},shape:{type:[{code:"string"}]},color:{max:9007199254740991,type:[{code:"string"}]},imprint:{max:9007199254740991,type:[{code:"string"}]},image:{max:9007199254740991,type:[{code:"Attachment"}]},scoring:{type:[{code:"CodeableConcept"}]}}},ProductShelfLife:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},identifier:{type:[{code:"Identifier"}]},type:{min:1,type:[{code:"CodeableConcept"}]},period:{min:1,type:[{code:"Quantity"}]},specialPrecautionsForStorage:{max:9007199254740991,type:[{code:"CodeableConcept"}]}}},Quantity:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Range:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},low:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},high:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},Ratio:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},numerator:{type:[{code:"Quantity"}]},denominator:{type:[{code:"Quantity"}]}}},Reference:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},reference:{type:[{code:"string"}]},type:{type:[{code:"uri"}]},identifier:{type:[{code:"Identifier"}]},display:{type:[{code:"string"}]}}},RelatedArtifact:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},label:{type:[{code:"string"}]},display:{type:[{code:"string"}]},citation:{type:[{code:"markdown"}]},url:{type:[{code:"url"}]},document:{type:[{code:"Attachment"}]},resource:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/Resource"]}]}}},SampledData:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},origin:{min:1,type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},period:{min:1,type:[{code:"decimal"}]},factor:{type:[{code:"decimal"}]},lowerLimit:{type:[{code:"decimal"}]},upperLimit:{type:[{code:"decimal"}]},dimensions:{min:1,type:[{code:"positiveInt"}]},data:{type:[{code:"string"}]}}},Signature:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,max:9007199254740991,type:[{code:"Coding"}]},when:{min:1,type:[{code:"instant"}]},who:{min:1,type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/PractitionerRole","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/Device","http://hl7.org/fhir/StructureDefinition/Organization"]}]},onBehalfOf:{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/PractitionerRole","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/Device","http://hl7.org/fhir/StructureDefinition/Organization"]}]},targetFormat:{type:[{code:"code"}]},sigFormat:{type:[{code:"code"}]},data:{type:[{code:"base64Binary"}]}}},SubstanceAmount:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},"amount[x]":{type:[{code:"Quantity"},{code:"Range"},{code:"string"}]},amountType:{type:[{code:"CodeableConcept"}]},amountText:{type:[{code:"string"}]},referenceRange:{type:[{code:"SubstanceAmountReferenceRange"}]}}},SubstanceAmountReferenceRange:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},lowLimit:{type:[{code:"Quantity"}]},highLimit:{type:[{code:"Quantity"}]}}},Timing:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},event:{max:9007199254740991,type:[{code:"dateTime"}]},repeat:{type:[{code:"TimingRepeat"}]},code:{type:[{code:"CodeableConcept"}]}}},TimingRepeat:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},"bounds[x]":{type:[{code:"Duration"},{code:"Range"},{code:"Period"}]},count:{type:[{code:"positiveInt"}]},countMax:{type:[{code:"positiveInt"}]},duration:{type:[{code:"decimal"}]},durationMax:{type:[{code:"decimal"}]},durationUnit:{type:[{code:"code"}]},frequency:{type:[{code:"positiveInt"}]},frequencyMax:{type:[{code:"positiveInt"}]},period:{type:[{code:"decimal"}]},periodMax:{type:[{code:"decimal"}]},periodUnit:{type:[{code:"code"}]},dayOfWeek:{max:9007199254740991,type:[{code:"code"}]},timeOfDay:{max:9007199254740991,type:[{code:"time"}]},when:{max:9007199254740991,type:[{code:"code"}]},offset:{type:[{code:"unsignedInt"}]}}},TriggerDefinition:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},name:{type:[{code:"string"}]},"timing[x]":{type:[{code:"Timing"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Schedule"]},{code:"date"},{code:"dateTime"}]},data:{max:9007199254740991,type:[{code:"DataRequirement"}]},condition:{type:[{code:"Expression"}]}}},UsageContext:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},code:{min:1,type:[{code:"Coding"}]},"value[x]":{min:1,type:[{code:"CodeableConcept"},{code:"Quantity"},{code:"Range"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/PlanDefinition","http://hl7.org/fhir/StructureDefinition/ResearchStudy","http://hl7.org/fhir/StructureDefinition/InsurancePlan","http://hl7.org/fhir/StructureDefinition/HealthcareService","http://hl7.org/fhir/StructureDefinition/Group","http://hl7.org/fhir/StructureDefinition/Location","http://hl7.org/fhir/StructureDefinition/Organization"]}]}}},MoneyQuantity:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},SimpleQuantity:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{max:0,type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},IdentityProvider:{elements:{authorizeUrl:{min:1,type:[{code:"string"}]},tokenUrl:{min:1,type:[{code:"string"}]},tokenAuthMethod:{type:[{code:"code"}]},userInfoUrl:{min:1,type:[{code:"string"}]},clientId:{min:1,type:[{code:"string"}]},clientSecret:{min:1,type:[{code:"string"}]},usePkce:{type:[{code:"boolean"}]},useSubject:{type:[{code:"boolean"}]}}}};var sr=rr(or);var Gt=Object.create(null);function ar(i){let e;return e=Gt[i],e||(e=Gt[i]=Object.create(null)),e}function cr(i,e){if(e){let t=ar(e)[i];if(t)return t}return sr[i]}var Zt={base64Binary:/^([A-Za-z\d+/]{4})*([A-Za-z\d+/]{2}==|[A-Za-z\d+/]{3}=)?$/,canonical:/^\S*$/,code:/^[^\s]+( [^\s]+)*$/,date:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1]))?)?$/,dateTime:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1])(T([01]\d|2[0-3])(:[0-5]\d:([0-5]\d|60)(\.\d{1,9})?)?)?)?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00)?)?)?$/,id:/^[A-Za-z0-9\-.]{1,64}$/,instant:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])T([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00))$/,markdown:/^[\r\n\t\u0020-\uFFFF]+$/,oid:/^urn:oid:[0-2](\.(0|[1-9]\d*))+$/,string:/^[\r\n\t\u0020-\uFFFF]+$/,time:/^([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?$/,uri:/^\S*$/,url:/^\S*$/,uuid:/^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,xhtml:/.*/};function a(i){return[{type:u.boolean,value:i}]}function L(i){return i==null?{type:"undefined",value:void 0}:Number.isSafeInteger(i)?{type:u.integer,value:i}:typeof i=="number"?{type:u.decimal,value:i}:typeof i=="boolean"?{type:u.boolean,value:i}:typeof i=="string"?{type:u.string,value:i}:y(i)?{type:u.Quantity,value:i}:Q(i)?{type:i.resourceType,value:i}:ni(i)?{type:u.CodeableConcept,value:i}:ii(i)?{type:u.Coding,value:i}:{type:u.BackboneElement,value:i}}function v(i){return i.length===0?!1:!!i[0].value}function x(i,e){if(i.length!==0){if(i.length===1&&(!e||i[0].type===e))return i[0];throw new Error(`Expected singleton of type ${e}, but found ${JSON.stringify(i)}`)}}function ur(i,e,t){if(!i.value)return;let n=br(i.type,e,t?.profileUrl);return n?lr(i,e,n):dr(i,e)}function lr(i,e,t){let n=i.value,r=t.type;if(!r||r.length===0)return;let o,s="undefined",c,p=t.path.lastIndexOf("."),N=t.path.substring(p+1);for(let E of r){let $=N.replace("[x]",W(E.code));if(o=n[$],c=n["_"+$],o!==void 0||c!==void 0){s=E.code;break}}if(c)if(Array.isArray(o)){o=o.slice();for(let E=0;E<Math.max(o.length,c.length);E++)o[E]=jt(o[E],c[E])}else o=jt(o,c);if(!j(o))return(s==="Element"||s==="BackboneElement")&&(s=t.type[0].code),Array.isArray(o)?o.map(E=>Yt(E,s)):Yt(o,s)}function Yt(i,e){return e==="Resource"&&Q(i)&&(e=i.resourceType),{type:e,value:i}}function dr(i,e){let t=i.value;if(!t||typeof t!="object")return;let n;if(e in t){let r=t[e];Array.isArray(r)?n=r.map(L):n=L(r)}else{let r=e.endsWith("[x]")?e.substring(0,e.length-3):e;for(let o of Object.values(u)){let s=r+W(o);if(s in t){let c=t[s];Array.isArray(c)?n=c.map(p=>({type:o,value:p})):n={type:o,value:c};break}}}if(Array.isArray(n)){if(n.length===0||j(n[0]))return}else if(j(n))return;return n}function Xt(i){let e=[];for(let t of i){let n=!1;for(let r of e)if(v(qe(t,r))){n=!0;break}n||e.push(t)}return e}function pr(i){return a(!v(i))}function hr(i,e){return i.length===0||e.length===0?[]:i.length!==e.length?a(!1):a(i.every((t,n)=>v(qe(t,e[n]))))}function fr(i,e){return i.length===0||e.length===0?[]:i.length!==e.length?a(!0):a(i.some((t,n)=>!v(qe(t,e[n]))))}function qe(i,e){let t=i.value?.valueOf(),n=e.value?.valueOf();return typeof t=="number"&&typeof n=="number"?a(Math.abs(t-n)<1e-8):y(t)&&y(n)?a(ei(t,n)):a(typeof t=="object"&&typeof n=="object"?We(i,e):t===n)}function Jt(i,e){return i.length===0&&e.length===0?a(!0):i.length!==e.length?a(!1):(i.sort($t),e.sort($t),a(i.every((t,n)=>v(_r(t,e[n])))))}function _r(i,e){let{type:t,value:n}=i,{type:r,value:o}=e,s=n?.valueOf(),c=o?.valueOf();return typeof s=="number"&&typeof c=="number"?a(Math.abs(s-c)<.01):y(s)&&y(c)?a(ei(s,c)):a(t==="Coding"&&r==="Coding"?typeof s!="object"||typeof c!="object"?!1:s.code===c.code&&s.system===c.system:typeof s=="object"&&typeof c=="object"?We({...s,id:void 0},{...c,id:void 0}):typeof s=="string"&&typeof c=="string"?s.toLowerCase()===c.toLowerCase():s===c)}function $t(i,e){let t=i.value?.valueOf(),n=e.value?.valueOf();return typeof t=="number"&&typeof n=="number"?t-n:typeof t=="string"&&typeof n=="string"?t.localeCompare(n):0}function Kt(i,e){let{value:t}=i;if(t==null)return!1;switch(e){case"Boolean":return typeof t=="boolean";case"Decimal":case"Integer":return typeof t=="number";case"Date":return mr(t);case"DateTime":return $e(t);case"Time":return typeof t=="string"&&!!/^T\d/.exec(t);case"Period":return Er(t);case"Quantity":return y(t);default:return i.type===e||typeof t=="object"&&t?.resourceType===e}}function mr(i){return typeof i=="string"&&!!Zt.date.exec(i)}function $e(i){return typeof i=="string"&&!!Zt.dateTime.exec(i)}function Er(i){return!!(i&&typeof i=="object"&&("start"in i&&$e(i.start)||"end"in i&&$e(i.end)))}function y(i){return!!(i&&typeof i=="object"&&"value"in i&&typeof i.value=="number")}function ei(i,e){return Math.abs(i.value-e.value)<.01&&(i.unit===e.unit||i.code===e.code||i.unit===e.code||i.code===e.unit)}function We(i,e){let t=Object.keys(i),n=Object.keys(e);if(t.length!==n.length)return!1;for(let r of t){let o=i[r],s=e[r];if(Ht(o)&&Ht(s)){if(!We(o,s))return!1}else if(o!==s)return!1}return!0}function Ht(i){return i!==null&&typeof i=="object"}function jt(i,e){if(e){if(typeof e!="object")throw new Error("Primitive extension must be an object");return Ir(i??{},e)}return i}function Ir(i,e){return delete e.__proto__,delete e.constructor,Object.assign(i,e)}function Tr(i,e){return Q(i,e)&&"id"in i&&typeof i.id=="string"}function h(i){let e=ti(i)??"undefined/undefined",t=yr(i);return t===e?{reference:e}:{reference:e,display:t}}function ti(i){if(ri(i))return i.reference;if(Tr(i))return`${i.resourceType}/${i.id}`}function Or(i){if(i)return ri(i)?i.reference.split("/")[1]:i.id}function Sr(i){return i.resourceType==="Patient"||i.resourceType==="Practitioner"||i.resourceType==="RelatedPerson"}function yr(i){if(Sr(i)){let e=Cr(i);if(e)return e}if(i.resourceType==="Device"){let e=gr(i);if(e)return e}if(i.resourceType==="MedicationRequest"&&i.medicationCodeableConcept)return qt(i.medicationCodeableConcept);if(i.resourceType==="Subscription"&&i.criteria)return i.criteria;if(i.resourceType==="User"&&i.email)return i.email;if("name"in i&&i.name&&typeof i.name=="string")return i.name;if("code"in i&&i.code){let e=i.code;if(Array.isArray(e)&&(e=e[0]),ni(e))return qt(e);if(Dr(e))return e.text}return ti(i)??""}function Cr(i){let e=i.name;if(e&&e.length>0)return xr(e[0])}function gr(i){let e=i.deviceName;if(e&&e.length>0)return e[0].name}function Ar(i,e){let t=new Date(i);t.setUTCHours(0,0,0,0);let n=e?new Date(e):new Date;n.setUTCHours(0,0,0,0);let r=t.getUTCFullYear(),o=t.getUTCMonth(),s=t.getUTCDate(),c=n.getUTCFullYear(),p=n.getUTCMonth(),N=n.getUTCDate(),E=c-r;(p<o||p===o&&N<s)&&E--;let $=c*12+p-(r*12+o);N<s&&$--;let qn=Math.floor((n.getTime()-t.getTime())/(1e3*60*60*24));return{years:E,months:$,days:qn}}function Rr(i,...e){let t=i;for(let n=0;n<e.length&&t;n++)t=t?.extension?.find(r=>r.url===e[n]);return t}function j(i){if(i==null)return!0;let e=typeof i;return e==="string"||e==="object"?!Nr(i):!1}function Nr(i){if(i==null)return!1;let e=typeof i;return e==="string"&&i!==""||e==="object"&&("length"in i&&i.length>0||Object.keys(i).length>0)}function Qe(i){return!!/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i.exec(i)}function ze(i){return i!==null&&typeof i=="object"}function ii(i){return ze(i)&&"code"in i&&typeof i.code=="string"}function ni(i){return ze(i)&&"coding"in i&&Array.isArray(i.coding)&&i.coding.every(ii)}function Dr(i){return ze(i)&&"text"in i&&typeof i.text=="string"}var vr=[];for(let i=0;i<256;i++)vr.push(i.toString(16).padStart(2,"0"));function W(i){return i?i.charAt(0).toUpperCase()+i.substring(1):""}function xr(i,e){let t=[];if(i.prefix&&e?.prefix!==!1&&t.push(...i.prefix),i.given&&t.push(...i.given),i.family&&t.push(i.family),i.suffix&&e?.suffix!==!1&&t.push(...i.suffix),i.use&&(e?.all||e?.use)&&t.push("["+i.use+"]"),t.length===0){let n=H(i.text);if(n)return n}return t.join(" ").trim()}function qt(i){return i?H(i.text)||(i.coding?i.coding.map(t=>Pr(t)).join(", "):""):""}function Pr(i,e){let t=H(i?.display);if(t){let n=e?H(i?.code):void 0;return`${t}${n?" ("+n+")":""}`}return H(i?.code)??""}function H(i){return typeof i=="string"?i:void 0}var u={Address:"Address",Age:"Age",Annotation:"Annotation",Attachment:"Attachment",BackboneElement:"BackboneElement",CodeableConcept:"CodeableConcept",Coding:"Coding",ContactDetail:"ContactDetail",ContactPoint:"ContactPoint",Contributor:"Contributor",Count:"Count",DataRequirement:"DataRequirement",Distance:"Distance",Dosage:"Dosage",Duration:"Duration",Expression:"Expression",Extension:"Extension",HumanName:"HumanName",Identifier:"Identifier",MarketingStatus:"MarketingStatus",Meta:"Meta",Money:"Money",Narrative:"Narrative",ParameterDefinition:"ParameterDefinition",Period:"Period",Population:"Population",ProdCharacteristic:"ProdCharacteristic",ProductShelfLife:"ProductShelfLife",Quantity:"Quantity",Range:"Range",Ratio:"Ratio",Reference:"Reference",RelatedArtifact:"RelatedArtifact",SampledData:"SampledData",Signature:"Signature",SubstanceAmount:"SubstanceAmount",SystemString:"http://hl7.org/fhirpath/System.String",Timing:"Timing",TriggerDefinition:"TriggerDefinition",UsageContext:"UsageContext",base64Binary:"base64Binary",boolean:"boolean",canonical:"canonical",code:"code",date:"date",dateTime:"dateTime",decimal:"decimal",id:"id",instant:"instant",integer:"integer",markdown:"markdown",oid:"oid",positiveInt:"positiveInt",string:"string",time:"time",unsignedInt:"unsignedInt",uri:"uri",url:"url",uuid:"uuid"};function br(i,e,t){let n=cr(i,t);if(n)return Ur(n.elements,e)}function Ur(i,e){let t=i[e]??i[e+"[x]"];if(t)return t;for(let n=0;n<e.length;n++){let r=e[n];if(r>="A"&&r<="Z"){let o=e.slice(0,n)+"[x]",s=i[o];if(s)return s}}}function Q(i,e){return!(!i||typeof i!="object"||!("resourceType"in i)||e&&i.resourceType!==e)}function ri(i){return!!(i&&typeof i=="object"&&"reference"in i&&typeof i.reference=="string")}function ye(i){if(i.startsWith("T"))return i+"T00:00:00.000Z".substring(i.length);if(i.length<=10)return i;try{return new Date(i).toISOString()}catch{return i}}var D=()=>[],O={empty:(i,e)=>a(e.length===0||e.every(t=>j(t.value))),hasValue:(i,e)=>a(e.length!==0),exists:(i,e,t)=>a(t?e.filter(n=>v(t.eval(i,[n]))).length>0:e.length>0&&e.every(n=>!j(n.value))),all:(i,e,t)=>a(e.every(n=>v(t.eval(i,[n])))),allTrue:(i,e)=>{for(let t of e)if(!t.value)return a(!1);return a(!0)},anyTrue:(i,e)=>{for(let t of e)if(t.value)return a(!0);return a(!1)},allFalse:(i,e)=>{for(let t of e)if(t.value)return a(!1);return a(!0)},anyFalse:(i,e)=>{for(let t of e)if(!t.value)return a(!0);return a(!1)},subsetOf:(i,e,t)=>{if(e.length===0)return a(!0);let n=t.eval(i,U(i));return n.length===0?a(!1):a(e.every(r=>n.some(o=>o.value===r.value)))},supersetOf:(i,e,t)=>{let n=t.eval(i,U(i));return n.length===0?a(!0):e.length===0?a(!1):a(n.every(r=>e.some(o=>o.value===r.value)))},count:(i,e)=>[{type:u.integer,value:e.length}],distinct:(i,e)=>{let t=[];for(let n of e)t.some(r=>r.value===n.value)||t.push(n);return t},isDistinct:(i,e)=>a(e.length===O.distinct(i,e).length),where:(i,e,t)=>e.filter(n=>v(t.eval(i,[n]))),select:(i,e,t)=>e.map(n=>t.eval({parent:i,variables:{$this:n}},[n])).flat(),repeat:D,ofType:(i,e,t)=>e.filter(n=>n.type===t.name),single:(i,e)=>{if(e.length>1)throw new Error("Expected input length one for single()");return e.length===0?[]:e.slice(0,1)},first:(i,e)=>e.length===0?[]:e.slice(0,1),last:(i,e)=>e.length===0?[]:e.slice(e.length-1,e.length),tail:(i,e)=>e.length===0?[]:e.slice(1,e.length),skip:(i,e,t)=>{let n=t.eval(i,e)[0]?.value;if(typeof n!="number")throw new Error("Expected a number for skip(num)");return n>=e.length?[]:n<=0?e:e.slice(n,e.length)},take:(i,e,t)=>{let n=t.eval(i,e)[0]?.value;if(typeof n!="number")throw new Error("Expected a number for take(num)");return n>=e.length?e:n<=0?[]:e.slice(0,n)},intersect:(i,e,t)=>{if(!t)return e;let n=t.eval(i,U(i)),r=[];for(let o of e)!r.some(s=>s.value===o.value)&&n.some(s=>s.value===o.value)&&r.push(o);return r},exclude:(i,e,t)=>{if(!t)return e;let n=t.eval(i,U(i)),r=[];for(let o of e)n.some(s=>s.value===o.value)||r.push(o);return r},union:(i,e,t)=>{if(!t)return e;let n=t.eval(i,U(i));return Xt([...e,...n])},combine:(i,e,t)=>{if(!t)return e;let n=t.eval(i,U(i));return[...e,...n]},htmlChecks:(i,e,t)=>[L(!0)],iif:(i,e,t,n,r)=>{let o=t.eval(i,e);if(o.length>1||o.length===1&&typeof o[0].value!="boolean")throw new Error("Expected criterion to evaluate to a Boolean");return v(o)?n.eval(i,e):r?r.eval(i,e):[]},toBoolean:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);if(typeof t=="boolean")return[{type:u.boolean,value:t}];if(typeof t=="number"&&(t===0||t===1))return a(!!t);if(typeof t=="string"){let n=t.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(n))return a(!0);if(["false","f","no","n","0","0.0"].includes(n))return a(!1)}return[]},convertsToBoolean:(i,e)=>e.length===0?[]:a(O.toBoolean(i,e).length===1),toInteger:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return typeof t=="number"?[{type:u.integer,value:t}]:typeof t=="string"&&/^[+-]?\d+$/.exec(t)?[{type:u.integer,value:parseInt(t,10)}]:typeof t=="boolean"?[{type:u.integer,value:t?1:0}]:[]},convertsToInteger:(i,e)=>e.length===0?[]:a(O.toInteger(i,e).length===1),toDate:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return typeof t=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(t)?[{type:u.date,value:ye(t)}]:[]},convertsToDate:(i,e)=>e.length===0?[]:a(O.toDate(i,e).length===1),toDateTime:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return typeof t=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(t)?[{type:u.dateTime,value:ye(t)}]:[]},convertsToDateTime:(i,e)=>e.length===0?[]:a(O.toDateTime(i,e).length===1),toDecimal:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return typeof t=="number"?[{type:u.decimal,value:t}]:typeof t=="string"&&/^-?\d{1,9}(\.\d{1,9})?$/.exec(t)?[{type:u.decimal,value:parseFloat(t)}]:typeof t=="boolean"?[{type:u.decimal,value:t?1:0}]:[]},convertsToDecimal:(i,e)=>e.length===0?[]:a(O.toDecimal(i,e).length===1),toQuantity:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return y(t)?[{type:u.Quantity,value:t}]:typeof t=="number"?[{type:u.Quantity,value:{value:t,unit:"1"}}]:typeof t=="string"&&/^-?\d{1,9}(\.\d{1,9})?/.exec(t)?[{type:u.Quantity,value:{value:parseFloat(t),unit:"1"}}]:typeof t=="boolean"?[{type:u.Quantity,value:{value:t?1:0,unit:"1"}}]:[]},convertsToQuantity:(i,e)=>e.length===0?[]:a(O.toQuantity(i,e).length===1),toString:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return t==null?[]:y(t)?[{type:u.string,value:`${t.value} '${t.unit}'`}]:[{type:u.string,value:t.toString()}]},convertsToString:(i,e)=>e.length===0?[]:a(O.toString(i,e).length===1),toTime:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);if(typeof t=="string"){let n=/^T?(\d{2}(:\d{2}(:\d{2})?)?)/.exec(t);if(n)return[{type:u.time,value:ye("T"+n[1])}]}return[]},convertsToTime:(i,e)=>e.length===0?[]:a(O.toTime(i,e).length===1),indexOf:(i,e,t)=>S((n,r)=>n.indexOf(r),i,e,t),substring:(i,e,t,n)=>S((r,o,s)=>{let c=o,p=s?c+s:r.length;return c<0||c>=r.length?void 0:r.substring(c,p)},i,e,t,n),startsWith:(i,e,t)=>S((n,r)=>n.startsWith(r),i,e,t),endsWith:(i,e,t)=>S((n,r)=>n.endsWith(r),i,e,t),contains:(i,e,t)=>S((n,r)=>n.includes(r),i,e,t),upper:(i,e)=>S(t=>t.toUpperCase(),i,e),lower:(i,e)=>S(t=>t.toLowerCase(),i,e),replace:(i,e,t,n)=>S((r,o,s)=>r.replaceAll(o,s),i,e,t,n),matches:(i,e,t)=>S((n,r)=>!!new RegExp(r).exec(n),i,e,t),replaceMatches:(i,e,t,n)=>S((r,o,s)=>r.replaceAll(o,s),i,e,t,n),length:(i,e)=>S(t=>t.length,i,e),toChars:(i,e)=>S(t=>t?t.split(""):void 0,i,e),encode:D,decode:D,escape:D,unescape:D,trim:D,split:D,join:(i,e,t)=>{let n=t?.eval(i,U(i))[0]?.value??"";if(typeof n!="string")throw new Error("Separator must be a string.");return[{type:u.string,value:e.map(r=>r.value?.toString()??"").join(n)}]},abs:(i,e)=>A(Math.abs,i,e),ceiling:(i,e)=>A(Math.ceil,i,e),exp:(i,e)=>A(Math.exp,i,e),floor:(i,e)=>A(Math.floor,i,e),ln:(i,e)=>A(Math.log,i,e),log:(i,e,t)=>A((n,r)=>Math.log(n)/Math.log(r),i,e,t),power:(i,e,t)=>A(Math.pow,i,e,t),round:(i,e)=>A(Math.round,i,e),sqrt:(i,e)=>A(Math.sqrt,i,e),truncate:(i,e)=>A(t=>t|0,i,e),children:D,descendants:D,trace:(i,e,t)=>e,now:()=>[{type:u.dateTime,value:new Date().toISOString()}],timeOfDay:()=>[{type:u.time,value:new Date().toISOString().substring(11)}],today:()=>[{type:u.date,value:new Date().toISOString().substring(0,10)}],between:(i,e,t,n,r)=>{let o=O.toDateTime(i,t.eval(i,e));if(o.length===0)throw new Error("Invalid start date");let s=O.toDateTime(i,n.eval(i,e));if(s.length===0)throw new Error("Invalid end date");let c=r.eval(i,e)[0]?.value;if(c!=="years"&&c!=="months"&&c!=="days")throw new Error("Invalid units");let p=Ar(o[0].value,s[0].value);return[{type:u.Quantity,value:{value:p[c],unit:c}}]},is:(i,e,t)=>{let n="";return t instanceof ge?n=t.name:t instanceof oi&&(n=t.left.name+"."+t.right.name),n?e.map(r=>({type:u.boolean,value:Kt(r,n)})):[]},not:(i,e)=>O.toBoolean(i,e).map(t=>({type:u.boolean,value:!t.value})),resolve:(i,e)=>e.map(t=>{let n=t.value,r;if(typeof n=="string")r=n;else if(typeof n=="object"){let o=n;if(o.resource)return L(o.resource);o.reference?r=o.reference:o.type&&o.identifier&&(r=`${o.type}?identifier=${o.identifier.system}|${o.identifier.value}`)}if(r?.includes("?")){let[o]=r.split("?");return{type:o,value:{resourceType:o}}}if(r?.includes("/")){let[o,s]=r.split("/");return{type:o,value:{resourceType:o,id:s}}}return{type:u.BackboneElement,value:void 0}}).filter(t=>!!t.value),as:(i,e)=>e,type:(i,e)=>e.map(({value:t})=>typeof t=="boolean"?{type:u.BackboneElement,value:{namespace:"System",name:"Boolean"}}:typeof t=="number"?{type:u.BackboneElement,value:{namespace:"System",name:"Integer"}}:Q(t)?{type:u.BackboneElement,value:{namespace:"FHIR",name:t.resourceType}}:{type:u.BackboneElement,value:null}),conformsTo:(i,e,t)=>{let n=t.eval(i,e)[0].value;if(!n.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");let r=n.replace("http://hl7.org/fhir/StructureDefinition/","");return e.map(o=>({type:u.boolean,value:o.value?.resourceType===r}))},getResourceKey:(i,e)=>{let t=e[0].value;return t?.id?[{type:u.id,value:t.id}]:[]},getReferenceKey:(i,e,t)=>{let n=e[0].value;if(!n?.reference)return[];let r="";return t instanceof ge&&(r=t.name),r&&!n.reference.startsWith(r+"/")?[]:[{type:u.id,value:Or(n)}]},extension:(i,e,t)=>{let n=t.eval(i,e)[0].value,r=e?.[0]?.value;if(r){let o=Rr(r,n);if(o)return[{type:u.Extension,value:o}]}return[]}};function S(i,e,t,...n){if(t.length===0)return[];let[{value:r}]=R(t,1);if(typeof r!="string")throw new Error("String function cannot be called with non-string");let o=i(r,...n.map(s=>s?.eval(e,t)[0]?.value));return o===void 0?[]:Array.isArray(o)?o.map(L):[L(o)]}function A(i,e,t,...n){if(t.length===0)return[];let[{value:r}]=R(t,1),o=y(r),s=o?r.value:r;if(typeof s!="number")throw new Error("Math function cannot be called with non-number");let c=i(s,...n.map(E=>E.eval(e,t)[0]?.value)),p=o?u.Quantity:t[0].type,N=o?{...r,value:c}:c;return[{type:p,value:N}]}function R(i,e){if(i.length!==e)throw new Error(`Expected ${e} arguments`);for(let t of i)if(t==null)throw new Error("Expected non-null argument");return i}function U(i){let e=i;for(;e.parent?.variables.$this;)e=e.parent;return[e.variables.$this]}var M=class{constructor(i){this.value=i}eval(){return[this.value]}toString(){let i=this.value.value;return typeof i=="string"?`'${i}'`:i.toString()}},ge=class{constructor(i){this.name=i}eval(i,e){if(this.name==="$this")return e;let t=this.getVariable(i);if(t)return[t];if(this.name.startsWith("%"))throw new Error(`Undefined variable ${this.name}`);return e.flatMap(n=>this.evalValue(n)).filter(n=>n?.value!==void 0)}getVariable(i){let e=i.variables[this.name];if(e!==void 0)return e;if(i.parent)return this.getVariable(i.parent)}evalValue(i){let e=i.value;if(!(!e||typeof e!="object"))return Q(e,this.name)?i:ur(i,this.name)}toString(){return this.name}},Lr=class{eval(){return[]}toString(){return"{}"}},Vr=class extends Kn{constructor(i,e,t){super(i,e),this.impl=t}eval(i,e){return this.impl(this.child.eval(i,e))}toString(){return this.operator+this.child.toString()}},wr=class extends q{constructor(i,e){super("as",i,e)}eval(i,e){return O.ofType(i,this.left.eval(i,e),this.right)}},C=class extends q{},g=class extends C{constructor(i,e,t,n){super(i,e,t),this.impl=n}eval(i,e){let t=this.left.eval(i,e);if(t.length!==1)return[];let n=this.right.eval(i,e);if(n.length!==1)return[];let r=t[0].value,o=n[0].value,s=y(r)?r.value:r,c=y(o)?o.value:o,p=this.impl(s,c);return typeof p=="boolean"?a(p):y(r)?[{type:u.Quantity,value:{...r,value:p}}]:[L(p)]}},Mr=class extends q{constructor(i,e){super("&",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e),r=[...t,...n];return r.length>0&&r.every(o=>typeof o.value=="string")?[{type:u.string,value:r.map(o=>o.value).join("")}]:r}},kr=class extends C{constructor(i,e){super("contains",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return a(t.some(r=>r.value===n[0].value))}},Br=class extends C{constructor(i,e){super("in",i,e)}eval(i,e){let t=x(this.left.eval(i,e)),n=this.right.eval(i,e);return t?a(n.some(r=>r.value===t.value)):[]}},oi=class extends q{constructor(i,e){super(".",i,e)}eval(i,e){return this.right.eval(i,this.left.eval(i,e))}toString(){return`${this.left.toString()}.${this.right.toString()}`}},Fr=class extends q{constructor(i,e){super("|",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return Xt([...t,...n])}},Gr=class extends C{constructor(i,e){super("=",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return hr(t,n)}},Yr=class extends C{constructor(i,e){super("!=",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return fr(t,n)}},$r=class extends C{constructor(i,e){super("~",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return Jt(t,n)}},Hr=class extends C{constructor(i,e){super("!~",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return pr(Jt(t,n))}},jr=class extends C{constructor(i,e){super("is",i,e)}eval(i,e){let t=this.left.eval(i,e);if(t.length!==1)return[];let n=this.right.name;return a(Kt(t[0],n))}},qr=class extends C{constructor(i,e){super("and",i,e)}eval(i,e){let t=x(this.left.eval(i,e),"boolean"),n=x(this.right.eval(i,e),"boolean");return t?.value===!0&&n?.value===!0?a(!0):t?.value===!1||n?.value===!1?a(!1):[]}},Wr=class extends C{constructor(i,e){super("or",i,e)}eval(i,e){let t=x(this.left.eval(i,e),"boolean"),n=x(this.right.eval(i,e),"boolean");return t?.value===!1&&n?.value===!1?a(!1):t?.value||n?.value?a(!0):[]}},Qr=class extends C{constructor(i,e){super("xor",i,e)}eval(i,e){let t=x(this.left.eval(i,e),"boolean"),n=x(this.right.eval(i,e),"boolean");return!t||!n?[]:a(t.value!==n.value)}},zr=class extends C{constructor(i,e){super("implies",i,e)}eval(i,e){let t=x(this.left.eval(i,e),"boolean"),n=x(this.right.eval(i,e),"boolean");return n?.value===!0||t?.value===!1?a(!0):!t||!n?[]:a(!1)}},Zr=class{constructor(i,e){this.name=i,this.args=e}eval(i,e){let t=O[this.name];if(!t)throw new Error("Unrecognized function: "+this.name);return t(i,e,...this.args)}toString(){return`${this.name}(${this.args.map(i=>i.toString()).join(", ")})`}},Xr=class{constructor(i,e){this.left=i,this.expr=e}eval(i,e){let t=this.expr.eval(i,e);if(t.length!==1)return[];let n=t[0].value;if(typeof n!="number")throw new Error("Invalid indexer expression: should return integer}");let r=this.left.eval(i,e);return n in r?[r[n]]:[]}toString(){return`${this.left.toString()}[${this.expr.toString()}]`}};var si=["!=","!~","<=",">=","{}","->"];var l={FunctionCall:0,Dot:1,Indexer:2,UnaryAdd:3,UnarySubtract:3,Multiply:4,Divide:4,IntegerDivide:4,Modulo:4,Add:5,Subtract:5,Ampersand:5,Is:6,As:6,Union:7,GreaterThan:8,GreaterThanOrEquals:8,LessThan:8,LessThanOrEquals:8,Equals:9,Equivalent:9,NotEquals:9,NotEquivalent:9,In:10,Contains:10,And:11,Xor:12,Or:12,Implies:13,Arrow:100,Semicolon:200},Jr={parse(i){let e=i.consumeAndParse();if(!i.match(")"))throw new Error("Parse error: expected `)` got `"+i.peek()?.value+"`");return e}},Kr={parse(i,e){let t=i.consumeAndParse();if(!i.match("]"))throw new Error("Parse error: expected `]`");return new Xr(e,t)},precedence:l.Indexer},eo={parse(i,e){if(!(e instanceof ge))throw new Error("Unexpected parentheses");let t=[];for(;!i.match(")");)t.push(i.consumeAndParse()),i.match(",");return new Zr(e.name,t)},precedence:l.FunctionCall};function to(i){let e=i.split(" "),t=parseFloat(e[0]),n=e[1];return n?.startsWith("'")&&n.endsWith("'")?n=n.substring(1,n.length-1):n="{"+n+"}",{value:t,unit:n}}function Ze(){return new er().registerPrefix("String",{parse:(i,e)=>new M({type:u.string,value:e.value})}).registerPrefix("DateTime",{parse:(i,e)=>new M({type:u.dateTime,value:ye(e.value)})}).registerPrefix("Quantity",{parse:(i,e)=>new M({type:u.Quantity,value:to(e.value)})}).registerPrefix("Number",{parse:(i,e)=>new M({type:e.value.includes(".")?u.decimal:u.integer,value:parseFloat(e.value)})}).registerPrefix("true",{parse:()=>new M({type:u.boolean,value:!0})}).registerPrefix("false",{parse:()=>new M({type:u.boolean,value:!1})}).registerPrefix("Symbol",{parse:(i,e)=>new ge(e.value)}).registerPrefix("{}",{parse:()=>new Lr}).registerPrefix("(",Jr).registerInfix("[",Kr).registerInfix("(",eo).prefix("+",l.UnaryAdd,(i,e)=>new Vr("+",e,t=>t)).prefix("-",l.UnarySubtract,(i,e)=>new g("-",e,e,(t,n)=>-n)).infixLeft(".",l.Dot,(i,e,t)=>new oi(i,t)).infixLeft("/",l.Divide,(i,e,t)=>new g("/",i,t,(n,r)=>n/r)).infixLeft("*",l.Multiply,(i,e,t)=>new g("*",i,t,(n,r)=>n*r)).infixLeft("+",l.Add,(i,e,t)=>new g("+",i,t,(n,r)=>n+r)).infixLeft("-",l.Subtract,(i,e,t)=>new g("-",i,t,(n,r)=>n-r)).infixLeft("|",l.Union,(i,e,t)=>new Fr(i,t)).infixLeft("=",l.Equals,(i,e,t)=>new Gr(i,t)).infixLeft("!=",l.NotEquals,(i,e,t)=>new Yr(i,t)).infixLeft("~",l.Equivalent,(i,e,t)=>new $r(i,t)).infixLeft("!~",l.NotEquivalent,(i,e,t)=>new Hr(i,t)).infixLeft("<",l.LessThan,(i,e,t)=>new g("<",i,t,(n,r)=>n<r)).infixLeft("<=",l.LessThanOrEquals,(i,e,t)=>new g("<=",i,t,(n,r)=>n<=r)).infixLeft(">",l.GreaterThan,(i,e,t)=>new g(">",i,t,(n,r)=>n>r)).infixLeft(">=",l.GreaterThanOrEquals,(i,e,t)=>new g(">=",i,t,(n,r)=>n>=r)).infixLeft("&",l.Ampersand,(i,e,t)=>new Mr(i,t)).infixLeft("and",l.And,(i,e,t)=>new qr(i,t)).infixLeft("as",l.As,(i,e,t)=>new wr(i,t)).infixLeft("contains",l.Contains,(i,e,t)=>new kr(i,t)).infixLeft("div",l.Divide,(i,e,t)=>new g("div",i,t,(n,r)=>n/r|0)).infixLeft("in",l.In,(i,e,t)=>new Br(i,t)).infixLeft("is",l.Is,(i,e,t)=>new jr(i,t)).infixLeft("mod",l.Modulo,(i,e,t)=>new g("mod",i,t,(n,r)=>n%r)).infixLeft("or",l.Or,(i,e,t)=>new Wr(i,t)).infixLeft("xor",l.Xor,(i,e,t)=>new Qr(i,t)).infixLeft("implies",l.Implies,(i,e,t)=>new zr(i,t))}var Po=Ze();var io=(i=>(i.BOOLEAN="BOOLEAN",i.NUMBER="NUMBER",i.QUANTITY="QUANTITY",i.TEXT="TEXT",i.REFERENCE="REFERENCE",i.CANONICAL="CANONICAL",i.DATE="DATE",i.DATETIME="DATETIME",i.PERIOD="PERIOD",i.UUID="UUID",i))(io||{});var no=(i=>(i.EQUALS="eq",i.NOT_EQUALS="ne",i.GREATER_THAN="gt",i.LESS_THAN="lt",i.GREATER_THAN_OR_EQUALS="ge",i.LESS_THAN_OR_EQUALS="le",i.STARTS_AFTER="sa",i.ENDS_BEFORE="eb",i.APPROXIMATELY="ap",i.CONTAINS="contains",i.STARTS_WITH="sw",i.EXACT="exact",i.TEXT="text",i.NOT="not",i.ABOVE="above",i.BELOW="below",i.IN="in",i.NOT_IN="not-in",i.OF_TYPE="of-type",i.MISSING="missing",i.PRESENT="present",i.IDENTIFIER="identifier",i.ITERATE="iterate",i))(no||{});var ro=(i=>(i.READ="read",i.VREAD="vread",i.UPDATE="update",i.PATCH="patch",i.DELETE="delete",i.HISTORY="history",i.HISTORY_INSTANCE="history-instance",i.HISTORY_TYPE="history-type",i.HISTORY_SYSTEM="history-system",i.CREATE="create",i.SEARCH="search",i.SEARCH_TYPE="search-type",i.SEARCH_SYSTEM="search-system",i.SEARCH_COMPARTMENT="search-compartment",i.CAPABILITIES="capabilities",i.TRANSACTION="transaction",i.BATCH="batch",i.OPERATION="operation",i))(ro||{});function Re(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,i=>{let e=Math.random()*16|0;return(i==="x"?e:e&3|8).toString(16)})}var oo={CSS:"text/css",DICOM:"application/dicom",FAVICON:"image/vnd.microsoft.icon",FHIR_JSON:"application/fhir+json",FORM_URL_ENCODED:"application/x-www-form-urlencoded",HL7_V2:"x-application/hl7-v2+er7",HTML:"text/html",JAVASCRIPT:"text/javascript",JSON:"application/json",JSON_PATCH:"application/json-patch+json",PNG:"image/png",SCIM_JSON:"application/scim+json",SVG:"image/svg+xml",TEXT:"text/plain",TYPESCRIPT:"text/typescript",PING:"x-application/ping",XML:"text/xml",CDA_XML:"application/cda+xml"};var so;so=Symbol.toStringTag;var bo={Event:typeof globalThis.Event<"u"?globalThis.Event:void 0,ErrorEvent:void 0,CloseEvent:void 0};var Uo={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0,startClosed:!1,debug:!1};var Lo=oo.FHIR_JSON+", */*; q=0.1";var ao=(i=>(i.ClientCredentials="client_credentials",i.AuthorizationCode="authorization_code",i.RefreshToken="refresh_token",i.JwtBearer="urn:ietf:params:oauth:grant-type:jwt-bearer",i.TokenExchange="urn:ietf:params:oauth:grant-type:token-exchange",i))(ao||{}),co=(i=>(i.AccessToken="urn:ietf:params:oauth:token-type:access_token",i.RefreshToken="urn:ietf:params:oauth:token-type:refresh_token",i.IdToken="urn:ietf:params:oauth:token-type:id_token",i.Saml1Token="urn:ietf:params:oauth:token-type:saml1",i.Saml2Token="urn:ietf:params:oauth:token-type:saml2",i))(co||{}),uo=(i=>(i.ClientSecretBasic="client_secret_basic",i.ClientSecretPost="client_secret_post",i.ClientSecretJwt="client_secret_jwt",i.PrivateKeyJwt="private_key_jwt",i.None="none",i))(uo||{}),lo=(i=>(i.JwtBearer="urn:ietf:params:oauth:client-assertion-type:jwt-bearer",i))(lo||{});var Vo=[...si,"->","<<",">>","=="];var wo=Ze().registerInfix("->",{precedence:l.Arrow}).registerInfix(";",{precedence:l.Semicolon});var Mo=" ".repeat(2);var ko=[...si,"eq","ne","co"];var Bo=Ze();var po=(i=>(i[i.NONE=0]="NONE",i[i.ERROR=1]="ERROR",i[i.WARN=2]="WARN",i[i.INFO=3]="INFO",i[i.DEBUG=4]="DEBUG",i))(po||{});function Ne(i){if(!i)return;let e=i.substring(0,4),t="01",n="01";return i.length>=8&&(t=i.substring(4,6),n=i.substring(6,8)),`${e}-${t}-${n}`}function f(i){if(!i)return;let e=i.substring(0,4),t="01",n="01",r="00",o="00",s="00",c="Z";return i.length>=8&&(t=i.substring(4,6),n=i.substring(6,8)),i.length>=12&&(r=i.substring(8,10),o=i.substring(10,12)),i.length>=14&&(s=i.substring(12,14)),i.length>14&&(c=i.substring(14),c==="+0000"&&(c="Z")),`${e}-${t}-${n}T${r}:${o}:${s}${c}`}function V(i){if(i)return i.substring(0,10).replace(/-/g,"")}function T(i){if(!i)return;let[e,t]=i.split("T"),n=e.replaceAll("-",""),r=(t??"").replaceAll(/\.\d+/g,"").replaceAll(/:/g,"").replaceAll(/Z/g,"+0000");return`${n}${r}`}var De="1.3.6.1.4.1.19376.1.5.3.1.3.1";var ai="2.16.840.1.113883.1.3";var ci="2.16.840.1.113883.2.20.5.1",ui="2.16.840.1.113883.3.26.1.1";var li="2.16.840.1.113883.4.1",di="2.16.840.1.113883.4.3",pi="2.16.840.1.113883.4.6",hi="2.16.840.1.113883.4.9",fi="2.16.840.1.113883.5.1",ve="2.16.840.1.113883.5.4",Xe="2.16.840.1.113883.5.6",Je="2.16.840.1.113883.5.25",k="2.16.840.1.113883.6.1",_i="2.16.840.1.113883.6.12",mi="2.16.840.1.113883.6.24",Ei="2.16.840.1.113883.6.69",Ii="2.16.840.1.113883.6.88",w="2.16.840.1.113883.6.96",Ti="2.16.840.1.113883.6.101",Oi="2.16.840.1.113883.6.209",Ke="2.16.840.1.113883.6.238",Si="2.16.840.1.113883.6.345";var yi="2.16.840.1.113883.10.20.15.3.8";var et="2.16.840.1.113883.10.20.22.1.1";var tt="2.16.840.1.113883.10.20.22.1.2";var xe="2.16.840.1.113883.10.20.22.2.1.1";var z="2.16.840.1.113883.10.20.22.2.2",Z="2.16.840.1.113883.10.20.22.2.2.1";var it="2.16.840.1.113883.10.20.22.2.3.1";var Ci="2.16.840.1.113883.10.20.22.2.4.1";var Pe="2.16.840.1.113883.10.20.22.2.5.1";var be="2.16.840.1.113883.10.20.22.2.6.1";var B="2.16.840.1.113883.10.20.22.2.7.1";var gi="2.16.840.1.113883.10.20.22.2.8";var P="2.16.840.1.113883.10.20.22.2.10";var nt="2.16.840.1.113883.10.20.22.2.17";var Ue="2.16.840.1.113883.10.20.22.2.18";var Ai="2.16.840.1.113883.10.20.22.2.22.1";var Ri="2.16.840.1.113883.10.20.22.2.23";var Ni="2.16.840.1.113883.10.20.22.2.56";var Le="2.16.840.1.113883.10.20.22.2.58";var X="2.16.840.1.113883.10.20.22.2.60";var Ve="2.16.840.1.113883.10.20.22.2.65";var we="2.16.840.1.113883.10.20.22.2.500",J="2.16.840.1.113883.10.20.22.4.1",Di="2.16.840.1.113883.10.20.22.4.1.2",K="2.16.840.1.113883.10.20.22.4.2",vi="2.16.840.1.113883.10.20.22.4.2.2",rt="2.16.840.1.113883.10.20.22.4.3";var ee="2.16.840.1.113883.10.20.22.4.4",xi="2.16.840.1.113883.10.20.22.4.4.2";var ot="2.16.840.1.113883.10.20.22.4.7";var st="2.16.840.1.113883.10.20.22.4.8";var at="2.16.840.1.113883.10.20.22.4.9";var te="2.16.840.1.113883.10.20.22.4.12";var ie="2.16.840.1.113883.10.20.22.4.13";var ne="2.16.840.1.113883.10.20.22.4.14";var ct="2.16.840.1.113883.10.20.22.4.16";var Pi="2.16.840.1.113883.10.20.22.4.20";var ut="2.16.840.1.113883.10.20.22.4.23";var re="2.16.840.1.113883.10.20.22.4.26",bi="2.16.840.1.113883.10.20.22.4.26.2",oe="2.16.840.1.113883.10.20.22.4.27",Ui="2.16.840.1.113883.10.20.22.4.27.2";var lt="2.16.840.1.113883.10.20.22.4.30";var dt="2.16.840.1.113883.10.20.22.4.32";var Li="2.16.840.1.113883.10.20.22.4.37",Vi="2.16.840.1.113883.10.20.22.4.38",wi="2.16.840.1.113883.10.20.22.4.38.1";var pt="2.16.840.1.113883.10.20.22.4.44";var ht="2.16.840.1.113883.10.20.22.4.49";var ft="2.16.840.1.113883.10.20.22.4.52";var _t="2.16.840.1.113883.10.20.22.4.54";var Mi="2.16.840.1.113883.10.20.22.4.66";var ki="2.16.840.1.113883.10.20.22.4.67";var Bi="2.16.840.1.113883.10.20.22.4.69",Fi="2.16.840.1.113883.10.20.22.4.70";var Gi="2.16.840.1.113883.10.20.22.4.74";var Yi="2.16.840.1.113883.10.20.22.4.75";var se="2.16.840.1.113883.10.20.22.4.78",$i="2.16.840.1.113883.10.20.22.4.78.2";var ae="2.16.840.1.113883.10.20.22.4.85";var Hi="2.16.840.1.113883.10.20.22.4.86";var ji="2.16.840.1.113883.10.20.22.4.114";var qi="2.16.840.1.113883.10.20.22.4.119";var Wi="2.16.840.1.113883.10.20.22.4.121";var Qi="2.16.840.1.113883.10.20.22.4.130";var zi="2.16.840.1.113883.10.20.22.4.133";var Me="2.16.840.1.113883.10.20.22.4.147",Zi="2.16.840.1.113883.10.20.22.4.200",Xi="2.16.840.1.113883.10.20.22.4.201";var Ji="2.16.840.1.113883.10.20.22.4.244";var Ki="2.16.840.1.113883.10.20.22.4.250";var en="2.16.840.1.113883.10.20.22.4.406",tn="2.16.840.1.113883.10.20.22.4.407";var nn="2.16.840.1.113883.10.20.22.4.416";var mt="2.16.840.1.113883.10.20.22.4.500",rn="2.16.840.1.113883.10.20.22.4.501";var on="2.16.840.1.113883.10.20.22.4.503",sn="2.16.840.1.113883.10.20.22.4.504";var an="2.16.840.1.113883.10.20.22.4.506",cn="2.16.840.1.113883.10.20.22.4.507",un="2.16.840.1.113883.10.20.22.4.508";var ln="2.16.840.1.113883.10.20.22.4.512";var Et="2.16.840.1.113883.12.292",It="2.16.840.1.113883.3.3719";var m=class{constructor(e,t,n,r){this.systemName=e,this.ccdaSystemOid=t,this.fhirSystemUrl=n,this.entries=r,this.ccdaToFhirMap={},this.fhirToCcdaMap={};for(let o of r)this.ccdaToFhirMap[o.ccdaValue]||(this.ccdaToFhirMap[o.ccdaValue]=o),this.fhirToCcdaMap[o.fhirValue]||(this.fhirToCcdaMap[o.fhirValue]=o)}getEntryByFhir(e){return this.fhirToCcdaMap[e]}getEntryByCcda(e){return this.ccdaToFhirMap[e]}mapCcdaToFhir(e){return this.ccdaToFhirMap[e]?.fhirValue}mapCcdaToFhirWithDefault(e,t){return e?this.mapCcdaToFhir(e)??t:t}mapFhirToCcdaWithDefault(e,t){return e?this.mapFhirToCcda(e)??t:t}mapCcdaToFhirCodeableConcept(e){let t=this.ccdaToFhirMap[e];if(t)return{coding:[{system:this.fhirSystemUrl,code:t.fhirValue,display:t.displayName}],text:t.displayName}}mapFhirToCcda(e){if(e)return this.fhirToCcdaMap[e]?.ccdaValue}mapFhirToCcdaCode(e){if(!e)return;let t=this.fhirToCcdaMap[e];if(t)return{"@_code":t.ccdaValue,"@_displayName":t.displayName,"@_codeSystem":this.ccdaSystemOid,"@_codeSystemName":pe.getEntryByCcda(this.ccdaSystemOid)?.displayName}}},b="http:",ke=`${I}/CodeSystem/condition-clinical`,Ot=`${I}/CodeSystem/condition-verification`,ho=`${I}/CodeSystem/v3-LanguageAbilityMode`,fo=`${I}/CodeSystem/v3-LanguageAbilityProficiency`,_o=`${I}/CodeSystem/v3-Race`,St=`${I}/CodeSystem/condition-category`,Be=`${I}/CodeSystem/condition-ver-status`,ce=`${I}/CodeSystem/allergyintolerance-clinical`,Fe=`${I}/CodeSystem/allergyintolerance-verification`,yt=`${I}/CodeSystem/v3-ActCode`,Ct=`${I}/CodeSystem/v3-ParticipationType`,gt=`${I}/CodeSystem/diagnosis-role`,dn=`${I}/CodeSystem/v3-Confidentiality`,pn=`${I}/CodeSystem/observation-category`,hn=`${_}/fhir/ValueSet/address-use`,fn=`${_}/fhir/ValueSet/name-use`,_n=`${_}/fhir/ValueSet/administrative-gender`,mn=`${_}/fhir/ValueSet/contactentity-use`,En=`${_}/fhir/ValueSet/medicationrequest-status`,mo=`${_}/fhir/StructureDefinition/language-mode`,Eo=`${_}/fhir/StructureDefinition/language-proficiency`,Io=`${_}/fhir/us/core/StructureDefinition/us-core-patient`,ue=`${_}/fhir/us/core/StructureDefinition/us-core-race`,le=`${_}/fhir/us/core/StructureDefinition/us-core-ethnicity`,At=`${_}/fhir/us/core/StructureDefinition/us-core-condition`,Rt=`${_}/fhir/us/core/StructureDefinition/us-core-medicationrequest`,To=`${_}/cda/template`,In=`${b}//ncithesaurus-stage.nci.nih.gov`,Tn=`${_}/fhir/sid/us-ssn`,On=`${_}/fhir/sid/us-dln`,Sn=`${_}/fhir/sid/us-npi`,yn=`${b}//fdasis.nlm.nih.gov`,Cn=`${b}//nucc.org/provider-taxonomy`,gn=`${b}//va.gov/terminology/medrt`,An=`${b}//hl7.org/fhir/ndfrt`,Rn=`${b}//nucc.org/cvx`,Nn=`${_}/fhir/sid/cvx`,Nt=`${b}//www.w3.org/2001/XMLSchema-instance`,de="https://medplum.com/fhir/StructureDefinition/ccda-narrative-reference",pe=new m("System","","",[{ccdaValue:ci,fhirValue:"https://fhir.infoway-inforoute.ca/CodeSystem/pCLOCD",displayName:"pan-Canadian LOINC Observation Code Database (pCLOCD)"},{ccdaValue:ui,fhirValue:In,displayName:"NCI Thesaurus"},{ccdaValue:li,fhirValue:Tn,displayName:"SSN"},{ccdaValue:di,fhirValue:On,displayName:"DLN"},{ccdaValue:pi,fhirValue:Sn,displayName:"NPI"},{ccdaValue:hi,fhirValue:yn,displayName:"Unique Ingredient Identifier (UNII)"},{ccdaValue:k,fhirValue:Ae,displayName:"LOINC"},{ccdaValue:_i,fhirValue:Qt,displayName:"Current Procedural Terminology (CPT)"},{ccdaValue:mi,fhirValue:"urn:iso:std:iso:11073:10101",displayName:"Medical Device Communications (MDC)"},{ccdaValue:Ei,fhirValue:zt,displayName:"National Drug Code (NDC)"},{ccdaValue:Ii,fhirValue:Wt,displayName:"RxNorm"},{ccdaValue:w,fhirValue:je,displayName:"SNOMED CT"},{ccdaValue:Ti,fhirValue:Cn,displayName:"NUCC Health Care Provider Taxonomy"},{ccdaValue:Si,fhirValue:gn,displayName:"Medication Reference Terminology (MED-RT)"},{ccdaValue:Oi,fhirValue:An,displayName:"National Drug File Reference Terminology (NDF-RT)"},{ccdaValue:Et,fhirValue:Rn,displayName:"CVX"},{ccdaValue:Je,fhirValue:"Confidentiality",displayName:"Confidentiality"},{ccdaValue:Et,fhirValue:Nn,displayName:"Vaccine Administered Code Set (CVX)"}]);function F(i){if(i)return pe.mapCcdaToFhir(i)??`urn:oid:${i}`}function Dt(i){if(i)return i.startsWith("urn:oid:")?i.replace("urn:oid:",""):pe.mapFhirToCcda(i)}function d(i){if(!i?.coding)return;let e=Tt(i.coding[0]);if(i.coding.length>1){e.translation=[];for(let t=1;t<i.coding.length;t++)e.translation.push(Tt(i.coding[t]))}return e}function Tt(i){let e=i?.system?pe.getEntryByFhir(i.system):void 0,t=e?.ccdaValue,n=e?.displayName,r=i.system?.startsWith("urn:oid:")?i.system.replace("urn:oid:",""):void 0;return{"@_code":i.code,"@_displayName":i.display,"@_codeSystem":t??r,"@_codeSystemName":n}}function G(i){let e=d(i);if(e)return{"@_xsi:type":"CD",...e}}var vt=new m("Confidentiality",Je,dn,[{ccdaValue:"U",fhirValue:"U",displayName:"unrestricted"},{ccdaValue:"L",fhirValue:"L",displayName:"low"},{ccdaValue:"M",fhirValue:"M",displayName:"moderate"},{ccdaValue:"N",fhirValue:"N",displayName:"normal"},{ccdaValue:"R",fhirValue:"R",displayName:"restricted"},{ccdaValue:"V",fhirValue:"V",displayName:"very restricted"}]),he=new m("HumanNameUse","",fn,[{ccdaValue:"C",fhirValue:"usual",displayName:"Common/Called by"},{ccdaValue:"L",fhirValue:"official",displayName:"Legal"},{ccdaValue:"TEMP",fhirValue:"temp",displayName:"Temporary"},{ccdaValue:"P",fhirValue:"nickname",displayName:"Nickname"},{ccdaValue:"ANON",fhirValue:"anonymous",displayName:"Anonymous"},{ccdaValue:"L",fhirValue:"maiden",displayName:"Maiden"},{ccdaValue:"L",fhirValue:"old",displayName:"Old"}]),xt=new m("Gender","",_n,[{ccdaValue:"F",fhirValue:"female",displayName:"Female"},{ccdaValue:"M",fhirValue:"male",displayName:"Male"},{ccdaValue:"UN",fhirValue:"unknown",displayName:"Unknown"},{ccdaValue:"UN",fhirValue:"other",displayName:"Other"}]),fe=new m("AddressUse","",hn,[{ccdaValue:"HP",fhirValue:"home",displayName:"Home"},{ccdaValue:"WP",fhirValue:"work",displayName:"Work"}]),_e=new m("TelecomUse","",mn,[{ccdaValue:"WP",fhirValue:"work",displayName:"Work"},{ccdaValue:"HP",fhirValue:"home",displayName:"Home"}]),me=new m("AllergyStatus","",Fe,[{ccdaValue:"unconfirmed",fhirValue:"unconfirmed",displayName:"Unconfirmed"},{ccdaValue:"provisional",fhirValue:"provisional",displayName:"Provisional"},{ccdaValue:"differential",fhirValue:"differential",displayName:"Differential"},{ccdaValue:"confirmed",fhirValue:"confirmed",displayName:"Confirmed"},{ccdaValue:"refuted",fhirValue:"refuted",displayName:"Refuted"},{ccdaValue:"entered-in-error",fhirValue:"entered-in-error",displayName:"Entered in Error"},{ccdaValue:"unknown",fhirValue:"unknown",displayName:"Unknown"}]),Pt=new m("AllergyCategory",w,ce,[{ccdaValue:"414285001",fhirValue:"food",displayName:"Allergy to food (finding)"},{ccdaValue:"419511003",fhirValue:"medication",displayName:"Propensity to adverse reactions to drug (finding)"},{ccdaValue:"426232007",fhirValue:"environment",displayName:"Environmental allergy (finding)"},{ccdaValue:"418038007",fhirValue:"biologic",displayName:"Propensity to adverse reactions to substance (finding)"}]),Ee=new m("AllergySeverity",je,ce,[{ccdaValue:"255604002",fhirValue:"mild",displayName:"Mild"},{ccdaValue:"6736007",fhirValue:"moderate",displayName:"Moderate"},{ccdaValue:"24484000",fhirValue:"severe",displayName:"Severe"}]),Ie=new m("ProblemStatus","",Be,[{ccdaValue:"active",fhirValue:"active",displayName:"Active"},{ccdaValue:"inactive",fhirValue:"inactive",displayName:"Inactive"},{ccdaValue:"resolved",fhirValue:"inactive",displayName:"Resolved"},{ccdaValue:"remission",fhirValue:"inactive",displayName:"In Remission"},{ccdaValue:"relapse",fhirValue:"active",displayName:"Relapse"},{ccdaValue:"resolved relapse",fhirValue:"inactive",displayName:"Resolved Relapse"},{ccdaValue:"aborted",fhirValue:"aborted",displayName:"Aborted"}]),Te=new m("ImmunizationStatus","","",[{ccdaValue:"completed",fhirValue:"completed",displayName:"Completed"},{ccdaValue:"nullified",fhirValue:"entered-in-error",displayName:"Nullified"},{ccdaValue:"aborted",fhirValue:"not-done",displayName:"Aborted"},{ccdaValue:"cancelled",fhirValue:"not-done",displayName:"Cancelled"},{ccdaValue:"obsolete",fhirValue:"not-done",displayName:"Obsolete"}]),bt=new m("EncounterStatus","","",[{ccdaValue:"active",fhirValue:"in-progress",displayName:"In Progress"},{ccdaValue:"completed",fhirValue:"finished",displayName:"Finished"},{ccdaValue:"aborted",fhirValue:"cancelled",displayName:"Cancelled"},{ccdaValue:"cancelled",fhirValue:"cancelled",displayName:"Cancelled"},{ccdaValue:"unknown",fhirValue:"unknown",displayName:"Unknown"}]),Ut=new m("ProcedureStatus","","",[{ccdaValue:"completed",fhirValue:"completed",displayName:"Completed"},{ccdaValue:"aborted",fhirValue:"stopped",displayName:"Stopped"},{ccdaValue:"cancelled",fhirValue:"not-done",displayName:"Not Done"},{ccdaValue:"new",fhirValue:"not-done",displayName:"Draft"},{ccdaValue:"unknown",fhirValue:"unknown",displayName:"Unknown"}]),Oe=new m("MedicationStatus","",En,[{ccdaValue:"active",fhirValue:"active",displayName:"Active"},{ccdaValue:"completed",fhirValue:"completed",displayName:"Completed"},{ccdaValue:"aborted",fhirValue:"stopped",displayName:"Stopped"},{ccdaValue:"cancelled",fhirValue:"cancelled",displayName:"Cancelled"},{ccdaValue:"aborted",fhirValue:"entered-in-error",displayName:"Entered in Error"},{ccdaValue:"active",fhirValue:"draft",displayName:"Draft"},{ccdaValue:"cancelled",fhirValue:"unknown",displayName:"Unknown"},{ccdaValue:"nullified",fhirValue:"cancelled",displayName:"Nullified"},{ccdaValue:"obsolete",fhirValue:"cancelled",displayName:"Obsolete"}]),Lt=new m("ObservationCategory","",pn,[{ccdaValue:Vi,fhirValue:"social-history",displayName:"Social History"},{ccdaValue:wi,fhirValue:"social-history",displayName:"Social History V2"},{ccdaValue:se,fhirValue:"social-history",displayName:"Smoking Status"},{ccdaValue:$i,fhirValue:"social-history",displayName:"Current Smoking Status"},{ccdaValue:ae,fhirValue:"social-history",displayName:"Tobacco Use"},{ccdaValue:on,fhirValue:"social-history",displayName:"Basic Occupation"},{ccdaValue:sn,fhirValue:"social-history",displayName:"Basic Industry"},{ccdaValue:rn,fhirValue:"social-history",displayName:"Sexual Orientation"},{ccdaValue:cn,fhirValue:"social-history",displayName:"Sex Observation"},{ccdaValue:Zi,fhirValue:"social-history",displayName:"Gender Identity"},{ccdaValue:Xi,fhirValue:"social-history",displayName:"Gender Identity V2"},{ccdaValue:yi,fhirValue:"social-history",displayName:"Pregnancy Status"},{ccdaValue:an,fhirValue:"social-history",displayName:"Tribal Affiliation"},{ccdaValue:oe,fhirValue:"vital-signs",displayName:"Vital Signs Observation"},{ccdaValue:Ui,fhirValue:"vital-signs",displayName:"Vital Signs Observation V2"},{ccdaValue:re,fhirValue:"vital-signs",displayName:"Vital Signs Organizer"},{ccdaValue:bi,fhirValue:"vital-signs",displayName:"Vital Signs Organizer V2"},{ccdaValue:ln,fhirValue:"vital-signs",displayName:"Average Blood Pressure Organizer"},{ccdaValue:K,fhirValue:"laboratory",displayName:"Result Observation"},{ccdaValue:vi,fhirValue:"laboratory",displayName:"Result Observation V2"},{ccdaValue:en,fhirValue:"laboratory",displayName:"Laboratory Battery (ID)"},{ccdaValue:tn,fhirValue:"laboratory",displayName:"Laboratory Observation (ID)"},{ccdaValue:nn,fhirValue:"laboratory",displayName:"Laboratory Result Organizer (ID)"},{ccdaValue:J,fhirValue:"laboratory",displayName:"Result Organizer"},{ccdaValue:Di,fhirValue:"laboratory",displayName:"Result Organizer V2"},{ccdaValue:Bi,fhirValue:"survey",displayName:"Assessment Scale Observation"},{ccdaValue:Hi,fhirValue:"survey",displayName:"Assessment Scale Supporting Observation"},{ccdaValue:Gi,fhirValue:"survey",displayName:"Cognitive Status Result Observation"},{ccdaValue:Yi,fhirValue:"survey",displayName:"Cognitive Status Result Organizer"},{ccdaValue:ki,fhirValue:"survey",displayName:"Functional Status Result Observation"},{ccdaValue:Mi,fhirValue:"survey",displayName:"Functional Status Result Organizer"},{ccdaValue:ie,fhirValue:"exam",displayName:"Procedure Activity Observation"},{ccdaValue:ee,fhirValue:"exam",displayName:"Problem Observation"},{ccdaValue:xi,fhirValue:"exam",displayName:"Problem Observation V2"},{ccdaValue:Fi,fhirValue:"exam",displayName:"Pressure Ulcer Observation"},{ccdaValue:ji,fhirValue:"exam",displayName:"Wound Observation"},{ccdaValue:zi,fhirValue:"exam",displayName:"Wound Measurements Observation"},{ccdaValue:B,fhirValue:"exam",displayName:"Procedure Section"},{ccdaValue:un,fhirValue:"therapy",displayName:"Medication Adherence"},{ccdaValue:Qi,fhirValue:"therapy",displayName:"Nutrition Recommendations"},{ccdaValue:Ji,fhirValue:"therapy",displayName:"Diet Statement (Nutrition)"},{ccdaValue:Ki,fhirValue:"therapy",displayName:"Monitoring, Evaluation and Outcome (Nutrition)"}]);var Y=require("fast-xml-parser");var Oo=["ClinicalDocument.recordTarget",".id",".templateId",".name",".addr",".telecom",".streetAddressLine",".author",".effectiveTime","name.given","name.suffix","name.prefix","patient.raceCode","patient.ethnicGroupCode","patient.languageCommunication","component.structuredBody.component","component.structuredBody.component.section","component.section","component.observation","component.act","code.translation","section.entry","entry.act","entry.organizer","entry.substanceAdministration","entry.observation","entry.encounter","entry.procedure","encounter.performer","encounter.participant","encounter.entryRelationship","entryRelationship.observation","entryRelationship.substanceAdministration","entryRelationship.act","organizer.component","substanceAdministration.consumable.manufacturedProduct","substanceAdministration.entryRelationship","substanceAdministration.performer","act.entryRelationship","act.performer","observation.participant","observation.entryRelationship","observation.referenceRange","consumable.manufacturedProduct","manufacturedProduct.manufacturedMaterial","manufacturedProduct.manufacturerOrganization","manufacturedProduct.manufacturedLabeledDrug","manufacturedMaterial.code","manufacturedMaterial.lotNumberText"];function So(i){return new Y.XMLParser({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1,isArray:(n,r,o,s)=>Oo.some(c=>r.endsWith(c))}).parse(i).ClinicalDocument}function yo(i){return new Y.XMLBuilder({ignoreAttributes:!1,attributeNamePrefix:"@_",format:!0,suppressBooleanAttributes:!1,suppressEmptyNode:!0}).build({"?xml":{"@_version":"1.0","@_encoding":"UTF-8"},"?xml-stylesheet":{"@_type":"text/xsl","@_href":"CDA.xsl"},ClinicalDocument:{"@_xmlns":"urn:hl7-org:v3","@_xmlns:xsi":Nt,"@_xmlns:voc":"urn:hl7-org:v3/voc","@_xmlns:sdtc":"urn:hl7-org:sdtc",...i}})}function Vt(i){return new Y.XMLParser({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1}).parse(i)}function wt(i){return i?typeof i=="string"?i:new Y.XMLBuilder({ignoreAttributes:!1,attributeNamePrefix:"@_",format:!1,suppressBooleanAttributes:!1,suppressEmptyNode:!0}).build(i).split(`
|
|
2
|
-
`).map(n=>n.trim()).join(""):""}function Co(i){return new Mt(i).convert()}var Mt=class{constructor(e){this.resources=[];this.ccda=e}convert(){return this.processHeader(),{resourceType:"Bundle",type:"document",entry:[{resource:this.createComposition()},...this.patient?[{resource:this.patient}]:[],...this.resources.map(t=>({resource:t}))]}}processHeader(){let e=this.ccda.recordTarget?.[0]?.patientRole;e&&(this.patient=this.createPatient(e))}createPatient(e){let t=e.patient,n=[];return t.raceCode&&t.raceCode.length>0&&n.push({url:ue,extension:t.raceCode.map(r=>({url:"ombCategory",valueCoding:this.mapCodeToCoding(r)}))}),t.ethnicGroupCode&&t.ethnicGroupCode.length>0&&n.push({url:le,extension:t.ethnicGroupCode.map(r=>({url:"ombCategory",valueCoding:this.mapCodeToCoding(r)}))}),{resourceType:"Patient",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),name:this.mapCcdaNameArrayFhirHumanNameArray(t.name),gender:this.mapGenderCode(t.administrativeGenderCode?.["@_code"]),birthDate:Ne(t.birthTime?.["@_value"]),address:this.mapAddresses(e.addr),telecom:this.mapTelecom(e.telecom),extension:n.length>0?n:void 0}}mapId(e){let t=e?.find(n=>!n["@_extension"]&&n["@_root"]&&Qe(n["@_root"]));return t?t["@_root"]:Re()}mapIdentifiers(e){if(!e)return;let t=[];for(let n of e)!n["@_extension"]&&n["@_root"]&&Qe(n["@_root"])||t.push({system:F(n["@_root"]),value:n["@_extension"]});return t}mapCcdaNameArrayFhirHumanNameArray(e){return e?.map(t=>this.mapCcdaNameToFhirHumanName(t)).filter(Boolean)}mapCcdaNameToFhirHumanName(e){if(!e)return;let t={},n=e["@_use"]?he.mapCcdaToFhir(e["@_use"]):void 0;return n&&(t.use=n),e.prefix&&(t.prefix=e.prefix.map(Se)?.filter(Boolean)),e.family&&(t.family=Se(e.family)),e.given&&(t.given=e.given.map(Se)?.filter(Boolean)),e.suffix&&(t.suffix=e.suffix.map(Se)?.filter(Boolean)),t}mapAddresses(e){if(!(!e||e.length===0||e.every(t=>t["@_nullFlavor"]==="UNK")))return e?.map(t=>({"@_use":t["@_use"]?fe.mapCcdaToFhir(t["@_use"]):void 0,line:t.streetAddressLine,city:t.city,state:t.state,postalCode:t.postalCode,country:t.country}))}mapTelecom(e){if(!(!e||e.length===0||e.every(t=>t["@_nullFlavor"]==="UNK")))return e?.map(t=>({"@_use":t["@_use"]?_e.mapCcdaToFhir(t["@_use"]):void 0,system:this.getTelecomSystem(t["@_value"]),value:this.getTelecomValue(t["@_value"])}))}createComposition(){let e=this.ccda.component?.structuredBody?.component||[],t=[];for(let n of e)for(let r of n.section){let o=this.processSection(r);t.push({title:r.title,code:this.mapCode(r.code),text:{status:"generated",div:`<div xmlns="http://www.w3.org/1999/xhtml">${wt(r.text)}</div>`},entry:o.map(h)}),this.resources.push(...o)}return{resourceType:"Composition",id:this.mapId(this.ccda.id),language:this.ccda.languageCode?.["@_code"],status:"final",type:this.ccda.code?this.mapCode(this.ccda.code):{coding:[{system:Ae,code:"34133-9"}]},confidentiality:this.ccda.confidentialityCode?.["@_code"],author:this.ccda.author?.[0]?[this.mapAuthorToReference(this.ccda.author?.[0])]:[{display:"Medplum"}],custodian:this.mapCustodianToReference(this.ccda.custodian),event:this.mapDocumentationOfToEvent(this.ccda.documentationOf),date:f(this.ccda.effectiveTime?.[0]?.["@_value"])??new Date().toISOString(),title:this.ccda.title??"Medical Summary",section:t}}processSection(e){let t=[];if(e.entry)for(let n of e.entry)this.processEntry(e,n,t);return t}processEntry(e,t,n){for(let r of t.act??[]){let o=this.processAct(e,r);o&&n.push(o)}for(let r of t.substanceAdministration??[]){let o=this.processSubstanceAdministration(e,r);o&&n.push(o)}for(let r of t.organizer??[])n.push(this.processOrganizer(e,r));for(let r of t.observation??[])n.push(this.processObservation(e,r));for(let r of t.encounter??[])n.push(this.processEncounter(e,r));for(let r of t.procedure??[])n.push(this.processProcedure(e,r))}processAct(e,t){let n=e.templateId[0]["@_root"];switch(n){case be:return this.processAllergyIntoleranceAct(t);case Pe:return this.processConditionAct(t);case P:return this.processCarePlanAct(t);case Le:return this.processConditionAct(t);case B:return this.processProcedureAct(t);case De:return;case Ve:return;case Ue:return;default:throw new Error("Unhandled act templateId: "+n)}}processAllergyIntoleranceAct(e){let t=e.entryRelationship?.find(s=>s["@_typeCode"]==="SUBJ")?.observation?.[0];if(!t)return;let n={resourceType:"AllergyIntolerance",id:this.mapId(e.id),clinicalStatus:this.createClinicalStatus(e),verificationStatus:this.createVerificationStatus(),type:"allergy",category:["food"],patient:h(this.patient),recorder:this.mapAuthorToReference(e.author?.[0]),recordedDate:this.mapEffectiveTimeToDateTime(e.effectiveTime?.[0]),onsetDateTime:this.mapEffectiveTimeToDateTime(t.effectiveTime?.[0])};t.value?.["@_code"]==="414285001"&&(n.category=["food"]),n.extension=this.mapTextReference(t.text);let r=t.participant?.[0]?.participantRole?.playingEntity?.code;r&&(n.code=this.mapCode(r),n.code&&r.originalText?.reference?.["@_value"]&&(n.code.extension=this.mapTextReference(r.originalText)));let o=t.entryRelationship?.find(s=>s["@_typeCode"]==="MFST")?.observation;return o&&(n.reaction=o.map(s=>this.processReaction(s))),n.asserter=this.mapAuthorToReference(t.author?.[0]),n}processConditionAct(e){let t=e.entryRelationship?.find(r=>r["@_typeCode"]==="SUBJ")?.observation?.[0];if(!t)return;let n={resourceType:"Condition",id:this.mapId(e.id),identifier:this.concatArrays(this.mapIdentifiers(e.id),this.mapIdentifiers(t.id)),meta:{profile:[At]},clinicalStatus:{coding:[{system:ke,code:Ie.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active")}]},verificationStatus:{coding:[{system:Ot,code:"confirmed"}]},category:[{coding:[{system:St,code:"problem-list-item",display:"Problem List Item"}]}],code:this.mapCode(t.value),subject:h(this.patient),onsetDateTime:f(t.effectiveTime?.[0]?.low?.["@_value"]),abatementDateTime:f(t.effectiveTime?.[0]?.high?.["@_value"]),recordedDate:this.mapEffectiveTimeToDateTime(e.effectiveTime?.[0]),recorder:this.mapAuthorToReference(t.author?.[0]),asserter:this.mapAuthorToReference(t.author?.[0])};return n.extension=this.mapTextReference(t.text),n}processCarePlanAct(e){return{resourceType:"CarePlan",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"active",intent:"plan",title:"CARE PLAN",category:e.code?[this.mapCode(e.code)]:void 0,subject:h(this.patient),description:Se(e.text)}}processProcedureAct(e){return{resourceType:"Procedure",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"completed",code:this.mapCode(e.code),subject:h(this.patient),performedDateTime:f(e.effectiveTime?.[0]?.["@_value"]),recorder:this.mapAuthorToReference(e.author?.[0]),asserter:this.mapAuthorToReference(e.author?.[0]),extension:this.mapTextReference(e.text)}}processSubstanceAdministration(e,t){let n=e.templateId[0]["@_root"];switch(n){case xe:case P:return this.processMedicationSubstanceAdministration(t);case z:case Z:return this.processImmunizationSubstanceAdministration(t);default:throw new Error("Unhandled substance administration templateId: "+n)}}processMedicationSubstanceAdministration(e){let t=this.mapId(e.id),n=e.consumable?.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.code?.[0],r=e.routeCode,o=e.doseQuantity,s=e.consumable?.manufacturedProduct?.[0]?.manufacturerOrganization?.[0],c=e.entryRelationship?.find(E=>E.substanceAdministration?.[0]?.templateId?.[0]?.["@_root"]===Me)?.substanceAdministration?.[0],p,N;return s?p={resourceType:"Medication",id:"med-"+t,code:this.mapCode(n),extension:this.mapTextReference(n?.originalText),manufacturer:s?{identifier:{value:s.id?.[0]?.["@_root"]},display:s.name?.[0]}:void 0}:N={...this.mapCode(n),extension:this.mapTextReference(n?.originalText)},{resourceType:"MedicationRequest",id:t,contained:p?[p]:void 0,meta:{profile:[Rt]},extension:this.mapTextReference(e.text),status:Oe.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active"),intent:"order",medicationReference:p?{reference:"#med-"+t}:void 0,medicationCodeableConcept:N,subject:h(this.patient),authoredOn:f(e.author?.[0]?.time?.["@_value"]),dispenseRequest:e.effectiveTime?.[0]?{validityPeriod:{start:f(e.effectiveTime?.[0]?.low?.["@_value"]),end:f(e.effectiveTime?.[0]?.high?.["@_value"])}}:void 0,dosageInstruction:[{text:typeof e.text=="string"?e.text:void 0,extension:this.mapTextReference(c?.text),route:r?this.mapCode(r):void 0,timing:{repeat:e.effectiveTime?.[1]?.period?{period:Number(e.effectiveTime?.[1]?.period["@_value"]),periodUnit:e.effectiveTime?.[1]?.period["@_unit"]}:void 0},doseAndRate:o?[{doseQuantity:{system:He,value:Number(o["@_value"]),code:"[IU]",unit:"[IU]"}}]:void 0}]}}processImmunizationSubstanceAdministration(e){let t=e.consumable;if(!t)return;let n={resourceType:"Immunization",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:Te.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"completed"),vaccineCode:this.mapCode(t.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.code?.[0]),patient:h(this.patient),occurrenceDateTime:f(e.effectiveTime?.[0]?.["@_value"]),lotNumber:t.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.lotNumberText?.[0]};return e.performer&&(n.performer=this.mapCcdaPerformerArrayToImmunizationPerformerArray(e.performer)),n.extension=this.mapTextReference(e.text),e.consumable?.manufacturedProduct?.[0]?.manufacturerOrganization?.[0]&&(n.manufacturer={display:e.consumable?.manufacturedProduct?.[0]?.manufacturerOrganization?.[0]?.name?.[0]}),n}processReaction(e){let t={id:this.mapId(e.id),manifestation:[this.mapCode(e.value)],onset:f(e.effectiveTime?.[0]?.low?.["@_value"])};return this.processSeverity(e,t),t.manifestation&&t.manifestation.length>0&&e.text?.reference?.["@_value"]&&(t.manifestation[0].extension=this.mapTextReference(e.text)),t}processSeverity(e,t){let n=e.entryRelationship?.find(o=>o["@_typeCode"]==="SUBJ")?.observation?.[0];if(!n)return;let r=n.value?.["@_code"];r&&(t.severity=Ee.mapCcdaToFhir(r)),t.extension=this.mapTextReference(n.text)}mapEffectiveTimeToDateTime(e){if(e?.["@_value"])return f(e["@_value"]);if(e?.low?.["@_value"])return f(e.low["@_value"])}mapEffectiveTimeToPeriod(e){if(!e?.["@_value"]&&(e?.low||e?.high))return{start:f(e?.low?.["@_value"]),end:f(e?.high?.["@_value"])}}mapGenderCode(e){return e?{F:"female",M:"male",UN:"unknown"}[e]:void 0}getTelecomSystem(e){if(e)return e.startsWith("tel:")?"phone":e.startsWith("mailto:")?"email":"other"}getTelecomValue(e){if(e)return e.replace(/^(tel:|mailto:)/,"")}mapCode(e){if(!e)return;let t={coding:[{system:F(e["@_codeSystem"]),code:e["@_code"],display:e["@_displayName"]}],text:e["@_displayName"]};if(e.translation)for(let n of e.translation)t.coding.push({system:F(n["@_codeSystem"]),code:n["@_code"],display:n["@_displayName"]});return t}mapCodeToCoding(e){if(e)return{system:F(e["@_codeSystem"]),code:e["@_code"],display:e["@_displayName"]}}createClinicalStatus(e){return{coding:[{system:ce,code:me.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active")}]}}createVerificationStatus(){return{coding:[{system:Fe,code:"confirmed"}]}}mapAuthorToReference(e){if(!e)return;let t={resourceType:"Practitioner",id:this.mapId(e.assignedAuthor?.id),identifier:this.mapIdentifiers(e.assignedAuthor?.id),name:this.mapCcdaNameArrayFhirHumanNameArray(e.assignedAuthor?.assignedPerson?.name),address:this.mapAddresses(e.assignedAuthor?.addr),telecom:this.mapTelecom(e.assignedAuthor?.telecom),qualification:e.assignedAuthor?.code?[this.mapCode(e.assignedAuthor?.code)]:void 0};return this.resources.push(t),h(t)}mapAssignedEntityToReference(e){if(!e)return;let t=e.assignedPerson,n=e.representedOrganization,r={resourceType:"Practitioner",id:this.mapId(e?.id),identifier:this.mapIdentifiers(e?.id),name:this.mapCcdaNameArrayFhirHumanNameArray(t?.name),address:this.mapAddresses(e?.addr),telecom:this.mapTelecom(e?.telecom)};this.resources.push(r);let o={resourceType:"Organization",id:this.mapId(e?.id),identifier:this.mapIdentifiers(n?.id),name:n?.name?.[0],address:this.mapAddresses(n?.addr)};this.resources.push(o);let s={resourceType:"PractitionerRole",id:this.mapId(e?.id),practitioner:h(r),organization:h(o)};return this.resources.push(s),h(s)}mapCustodianToReference(e){if(!e)return;let t={resourceType:"Organization",id:this.mapId(e.assignedCustodian.representedCustodianOrganization.id),identifier:this.mapIdentifiers(e.assignedCustodian.representedCustodianOrganization.id),name:e.assignedCustodian.representedCustodianOrganization.name?.[0],address:this.mapAddresses(e.assignedCustodian.representedCustodianOrganization.addr),telecom:this.mapTelecom(e.assignedCustodian.representedCustodianOrganization.telecom)};return this.resources.push(t),h(t)}mapDocumentationOfToEvent(e){if(!e)return;let t=e.serviceEvent;if(t)return[{code:t.code?[this.mapCode(t.code)]:void 0,period:this.mapEffectiveTimeToPeriod(t.effectiveTime?.[0])}]}concatArrays(e,t){return e?t?[...e,...t]:e:t}mapCcdaPerformerArrayToImmunizationPerformerArray(e){let t=[];for(let n of e){let r=n.assignedEntity,o=this.mapAssignedEntityToReference(r);o&&t.push({actor:o})}return t}processOrganizer(e,t){return e.templateId[0]["@_root"]===we?this.processCareTeamOrganizer(t):this.processVitalsOrganizer(t)}processCareTeamOrganizer(e){let t=[];if(e.component)for(let r of e.component){let o=this.processCareTeamMember(r);o&&t.push(o)}return{resourceType:"CareTeam",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),participant:t.length>0?t:void 0}}processCareTeamMember(e){let t=e.act?.[0];if(!t)return;let n=t.performer?.[0];if(n)return{role:n.functionCode?[this.mapCode(n.functionCode)]:void 0,member:this.mapAssignedEntityToReference(n.assignedEntity),period:this.mapEffectiveTimeToPeriod(t.effectiveTime?.[0])}}processVitalsOrganizer(e){let t={resourceType:"Observation",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"final",category:this.mapObservationTemplateIdToObservationCategory(e.templateId),code:this.mapCode(e.code),subject:h(this.patient)};if(e.effectiveTime?.[0]?.["@_value"]&&(t.effectiveDateTime=f(e.effectiveTime?.[0]?.["@_value"])),e.component){let n=[];for(let r of e.component)n.push(...this.processVitalsComponent(r));n.length>0&&(t.hasMember=n)}return t}processVitalsComponent(e){let t=[];if(e.observation)for(let n of e.observation){let r=this.processVitalsObservation(n);t.push(h(r)),this.resources.push(r)}return t}processObservation(e,t){let n=t.templateId[0]["@_root"];if(n===X||n===Wi)return this.processGoalObservation(t);switch(e.templateId[0]["@_root"]){case P:case X:return this.processGoalObservation(t);default:return this.processVitalsObservation(t)}}processGoalObservation(e){let t={resourceType:"Goal",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),lifecycleStatus:this.mapGoalLifecycleStatus(e),description:this.mapCode(e.code),subject:h(this.patient),startDate:Ne(e.effectiveTime?.[0]?.["@_value"])};return t.target=e.entryRelationship?.map(n=>({measure:this.mapCode(n.act?.[0]?.code),detailCodeableConcept:this.mapCode(n.act?.[0]?.code),dueDate:f(n.act?.[0]?.effectiveTime?.[0]?.low?.["@_value"])})),t.extension=this.mapTextReference(e.text),t}mapGoalLifecycleStatus(e){return{active:"active",completed:"completed",cancelled:"cancelled",aborted:"cancelled"}[e.statusCode["@_code"]??"active"]}processVitalsObservation(e){let t={resourceType:"Observation",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"final",category:this.mapObservationTemplateIdToObservationCategory(e.templateId),code:this.mapCode(e.code),subject:h(this.patient),referenceRange:this.mapReferenceRangeArray(e.referenceRange),performer:e.author?.map(n=>this.mapAuthorToReference(n)).filter(Boolean)};if(e.value?.["@_xsi:type"])switch(e.value["@_xsi:type"]){case"PQ":case"CO":t.valueQuantity={value:e.value["@_value"]?parseFloat(e.value["@_value"]):void 0,unit:e.value["@_unit"],system:He,code:e.value["@_unit"]};break;case"CD":case"CE":t.valueCodeableConcept=this.mapCode(e.value);break;case"ST":t.valueString=e.value["#text"]??"";break;default:console.warn(`Unhandled observation value type: ${e.value["@_xsi:type"]}`)}return e.effectiveTime?.[0]?.["@_value"]&&(t.effectiveDateTime=f(e.effectiveTime?.[0]?.["@_value"])),t.extension=this.mapTextReference(e.text),t}mapObservationTemplateIdToObservationCategory(e){if(!e)return;let t=new Set,n=[];for(let r of e){let o=Lt.mapCcdaToFhirCodeableConcept(r["@_root"]);o?.coding?.[0]?.code&&!t.has(o.coding[0].code)&&(t.add(o.coding[0].code),n.push(o))}return Array.from(n.values())}mapReferenceRangeArray(e){if(!(!e||e.length===0))return e.map(t=>this.mapReferenceRange(t)).filter(Boolean)}mapReferenceRange(e){if(!e)return;let t=e.observationRange;if(!t)return;let n={};return n.extension=this.mapTextReference(t.text),n}processEncounter(e,t){let n={resourceType:"Encounter",id:this.mapId(t.id),identifier:this.mapIdentifiers(t.id),status:bt.mapCcdaToFhirWithDefault(t.statusCode?.["@_code"],"unknown"),class:{system:yt,code:t.code?.["@_code"]??"AMB",display:t.code?.["@_displayName"]??"Ambulatory"},type:t.code?[this.mapCode(t.code)]:void 0,subject:h(this.patient),period:this.mapEffectiveTimeToPeriod(t.effectiveTime?.[0])};if(t.performer&&(n.participant=t.performer.map(r=>({type:[{coding:[{system:Ct,code:r["@_typeCode"]??"PPRF",display:"Primary Performer"}]}],individual:this.mapAssignedEntityToReference(r.assignedEntity)}))),t.entryRelationship){let r=t.entryRelationship.filter(o=>o["@_typeCode"]==="RSON").map(o=>{let s=o.observation?.[0];if(!s)return;let c={resourceType:"Condition",id:this.mapId(s.id),identifier:this.mapIdentifiers(s.id),clinicalStatus:{coding:[{system:ke,code:"active"}]},verificationStatus:{coding:[{system:Be,code:"confirmed"}]},code:this.mapCode(s.value),subject:h(this.patient),onsetDateTime:f(s.effectiveTime?.[0]?.low?.["@_value"])};return this.resources.push(c),{condition:h(c),use:{coding:[{system:gt,code:"AD",display:"Admission diagnosis"}]}}}).filter(Boolean);r.length>0&&(n.diagnosis=r)}return n.extension=this.mapTextReference(t.text),n}processProcedure(e,t){return{resourceType:"Procedure",id:this.mapId(t.id),identifier:this.mapIdentifiers(t.id),status:Ut.mapCcdaToFhirWithDefault(t.statusCode?.["@_code"],"completed"),code:this.mapCode(t.code),subject:h(this.patient),performedPeriod:this.mapEffectiveTimeToPeriod(t.effectiveTime?.[0]),bodySite:t.targetSiteCode?[this.mapCode(t.targetSiteCode)]:void 0,extension:this.mapTextReference(t.text)}}mapTextReference(e){if(!(!e||typeof e!="object")&&e?.reference?.["@_value"])return[{url:de,valueString:e.reference?.["@_value"]}]}};function Se(i){if(i){if(typeof i=="string")return i;if(typeof i=="object"&&"#text"in i)return i["#text"]}}var kt=[{"@_root":et,"@_extension":"2015-08-01"},{"@_root":et},{"@_root":tt,"@_extension":"2015-08-01"},{"@_root":tt}],Dn=[{"@_root":be,"@_extension":"2015-08-01"}],vn=[{"@_root":xe,"@_extension":"2014-06-09"}],xn=[{"@_root":Pe,"@_extension":"2015-08-01"}],Ge=[{"@_root":z},{"@_root":z,"@_extension":"2015-08-01"},{"@_root":Z},{"@_root":Z,"@_extension":"2015-08-01"}],Pn=[{"@_root":Ci,"@_extension":"2015-08-01"}],bn=[{"@_root":nt},{"@_root":nt,"@_extension":"2015-08-01"}],Un=[{"@_root":B,"@_extension":"2014-06-09"}],go=[{"@_root":P,"@_extension":"2014-06-09"}],Ao=[{"@_root":it,"@_extension":"2015-08-01"}],Ln=[{"@_root":it,"@_extension":"2015-08-01"}],Vn=[{"@_root":Ri,"@_extension":"2015-08-01"}],wn=[{"@_root":gi}],Mn=[{"@_root":P},{"@_root":P,"@_extension":"2014-06-09"}],kn=[{"@_root":Ai,"@_extension":"2015-08-01"}],Bn=[{"@_root":X}],Fn=[{"@_root":Le,"@_extension":"2015-08-01"}],Gn=[{"@_root":De,"@_extension":"2014-06-09"}],Yn=[{"@_root":Ni,"@_extension":"2015-08-01"}],$n=[{"@_root":Ve,"@_extension":"2016-11-01"}],Hn=[{"@_root":we,"@_extension":"2022-06-01"}],jn=[{"@_root":Ue,"@_extension":"2015-08-01"}],Bt={"48765-2":Dn,"10160-0":vn,"11450-4":xn,"11369-6":Ge,"11348-0":Ge,"9176-8":Ge,"8716-3":Pn,"29762-2":bn,"47519-4":Un,"30954-2":Ln,"51848-0":wn,"18776-5":Mn,"46240-8":kn,"61146-7":Bn,"75310-3":Fn,"42349-1":Gn,"10190-7":Yn,"11488-4":$n,"85847-2":Hn,"48768-6":jn,"46264-8":Vn};function Ro(i){return new Ft(i).convert()}var Ft=class{constructor(e){this.bundle=e;let t=this.findResource("Composition");if(!t)throw new Error("Composition not found");let n=this.findResource("Patient");if(!n)throw new Error("Patient not found");this.composition=t,this.patient=n}convert(){let e=this.createSections();return{realmCode:{"@_code":"US"},typeId:{"@_root":ai,"@_extension":"POCD_HD000040"},templateId:kt,id:this.mapIdentifiers(this.composition.id,void 0),code:{"@_code":"34133-9","@_displayName":"Summarization of Episode Note","@_codeSystem":k,"@_codeSystemName":"LOINC"},title:this.composition.title,effectiveTime:this.mapEffectiveTime(this.composition.date,void 0),confidentialityCode:this.composition.confidentiality?vt.mapFhirToCcdaCode(this.composition.confidentiality):void 0,languageCode:{"@_code":this.composition.language??"en-US"},recordTarget:this.createRecordTarget(),author:this.mapAuthor(this.composition.author?.[0],this.composition.date),custodian:this.mapCustodian(this.composition.custodian),documentationOf:this.mapDocumentationOf(this.composition.event),component:e.length>0?{structuredBody:{component:e.map(t=>({section:[t]}))}}:void 0}}findResource(e){return this.bundle.entry?.find(t=>t.resource?.resourceType===e)?.resource}findResourceByReference(e){if(!e?.reference)return;let[t,n]=e.reference.split("/");if(!(!t||!n))return this.bundle.entry?.find(r=>r.resource?.resourceType===t&&r.resource?.id===n)?.resource}findResourcesByReferences(e){return e?e.map(t=>this.findResourceByReference(t)).filter(t=>!!t):[]}createRecordTarget(){if(!this.patient)throw new Error("Patient not found");return[{patientRole:{id:this.mapIdentifiers(this.patient.id,this.patient.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(this.patient.address),telecom:this.mapTelecom(this.patient.telecom),patient:this.mapPatient(this.patient)}}]}mapPatient(e){return{name:this.mapNames(e.name),administrativeGenderCode:this.mapGender(e.gender),birthTime:this.mapBirthDate(e.birthDate),raceCode:this.mapRace(e.extension),ethnicGroupCode:this.mapEthnicity(e.extension),languageCommunication:this.mapLanguageCommunication(e.communication)}}mapNames(e){return e?.map(t=>({"@_use":t.use?he.mapFhirToCcdaWithDefault(t.use,"L"):void 0,prefix:t.prefix,family:t.family,given:t.given,suffix:t.suffix}))}mapGender(e){if(e)return{"@_code":xt.mapFhirToCcda(e),"@_displayName":e?W(e):"Unknown","@_codeSystem":fi,"@_codeSystemName":"AdministrativeGender"}}mapBirthDate(e){if(e)return{"@_value":e.replace(/-/g,"")}}mapFhirAddressArrayToCcdaAddressArray(e){return!e||e.length===0?[{"@_nullFlavor":"UNK"}]:e.map(t=>this.mapFhirAddressToCcdaAddress(t)).filter(Boolean)}mapFhirAddressToCcdaAddress(e){return e?{"@_use":e.use?fe.mapFhirToCcda(e.use):void 0,streetAddressLine:e.line||[],city:e.city,state:e.state,postalCode:e.postalCode,country:e.country}:void 0}mapRace(e){let n=e?.find(r=>r.url===ue)?.extension?.find(r=>r.url==="ombCategory")?.valueCoding;if(n)return[{"@_code":n.code,"@_displayName":n.display,"@_codeSystem":Ke,"@_codeSystemName":"CDC Race and Ethnicity"}]}mapEthnicity(e){let n=e?.find(r=>r.url===le)?.extension?.find(r=>r.url==="ombCategory")?.valueCoding;if(n)return[{"@_code":n.code,"@_displayName":n.display,"@_codeSystem":Ke,"@_codeSystemName":"CDC Race and Ethnicity"}]}mapLanguageCommunication(e){if(e?.length)return[{"@_languageCode":e[0].language?.coding?.[0]?.code}]}createSections(){let e=[];if(this.composition.section)for(let t of this.composition.section)e.push(this.createSection(t));return e}createSection(e){let t=e.code?.coding?.[0]?.code;if(!t)throw new Error(`Missing section code: ${JSON.stringify(e.code)}`);let n=Bt[t];if(!n)throw new Error(`Unknown section code: ${t}`);let r=this.findResourcesByReferences(e.entry);return{templateId:n,code:d(e.code),title:e.title,text:this.mapFhirTextDivToCcdaSectionText(e.text),entry:r.map(o=>this.createEntry(e,o)).filter(Boolean),"@_nullFlavor":r.length===0?"NI":void 0}}createEntry(e,t){switch(t.resourceType){case"AllergyIntolerance":return this.createAllergyEntry(t);case"CarePlan":return this.createPlanOfTreatmentCarePlanEntry(t);case"CareTeam":return this.createCareTeamEntry(t);case"Condition":return this.createProblemEntry(t);case"DeviceUseStatement":return this.createDeviceUseStatementEntry(t);case"DiagnosticReport":return this.createDiagnosticReportEntry(t);case"Encounter":return this.createEncounterEntry(t);case"Goal":return this.createPlanOfTreatmentGoalEntry(t);case"Immunization":return this.createImmunizationEntry(t);case"MedicationRequest":return this.createMedicationEntry(t);case"Procedure":return this.createHistoryOfProceduresEntry(t);case"Observation":return this.createObservationEntry(t);case"ServiceRequest":return this.createPlanOfTreatmentServiceRequestEntry(t);default:throw new Error(`Unknown resource type: ${t.resourceType}`)}}mapFhirTextDivToCcdaSectionText(e){if(!e)return;let t=Vt(e.div)?.div;return t?.["@_xmlns"]&&delete t["@_xmlns"],t}createAllergyEntry(e){let t=e.reaction?.[0];return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":lt},{"@_root":lt,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"CONC","@_codeSystem":Xe},statusCode:{"@_code":me.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:this.mapEffectivePeriod(e.recordedDate,void 0),author:this.mapAuthor(e.recorder,e.recordedDate),text:this.createTextFromExtensions(e.extension),entryRelationship:[{"@_typeCode":"SUBJ",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":ot},{"@_root":ot,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"ASSERTION","@_codeSystem":ve},statusCode:{"@_code":"completed"},author:this.mapAuthor(e.asserter,e.recordedDate),effectiveTime:this.mapEffectivePeriod(e.onsetPeriod?.start??e.onsetDateTime,e.onsetPeriod?.end,!0),value:this.mapAllergyCategory(e.category),text:this.createTextFromExtensions(e.extension),participant:[{"@_typeCode":"CSM",participantRole:{"@_classCode":"MANU",playingEntity:{"@_classCode":"MMAT",code:{...d(e.code),originalText:e.code?.extension?{reference:this.getNarrativeReference(e.code?.extension)}:void 0}}}}],entryRelationship:t?[{"@_typeCode":"MFST","@_inversionInd":"true",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":at},{"@_root":at,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(t.id,void 0),code:{"@_code":"ASSERTION","@_codeSystem":ve},statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveDate(e.onsetDateTime,e.onsetPeriod),value:G(t.manifestation?.[0]),text:this.createTextFromExtensions(t.manifestation?.[0]?.extension),entryRelationship:[{"@_typeCode":"SUBJ","@_inversionInd":"true",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":st},{"@_root":st,"@_extension":"2014-06-09"}],code:{"@_code":"SEV","@_codeSystem":ve,"@_codeSystemName":"ActCode"},statusCode:{"@_code":"completed"},value:{"@_xsi:type":"CD","@_code":Ee.mapFhirToCcdaWithDefault(t.severity,"M"),"@_displayName":t.severity?W(t.severity):void 0,"@_codeSystem":w,"@_codeSystemName":"SNOMED CT"},text:this.createTextFromExtensions(t.extension)}]}]}]}]:[]}]}]}]}}mapAllergyCategory(e){if(!e||e.length===0)return;let t=Pt.mapFhirToCcdaCode(e[0]);if(t)return{"@_xsi:type":"CD",...t}}mapAuthor(e,t){if(!e)return;let n=this.findResourceByReference(e);if(n?.resourceType==="Practitioner")return[{templateId:[{"@_root":qi}],time:t?{"@_value":T(t)}:void 0,assignedAuthor:{id:this.mapIdentifiers(n.id,n.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(n.address),telecom:this.mapTelecom(n.telecom),code:d(n.qualification?.[0]),assignedPerson:{name:this.mapNames(n.name)}}}]}mapCustodian(e){if(!e)return;let t=this.findResourceByReference(e);if(t)return{assignedCustodian:{representedCustodianOrganization:{id:this.mapIdentifiers(t.id,t.identifier),name:t.name?[t.name]:void 0,telecom:this.mapTelecom(t.telecom),addr:this.mapFhirAddressArrayToCcdaAddressArray(t.address)}}}}mapDocumentationOf(e){if(!e||e.length===0)return;let t=e[0];if(!(!t||!t.code&&!t.period))return{serviceEvent:{"@_classCode":"PCPR",code:d(t.code?.[0]),effectiveTime:this.mapEffectiveDate(void 0,t.period)}}}createMedicationEntry(e){let t=e.contained?.find(s=>s.resourceType==="Medication"),n=t?.code||e.medicationCodeableConcept,r=t?.manufacturer,o=[];if(e.dispenseRequest?.validityPeriod){let s=this.mapEffectiveDate(void 0,e.dispenseRequest.validityPeriod);s&&o.push(...s)}return e.dosageInstruction?.[0]?.timing?.repeat?.period&&o.push({"@_xsi:type":"PIVL_TS","@_institutionSpecified":"true","@_operator":"A",period:{"@_value":e.dosageInstruction[0].timing.repeat.period.toString(),"@_unit":e.dosageInstruction[0].timing.repeat.periodUnit}}),{substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN",templateId:[{"@_root":ct,"@_extension":"2014-06-09"},{"@_root":ct}],id:[{"@_root":e.id||crypto.randomUUID()}],text:this.createTextFromExtensions(e.extension),statusCode:{"@_code":Oe.mapFhirToCcdaWithDefault(e.status,"active")},effectiveTime:o,routeCode:this.mapMedicationRoute(e.dosageInstruction?.[0]?.route),doseQuantity:this.mapDoseQuantity(e.dosageInstruction?.[0]?.doseAndRate?.[0]),consumable:{"@_typeCode":"CSM",manufacturedProduct:[{"@_classCode":"MANU",templateId:[{"@_root":ut,"@_extension":"2014-06-09"},{"@_root":ut}],manufacturedMaterial:[{code:[{...d(n),originalText:this.createTextFromExtensions(t?.extension)}]}],manufacturerOrganization:r?[{id:this.mapIdentifiers(r.id,r.identifier?[r.identifier]:void 0),name:[r.display]}]:void 0}]},entryRelationship:e.dosageInstruction?.filter(s=>!!s.extension)?.map(s=>({"@_typeCode":"COMP",substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN",templateId:[{"@_root":Me}],code:{"@_code":"76662-6","@_codeSystem":k,"@_codeSystemName":"LOINC","@_displayName":"Medication Instructions"},text:this.createTextFromExtensions(s.extension),consumable:{manufacturedProduct:[{manufacturedLabeledDrug:[{"@_nullFlavor":"NA"}]}]}}]}))}]}}mapMedicationRoute(e){if(e)return d(e)}mapDoseQuantity(e){if(e?.doseQuantity)return{"@_value":e.doseQuantity.value?.toString(),"@_unit":e.doseQuantity.unit}}mapTelecom(e){return!e||e.length===0?[{"@_nullFlavor":"UNK"}]:e?.map(t=>({"@_use":t.use?_e.mapFhirToCcda(t.use):void 0,"@_value":`${this.mapTelecomSystemToPrefix(t.system)}${t.value}`}))}mapTelecomSystemToPrefix(e){return e==="email"?"mailto:":e==="phone"?"tel:":e==="fax"?"fax:":""}mapIdentifiers(e,t){let n=[];if(e&&n.push({"@_root":e}),t)for(let r of t){let o=Dt(r.system);o&&n.push({"@_root":o,"@_extension":r.value})}return n}getNarrativeReference(e){let t=e?.find(n=>n.url===de)?.valueString;return t?{"@_value":t}:void 0}createTextFromExtensions(e){let t=this.getNarrativeReference(e);return t?{reference:t}:void 0}createProblemEntry(e){return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":rt},{"@_root":rt,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,void 0),code:{"@_code":"CONC","@_codeSystem":Xe},statusCode:{"@_code":Ie.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:this.mapEffectivePeriod(e.recordedDate,void 0),entryRelationship:[{"@_typeCode":"SUBJ",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":ee},{"@_root":ee,"@_extension":"2015-08-01"}],id:e.identifier?this.mapIdentifiers(void 0,e.identifier):[{"@_root":Re()}],text:this.createTextFromExtensions(e.extension),code:{"@_code":"55607006","@_codeSystem":w,"@_codeSystemName":"SNOMED CT","@_displayName":"Problem",translation:[{"@_code":"75323-6","@_codeSystem":k,"@_codeSystemName":"LOINC","@_displayName":"Condition"}]},statusCode:{"@_code":"completed"},effectiveTime:[{low:e.onsetDateTime?{"@_value":V(e.onsetDateTime)}:void 0,high:e.abatementDateTime?{"@_value":T(e.abatementDateTime)}:void 0}],value:G(e.code),author:this.mapAuthor(e.asserter,e.recordedDate)}]}]}]}}createImmunizationEntry(e){let t=e?.manufacturer,n={substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN","@_negationInd":"false",templateId:[{"@_root":ft},{"@_root":ft,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),text:this.createTextFromExtensions(e.extension),statusCode:{"@_code":Te.mapFhirToCcdaWithDefault(e.status,"completed")},effectiveTime:[{"@_value":V(e.occurrenceDateTime)}],consumable:{manufacturedProduct:[{"@_classCode":"MANU",templateId:[{"@_root":_t},{"@_root":_t,"@_extension":"2014-06-09"}],manufacturedMaterial:[{code:[d(e.vaccineCode)],lotNumberText:e.lotNumber?[e.lotNumber]:void 0}],manufacturerOrganization:t?[{id:this.mapIdentifiers(t.id,t.identifier?[t.identifier]:void 0),name:[t.display]}]:void 0}]}}]};return e.performer&&(n.substanceAdministration[0].performer=e.performer.map(r=>this.mapImmunizationPerformerToCcdaPerformer(r)).filter(Boolean)),n}mapImmunizationPerformerToCcdaPerformer(e){if(!e)return;let t=this.findResourceByReference(e.actor);if(!t)return;let n,r;return t.resourceType==="PractitionerRole"?(n=this.findResourceByReference(t.practitioner),r=this.findResourceByReference(t.organization)):t.resourceType==="Practitioner"?n=t:t.resourceType==="Organization"&&(r=t),{assignedEntity:{id:this.mapIdentifiers(t.id,t.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(n?.address),telecom:this.mapTelecom(t.telecom),assignedPerson:n?{id:this.mapIdentifiers(n.id,n.identifier),name:this.mapNames(n.name)}:void 0,representedOrganization:r?{id:this.mapIdentifiers(r.id,r.identifier),name:r.name?[r.name]:void 0,addr:this.mapFhirAddressArrayToCcdaAddressArray(r.address),telecom:this.mapTelecom(r.telecom)}:void 0}}}createObservationEntry(e){return e.hasMember?{organizer:[this.createVitalSignsOrganizer(e)]}:{observation:[this.createVitalSignObservation(e)]}}createPlanOfTreatmentCarePlanEntry(e){return{act:[{"@_classCode":"ACT","@_moodCode":"INT",id:this.mapIdentifiers(e.id,e.identifier),code:G(e.category?.[0]),templateId:[{"@_root":Pi}],statusCode:{"@_code":"completed"},text:e.description?{"#text":e.description}:this.createTextFromExtensions(e.extension)}]}}createPlanOfTreatmentGoalEntry(e){return{observation:[{"@_classCode":"OBS","@_moodCode":"GOL",templateId:[{"@_root":pt}],id:this.mapIdentifiers(e.id,e.identifier),code:d(e.description),statusCode:{"@_code":this.mapPlanOfTreatmentStatus(e.lifecycleStatus)},effectiveTime:[{"@_value":T(e.startDate)}],text:this.createTextFromExtensions(e.extension),entryRelationship:e.target?.map(n=>({"@_typeCode":"RSON","@_inversionInd":"true",act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":te},{"@_root":te,"@_extension":"2014-06-09"}],code:d(n.measure),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":T(e.startDate)}]}]}))}]}}mapPlanOfTreatmentStatus(e){switch(e){case"achieved":return"completed";case"cancelled":return"cancelled";default:return"active"}}createVitalSignsOrganizer(e){let t=[];if(e.hasMember)for(let r of e.hasMember){let o=this.findResourceByReference(r);if(!(!o||o.resourceType!=="Observation"))if(o.component)for(let s of o.component)t.push({observation:[this.createVitalSignComponentObservation(o,s)]});else t.push({observation:[this.createVitalSignObservation(o)]})}return{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":re},{"@_root":re,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:d(e.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":T(e.effectiveDateTime)}],component:t}}createVitalSignObservation(e){return{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:d(e.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":T(e.effectiveDateTime)}],value:this.mapObservationValue(e),referenceRange:this.mapReferenceRangeArray(e.referenceRange),text:this.createTextFromExtensions(e.extension),author:this.mapAuthor(e.performer?.[0],e.effectiveDateTime)}}createVitalSignComponentObservation(e,t){return{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:d(t.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":T(e.effectiveDateTime)}],value:this.mapObservationValue(t),referenceRange:this.mapReferenceRangeArray(t.referenceRange),text:this.createTextFromExtensions(t.extension),author:this.mapAuthor(e.performer?.[0],e.effectiveDateTime)}}mapObservationTemplateId(e){let t=e.code?.coding?.[0]?.code,n=e.category?.[0]?.coding?.[0]?.code;return t==="72166-2"?[{"@_root":se},{"@_root":se,"@_extension":"2014-06-09"}]:t==="11367-0"?[{"@_root":ae},{"@_root":ae,"@_extension":"2014-06-09"}]:n==="exam"?[{"@_root":ie},{"@_root":ie,"@_extension":"2014-06-09"}]:n==="laboratory"?[{"@_root":K},{"@_root":K,"@_extension":"2015-08-01"}]:[{"@_root":oe},{"@_root":oe,"@_extension":"2014-06-09"}]}mapObservationValue(e){if(e.valueQuantity)return{"@_xsi:type":"PQ","@_unit":e.valueQuantity.unit,"@_value":e.valueQuantity.value?.toString()};if(e.valueCodeableConcept)return G(e.valueCodeableConcept);if(e.valueString)return{"@_xsi:type":"ST","#text":e.valueString}}mapReferenceRangeArray(e){if(!(!e||e.length===0))return e.map(t=>this.mapReferenceRange(t)).filter(Boolean)}mapReferenceRange(e){if(!e)return;let t=this.getNarrativeReference(e.extension);return t?{observationRange:{text:{reference:t},value:{"@_xsi:type":"ED",reference:t}}}:{observationRange:{text:this.createTextFromExtensions(e.extension)}}}createHistoryOfProceduresEntry(e){if(e.resourceType==="Procedure"){let t=["183948003","409063005","311331002","61310001","183945009","309814009","278373008","410606002","183933003","24642003","225338006","128939004"],n=e.code?.coding?.[0]?.code;return n&&t.includes(n)?{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":te},{"@_root":te,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:d(e.code),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.performedDateTime,e.performedPeriod),text:this.createTextFromExtensions(e.extension)}]}:{procedure:[{"@_classCode":"PROC","@_moodCode":"EVN",templateId:[{"@_root":ne},{"@_root":ne,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:d(e.code),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.performedDateTime,e.performedPeriod),text:this.createTextFromExtensions(e.extension),targetSiteCode:d(e.bodySite?.[0]),participant:[this.mapLocationToParticipant(e.location)].filter(Boolean)}]}}if(e.resourceType==="Observation")return{observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:d(e.code),value:this.mapObservationValue(e),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.effectiveDateTime,e.effectivePeriod),text:this.createTextFromExtensions(e.extension)}]};throw new Error(`Unknown history of procedures resource type: ${e.resourceType}`)}mapLocationToParticipant(e){if(!e)return;let t=this.findResourceByReference(e);if(t)return{"@_typeCode":"LOC",participantRole:{"@_classCode":"SDLOC",templateId:[{"@_root":dt}],id:this.mapIdentifiers(t.id,t.identifier),code:d(t.type?.[0]),addr:t.address?this.mapFhirAddressArrayToCcdaAddressArray([t.address]):void 0,telecom:this.mapTelecom(t.telecom),playingEntity:{"@_classCode":"PLC",name:t.name?[t.name]:void 0}}}}mapEffectiveTime(e,t){if(t)return[{low:{"@_value":T(t.start)},high:{"@_value":T(t.end)}}];if(e)return[{"@_value":T(e)}]}mapEffectiveDate(e,t){if(t)return[{"@_xsi:type":"IVL_TS",low:t.start?{"@_value":V(t.start)}:void 0,high:t.end?{"@_value":V(t.end)}:void 0}];if(e)return[{"@_value":V(e)}]}mapEffectivePeriod(e,t,n=!1){if(!e&&!t)return;let r={};return e?r.low={"@_value":T(e)}:n&&(r.low={"@_nullFlavor":"NI"}),t?r.high={"@_value":T(t)}:n&&(r.high={"@_nullFlavor":"NI"}),[r]}createEncounterEntry(e){return{encounter:[{"@_classCode":"ENC","@_moodCode":"EVN",templateId:[{"@_root":ht},{"@_root":ht,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:d(e.type?.[0]),text:this.createTextFromExtensions(e.extension),effectiveTime:this.mapEffectiveTime(void 0,e.period),entryRelationship:e.participant?.map(t=>({"@_typeCode":"LOC",participantRole:{"@_classCode":"SDLOC",templateId:[{"@_root":dt}],code:d(t.type?.[0])}}))}]}}createCareTeamEntry(e){return{organizer:[{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":mt,"@_extension":"2022-07-01"},{"@_root":mt,"@_extension":"2022-06-01"}],id:this.mapIdentifiers(e.id,e.identifier),component:e.participant?.map(t=>({"@_typeCode":"PRF",role:t.role}))}]}}createPlanOfTreatmentServiceRequestEntry(e){return{observation:[{"@_classCode":"OBS","@_moodCode":"RQO",templateId:[{"@_root":pt}],id:this.mapIdentifiers(e.id,e.identifier),code:d(e.code),statusCode:{"@_code":this.mapPlanOfTreatmentStatus(e.status)},effectiveTime:[{"@_value":T(e.occurrenceDateTime)}],text:this.createTextFromExtensions(e.extension)}]}}createDiagnosticReportEntry(e){let t=[];if(e.result)for(let n of e.result){let r=this.findResourceByReference(n);!r||r.resourceType!=="Observation"||t.push({observation:[this.createVitalSignObservation(r)]})}return{organizer:[{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":J},{"@_root":J,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:d(e.code),statusCode:{"@_code":"completed"},component:t}]}}createDeviceUseStatementEntry(e){let t=this.findResourceByReference(e.device);if(!t)return;let n=[],r=this.mapIdentifiers(t.id,t.identifier);return r&&n.push(...r),t.udiCarrier?.[0]?.deviceIdentifier&&n.push({"@_root":It,"@_extension":t.udiCarrier[0].carrierHRF,"@_assigningAuthorityName":"FDA"}),{procedure:[{"@_classCode":"PROC","@_moodCode":"EVN",templateId:[{"@_root":ne,"@_extension":"2014-06-09"},{"@_root":ne}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"360030002","@_codeSystem":w,"@_codeSystemName":"SNOMED CT","@_displayName":"Application of medical device"},statusCode:{"@_code":"completed"},participant:[{"@_typeCode":"DEV",participantRole:{"@_classCode":"MANU",templateId:[{"@_root":Li}],id:n,playingDevice:{"@_classCode":"DEV",code:d(t.type)},scopingEntity:{id:[{"@_root":It}]}}}]}]}}};0&&(module.exports={ACT_CODE_SYSTEM,ADDRESS_USE_MAPPER,ADDRESS_USE_VALUE_SET,ADMINISTRATIVE_GENDER_VALUE_SET,ALLERGIES_SECTION_TEMPLATE_IDS,ALLERGY_CATEGORY_MAPPER,ALLERGY_CLINICAL_CODE_SYSTEM,ALLERGY_SEVERITY_MAPPER,ALLERGY_STATUS_MAPPER,ALLERGY_VERIFICATION_CODE_SYSTEM,ASSESSMENTS_SECTION_TEMPLATE_IDS,CARE_TEAM_SECTION_TEMPLATE_IDS,CCDA_NARRATIVE_REFERENCE_URL,CCDA_TEMPLATE_CODE_SYSTEM,CCDA_TEMPLATE_IDS,CLINICAL_CONDITION_CODE_SYSTEM,CLINICAL_NOTES_SECTION_TEMPLATE_IDS,CONDITION_CATEGORY_CODE_SYSTEM,CONDITION_VERIFICATION_CODE_SYSTEM,CONDITION_VER_STATUS_CODE_SYSTEM,CONFIDENTIALITY_CODE_SYSTEM,CONFIDENTIALITY_MAPPER,CONTACT_ENTITY_USE_VALUE_SET,CVX_URL,DEVICES_SECTION_TEMPLATE_IDS,DIAGNOSIS_ROLE_CODE_SYSTEM,ENCOUNTERS_SECTION_TEMPLATE_IDS,ENCOUNTER_STATUS_MAPPER,EnumMapper,FHIR_CVX_URL,GENDER_MAPPER,GOALS_SECTION_TEMPLATE_IDS,HEALTH_CONCERNS_SECTION_TEMPLATE_IDS,HTTP,HUMAN_NAME_USE_MAPPER,IMMUNIZATIONS_SECTION_TEMPLATE_IDS,IMMUNIZATION_STATUS_MAPPER,INSURANCE_SECTION_TEMPLATE_IDS,LAB_TESTS_SECTION_TEMPLATE_IDS,LANGUAGE_MODE_CODE_SYSTEM,LANGUAGE_MODE_URL,LANGUAGE_PROFICIENCY_CODE_SYSTEM,LANGUAGE_PROFICIENCY_URL,LOINC_TO_TEMPLATE_IDS,MEDICATIONS_SECTION_TEMPLATE_IDS,MEDICATION_REQUEST_STATUS_VALUE_SET,MEDICATION_STATUS_MAPPER,MENTAL_STATUS_SECTION_TEMPLATE_IDS,NAME_USE_VALUE_SET,NCI_THESAURUS_URL,NDFRT_URL,NUCC_TAXONOMY_URL,OBSERVATION_CATEGORY_CODE_SYSTEM,OBSERVATION_CATEGORY_MAPPER,PARTICIPATION_CODE_SYSTEM,PATIENT_NOTES_SECTION_TEMPLATE_IDS,PLAN_OF_TREATMENT_SECTION_TEMPLATE_IDS,PROBLEMS_SECTION_TEMPLATE_IDS,PROBLEM_STATUS_MAPPER,PROCEDURES_SECTION_TEMPLATE_IDS,PROCEDURE_STATUS_MAPPER,RACE_CODE_SYSTEM,REASON_FOR_REFERRAL_SECTION_TEMPLATE_IDS,RESULTS_SECTION_TEMPLATE_IDS,SOCIAL_HISTORY_SECTION_TEMPLATE_IDS,SYSTEM_MAPPER,TELECOM_USE_MAPPER,UNII_URL,US_CORE_CONDITION_URL,US_CORE_ETHNICITY_URL,US_CORE_MEDICATION_REQUEST_URL,US_CORE_PATIENT_URL,US_CORE_RACE_URL,US_DRIVER_LICENSE_URL,US_NPI_URL,US_SSN_URL,VA_MEDRT_URL,VITAL_SIGNS_SECTION_TEMPLATE_IDS,XSI_URL,convertCcdaToFhir,convertCcdaToXml,convertFhirToCcda,convertToCompactXml,convertXmlToCcda,mapCcdaSystemToFhir,mapCcdaToFhirDate,mapCcdaToFhirDateTime,mapCodeableConceptToCcdaCode,mapCodeableConceptToCcdaValue,mapCodingToCcdaCode,mapFhirSystemToCcda,mapFhirToCcdaDate,mapFhirToCcdaDateTime,parseXml});
|
|
1
|
+
"use strict";var rt=Object.defineProperty;var Nr=Object.getOwnPropertyDescriptor;var Rr=Object.getOwnPropertyNames;var Dr=Object.prototype.hasOwnProperty;var vr=(i,e)=>{for(var t in e)rt(i,t,{get:e[t],enumerable:!0})},xr=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Rr(e))!Dr.call(i,r)&&r!==t&&rt(i,r,{get:()=>e[r],enumerable:!(n=Nr(e,r))||n.enumerable});return i};var Pr=i=>xr(rt({},"__esModule",{value:!0}),i);var Ko={};vr(Ko,{ACT_CODE_SYSTEM:()=>wt,ADDRESS_USE_MAPPER:()=>Ne,ADDRESS_USE_VALUE_SET:()=>jn,ADMINISTRATIVE_GENDER_CODE_SYSTEM:()=>Yn,ADMINISTRATIVE_GENDER_VALUE_SET:()=>Wn,ALLERGIES_SECTION_TEMPLATE_IDS:()=>sr,ALLERGY_CATEGORY_MAPPER:()=>pi,ALLERGY_CLINICAL_CODE_SYSTEM:()=>me,ALLERGY_SEVERITY_MAPPER:()=>ve,ALLERGY_STATUS_MAPPER:()=>De,ALLERGY_VERIFICATION_CODE_SYSTEM:()=>nt,ASSESSMENTS_SECTION_TEMPLATE_IDS:()=>_r,CARE_TEAM_SECTION_TEMPLATE_IDS:()=>Cr,CCDA_NARRATIVE_REFERENCE_URL:()=>Ie,CCDA_TEMPLATE_CODE_SYSTEM:()=>Ho,CCDA_TEMPLATE_IDS:()=>Ti,CLINICAL_CONDITION_CODE_SYSTEM:()=>tt,CLINICAL_NOTES_SECTION_TEMPLATE_IDS:()=>Zo,CONDITION_CATEGORY_CODE_SYSTEM:()=>Mt,CONDITION_VERIFICATION_CODE_SYSTEM:()=>Vt,CONDITION_VER_STATUS_CODE_SYSTEM:()=>it,CONFIDENTIALITY_CODE_SYSTEM:()=>Hn,CONFIDENTIALITY_MAPPER:()=>di,CONTACT_ENTITY_USE_VALUE_SET:()=>Qn,CVX_URL:()=>rr,DEVICES_SECTION_TEMPLATE_IDS:()=>fr,DIAGNOSIS_ROLE_CODE_SYSTEM:()=>kt,ENCOUNTERS_SECTION_TEMPLATE_IDS:()=>Er,ENCOUNTER_STATUS_MAPPER:()=>hi,EnumMapper:()=>E,FHIR_CVX_URL:()=>or,GENDER_MAPPER:()=>li,GOALS_SECTION_TEMPLATE_IDS:()=>Ir,HEALTH_CONCERNS_SECTION_TEMPLATE_IDS:()=>Tr,HTTP:()=>M,HUMAN_NAME_USE_MAPPER:()=>Ae,IMMUNIZATIONS_SECTION_TEMPLATE_IDS:()=>ur,IMMUNIZATION_STATUS_MAPPER:()=>xe,INSURANCE_SECTION_TEMPLATE_IDS:()=>gr,LAB_TESTS_SECTION_TEMPLATE_IDS:()=>Xo,LANGUAGE_MODE_CODE_SYSTEM:()=>wo,LANGUAGE_MODE_URL:()=>Fo,LANGUAGE_PROFICIENCY_CODE_SYSTEM:()=>Bo,LANGUAGE_PROFICIENCY_URL:()=>Go,LOINC_ADMINISTRATIVE_SEX:()=>ai,LOINC_ALLERGIES_SECTION:()=>Ht,LOINC_ASSESSMENTS_SECTION:()=>Se,LOINC_BIRTH_SEX:()=>ci,LOINC_CARE_TEAM_SECTION:()=>ei,LOINC_CONDITION:()=>ni,LOINC_DEVICES_SECTION:()=>Zt,LOINC_ENCOUNTERS_SECTION:()=>Xt,LOINC_GOALS_SECTION:()=>Y,LOINC_HEALTH_CONCERNS_SECTION:()=>H,LOINC_HISTORY_OF_TOBACCO_USE:()=>si,LOINC_IMMUNIZATIONS_SECTION:()=>$t,LOINC_INSURANCE_SECTION:()=>ti,LOINC_MEDICATIONS_SECTION:()=>jt,LOINC_MEDICATION_INSTRUCTIONS:()=>ii,LOINC_MENTAL_STATUS_SECTION:()=>Kt,LOINC_NOTES_SECTION:()=>ye,LOINC_NOTE_DOCUMENT:()=>$o,LOINC_OVERALL_GOAL:()=>ri,LOINC_PATIENT_SUMMARY_DOCUMENT:()=>jo,LOINC_PLAN_OF_TREATMENT_SECTION:()=>Oe,LOINC_PROBLEMS_SECTION:()=>Te,LOINC_PROCEDURES_SECTION:()=>zt,LOINC_REASON_FOR_REFERRAL_SECTION:()=>Jt,LOINC_RESULTS_SECTION:()=>qt,LOINC_SOCIAL_HISTORY_SECTION:()=>Wt,LOINC_SUMMARY_OF_EPISODE_NOTE:()=>Ce,LOINC_TOBACCO_SMOKING_STATUS:()=>oi,LOINC_TO_TEMPLATE_IDS:()=>Oi,LOINC_VITAL_SIGNS_SECTION:()=>Qt,MEDICATIONS_SECTION_TEMPLATE_IDS:()=>ar,MEDICATION_REQUEST_STATUS_VALUE_SET:()=>zn,MEDICATION_STATUS_MAPPER:()=>Pe,MENTAL_STATUS_SECTION_TEMPLATE_IDS:()=>Sr,NAME_USE_VALUE_SET:()=>qn,NCI_THESAURUS_URL:()=>Zn,NDFRT_URL:()=>nr,NUCC_TAXONOMY_URL:()=>tr,OBSERVATION_CATEGORY_CODE_SYSTEM:()=>$n,OBSERVATION_CATEGORY_MAPPER:()=>_i,PARTICIPATION_CODE_SYSTEM:()=>Bt,PATIENT_NOTES_SECTION_TEMPLATE_IDS:()=>yr,PLAN_OF_TREATMENT_SECTION_TEMPLATE_IDS:()=>mr,PROBLEMS_SECTION_TEMPLATE_IDS:()=>cr,PROBLEM_STATUS_MAPPER:()=>q,PROCEDURES_SECTION_TEMPLATE_IDS:()=>pr,PROCEDURE_STATUS_MAPPER:()=>fi,RACE_CODE_SYSTEM:()=>ko,REASON_FOR_REFERRAL_SECTION_TEMPLATE_IDS:()=>Or,RESULTS_SECTION_TEMPLATE_IDS:()=>hr,SOCIAL_HISTORY_SECTION_TEMPLATE_IDS:()=>lr,SYSTEM_MAPPER:()=>ge,TELECOM_USE_MAPPER:()=>Re,UNII_URL:()=>er,US_CORE_CONDITION_URL:()=>Ft,US_CORE_ETHNICITY_URL:()=>Ee,US_CORE_MEDICATION_REQUEST_URL:()=>Gt,US_CORE_PATIENT_URL:()=>Yo,US_CORE_RACE_URL:()=>G,US_DRIVER_LICENSE_URL:()=>Jn,US_NPI_URL:()=>Kn,US_SSN_URL:()=>Xn,VA_MEDRT_URL:()=>ir,VITAL_SIGNS_SECTION_TEMPLATE_IDS:()=>dr,XSI_URL:()=>Yt,convertCcdaToFhir:()=>zo,convertCcdaToXml:()=>Qo,convertFhirToCcda:()=>Jo,convertToCompactXml:()=>Ei,convertXmlToCcda:()=>Wo,mapCcdaSystemToFhir:()=>$,mapCcdaToFhirDate:()=>Ge,mapCcdaToFhirDateTime:()=>m,mapCodeableConceptToCcdaCode:()=>p,mapCodeableConceptToCcdaValue:()=>j,mapCodingToCcdaCode:()=>Ut,mapFhirSystemToCcda:()=>ui,mapFhirToCcdaDate:()=>L,mapFhirToCcdaDateTime:()=>O,parseXml:()=>mi});module.exports=Pr(Ko);var br=class{constructor(i,e){this.operator=i,this.child=e}toString(){return`${this.operator}(${this.child.toString()})`}},X=class{constructor(i,e,t){this.operator=i,this.left=e,this.right=t}toString(){return`${this.left.toString()} ${this.operator} ${this.right.toString()}`}},Lr=class{constructor(){this.prefixParselets={},this.infixParselets={}}registerInfix(i,e){return this.infixParselets[i]=e,this}registerPrefix(i,e){return this.prefixParselets[i]=e,this}prefix(i,e,t){return this.registerPrefix(i,{parse(n,r){let o=n.consumeAndParse(e);return t(r,o)}})}infixLeft(i,e,t){return this.registerInfix(i,{parse(n,r,o){let s=n.consumeAndParse(e);return t(r,o,s)},precedence:e})}construct(i){return new Ur(i,this.prefixParselets,this.infixParselets)}},Ur=class{constructor(i,e,t){this.tokens=i,this.prefixParselets=e,this.infixParselets=t}hasMore(){return this.tokens.length>0}match(i){return this.peek()?.id!==i?!1:(this.consume(),!0)}consumeAndParse(i=1/0){let e=this.consume(),t=this.prefixParselets[e.id];if(!t)throw Error(`Parse error at "${e.value}" (line ${e.line}, column ${e.column}). No matching prefix parselet.`);let n=t.parse(this,e);for(;i>this.getPrecedence();){let r=this.consume();n=this.getInfixParselet(r).parse(this,n,r)}return n}getPrecedence(){let i=this.peek();if(!i)return 1/0;let e=this.getInfixParselet(i);return e?e.precedence:1/0}consume(i,e){if(!this.tokens.length)throw Error("Cant consume unknown more tokens.");if(i&&this.peek()?.id!==i){let t=this.peek();throw Error(`Expected ${i} but got "${t.id}" (${t.value}) at line ${t.line} column ${t.column}.`)}if(e&&this.peek()?.value!==e){let t=this.peek();throw Error(`Expected "${e}" but got "${t.value}" at line ${t.line} column ${t.column}.`)}return this.tokens.shift()}peek(){return this.tokens.length>0?this.tokens[0]:void 0}removeComments(){this.tokens=this.tokens.filter(i=>i.id!=="Comment")}getInfixParselet(i){return this.infixParselets[i.id==="Symbol"?i.value:i.id]}},st="http://unitsofmeasure.org",we="http://loinc.org",at="http://snomed.info/sct",Di="http://www.nlm.nih.gov/research/umls/rxnorm",vi="http://www.ama-assn.org/go/cpt";var xi="http://hl7.org/fhir/sid/ndc",_="http://hl7.org",T="http://terminology.hl7.org";var Vr="unauthorized";var Ve={resourceType:"OperationOutcome",id:Vr,issue:[{severity:"error",code:"login",details:{text:"Unauthorized"}}]},ts={...Ve,issue:[...Ve.issue,{severity:"error",code:"expired",details:{text:"Token expired"}}]},is={...Ve,issue:[...Ve.issue,{severity:"error",code:"invalid",details:{text:"Token not issued for this audience"}}]};function Mr(i,e){let t=e.max&&e.max===Number.MAX_SAFE_INTEGER?Number.POSITIVE_INFINITY:e.max;return{path:i,description:"",type:e.type??[],min:e.min??0,max:t??1,isArray:!!t&&t>1,constraints:[]}}function wr(i){let e=Object.create(null);for(let[t,n]of Object.entries(i))e[t]={name:t,type:t,path:t,elements:Object.fromEntries(Object.entries(n.elements).map(([r,o])=>[r,Mr(r,o)])),constraints:[],innerTypes:[]};return e}var Br={Element:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]}}},BackboneElement:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]}}},Address:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},use:{type:[{code:"code"}]},type:{type:[{code:"code"}]},text:{type:[{code:"string"}]},line:{max:9007199254740991,type:[{code:"string"}]},city:{type:[{code:"string"}]},district:{type:[{code:"string"}]},state:{type:[{code:"string"}]},postalCode:{type:[{code:"string"}]},country:{type:[{code:"string"}]},period:{type:[{code:"Period"}]}}},Age:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Annotation:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},"author[x]":{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Organization"]},{code:"string"}]},time:{type:[{code:"dateTime"}]},text:{min:1,type:[{code:"markdown"}]}}},Attachment:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},contentType:{type:[{code:"code"}]},language:{type:[{code:"code"}]},data:{type:[{code:"base64Binary"}]},url:{type:[{code:"url"}]},size:{type:[{code:"unsignedInt"}]},hash:{type:[{code:"base64Binary"}]},title:{type:[{code:"string"}]},creation:{type:[{code:"dateTime"}]}}},CodeableConcept:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},coding:{max:9007199254740991,type:[{code:"Coding"}]},text:{type:[{code:"string"}]}}},Coding:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},system:{type:[{code:"uri"}]},version:{type:[{code:"string"}]},code:{type:[{code:"code"}]},display:{type:[{code:"string"}]},userSelected:{type:[{code:"boolean"}]}}},ContactDetail:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},name:{type:[{code:"string"}]},telecom:{max:9007199254740991,type:[{code:"ContactPoint"}]}}},ContactPoint:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},system:{type:[{code:"code"}]},value:{type:[{code:"string"}]},use:{type:[{code:"code"}]},rank:{type:[{code:"positiveInt"}]},period:{type:[{code:"Period"}]}}},Contributor:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},name:{min:1,type:[{code:"string"}]},contact:{max:9007199254740991,type:[{code:"ContactDetail"}]}}},Count:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},DataRequirement:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},profile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]},"subject[x]":{type:[{code:"CodeableConcept"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Group"]}]},mustSupport:{max:9007199254740991,type:[{code:"string"}]},codeFilter:{max:9007199254740991,type:[{code:"DataRequirementCodeFilter"}]},dateFilter:{max:9007199254740991,type:[{code:"DataRequirementDateFilter"}]},limit:{type:[{code:"positiveInt"}]},sort:{max:9007199254740991,type:[{code:"DataRequirementSort"}]}}},DataRequirementCodeFilter:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{type:[{code:"string"}]},searchParam:{type:[{code:"string"}]},valueSet:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/ValueSet"]}]},code:{max:9007199254740991,type:[{code:"Coding"}]}}},DataRequirementDateFilter:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{type:[{code:"string"}]},searchParam:{type:[{code:"string"}]},"value[x]":{type:[{code:"dateTime"},{code:"Period"},{code:"Duration"}]}}},DataRequirementSort:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},direction:{min:1,type:[{code:"code"}]}}},Distance:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Dosage:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},sequence:{type:[{code:"integer"}]},text:{type:[{code:"string"}]},additionalInstruction:{max:9007199254740991,type:[{code:"CodeableConcept"}]},patientInstruction:{type:[{code:"string"}]},timing:{type:[{code:"Timing"}]},"asNeeded[x]":{type:[{code:"boolean"},{code:"CodeableConcept"}]},site:{type:[{code:"CodeableConcept"}]},route:{type:[{code:"CodeableConcept"}]},method:{type:[{code:"CodeableConcept"}]},doseAndRate:{max:9007199254740991,type:[{code:"DosageDoseAndRate"}]},maxDosePerPeriod:{type:[{code:"Ratio"}]},maxDosePerAdministration:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},maxDosePerLifetime:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},DosageDoseAndRate:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{type:[{code:"CodeableConcept"}]},"dose[x]":{type:[{code:"Range"},{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},"rate[x]":{type:[{code:"Ratio"},{code:"Range"},{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},Duration:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},ElementDefinition:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},representation:{max:9007199254740991,type:[{code:"code"}]},sliceName:{type:[{code:"string"}]},sliceIsConstraining:{type:[{code:"boolean"}]},label:{type:[{code:"string"}]},code:{max:9007199254740991,type:[{code:"Coding"}]},slicing:{type:[{code:"ElementDefinitionSlicing"}]},short:{type:[{code:"string"}]},definition:{type:[{code:"markdown"}]},comment:{type:[{code:"markdown"}]},requirements:{type:[{code:"markdown"}]},alias:{max:9007199254740991,type:[{code:"string"}]},min:{type:[{code:"unsignedInt"}]},max:{type:[{code:"string"}]},base:{type:[{code:"ElementDefinitionBase"}]},contentReference:{type:[{code:"uri"}]},type:{max:9007199254740991,type:[{code:"ElementDefinitionType"}]},"defaultValue[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},meaningWhenMissing:{type:[{code:"markdown"}]},orderMeaning:{type:[{code:"string"}]},"fixed[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},"pattern[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},example:{max:9007199254740991,type:[{code:"ElementDefinitionExample"}]},"minValue[x]":{type:[{code:"date"},{code:"dateTime"},{code:"instant"},{code:"time"},{code:"decimal"},{code:"integer"},{code:"positiveInt"},{code:"unsignedInt"},{code:"Quantity"}]},"maxValue[x]":{type:[{code:"date"},{code:"dateTime"},{code:"instant"},{code:"time"},{code:"decimal"},{code:"integer"},{code:"positiveInt"},{code:"unsignedInt"},{code:"Quantity"}]},maxLength:{type:[{code:"integer"}]},condition:{max:9007199254740991,type:[{code:"id"}]},constraint:{max:9007199254740991,type:[{code:"ElementDefinitionConstraint"}]},mustSupport:{type:[{code:"boolean"}]},isModifier:{type:[{code:"boolean"}]},isModifierReason:{type:[{code:"string"}]},isSummary:{type:[{code:"boolean"}]},binding:{type:[{code:"ElementDefinitionBinding"}]},mapping:{max:9007199254740991,type:[{code:"ElementDefinitionMapping"}]}}},ElementDefinitionSlicingDiscriminator:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},path:{min:1,type:[{code:"string"}]}}},ElementDefinitionSlicing:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},discriminator:{max:9007199254740991,type:[{code:"ElementDefinitionSlicingDiscriminator"}]},description:{type:[{code:"string"}]},ordered:{type:[{code:"boolean"}]},rules:{min:1,type:[{code:"code"}]}}},ElementDefinitionBase:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},min:{min:1,type:[{code:"unsignedInt"}]},max:{min:1,type:[{code:"string"}]}}},ElementDefinitionType:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},code:{min:1,type:[{code:"uri"}]},profile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition","http://hl7.org/fhir/StructureDefinition/ImplementationGuide"]}]},targetProfile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition","http://hl7.org/fhir/StructureDefinition/ImplementationGuide"]}]},aggregation:{max:9007199254740991,type:[{code:"code"}]},versioning:{type:[{code:"code"}]}}},ElementDefinitionExample:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},label:{min:1,type:[{code:"string"}]},"value[x]":{min:1,type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]}}},ElementDefinitionConstraint:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},key:{min:1,type:[{code:"id"}]},requirements:{type:[{code:"string"}]},severity:{min:1,type:[{code:"code"}]},human:{min:1,type:[{code:"string"}]},expression:{type:[{code:"string"}]},xpath:{type:[{code:"string"}]},source:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]}}},ElementDefinitionBinding:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},strength:{min:1,type:[{code:"code"}]},description:{type:[{code:"string"}]},valueSet:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/ValueSet"]}]}}},ElementDefinitionMapping:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},identity:{min:1,type:[{code:"id"}]},language:{type:[{code:"code"}]},map:{min:1,type:[{code:"string"}]},comment:{type:[{code:"string"}]}}},Expression:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},description:{type:[{code:"string"}]},name:{type:[{code:"id"}]},language:{min:1,type:[{code:"code"}]},expression:{type:[{code:"string"}]},reference:{type:[{code:"uri"}]}}},Extension:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},url:{min:1,type:[{code:"uri"}]},"value[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]}}},HumanName:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},use:{type:[{code:"code"}]},text:{type:[{code:"string"}]},family:{type:[{code:"string"}]},given:{max:9007199254740991,type:[{code:"string"}]},prefix:{max:9007199254740991,type:[{code:"string"}]},suffix:{max:9007199254740991,type:[{code:"string"}]},period:{type:[{code:"Period"}]}}},Identifier:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},use:{type:[{code:"code"}]},type:{type:[{code:"CodeableConcept"}]},system:{type:[{code:"uri"}]},value:{type:[{code:"string"}]},period:{type:[{code:"Period"}]},assigner:{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Organization"]}]}}},MarketingStatus:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},country:{min:1,type:[{code:"CodeableConcept"}]},jurisdiction:{type:[{code:"CodeableConcept"}]},status:{min:1,type:[{code:"CodeableConcept"}]},dateRange:{min:1,type:[{code:"Period"}]},restoreDate:{type:[{code:"dateTime"}]}}},Meta:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},versionId:{type:[{code:"id"}]},lastUpdated:{type:[{code:"instant"}]},source:{type:[{code:"uri"}]},profile:{max:9007199254740991,type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]},security:{max:9007199254740991,type:[{code:"Coding"}]},tag:{max:9007199254740991,type:[{code:"Coding"}]},project:{type:[{code:"uri"}]},author:{type:[{code:"Reference"}]},onBehalfOf:{type:[{code:"Reference"}]},account:{type:[{code:"Reference"}]},accounts:{max:9007199254740991,type:[{code:"Reference"}]},compartment:{max:9007199254740991,type:[{code:"Reference"}]}}},Money:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},currency:{type:[{code:"code"}]}}},Narrative:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},status:{min:1,type:[{code:"code"}]},div:{min:1,type:[{code:"xhtml"}]}}},ParameterDefinition:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},name:{type:[{code:"code"}]},use:{min:1,type:[{code:"code"}]},min:{type:[{code:"integer"}]},max:{type:[{code:"string"}]},documentation:{type:[{code:"string"}]},type:{min:1,type:[{code:"code"}]},profile:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]}}},Period:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},start:{type:[{code:"dateTime"}]},end:{type:[{code:"dateTime"}]}}},Population:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},"age[x]":{type:[{code:"Range"},{code:"CodeableConcept"}]},gender:{type:[{code:"CodeableConcept"}]},race:{type:[{code:"CodeableConcept"}]},physiologicalCondition:{type:[{code:"CodeableConcept"}]}}},ProdCharacteristic:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},height:{type:[{code:"Quantity"}]},width:{type:[{code:"Quantity"}]},depth:{type:[{code:"Quantity"}]},weight:{type:[{code:"Quantity"}]},nominalVolume:{type:[{code:"Quantity"}]},externalDiameter:{type:[{code:"Quantity"}]},shape:{type:[{code:"string"}]},color:{max:9007199254740991,type:[{code:"string"}]},imprint:{max:9007199254740991,type:[{code:"string"}]},image:{max:9007199254740991,type:[{code:"Attachment"}]},scoring:{type:[{code:"CodeableConcept"}]}}},ProductShelfLife:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},identifier:{type:[{code:"Identifier"}]},type:{min:1,type:[{code:"CodeableConcept"}]},period:{min:1,type:[{code:"Quantity"}]},specialPrecautionsForStorage:{max:9007199254740991,type:[{code:"CodeableConcept"}]}}},Quantity:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Range:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},low:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},high:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},Ratio:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},numerator:{type:[{code:"Quantity"}]},denominator:{type:[{code:"Quantity"}]}}},Reference:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},reference:{type:[{code:"string"}]},type:{type:[{code:"uri"}]},identifier:{type:[{code:"Identifier"}]},display:{type:[{code:"string"}]}}},RelatedArtifact:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},label:{type:[{code:"string"}]},display:{type:[{code:"string"}]},citation:{type:[{code:"markdown"}]},url:{type:[{code:"url"}]},document:{type:[{code:"Attachment"}]},resource:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/Resource"]}]}}},SampledData:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},origin:{min:1,type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},period:{min:1,type:[{code:"decimal"}]},factor:{type:[{code:"decimal"}]},lowerLimit:{type:[{code:"decimal"}]},upperLimit:{type:[{code:"decimal"}]},dimensions:{min:1,type:[{code:"positiveInt"}]},data:{type:[{code:"string"}]}}},Signature:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,max:9007199254740991,type:[{code:"Coding"}]},when:{min:1,type:[{code:"instant"}]},who:{min:1,type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/PractitionerRole","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/Device","http://hl7.org/fhir/StructureDefinition/Organization"]}]},onBehalfOf:{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/PractitionerRole","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/Device","http://hl7.org/fhir/StructureDefinition/Organization"]}]},targetFormat:{type:[{code:"code"}]},sigFormat:{type:[{code:"code"}]},data:{type:[{code:"base64Binary"}]}}},SubstanceAmount:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},"amount[x]":{type:[{code:"Quantity"},{code:"Range"},{code:"string"}]},amountType:{type:[{code:"CodeableConcept"}]},amountText:{type:[{code:"string"}]},referenceRange:{type:[{code:"SubstanceAmountReferenceRange"}]}}},SubstanceAmountReferenceRange:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},lowLimit:{type:[{code:"Quantity"}]},highLimit:{type:[{code:"Quantity"}]}}},Timing:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},modifierExtension:{max:9007199254740991,type:[{code:"Extension"}]},event:{max:9007199254740991,type:[{code:"dateTime"}]},repeat:{type:[{code:"TimingRepeat"}]},code:{type:[{code:"CodeableConcept"}]}}},TimingRepeat:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},"bounds[x]":{type:[{code:"Duration"},{code:"Range"},{code:"Period"}]},count:{type:[{code:"positiveInt"}]},countMax:{type:[{code:"positiveInt"}]},duration:{type:[{code:"decimal"}]},durationMax:{type:[{code:"decimal"}]},durationUnit:{type:[{code:"code"}]},frequency:{type:[{code:"positiveInt"}]},frequencyMax:{type:[{code:"positiveInt"}]},period:{type:[{code:"decimal"}]},periodMax:{type:[{code:"decimal"}]},periodUnit:{type:[{code:"code"}]},dayOfWeek:{max:9007199254740991,type:[{code:"code"}]},timeOfDay:{max:9007199254740991,type:[{code:"time"}]},when:{max:9007199254740991,type:[{code:"code"}]},offset:{type:[{code:"unsignedInt"}]}}},TriggerDefinition:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},name:{type:[{code:"string"}]},"timing[x]":{type:[{code:"Timing"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Schedule"]},{code:"date"},{code:"dateTime"}]},data:{max:9007199254740991,type:[{code:"DataRequirement"}]},condition:{type:[{code:"Expression"}]}}},UsageContext:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},code:{min:1,type:[{code:"Coding"}]},"value[x]":{min:1,type:[{code:"CodeableConcept"},{code:"Quantity"},{code:"Range"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/PlanDefinition","http://hl7.org/fhir/StructureDefinition/ResearchStudy","http://hl7.org/fhir/StructureDefinition/InsurancePlan","http://hl7.org/fhir/StructureDefinition/HealthcareService","http://hl7.org/fhir/StructureDefinition/Group","http://hl7.org/fhir/StructureDefinition/Location","http://hl7.org/fhir/StructureDefinition/Organization"]}]}}},MoneyQuantity:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},SimpleQuantity:{elements:{id:{type:[{code:"string"}]},extension:{max:9007199254740991,type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{max:0,type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},IdentityProvider:{elements:{authorizeUrl:{min:1,type:[{code:"string"}]},tokenUrl:{min:1,type:[{code:"string"}]},tokenAuthMethod:{type:[{code:"code"}]},userInfoUrl:{min:1,type:[{code:"string"}]},clientId:{min:1,type:[{code:"string"}]},clientSecret:{min:1,type:[{code:"string"}]},usePkce:{type:[{code:"boolean"}]},useSubject:{type:[{code:"boolean"}]}}}};var kr=wr(Br);var yi=Object.create(null);function Fr(i){let e;return e=yi[i],e||(e=yi[i]=Object.create(null)),e}function Gr(i,e){if(e){let t=Fr(e)[i];if(t)return t}return kr[i]}var Pi={base64Binary:/^([A-Za-z\d+/]{4})*([A-Za-z\d+/]{2}==|[A-Za-z\d+/]{3}=)?$/,canonical:/^\S*$/,code:/^[^\s]+( [^\s]+)*$/,date:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1]))?)?$/,dateTime:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1])(T([01]\d|2[0-3])(:[0-5]\d:([0-5]\d|60)(\.\d{1,9})?)?)?)?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00)?)?)?$/,id:/^[A-Za-z0-9\-.]{1,64}$/,instant:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])T([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00))$/,markdown:/^[\r\n\t\u0020-\uFFFF]+$/,oid:/^urn:oid:[0-2](\.(0|[1-9]\d*))+$/,string:/^[\r\n\t\u0020-\uFFFF]+$/,time:/^([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?$/,uri:/^\S*$/,url:/^\S*$/,uuid:/^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,xhtml:/.*/};function c(i){return[{type:u.boolean,value:i}]}function B(i){return i==null?{type:"undefined",value:void 0}:Number.isSafeInteger(i)?{type:u.integer,value:i}:typeof i=="number"?{type:u.decimal,value:i}:typeof i=="boolean"?{type:u.boolean,value:i}:typeof i=="string"?{type:u.string,value:i}:g(i)?{type:u.Quantity,value:i}:K(i)?{type:i.resourceType,value:i}:Bi(i)?{type:u.CodeableConcept,value:i}:wi(i)?{type:u.Coding,value:i}:{type:u.BackboneElement,value:i}}function x(i){return i.length===0?!1:!!i[0].value}function P(i,e){if(i.length!==0){if(i.length===1&&(!e||i[0].type===e))return i[0];throw new Error(`Expected singleton of type ${e}, but found ${JSON.stringify(i)}`)}}function Yr(i,e,t){if(!i.value)return;let n=lo(i.type,e,t?.profileUrl);return n?Hr(i,e,n):$r(i,e)}function Hr(i,e,t){let n=i.value,r=t.type;if(!r||r.length===0)return;let o,s="undefined",a,h=t.path.lastIndexOf("."),S=t.path.substring(h+1);for(let I of r){let Q=S.replace("[x]",J(I.code));if(o=n[Q],a=n["_"+Q],o!==void 0||a!==void 0){s=I.code;break}}if(a)if(Array.isArray(o)){o=o.slice();for(let I=0;I<Math.max(o.length,a.length);I++)o[I]=Ni(o[I],a[I])}else o=Ni(o,a);if(!Z(o))return(s==="Element"||s==="BackboneElement")&&(s=t.type[0].code),Array.isArray(o)?o.map(I=>Ci(I,s)):Ci(o,s)}function Ci(i,e){return e==="Resource"&&K(i)&&(e=i.resourceType),{type:e,value:i}}function $r(i,e){let t=i.value;if(!t||typeof t!="object")return;let n;if(e in t){let r=t[e];Array.isArray(r)?n=r.map(B):n=B(r)}else{let r=e.endsWith("[x]")?e.substring(0,e.length-3):e;for(let o of Object.values(u)){let s=r+J(o);if(s in t){let a=t[s];Array.isArray(a)?n=a.map(h=>({type:o,value:h})):n={type:o,value:a};break}}}if(Array.isArray(n)){if(n.length===0||Z(n[0]))return}else if(Z(n))return;return n}function bi(i){let e=[];for(let t of i){let n=!1;for(let r of e)if(x(Be(t,r))){n=!0;break}n||e.push(t)}return e}function jr(i){return c(!x(i))}function qr(i,e){return i.length===0||e.length===0?[]:i.length!==e.length?c(!1):c(i.every((t,n)=>x(Be(t,e[n]))))}function Wr(i,e){return i.length===0||e.length===0?[]:i.length!==e.length?c(!0):c(i.some((t,n)=>!x(Be(t,e[n]))))}function Be(i,e){let t=i.value?.valueOf(),n=e.value?.valueOf();return typeof t=="number"&&typeof n=="number"?c(Math.abs(t-n)<1e-8):g(t)&&g(n)?c(Vi(t,n)):c(typeof t=="object"&&typeof n=="object"?ct(i,e):t===n)}function Li(i,e){return i.length===0&&e.length===0?c(!0):i.length!==e.length?c(!1):(i.sort(gi),e.sort(gi),c(i.every((t,n)=>x(Qr(t,e[n])))))}function Qr(i,e){let{type:t,value:n}=i,{type:r,value:o}=e,s=n?.valueOf(),a=o?.valueOf();return typeof s=="number"&&typeof a=="number"?c(Math.abs(s-a)<.01):g(s)&&g(a)?c(Vi(s,a)):c(t==="Coding"&&r==="Coding"?typeof s!="object"||typeof a!="object"?!1:s.code===a.code&&s.system===a.system:typeof s=="object"&&typeof a=="object"?ct({...s,id:void 0},{...a,id:void 0}):typeof s=="string"&&typeof a=="string"?s.toLowerCase()===a.toLowerCase():s===a)}function gi(i,e){let t=i.value?.valueOf(),n=e.value?.valueOf();return typeof t=="number"&&typeof n=="number"?t-n:typeof t=="string"&&typeof n=="string"?t.localeCompare(n):0}function Ui(i,e){let{value:t}=i;if(t==null)return!1;let n=e;switch(n.startsWith("System.")&&(n=n.substring(7)),n.startsWith("FHIR.")&&(n=n.substring(5)),n){case"Boolean":return typeof t=="boolean";case"Decimal":case"Integer":return typeof t=="number";case"Date":return zr(t);case"DateTime":return ot(t);case"Time":return typeof t=="string"&&!!/^T\d/.exec(t);case"Period":return Zr(t);case"Quantity":return g(t);default:return i.type===n||typeof t=="object"&&t?.resourceType===n}}function zr(i){return typeof i=="string"&&!!Pi.date.exec(i)}function ot(i){return typeof i=="string"&&!!Pi.dateTime.exec(i)}function Zr(i){return!!(i&&typeof i=="object"&&("start"in i&&ot(i.start)||"end"in i&&ot(i.end)))}function g(i){return!!(i&&typeof i=="object"&&"value"in i&&typeof i.value=="number")}function Vi(i,e){return Math.abs(i.value-e.value)<.01&&(i.unit===e.unit||i.code===e.code||i.unit===e.code||i.code===e.unit)}function ct(i,e){let t=Object.keys(i),n=Object.keys(e);if(t.length!==n.length)return!1;for(let r of t){let o=i[r],s=e[r];if(Ai(o)&&Ai(s)){if(!ct(o,s))return!1}else if(o!==s)return!1}return!0}function Ai(i){return i!==null&&typeof i=="object"}function Ni(i,e){if(e){if(typeof e!="object")throw new Error("Primitive extension must be an object");return Xr(i??{},e)}return i}function Xr(i,e){return delete e.__proto__,delete e.constructor,Object.assign(i,e)}function Jr(i,e){return K(i,e)&&"id"in i&&typeof i.id=="string"}function f(i){let e=Mi(i)??"undefined/undefined",t=to(i);return t===e?{reference:e}:{reference:e,display:t}}function Mi(i){if(ki(i))return i.reference;if(Jr(i))return`${i.resourceType}/${i.id}`}function Kr(i){if(i)return ki(i)?i.reference.split("/")[1]:i.id}function eo(i){return i.resourceType==="Patient"||i.resourceType==="Practitioner"||i.resourceType==="RelatedPerson"}function to(i){if(eo(i)){let e=io(i);if(e)return e}if(i.resourceType==="Device"){let e=no(i);if(e)return e}if(i.resourceType==="MedicationRequest"&&i.medicationCodeableConcept)return Ri(i.medicationCodeableConcept);if(i.resourceType==="Subscription"&&i.criteria)return i.criteria;if(i.resourceType==="User"&&i.email)return i.email;if("name"in i&&i.name&&typeof i.name=="string")return i.name;if("code"in i&&i.code){let e=i.code;if(Array.isArray(e)&&(e=e[0]),Bi(e))return Ri(e);if(so(e))return e.text}return Mi(i)??""}function io(i){let e=i.name;if(e&&e.length>0)return co(e[0])}function no(i){let e=i.deviceName;if(e&&e.length>0)return e[0].name}function ro(i,e){let t=new Date(i);t.setUTCHours(0,0,0,0);let n=e?new Date(e):new Date;n.setUTCHours(0,0,0,0);let r=t.getUTCFullYear(),o=t.getUTCMonth(),s=t.getUTCDate(),a=n.getUTCFullYear(),h=n.getUTCMonth(),S=n.getUTCDate(),I=a-r;(h<o||h===o&&S<s)&&I--;let Q=a*12+h-(r*12+o);S<s&&Q--;let Ar=Math.floor((n.getTime()-t.getTime())/(1e3*60*60*24));return{years:I,months:Q,days:Ar}}function ke(i,...e){let t=i;for(let n=0;n<e.length&&t;n++)t=t?.extension?.find(r=>r.url===e[n]);return t}function Z(i){if(i==null)return!0;let e=typeof i;return e==="string"||e==="object"?!oo(i):!1}function oo(i){if(i==null)return!1;let e=typeof i;return e==="string"&&i!==""||e==="object"&&("length"in i&&i.length>0||Object.keys(i).length>0)}function ut(i){return!!/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i.exec(i)}function dt(i){return i!==null&&typeof i=="object"}function wi(i){return dt(i)&&"code"in i&&typeof i.code=="string"}function Bi(i){return dt(i)&&"coding"in i&&Array.isArray(i.coding)&&i.coding.every(wi)}function so(i){return dt(i)&&"text"in i&&typeof i.text=="string"}var ao=[];for(let i=0;i<256;i++)ao.push(i.toString(16).padStart(2,"0"));function J(i){return i?i.charAt(0).toUpperCase()+i.substring(1):""}function co(i,e){let t=[];if(i.prefix&&e?.prefix!==!1&&t.push(...i.prefix),i.given&&t.push(...i.given),i.family&&t.push(i.family),i.suffix&&e?.suffix!==!1&&t.push(...i.suffix),i.use&&(e?.all||e?.use)&&t.push("["+i.use+"]"),t.length===0){let n=z(i.text);if(n)return n}return t.join(" ").trim()}function Ri(i){return i?z(i.text)||(i.coding?i.coding.map(t=>uo(t)).join(", "):""):""}function uo(i,e){let t=z(i?.display);if(t){let n=e?z(i?.code):void 0;return`${t}${n?" ("+n+")":""}`}return z(i?.code)??""}function z(i){return typeof i=="string"?i:void 0}var u={Address:"Address",Age:"Age",Annotation:"Annotation",Attachment:"Attachment",BackboneElement:"BackboneElement",CodeableConcept:"CodeableConcept",Coding:"Coding",ContactDetail:"ContactDetail",ContactPoint:"ContactPoint",Contributor:"Contributor",Count:"Count",DataRequirement:"DataRequirement",Distance:"Distance",Dosage:"Dosage",Duration:"Duration",Expression:"Expression",Extension:"Extension",HumanName:"HumanName",Identifier:"Identifier",MarketingStatus:"MarketingStatus",Meta:"Meta",Money:"Money",Narrative:"Narrative",ParameterDefinition:"ParameterDefinition",Period:"Period",Population:"Population",ProdCharacteristic:"ProdCharacteristic",ProductShelfLife:"ProductShelfLife",Quantity:"Quantity",Range:"Range",Ratio:"Ratio",Reference:"Reference",RelatedArtifact:"RelatedArtifact",SampledData:"SampledData",Signature:"Signature",SubstanceAmount:"SubstanceAmount",SystemString:"http://hl7.org/fhirpath/System.String",Timing:"Timing",TriggerDefinition:"TriggerDefinition",UsageContext:"UsageContext",base64Binary:"base64Binary",boolean:"boolean",canonical:"canonical",code:"code",date:"date",dateTime:"dateTime",decimal:"decimal",id:"id",instant:"instant",integer:"integer",markdown:"markdown",oid:"oid",positiveInt:"positiveInt",string:"string",time:"time",unsignedInt:"unsignedInt",uri:"uri",url:"url",uuid:"uuid"};function lo(i,e,t){let n=Gr(i,t);if(n)return po(n.elements,e)}function po(i,e){let t=i[e]??i[e+"[x]"];if(t)return t;for(let n=0;n<e.length;n++){let r=e[n];if(r>="A"&&r<="Z"){let o=e.slice(0,n)+"[x]",s=i[o];if(s)return s}}}function K(i,e){return!(!i||typeof i!="object"||!("resourceType"in i)||e&&i.resourceType!==e)}function ki(i){return!!(i&&typeof i=="object"&&"reference"in i&&typeof i.reference=="string")}function Ue(i){if(i.startsWith("T"))return i+"T00:00:00.000Z".substring(i.length);if(i.length<=10)return i;try{return new Date(i).toISOString()}catch{return i}}var v=()=>[],y={empty:(i,e)=>c(e.length===0||e.every(t=>Z(t.value))),hasValue:(i,e)=>c(e.length!==0),exists:(i,e,t)=>c(t?e.filter(n=>x(t.eval(i,[n]))).length>0:e.length>0&&e.every(n=>!Z(n.value))),all:(i,e,t)=>c(e.every(n=>x(t.eval(i,[n])))),allTrue:(i,e)=>{for(let t of e)if(!t.value)return c(!1);return c(!0)},anyTrue:(i,e)=>{for(let t of e)if(t.value)return c(!0);return c(!1)},allFalse:(i,e)=>{for(let t of e)if(t.value)return c(!1);return c(!0)},anyFalse:(i,e)=>{for(let t of e)if(!t.value)return c(!0);return c(!1)},subsetOf:(i,e,t)=>{if(e.length===0)return c(!0);let n=t.eval(i,w(i));return n.length===0?c(!1):c(e.every(r=>n.some(o=>o.value===r.value)))},supersetOf:(i,e,t)=>{let n=t.eval(i,w(i));return n.length===0?c(!0):e.length===0?c(!1):c(n.every(r=>e.some(o=>o.value===r.value)))},count:(i,e)=>[{type:u.integer,value:e.length}],distinct:(i,e)=>{let t=[];for(let n of e)t.some(r=>r.value===n.value)||t.push(n);return t},isDistinct:(i,e)=>c(e.length===y.distinct(i,e).length),where:(i,e,t)=>e.filter(n=>x(t.eval(i,[n]))),select:(i,e,t)=>e.map(n=>t.eval({parent:i,variables:{$this:n}},[n])).flat(),repeat:v,ofType:(i,e,t)=>e.filter(n=>n.type===t.name),single:(i,e)=>{if(e.length>1)throw new Error("Expected input length one for single()");return e.length===0?[]:e.slice(0,1)},first:(i,e)=>e.length===0?[]:e.slice(0,1),last:(i,e)=>e.length===0?[]:e.slice(e.length-1,e.length),tail:(i,e)=>e.length===0?[]:e.slice(1,e.length),skip:(i,e,t)=>{let n=t.eval(i,e)[0]?.value;if(typeof n!="number")throw new Error("Expected a number for skip(num)");return n>=e.length?[]:n<=0?e:e.slice(n,e.length)},take:(i,e,t)=>{let n=t.eval(i,e)[0]?.value;if(typeof n!="number")throw new Error("Expected a number for take(num)");return n>=e.length?e:n<=0?[]:e.slice(0,n)},intersect:(i,e,t)=>{if(!t)return e;let n=t.eval(i,w(i)),r=[];for(let o of e)!r.some(s=>s.value===o.value)&&n.some(s=>s.value===o.value)&&r.push(o);return r},exclude:(i,e,t)=>{if(!t)return e;let n=t.eval(i,w(i)),r=[];for(let o of e)n.some(s=>s.value===o.value)||r.push(o);return r},union:(i,e,t)=>{if(!t)return e;let n=t.eval(i,w(i));return bi([...e,...n])},combine:(i,e,t)=>{if(!t)return e;let n=t.eval(i,w(i));return[...e,...n]},htmlChecks:(i,e,t)=>[B(!0)],iif:(i,e,t,n,r)=>{let o=t.eval(i,e);if(o.length>1||o.length===1&&typeof o[0].value!="boolean")throw new Error("Expected criterion to evaluate to a Boolean");return x(o)?n.eval(i,e):r?r.eval(i,e):[]},toBoolean:(i,e)=>{if(e.length===0)return[];let[{value:t}]=D(e,1);if(typeof t=="boolean")return[{type:u.boolean,value:t}];if(typeof t=="number"&&(t===0||t===1))return c(!!t);if(typeof t=="string"){let n=t.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(n))return c(!0);if(["false","f","no","n","0","0.0"].includes(n))return c(!1)}return[]},convertsToBoolean:(i,e)=>e.length===0?[]:c(y.toBoolean(i,e).length===1),toInteger:(i,e)=>{if(e.length===0)return[];let[{value:t}]=D(e,1);return typeof t=="number"?[{type:u.integer,value:t}]:typeof t=="string"&&/^[+-]?\d+$/.exec(t)?[{type:u.integer,value:parseInt(t,10)}]:typeof t=="boolean"?[{type:u.integer,value:t?1:0}]:[]},convertsToInteger:(i,e)=>e.length===0?[]:c(y.toInteger(i,e).length===1),toDate:(i,e)=>{if(e.length===0)return[];let[{value:t}]=D(e,1);return typeof t=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(t)?[{type:u.date,value:Ue(t)}]:[]},convertsToDate:(i,e)=>e.length===0?[]:c(y.toDate(i,e).length===1),toDateTime:(i,e)=>{if(e.length===0)return[];let[{value:t}]=D(e,1);return typeof t=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(t)?[{type:u.dateTime,value:Ue(t)}]:[]},convertsToDateTime:(i,e)=>e.length===0?[]:c(y.toDateTime(i,e).length===1),toDecimal:(i,e)=>{if(e.length===0)return[];let[{value:t}]=D(e,1);return typeof t=="number"?[{type:u.decimal,value:t}]:typeof t=="string"&&/^-?\d{1,9}(\.\d{1,9})?$/.exec(t)?[{type:u.decimal,value:parseFloat(t)}]:typeof t=="boolean"?[{type:u.decimal,value:t?1:0}]:[]},convertsToDecimal:(i,e)=>e.length===0?[]:c(y.toDecimal(i,e).length===1),toQuantity:(i,e)=>{if(e.length===0)return[];let[{value:t}]=D(e,1);return g(t)?[{type:u.Quantity,value:t}]:typeof t=="number"?[{type:u.Quantity,value:{value:t,unit:"1"}}]:typeof t=="string"&&/^-?\d{1,9}(\.\d{1,9})?/.exec(t)?[{type:u.Quantity,value:{value:parseFloat(t),unit:"1"}}]:typeof t=="boolean"?[{type:u.Quantity,value:{value:t?1:0,unit:"1"}}]:[]},convertsToQuantity:(i,e)=>e.length===0?[]:c(y.toQuantity(i,e).length===1),toString:(i,e)=>{if(e.length===0)return[];let[{value:t}]=D(e,1);return t==null?[]:g(t)?[{type:u.string,value:`${t.value} '${t.unit}'`}]:[{type:u.string,value:t.toString()}]},convertsToString:(i,e)=>e.length===0?[]:c(y.toString(i,e).length===1),toTime:(i,e)=>{if(e.length===0)return[];let[{value:t}]=D(e,1);if(typeof t=="string"){let n=/^T?(\d{2}(:\d{2}(:\d{2})?)?)/.exec(t);if(n)return[{type:u.time,value:Ue("T"+n[1])}]}return[]},convertsToTime:(i,e)=>e.length===0?[]:c(y.toTime(i,e).length===1),indexOf:(i,e,t)=>C((n,r)=>n.indexOf(r),i,e,t),substring:(i,e,t,n)=>C((r,o,s)=>{let a=o,h=s?a+s:r.length;return a<0||a>=r.length?void 0:r.substring(a,h)},i,e,t,n),startsWith:(i,e,t)=>C((n,r)=>n.startsWith(r),i,e,t),endsWith:(i,e,t)=>C((n,r)=>n.endsWith(r),i,e,t),contains:(i,e,t)=>C((n,r)=>n.includes(r),i,e,t),upper:(i,e)=>C(t=>t.toUpperCase(),i,e),lower:(i,e)=>C(t=>t.toLowerCase(),i,e),replace:(i,e,t,n)=>C((r,o,s)=>r.replaceAll(o,s),i,e,t,n),matches:(i,e,t)=>C((n,r)=>!!new RegExp(r).exec(n),i,e,t),replaceMatches:(i,e,t,n)=>C((r,o,s)=>r.replaceAll(o,s),i,e,t,n),length:(i,e)=>C(t=>t.length,i,e),toChars:(i,e)=>C(t=>t?t.split(""):void 0,i,e),encode:v,decode:v,escape:v,unescape:v,trim:v,split:v,join:(i,e,t)=>{let n=t?.eval(i,w(i))[0]?.value??"";if(typeof n!="string")throw new Error("Separator must be a string.");return[{type:u.string,value:e.map(r=>r.value?.toString()??"").join(n)}]},abs:(i,e)=>R(Math.abs,i,e),ceiling:(i,e)=>R(Math.ceil,i,e),exp:(i,e)=>R(Math.exp,i,e),floor:(i,e)=>R(Math.floor,i,e),ln:(i,e)=>R(Math.log,i,e),log:(i,e,t)=>R((n,r)=>Math.log(n)/Math.log(r),i,e,t),power:(i,e,t)=>R(Math.pow,i,e,t),round:(i,e)=>R(Math.round,i,e),sqrt:(i,e)=>R(Math.sqrt,i,e),truncate:(i,e)=>R(t=>t|0,i,e),children:v,descendants:v,trace:(i,e,t)=>e,now:()=>[{type:u.dateTime,value:new Date().toISOString()}],timeOfDay:()=>[{type:u.time,value:new Date().toISOString().substring(11)}],today:()=>[{type:u.date,value:new Date().toISOString().substring(0,10)}],between:(i,e,t,n,r)=>{let o=y.toDateTime(i,t.eval(i,e));if(o.length===0)throw new Error("Invalid start date");let s=y.toDateTime(i,n.eval(i,e));if(s.length===0)throw new Error("Invalid end date");let a=r.eval(i,e)[0]?.value;if(a!=="years"&&a!=="months"&&a!=="days")throw new Error("Invalid units");let h=ro(o[0].value,s[0].value);return[{type:u.Quantity,value:{value:h[a],unit:a}}]},is:(i,e,t)=>{let n="";return t instanceof Me?n=t.name:t instanceof Fi&&(n=t.left.name+"."+t.right.name),n?e.map(r=>({type:u.boolean,value:Ui(r,n)})):[]},not:(i,e)=>y.toBoolean(i,e).map(t=>({type:u.boolean,value:!t.value})),resolve:(i,e)=>e.map(t=>{let n=t.value,r;if(typeof n=="string")r=n;else if(typeof n=="object"){let o=n;if(o.resource)return B(o.resource);o.reference?r=o.reference:o.type&&o.identifier&&(r=`${o.type}?identifier=${o.identifier.system}|${o.identifier.value}`)}if(r?.includes("?")){let[o]=r.split("?");return{type:o,value:{resourceType:o}}}if(r?.includes("/")){let[o,s]=r.split("/");return{type:o,value:{resourceType:o,id:s}}}return{type:u.BackboneElement,value:void 0}}).filter(t=>!!t.value),as:(i,e)=>e,type:(i,e)=>e.map(({value:t})=>typeof t=="boolean"?{type:u.BackboneElement,value:{namespace:"System",name:"Boolean"}}:typeof t=="number"?{type:u.BackboneElement,value:{namespace:"System",name:"Integer"}}:K(t)?{type:u.BackboneElement,value:{namespace:"FHIR",name:t.resourceType}}:{type:u.BackboneElement,value:null}),conformsTo:(i,e,t)=>{let n=t.eval(i,e)[0].value;if(!n.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");let r=n.replace("http://hl7.org/fhir/StructureDefinition/","");return e.map(o=>({type:u.boolean,value:o.value?.resourceType===r}))},getResourceKey:(i,e)=>{let t=e[0].value;return t?.id?[{type:u.id,value:t.id}]:[]},getReferenceKey:(i,e,t)=>{let n=e[0].value;if(!n?.reference)return[];let r="";return t instanceof Me&&(r=t.name),r&&!n.reference.startsWith(r+"/")?[]:[{type:u.id,value:Kr(n)}]},extension:(i,e,t)=>{let n=t.eval(i,e)[0].value,r=e?.[0]?.value;if(r){let o=ke(r,n);if(o)return[{type:u.Extension,value:o}]}return[]}};function C(i,e,t,...n){if(t.length===0)return[];let[{value:r}]=D(t,1);if(typeof r!="string")throw new Error("String function cannot be called with non-string");let o=i(r,...n.map(s=>s?.eval(e,t)[0]?.value));return o===void 0?[]:Array.isArray(o)?o.map(B):[B(o)]}function R(i,e,t,...n){if(t.length===0)return[];let[{value:r}]=D(t,1),o=g(r),s=o?r.value:r;if(typeof s!="number")throw new Error("Math function cannot be called with non-number");let a=i(s,...n.map(I=>I.eval(e,t)[0]?.value)),h=o?u.Quantity:t[0].type,S=o?{...r,value:a}:a;return[{type:h,value:S}]}function D(i,e){if(i.length!==e)throw new Error(`Expected ${e} arguments`);for(let t of i)if(t==null)throw new Error("Expected non-null argument");return i}function w(i){let e=i;for(;e.parent?.variables.$this;)e=e.parent;return[e.variables.$this]}var k=class{constructor(i){this.value=i}eval(){return[this.value]}toString(){let i=this.value.value;return typeof i=="string"?`'${i}'`:i.toString()}},Me=class{constructor(i){this.name=i}eval(i,e){if(this.name==="$this")return e;let t=this.getVariable(i);if(t)return[t];if(this.name.startsWith("%"))throw new Error(`Undefined variable ${this.name}`);return e.flatMap(n=>this.evalValue(n)).filter(n=>n?.value!==void 0)}getVariable(i){let e=i.variables[this.name];if(e!==void 0)return e;if(i.parent)return this.getVariable(i.parent)}evalValue(i){let e=i.value;if(!(!e||typeof e!="object"))return K(e,this.name)?i:Yr(i,this.name)}toString(){return this.name}},ho=class{eval(){return[]}toString(){return"{}"}},fo=class extends br{constructor(i,e,t){super(i,e),this.impl=t}eval(i,e){return this.impl(this.child.eval(i,e))}toString(){return this.operator+this.child.toString()}},_o=class extends X{constructor(i,e){super("as",i,e)}eval(i,e){return y.ofType(i,this.left.eval(i,e),this.right)}},A=class extends X{},N=class extends A{constructor(i,e,t,n){super(i,e,t),this.impl=n}eval(i,e){let t=this.left.eval(i,e);if(t.length!==1)return[];let n=this.right.eval(i,e);if(n.length!==1)return[];let r=t[0].value,o=n[0].value,s=g(r)?r.value:r,a=g(o)?o.value:o,h=this.impl(s,a);return typeof h=="boolean"?c(h):g(r)?[{type:u.Quantity,value:{...r,value:h}}]:[B(h)]}},mo=class extends X{constructor(i,e){super("&",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e),r=[...t,...n];return r.length>0&&r.every(o=>typeof o.value=="string")?[{type:u.string,value:r.map(o=>o.value).join("")}]:r}},Eo=class extends A{constructor(i,e){super("contains",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return c(t.some(r=>r.value===n[0].value))}},Io=class extends A{constructor(i,e){super("in",i,e)}eval(i,e){let t=P(this.left.eval(i,e)),n=this.right.eval(i,e);return t?c(n.some(r=>Be(t,r)[0].value)):[]}},Fi=class extends X{constructor(i,e){super(".",i,e)}eval(i,e){return this.right.eval(i,this.left.eval(i,e))}toString(){return`${this.left.toString()}.${this.right.toString()}`}},To=class extends X{constructor(i,e){super("|",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return bi([...t,...n])}},Oo=class extends A{constructor(i,e){super("=",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return qr(t,n)}},So=class extends A{constructor(i,e){super("!=",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return Wr(t,n)}},yo=class extends A{constructor(i,e){super("~",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return Li(t,n)}},Co=class extends A{constructor(i,e){super("!~",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return jr(Li(t,n))}},go=class extends A{constructor(i,e){super("is",i,e)}eval(i,e){let t=this.left.eval(i,e);if(t.length!==1)return[];let n=this.right.name;return c(Ui(t[0],n))}},Ao=class extends A{constructor(i,e){super("and",i,e)}eval(i,e){let t=P(this.left.eval(i,e),"boolean"),n=P(this.right.eval(i,e),"boolean");return t?.value===!0&&n?.value===!0?c(!0):t?.value===!1||n?.value===!1?c(!1):[]}},No=class extends A{constructor(i,e){super("or",i,e)}eval(i,e){let t=P(this.left.eval(i,e),"boolean"),n=P(this.right.eval(i,e),"boolean");return t?.value===!1&&n?.value===!1?c(!1):t?.value||n?.value?c(!0):[]}},Ro=class extends A{constructor(i,e){super("xor",i,e)}eval(i,e){let t=P(this.left.eval(i,e),"boolean"),n=P(this.right.eval(i,e),"boolean");return!t||!n?[]:c(t.value!==n.value)}},Do=class extends A{constructor(i,e){super("implies",i,e)}eval(i,e){let t=P(this.left.eval(i,e),"boolean"),n=P(this.right.eval(i,e),"boolean");return n?.value===!0||t?.value===!1?c(!0):!t||!n?[]:c(!1)}},vo=class{constructor(i,e){this.name=i,this.args=e}eval(i,e){let t=y[this.name];if(!t)throw new Error("Unrecognized function: "+this.name);return t(i,e,...this.args)}toString(){return`${this.name}(${this.args.map(i=>i.toString()).join(", ")})`}},xo=class{constructor(i,e){this.left=i,this.expr=e}eval(i,e){let t=this.expr.eval(i,e);if(t.length!==1)return[];let n=t[0].value;if(typeof n!="number")throw new Error("Invalid indexer expression: should return integer}");let r=this.left.eval(i,e);return n in r?[r[n]]:[]}toString(){return`${this.left.toString()}[${this.expr.toString()}]`}};var Gi=["!=","!~","<=",">=","{}","->"];var l={FunctionCall:0,Dot:1,Indexer:2,UnaryAdd:3,UnarySubtract:3,Multiply:4,Divide:4,IntegerDivide:4,Modulo:4,Add:5,Subtract:5,Ampersand:5,Is:6,As:6,Union:7,GreaterThan:8,GreaterThanOrEquals:8,LessThan:8,LessThanOrEquals:8,Equals:9,Equivalent:9,NotEquals:9,NotEquivalent:9,In:10,Contains:10,And:11,Xor:12,Or:12,Implies:13,Arrow:100,Semicolon:200},Po={parse(i){let e=i.consumeAndParse();if(!i.match(")"))throw new Error("Parse error: expected `)` got `"+i.peek()?.value+"`");return e}},bo={parse(i,e){let t=i.consumeAndParse();if(!i.match("]"))throw new Error("Parse error: expected `]`");return new xo(e,t)},precedence:l.Indexer},Lo={parse(i,e){if(!(e instanceof Me))throw new Error("Unexpected parentheses");let t=[];for(;!i.match(")");)t.push(i.consumeAndParse()),i.match(",");return new vo(e.name,t)},precedence:l.FunctionCall};function Uo(i){let e=i.split(" "),t=parseFloat(e[0]),n=e[1];return n?.startsWith("'")&&n.endsWith("'")?n=n.substring(1,n.length-1):n="{"+n+"}",{value:t,unit:n}}function lt(){return new Lr().registerPrefix("String",{parse:(i,e)=>new k({type:u.string,value:e.value})}).registerPrefix("DateTime",{parse:(i,e)=>new k({type:u.dateTime,value:Ue(e.value)})}).registerPrefix("Quantity",{parse:(i,e)=>new k({type:u.Quantity,value:Uo(e.value)})}).registerPrefix("Number",{parse:(i,e)=>new k({type:e.value.includes(".")?u.decimal:u.integer,value:parseFloat(e.value)})}).registerPrefix("true",{parse:()=>new k({type:u.boolean,value:!0})}).registerPrefix("false",{parse:()=>new k({type:u.boolean,value:!1})}).registerPrefix("Symbol",{parse:(i,e)=>new Me(e.value)}).registerPrefix("{}",{parse:()=>new ho}).registerPrefix("(",Po).registerInfix("[",bo).registerInfix("(",Lo).prefix("+",l.UnaryAdd,(i,e)=>new fo("+",e,t=>t)).prefix("-",l.UnarySubtract,(i,e)=>new N("-",e,e,(t,n)=>-n)).infixLeft(".",l.Dot,(i,e,t)=>new Fi(i,t)).infixLeft("/",l.Divide,(i,e,t)=>new N("/",i,t,(n,r)=>n/r)).infixLeft("*",l.Multiply,(i,e,t)=>new N("*",i,t,(n,r)=>n*r)).infixLeft("+",l.Add,(i,e,t)=>new N("+",i,t,(n,r)=>n+r)).infixLeft("-",l.Subtract,(i,e,t)=>new N("-",i,t,(n,r)=>n-r)).infixLeft("|",l.Union,(i,e,t)=>new To(i,t)).infixLeft("=",l.Equals,(i,e,t)=>new Oo(i,t)).infixLeft("!=",l.NotEquals,(i,e,t)=>new So(i,t)).infixLeft("~",l.Equivalent,(i,e,t)=>new yo(i,t)).infixLeft("!~",l.NotEquivalent,(i,e,t)=>new Co(i,t)).infixLeft("<",l.LessThan,(i,e,t)=>new N("<",i,t,(n,r)=>n<r)).infixLeft("<=",l.LessThanOrEquals,(i,e,t)=>new N("<=",i,t,(n,r)=>n<=r)).infixLeft(">",l.GreaterThan,(i,e,t)=>new N(">",i,t,(n,r)=>n>r)).infixLeft(">=",l.GreaterThanOrEquals,(i,e,t)=>new N(">=",i,t,(n,r)=>n>=r)).infixLeft("&",l.Ampersand,(i,e,t)=>new mo(i,t)).infixLeft("and",l.And,(i,e,t)=>new Ao(i,t)).infixLeft("as",l.As,(i,e,t)=>new _o(i,t)).infixLeft("contains",l.Contains,(i,e,t)=>new Eo(i,t)).infixLeft("div",l.Divide,(i,e,t)=>new N("div",i,t,(n,r)=>n/r|0)).infixLeft("in",l.In,(i,e,t)=>new Io(i,t)).infixLeft("is",l.Is,(i,e,t)=>new go(i,t)).infixLeft("mod",l.Modulo,(i,e,t)=>new N("mod",i,t,(n,r)=>n%r)).infixLeft("or",l.Or,(i,e,t)=>new No(i,t)).infixLeft("xor",l.Xor,(i,e,t)=>new Ro(i,t)).infixLeft("implies",l.Implies,(i,e,t)=>new Do(i,t))}var ns=lt();var d={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"},rs={contains:d.CONTAINS,exact:d.EXACT,above:d.ABOVE,below:d.BELOW,text:d.TEXT,not:d.NOT,in:d.IN,"not-in":d.NOT_IN,"of-type":d.OF_TYPE,missing:d.MISSING,identifier:d.IDENTIFIER,iterate:d.ITERATE},os={eq:d.EQUALS,ne:d.NOT_EQUALS,lt:d.LESS_THAN,le:d.LESS_THAN_OR_EQUALS,gt:d.GREATER_THAN,ge:d.GREATER_THAN_OR_EQUALS,sa:d.STARTS_AFTER,eb:d.ENDS_BEFORE,ap:d.APPROXIMATELY,sw:d.STARTS_WITH};var ss=[d.MISSING,d.PRESENT];var Le={READ:"read",VREAD:"vread",UPDATE:"update",PATCH:"patch",DELETE:"delete",HISTORY:"history",HISTORY_INSTANCE:"history-instance",HISTORY_TYPE:"history-type",HISTORY_SYSTEM:"history-system",CREATE:"create",SEARCH:"search",SEARCH_TYPE:"search-type",SEARCH_SYSTEM:"search-system",SEARCH_COMPARTMENT:"search-compartment",CAPABILITIES:"capabilities",TRANSACTION:"transaction",BATCH:"batch",OPERATION:"operation"},as=[Le.READ,Le.VREAD,Le.HISTORY,Le.HISTORY_INSTANCE];function Fe(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,i=>{let e=Math.random()*16|0;return(i==="x"?e:e&3|8).toString(16)})}var Vo={CSS:"text/css",DICOM:"application/dicom",FAVICON:"image/vnd.microsoft.icon",FHIR_JSON:"application/fhir+json",FORM_URL_ENCODED:"application/x-www-form-urlencoded",HL7_V2:"x-application/hl7-v2+er7",HTML:"text/html",JAVASCRIPT:"text/javascript",JSON:"application/json",JSON_PATCH:"application/json-patch+json",PNG:"image/png",SCIM_JSON:"application/scim+json",SVG:"image/svg+xml",TEXT:"text/plain",TYPESCRIPT:"text/typescript",PING:"x-application/ping",XML:"text/xml",CDA_XML:"application/cda+xml"};var Mo;Mo=Symbol.toStringTag;var cs={Event:typeof globalThis.Event<"u"?globalThis.Event:void 0,ErrorEvent:void 0,CloseEvent:void 0};var us={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 ds=Vo.FHIR_JSON+", */*; q=0.1";var ls=[...Gi,"->","<<",">>","=="];var ps=lt().registerInfix("->",{precedence:l.Arrow}).registerInfix(";",{precedence:l.Semicolon});var hs=" ".repeat(2);var fs=[...Gi,"eq","ne","co"];var _s={eq:d.EXACT,ne:d.NOT_EQUALS,co:d.CONTAINS,sw:d.STARTS_WITH,ew:void 0,gt:d.GREATER_THAN,lt:d.LESS_THAN,ge:d.GREATER_THAN_OR_EQUALS,le:d.LESS_THAN_OR_EQUALS,ap:d.APPROXIMATELY,sa:d.STARTS_AFTER,eb:d.ENDS_BEFORE,pr:d.PRESENT,po:void 0,ss:void 0,sb:void 0,in:d.IN,ni:d.NOT_IN,re:d.EQUALS,identifier:d.IDENTIFIER};var ms=lt();function Ge(i){if(!i)return;let e=i.substring(0,4),t="01",n="01";return i.length>=8&&(t=i.substring(4,6),n=i.substring(6,8)),`${e}-${t}-${n}`}function m(i){if(!i)return;let e=i.substring(0,4),t="01",n="01",r="00",o="00",s="00",a="Z";return i.length>=8&&(t=i.substring(4,6),n=i.substring(6,8)),i.length>=12&&(r=i.substring(8,10),o=i.substring(10,12)),i.length>=14&&(s=i.substring(12,14)),i.length>14&&(a=i.substring(14),a==="+0000"&&(a="Z")),`${e}-${t}-${n}T${r}:${o}:${s}${a}`}function L(i){if(i)return i.substring(0,10).replace(/-/g,"")}function O(i){if(!i)return;let[e,t]=i.split("T"),n=e.replaceAll("-",""),r=(t??"").replaceAll(/\.\d+/g,"").replaceAll(/:/g,"").replaceAll(/Z/g,"+0000");return`${n}${r}`}var Ye="1.3.6.1.4.1.19376.1.5.3.1.3.1";var Yi="2.16.840.1.113883.1.3";var Hi="2.16.840.1.113883.2.20.5.1",$i="2.16.840.1.113883.3.26.1.1";var ji="2.16.840.1.113883.4.1",qi="2.16.840.1.113883.4.3",Wi="2.16.840.1.113883.4.6",Qi="2.16.840.1.113883.4.9",He="2.16.840.1.113883.5.1",$e="2.16.840.1.113883.5.4",pt="2.16.840.1.113883.5.6",ht="2.16.840.1.113883.5.25",b="2.16.840.1.113883.6.1",zi="2.16.840.1.113883.6.12",Zi="2.16.840.1.113883.6.24",Xi="2.16.840.1.113883.6.69",Ji="2.16.840.1.113883.6.88",U="2.16.840.1.113883.6.96",Ki="2.16.840.1.113883.6.101",en="2.16.840.1.113883.6.209",je="2.16.840.1.113883.6.238",tn="2.16.840.1.113883.6.345";var nn="2.16.840.1.113883.10.20.15.3.8";var ft="2.16.840.1.113883.10.20.22.1.1";var _t="2.16.840.1.113883.10.20.22.1.2";var qe="2.16.840.1.113883.10.20.22.2.1.1";var ee="2.16.840.1.113883.10.20.22.2.2",te="2.16.840.1.113883.10.20.22.2.2.1";var mt="2.16.840.1.113883.10.20.22.2.3.1";var rn="2.16.840.1.113883.10.20.22.2.4.1";var ie="2.16.840.1.113883.10.20.22.2.5.1";var ne="2.16.840.1.113883.10.20.22.2.6.1";var F="2.16.840.1.113883.10.20.22.2.7.1";var We="2.16.840.1.113883.10.20.22.2.8";var V="2.16.840.1.113883.10.20.22.2.10";var Et="2.16.840.1.113883.10.20.22.2.17";var Qe="2.16.840.1.113883.10.20.22.2.18";var on="2.16.840.1.113883.10.20.22.2.22.1";var sn="2.16.840.1.113883.10.20.22.2.23";var an="2.16.840.1.113883.10.20.22.2.56";var ze="2.16.840.1.113883.10.20.22.2.58";var re="2.16.840.1.113883.10.20.22.2.60";var Ze="2.16.840.1.113883.10.20.22.2.65";var Xe="2.16.840.1.113883.10.20.22.2.500",oe="2.16.840.1.113883.10.20.22.4.1",cn="2.16.840.1.113883.10.20.22.4.1.2",se="2.16.840.1.113883.10.20.22.4.2",un="2.16.840.1.113883.10.20.22.4.2.2",It="2.16.840.1.113883.10.20.22.4.3";var ae="2.16.840.1.113883.10.20.22.4.4",dn="2.16.840.1.113883.10.20.22.4.4.2";var Tt="2.16.840.1.113883.10.20.22.4.7";var Ot="2.16.840.1.113883.10.20.22.4.8";var St="2.16.840.1.113883.10.20.22.4.9";var ce="2.16.840.1.113883.10.20.22.4.12";var ue="2.16.840.1.113883.10.20.22.4.13";var de="2.16.840.1.113883.10.20.22.4.14";var yt="2.16.840.1.113883.10.20.22.4.16";var ln="2.16.840.1.113883.10.20.22.4.20";var Ct="2.16.840.1.113883.10.20.22.4.23";var le="2.16.840.1.113883.10.20.22.4.26",pn="2.16.840.1.113883.10.20.22.4.26.2",pe="2.16.840.1.113883.10.20.22.4.27",hn="2.16.840.1.113883.10.20.22.4.27.2";var gt="2.16.840.1.113883.10.20.22.4.30";var At="2.16.840.1.113883.10.20.22.4.32";var fn="2.16.840.1.113883.10.20.22.4.37",_n="2.16.840.1.113883.10.20.22.4.38",mn="2.16.840.1.113883.10.20.22.4.38.1";var Nt="2.16.840.1.113883.10.20.22.4.44";var Rt="2.16.840.1.113883.10.20.22.4.49";var Dt="2.16.840.1.113883.10.20.22.4.52";var vt="2.16.840.1.113883.10.20.22.4.54";var En="2.16.840.1.113883.10.20.22.4.66";var In="2.16.840.1.113883.10.20.22.4.67";var Tn="2.16.840.1.113883.10.20.22.4.69",On="2.16.840.1.113883.10.20.22.4.70";var Sn="2.16.840.1.113883.10.20.22.4.74";var yn="2.16.840.1.113883.10.20.22.4.75";var he="2.16.840.1.113883.10.20.22.4.78",Cn="2.16.840.1.113883.10.20.22.4.78.2";var fe="2.16.840.1.113883.10.20.22.4.85";var gn="2.16.840.1.113883.10.20.22.4.86";var An="2.16.840.1.113883.10.20.22.4.114";var Nn="2.16.840.1.113883.10.20.22.4.119";var Je="2.16.840.1.113883.10.20.22.4.121";var Rn="2.16.840.1.113883.10.20.22.4.130";var xt="2.16.840.1.113883.10.20.22.4.132",Dn="2.16.840.1.113883.10.20.22.4.133";var Ke="2.16.840.1.113883.10.20.22.4.147",_e="2.16.840.1.113883.10.20.22.4.200",vn="2.16.840.1.113883.10.20.22.4.201",xn="2.16.840.1.113883.10.20.22.4.202";var Pn="2.16.840.1.113883.10.20.22.4.244";var bn="2.16.840.1.113883.10.20.22.4.250";var Ln="2.16.840.1.113883.10.20.22.4.406",Un="2.16.840.1.113883.10.20.22.4.407";var Vn="2.16.840.1.113883.10.20.22.4.416";var Pt="2.16.840.1.113883.10.20.22.4.500",Mn="2.16.840.1.113883.10.20.22.4.501";var wn="2.16.840.1.113883.10.20.22.4.503",Bn="2.16.840.1.113883.10.20.22.4.504";var kn="2.16.840.1.113883.10.20.22.4.506",et="2.16.840.1.113883.10.20.22.4.507",Fn="2.16.840.1.113883.10.20.22.4.508";var Gn="2.16.840.1.113883.10.20.22.4.512";var bt="2.16.840.1.113883.12.292",Lt="2.16.840.1.113883.3.3719";var E=class{constructor(e,t,n,r){this.systemName=e,this.ccdaSystemOid=t,this.fhirSystemUrl=n,this.entries=r,this.ccdaToFhirMap={},this.fhirToCcdaMap={};for(let o of r)this.ccdaToFhirMap[o.ccdaValue]||(this.ccdaToFhirMap[o.ccdaValue]=o),this.fhirToCcdaMap[o.fhirValue]||(this.fhirToCcdaMap[o.fhirValue]=o)}getEntryByFhir(e){return this.fhirToCcdaMap[e]}getEntryByCcda(e){return this.ccdaToFhirMap[e]}mapCcdaToFhir(e){return this.ccdaToFhirMap[e]?.fhirValue}mapCcdaToFhirWithDefault(e,t){return e?this.mapCcdaToFhir(e)??t:t}mapFhirToCcdaWithDefault(e,t){return e?this.mapFhirToCcda(e)??t:t}mapCcdaToFhirCodeableConcept(e){let t=this.ccdaToFhirMap[e];if(t)return{coding:[{system:this.fhirSystemUrl,code:t.fhirValue,display:t.displayName}],text:t.displayName}}mapFhirToCcda(e){if(e)return this.fhirToCcdaMap[e]?.ccdaValue}mapFhirToCcdaCode(e){if(!e)return;let t=this.fhirToCcdaMap[e];if(t)return{"@_code":t.ccdaValue,"@_displayName":t.displayName,"@_codeSystem":this.ccdaSystemOid,"@_codeSystemName":ge.getEntryByCcda(this.ccdaSystemOid)?.displayName}}},M="http:",Yn=`${_}/fhir/administrative-gender`,tt=`${T}/CodeSystem/condition-clinical`,Vt=`${T}/CodeSystem/condition-verification`,wo=`${T}/CodeSystem/v3-LanguageAbilityMode`,Bo=`${T}/CodeSystem/v3-LanguageAbilityProficiency`,ko=`${T}/CodeSystem/v3-Race`,Mt=`${T}/CodeSystem/condition-category`,it=`${T}/CodeSystem/condition-ver-status`,me=`${T}/CodeSystem/allergyintolerance-clinical`,nt=`${T}/CodeSystem/allergyintolerance-verification`,wt=`${T}/CodeSystem/v3-ActCode`,Bt=`${T}/CodeSystem/v3-ParticipationType`,kt=`${T}/CodeSystem/diagnosis-role`,Hn=`${T}/CodeSystem/v3-Confidentiality`,$n=`${T}/CodeSystem/observation-category`,jn=`${_}/fhir/ValueSet/address-use`,qn=`${_}/fhir/ValueSet/name-use`,Wn=`${_}/fhir/ValueSet/administrative-gender`,Qn=`${_}/fhir/ValueSet/contactentity-use`,zn=`${_}/fhir/ValueSet/medicationrequest-status`,Fo=`${_}/fhir/StructureDefinition/language-mode`,Go=`${_}/fhir/StructureDefinition/language-proficiency`,Yo=`${_}/fhir/us/core/StructureDefinition/us-core-patient`,G=`${_}/fhir/us/core/StructureDefinition/us-core-race`,Ee=`${_}/fhir/us/core/StructureDefinition/us-core-ethnicity`,Ft=`${_}/fhir/us/core/StructureDefinition/us-core-condition`,Gt=`${_}/fhir/us/core/StructureDefinition/us-core-medicationrequest`,Ho=`${_}/cda/template`,Zn=`${M}//ncithesaurus-stage.nci.nih.gov`,Xn=`${_}/fhir/sid/us-ssn`,Jn=`${_}/fhir/sid/us-dln`,Kn=`${_}/fhir/sid/us-npi`,er=`${M}//fdasis.nlm.nih.gov`,tr=`${M}//nucc.org/provider-taxonomy`,ir=`${M}//va.gov/terminology/medrt`,nr=`${M}//hl7.org/fhir/ndfrt`,rr=`${M}//nucc.org/cvx`,or=`${_}/fhir/sid/cvx`,Yt=`${M}//www.w3.org/2001/XMLSchema-instance`,Ie="https://medplum.com/fhir/StructureDefinition/ccda-narrative-reference",Ht="48765-2",$t="11369-6",jt="10160-0",Te="11450-4",qt="30954-2",Wt="29762-2",Qt="8716-3",zt="47519-4",Oe="18776-5",Se="51848-0",Zt="46264-8",Y="61146-7",H="75310-3",Xt="46240-8",Jt="42349-1",Kt="10190-7",ei="85847-2",ti="48768-6",ye="11488-4",$o="34109-9",jo="60591-5",Ce="34133-9",ii="76662-6",ni="75323-6",ri="58144-7",oi="72166-2",si="11367-0",ai="46098-0",ci="76689-9",ge=new E("System","","",[{ccdaValue:Hi,fhirValue:"https://fhir.infoway-inforoute.ca/CodeSystem/pCLOCD",displayName:"pan-Canadian LOINC Observation Code Database (pCLOCD)"},{ccdaValue:$i,fhirValue:Zn,displayName:"NCI Thesaurus"},{ccdaValue:ji,fhirValue:Xn,displayName:"SSN"},{ccdaValue:qi,fhirValue:Jn,displayName:"DLN"},{ccdaValue:Wi,fhirValue:Kn,displayName:"NPI"},{ccdaValue:Qi,fhirValue:er,displayName:"Unique Ingredient Identifier (UNII)"},{ccdaValue:b,fhirValue:we,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:Xi,fhirValue:xi,displayName:"National Drug Code (NDC)"},{ccdaValue:Ji,fhirValue:Di,displayName:"RxNorm"},{ccdaValue:U,fhirValue:at,displayName:"SNOMED CT"},{ccdaValue:Ki,fhirValue:tr,displayName:"NUCC Health Care Provider Taxonomy"},{ccdaValue:tn,fhirValue:ir,displayName:"Medication Reference Terminology (MED-RT)"},{ccdaValue:en,fhirValue:nr,displayName:"National Drug File Reference Terminology (NDF-RT)"},{ccdaValue:bt,fhirValue:rr,displayName:"CVX"},{ccdaValue:ht,fhirValue:"Confidentiality",displayName:"Confidentiality"},{ccdaValue:He,fhirValue:Yn,displayName:"Administrative Sex"},{ccdaValue:bt,fhirValue:or,displayName:"Vaccine Administered Code Set (CVX)"}]);function $(i){if(i)return ge.mapCcdaToFhir(i)??`urn:oid:${i}`}function ui(i){if(i)return i.startsWith("urn:oid:")?i.replace("urn:oid:",""):ge.mapFhirToCcda(i)}function p(i){if(!i?.coding)return;let e=Ut(i.coding[0]);if(i.coding.length>1){e.translation=[];for(let t=1;t<i.coding.length;t++)e.translation.push(Ut(i.coding[t]))}return e}function Ut(i){let e=i?.system?ge.getEntryByFhir(i.system):void 0,t=e?.ccdaValue,n=e?.displayName,r=i.system?.startsWith("urn:oid:")?i.system.replace("urn:oid:",""):void 0;return{"@_code":i.code,"@_displayName":i.display,"@_codeSystem":t??r,"@_codeSystemName":n}}function j(i){let e=p(i);if(e)return{"@_xsi:type":"CD",...e}}var di=new E("Confidentiality",ht,Hn,[{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"}]),Ae=new E("HumanNameUse","",qn,[{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"}]),li=new E("Gender","",Wn,[{ccdaValue:"F",fhirValue:"female",displayName:"Female"},{ccdaValue:"M",fhirValue:"male",displayName:"Male"},{ccdaValue:"UN",fhirValue:"unknown",displayName:"Unknown"},{ccdaValue:"UN",fhirValue:"other",displayName:"Other"}]),Ne=new E("AddressUse","",jn,[{ccdaValue:"HP",fhirValue:"home",displayName:"Home"},{ccdaValue:"WP",fhirValue:"work",displayName:"Work"}]),Re=new E("TelecomUse","",Qn,[{ccdaValue:"WP",fhirValue:"work",displayName:"Work"},{ccdaValue:"HP",fhirValue:"home",displayName:"Home"},{ccdaValue:"MC",fhirValue:"mobile",displayName:"Mobile"}]),De=new E("AllergyStatus","",nt,[{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"}]),pi=new E("AllergyCategory",U,me,[{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)"}]),ve=new E("AllergySeverity",at,me,[{ccdaValue:"255604002",fhirValue:"mild",displayName:"Mild"},{ccdaValue:"6736007",fhirValue:"moderate",displayName:"Moderate"},{ccdaValue:"24484000",fhirValue:"severe",displayName:"Severe"}]),q=new E("ProblemStatus","",it,[{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"}]),xe=new E("ImmunizationStatus","","",[{ccdaValue:"completed",fhirValue:"completed",displayName:"Completed"},{ccdaValue:"nullified",fhirValue:"entered-in-error",displayName:"Nullified"},{ccdaValue:"aborted",fhirValue:"not-done",displayName:"Aborted"},{ccdaValue:"cancelled",fhirValue:"not-done",displayName:"Cancelled"},{ccdaValue:"obsolete",fhirValue:"not-done",displayName:"Obsolete"}]),hi=new E("EncounterStatus","","",[{ccdaValue:"active",fhirValue:"in-progress",displayName:"In Progress"},{ccdaValue:"completed",fhirValue:"finished",displayName:"Finished"},{ccdaValue:"aborted",fhirValue:"cancelled",displayName:"Cancelled"},{ccdaValue:"cancelled",fhirValue:"cancelled",displayName:"Cancelled"},{ccdaValue:"unknown",fhirValue:"unknown",displayName:"Unknown"}]),fi=new E("ProcedureStatus","","",[{ccdaValue:"completed",fhirValue:"completed",displayName:"Completed"},{ccdaValue:"aborted",fhirValue:"stopped",displayName:"Stopped"},{ccdaValue:"cancelled",fhirValue:"not-done",displayName:"Not Done"},{ccdaValue:"new",fhirValue:"not-done",displayName:"Draft"},{ccdaValue:"unknown",fhirValue:"unknown",displayName:"Unknown"}]),Pe=new E("MedicationStatus","",zn,[{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"}]),_i=new E("ObservationCategory","",$n,[{ccdaValue:_n,fhirValue:"social-history",displayName:"Social History"},{ccdaValue:mn,fhirValue:"social-history",displayName:"Social History V2"},{ccdaValue:he,fhirValue:"social-history",displayName:"Smoking Status"},{ccdaValue:Cn,fhirValue:"social-history",displayName:"Current Smoking Status"},{ccdaValue:fe,fhirValue:"social-history",displayName:"Tobacco Use"},{ccdaValue:wn,fhirValue:"social-history",displayName:"Basic Occupation"},{ccdaValue:Bn,fhirValue:"social-history",displayName:"Basic Industry"},{ccdaValue:Mn,fhirValue:"social-history",displayName:"Sexual Orientation"},{ccdaValue:et,fhirValue:"social-history",displayName:"Sex Observation"},{ccdaValue:_e,fhirValue:"social-history",displayName:"Gender Identity"},{ccdaValue:vn,fhirValue:"social-history",displayName:"Gender Identity V2"},{ccdaValue:nn,fhirValue:"social-history",displayName:"Pregnancy Status"},{ccdaValue:kn,fhirValue:"social-history",displayName:"Tribal Affiliation"},{ccdaValue:pe,fhirValue:"vital-signs",displayName:"Vital Signs Observation"},{ccdaValue:hn,fhirValue:"vital-signs",displayName:"Vital Signs Observation V2"},{ccdaValue:le,fhirValue:"vital-signs",displayName:"Vital Signs Organizer"},{ccdaValue:pn,fhirValue:"vital-signs",displayName:"Vital Signs Organizer V2"},{ccdaValue:Gn,fhirValue:"vital-signs",displayName:"Average Blood Pressure Organizer"},{ccdaValue:se,fhirValue:"laboratory",displayName:"Result Observation"},{ccdaValue:un,fhirValue:"laboratory",displayName:"Result Observation V2"},{ccdaValue:Ln,fhirValue:"laboratory",displayName:"Laboratory Battery (ID)"},{ccdaValue:Un,fhirValue:"laboratory",displayName:"Laboratory Observation (ID)"},{ccdaValue:Vn,fhirValue:"laboratory",displayName:"Laboratory Result Organizer (ID)"},{ccdaValue:oe,fhirValue:"laboratory",displayName:"Result Organizer"},{ccdaValue:cn,fhirValue:"laboratory",displayName:"Result Organizer V2"},{ccdaValue:Tn,fhirValue:"survey",displayName:"Assessment Scale Observation"},{ccdaValue:gn,fhirValue:"survey",displayName:"Assessment Scale Supporting Observation"},{ccdaValue:Sn,fhirValue:"survey",displayName:"Cognitive Status Result Observation"},{ccdaValue:yn,fhirValue:"survey",displayName:"Cognitive Status Result Organizer"},{ccdaValue:In,fhirValue:"survey",displayName:"Functional Status Result Observation"},{ccdaValue:En,fhirValue:"survey",displayName:"Functional Status Result Organizer"},{ccdaValue:ue,fhirValue:"exam",displayName:"Procedure Activity Observation"},{ccdaValue:ae,fhirValue:"exam",displayName:"Problem Observation"},{ccdaValue:dn,fhirValue:"exam",displayName:"Problem Observation V2"},{ccdaValue:On,fhirValue:"exam",displayName:"Pressure Ulcer Observation"},{ccdaValue:An,fhirValue:"exam",displayName:"Wound Observation"},{ccdaValue:Dn,fhirValue:"exam",displayName:"Wound Measurements Observation"},{ccdaValue:F,fhirValue:"exam",displayName:"Procedure Section"},{ccdaValue:Fn,fhirValue:"therapy",displayName:"Medication Adherence"},{ccdaValue:Rn,fhirValue:"therapy",displayName:"Nutrition Recommendations"},{ccdaValue:Pn,fhirValue:"therapy",displayName:"Diet Statement (Nutrition)"},{ccdaValue:bn,fhirValue:"therapy",displayName:"Monitoring, Evaluation and Outcome (Nutrition)"}]);var W=require("fast-xml-parser");var qo=["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","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 Wo(i){return new W.XMLParser({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1,isArray:(n,r,o,s)=>qo.some(a=>r.endsWith(a))}).parse(i).ClinicalDocument}function Qo(i){return new W.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":Yt,"@_xmlns:voc":"urn:hl7-org:v3/voc","@_xmlns:sdtc":"urn:hl7-org:sdtc",...i}})}function mi(i){return new W.XMLParser({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1}).parse(i)}function Ei(i){return i?typeof i=="string"?i:new W.XMLBuilder({ignoreAttributes:!1,attributeNamePrefix:"@_",format:!1,suppressBooleanAttributes:!1,suppressEmptyNode:!0}).build(i).split(`
|
|
2
|
+
`).map(n=>n.trim()).join(""):""}function zo(i){return new Ii(i).convert()}var Ii=class{constructor(e){this.resources=[];this.ccda=e}convert(){return this.processHeader(),{resourceType:"Bundle",type:"document",entry:[{resource:this.createComposition()},...this.patient?[{resource:this.patient}]:[],...this.resources.map(t=>({resource:t}))]}}processHeader(){let e=this.ccda.recordTarget?.[0]?.patientRole;e&&(this.patient=this.createPatient(e))}createPatient(e){let t=e.patient,n=[];return t.raceCode&&t.raceCode.length>0&&!t.raceCode[0]["@_nullFlavor"]&&n.push({url:G,extension:t.raceCode.map(r=>({url:"ombCategory",valueCoding:this.mapCodeToCoding(r)}))}),t.ethnicGroupCode&&t.ethnicGroupCode.length>0&&!t.ethnicGroupCode[0]["@_nullFlavor"]&&n.push({url:Ee,extension:t.ethnicGroupCode.map(r=>({url:"ombCategory",valueCoding:this.mapCodeToCoding(r)}))}),{resourceType:"Patient",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),name:this.mapCcdaNameArrayFhirHumanNameArray(t.name),gender:this.mapGenderCode(t.administrativeGenderCode?.["@_code"]),birthDate:Ge(t.birthTime?.["@_value"]),address:this.mapAddresses(e.addr),telecom:this.mapTelecom(e.telecom),extension:n.length>0?n:void 0}}mapId(e){let t=e?.find(n=>!n["@_extension"]&&n["@_root"]&&ut(n["@_root"]));return t?t["@_root"]:Fe()}mapIdentifiers(e){if(!e)return;let t=[];for(let n of e)!n["@_extension"]&&n["@_root"]&&ut(n["@_root"])||t.push({system:$(n["@_root"]),value:n["@_extension"]});return t}mapCcdaNameArrayFhirHumanNameArray(e){return e?.map(t=>this.mapCcdaNameToFhirHumanName(t)).filter(Boolean)}mapCcdaNameToFhirHumanName(e){if(!e)return;let t={},n=e["@_use"]?Ae.mapCcdaToFhir(e["@_use"]):void 0;return n&&(t.use=n),e.prefix&&(t.prefix=e.prefix.map(be)?.filter(Boolean)),e.family&&(t.family=be(e.family)),e.given&&(t.given=e.given.map(be)?.filter(Boolean)),e.suffix&&(t.suffix=e.suffix.map(be)?.filter(Boolean)),t}mapAddresses(e){if(!(!e||e.length===0||e.every(t=>t["@_nullFlavor"]==="UNK")))return e?.map(t=>({"@_use":t["@_use"]?Ne.mapCcdaToFhir(t["@_use"]):void 0,line:t.streetAddressLine,city:t.city,state:t.state,postalCode:t.postalCode,country:t.country}))}mapTelecom(e){if(!(!e||e.length===0||e.every(t=>t["@_nullFlavor"]==="UNK")))return e?.map(t=>({"@_use":t["@_use"]?Re.mapCcdaToFhir(t["@_use"]):void 0,system:this.getTelecomSystem(t["@_value"]),value:this.getTelecomValue(t["@_value"])}))}createComposition(){let e=this.ccda.component?.structuredBody?.component||[],t=[];for(let n of e)for(let r of n.section){let o=this.processSection(r);t.push({title:r.title,code:this.mapCode(r.code),text:{status:"generated",div:`<div xmlns="http://www.w3.org/1999/xhtml">${Ei(r.text)}</div>`},entry:o.map(f)}),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:we,code:Ce}]},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:m(this.ccda.effectiveTime?.[0]?.["@_value"])??new Date().toISOString(),title:this.ccda.title??"Medical Summary",section:t}}processSection(e){let t=[];if(e.entry)for(let n of e.entry)this.processEntry(e,n,t);return t}processEntry(e,t,n){for(let r of t.act??[]){let o=this.processAct(e,r);o&&n.push(o)}for(let r of t.substanceAdministration??[]){let o=this.processSubstanceAdministration(e,r);o&&n.push(o)}for(let r of t.organizer??[])n.push(this.processOrganizer(e,r));for(let r of t.observation??[])n.push(this.processObservation(e,r));for(let r of t.encounter??[])n.push(this.processEncounter(e,r));for(let r of t.procedure??[])n.push(this.processProcedure(e,r))}processAct(e,t){let n=e.templateId[0]["@_root"];switch(n){case ne:return this.processAllergyIntoleranceAct(t);case ie:return this.processConditionAct(t);case V:return this.processCarePlanAct(t);case ze:return this.processConditionAct(t);case F:return this.processProcedureAct(t);case Ye:return;case Ze:return;case Qe:return;default:throw new Error("Unhandled act templateId: "+n)}}processAllergyIntoleranceAct(e){let t=e.entryRelationship?.find(s=>s["@_typeCode"]==="SUBJ")?.observation?.[0];if(!t)return;let n={resourceType:"AllergyIntolerance",id:this.mapId(e.id),clinicalStatus:this.createClinicalStatus(e),verificationStatus:this.createVerificationStatus(),type:"allergy",category:["food"],patient:f(this.patient),recorder:this.mapAuthorToReference(e.author?.[0]),recordedDate:this.mapEffectiveTimeToDateTime(e.effectiveTime?.[0]),onsetDateTime:this.mapEffectiveTimeToDateTime(t.effectiveTime?.[0])};t.value?.["@_code"]==="414285001"&&(n.category=["food"]),n.extension=this.mapTextReference(t.text);let r=t.participant?.[0]?.participantRole?.playingEntity?.code;r&&(n.code=this.mapCode(r),n.code&&r.originalText?.reference?.["@_value"]&&(n.code.extension=this.mapTextReference(r.originalText)));let o=t.entryRelationship?.find(s=>s["@_typeCode"]==="MFST")?.observation;return o&&(n.reaction=o.map(s=>this.processReaction(s))),n.asserter=this.mapAuthorToReference(t.author?.[0]),n}processConditionAct(e){let t=e.entryRelationship?.find(r=>r["@_typeCode"]==="SUBJ")?.observation?.[0];if(!t)return;let n={resourceType:"Condition",id:this.mapId(e.id),identifier:this.concatArrays(this.mapIdentifiers(e.id),this.mapIdentifiers(t.id)),meta:{profile:[Ft]},clinicalStatus:{coding:[{system:tt,code:q.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active")}]},verificationStatus:{coding:[{system:Vt,code:"confirmed"}]},category:[{coding:[{system:Mt,code:"problem-list-item",display:"Problem List Item"}]}],code:this.mapCode(t.value),subject:f(this.patient),onsetDateTime:m(t.effectiveTime?.[0]?.low?.["@_value"]),abatementDateTime:m(t.effectiveTime?.[0]?.high?.["@_value"]),recordedDate:this.mapEffectiveTimeToDateTime(e.effectiveTime?.[0]),recorder:this.mapAuthorToReference(t.author?.[0]),asserter:this.mapAuthorToReference(t.author?.[0])};return n.extension=this.mapTextReference(t.text),n}processCarePlanAct(e){return{resourceType:"CarePlan",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"completed",intent:"plan",title:"CARE PLAN",category:e.code?[this.mapCode(e.code)]:void 0,subject:f(this.patient),description:be(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:f(this.patient),performedDateTime:m(e.effectiveTime?.[0]?.["@_value"]),recorder:this.mapAuthorToReference(e.author?.[0]),asserter:this.mapAuthorToReference(e.author?.[0]),extension:this.mapTextReference(e.text)}}processSubstanceAdministration(e,t){let n=e.templateId[0]["@_root"];switch(n){case qe:case V:return this.processMedicationSubstanceAdministration(t);case ee:case te:return this.processImmunizationSubstanceAdministration(t);default:throw new Error("Unhandled substance administration templateId: "+n)}}processMedicationSubstanceAdministration(e){let t=this.mapId(e.id),n=e.consumable?.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.code?.[0],r=e.routeCode,o=e.doseQuantity,s=e.consumable?.manufacturedProduct?.[0]?.manufacturerOrganization?.[0],a=e.entryRelationship?.find(I=>I.substanceAdministration?.[0]?.templateId?.[0]?.["@_root"]===Ke)?.substanceAdministration?.[0],h,S;return s?h={resourceType:"Medication",id:"med-"+t,code:this.mapCode(n),extension:this.mapTextReference(n?.originalText),manufacturer:s?{identifier:{value:s.id?.[0]?.["@_root"]},display:s.name?.[0]}:void 0}:S={...this.mapCode(n),extension:this.mapTextReference(n?.originalText)},{resourceType:"MedicationRequest",id:t,contained:h?[h]:void 0,meta:{profile:[Gt]},extension:this.mapTextReference(e.text),status:Pe.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active"),intent:"order",medicationReference:h?{reference:"#med-"+t}:void 0,medicationCodeableConcept:S,subject:f(this.patient),authoredOn:m(e.author?.[0]?.time?.["@_value"]),dispenseRequest:e.effectiveTime?.[0]?{validityPeriod:{start:m(e.effectiveTime?.[0]?.low?.["@_value"]),end:m(e.effectiveTime?.[0]?.high?.["@_value"])}}:void 0,dosageInstruction:[{text:typeof e.text=="string"?e.text:void 0,extension:this.mapTextReference(a?.text),route:r?this.mapCode(r):void 0,timing:{repeat:e.effectiveTime?.[1]?.period?{period:Number(e.effectiveTime?.[1]?.period["@_value"]),periodUnit:e.effectiveTime?.[1]?.period["@_unit"]}:void 0},doseAndRate:o?[{doseQuantity:{system:st,value:Number(o["@_value"]),code:"[IU]",unit:"[IU]"}}]:void 0}]}}processImmunizationSubstanceAdministration(e){let t=e.consumable;if(!t)return;let n={resourceType:"Immunization",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:xe.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"completed"),vaccineCode:this.mapCode(t.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.code?.[0]),patient:f(this.patient),occurrenceDateTime:m(e.effectiveTime?.[0]?.["@_value"]),lotNumber:t.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.lotNumberText?.[0]};return e.performer&&(n.performer=this.mapCcdaPerformerArrayToImmunizationPerformerArray(e.performer)),n.extension=this.mapTextReference(e.text),e.consumable?.manufacturedProduct?.[0]?.manufacturerOrganization?.[0]&&(n.manufacturer={display:e.consumable?.manufacturedProduct?.[0]?.manufacturerOrganization?.[0]?.name?.[0]}),n}processReaction(e){let t={id:this.mapId(e.id),manifestation:[this.mapCode(e.value)],onset:m(e.effectiveTime?.[0]?.low?.["@_value"])};return this.processSeverity(e,t),t.manifestation&&t.manifestation.length>0&&e.text?.reference?.["@_value"]&&(t.manifestation[0].extension=this.mapTextReference(e.text)),t}processSeverity(e,t){let n=e.entryRelationship?.find(o=>o["@_typeCode"]==="SUBJ")?.observation?.[0];if(!n)return;let r=n.value?.["@_code"];r&&(t.severity=ve.mapCcdaToFhir(r)),t.extension=this.mapTextReference(n.text)}mapEffectiveTimeToDateTime(e){if(e?.["@_value"])return m(e["@_value"]);if(e?.low?.["@_value"])return m(e.low["@_value"])}mapEffectiveTimeToPeriod(e){if(!e?.["@_value"]&&(e?.low||e?.high))return{start:m(e?.low?.["@_value"]),end:m(e?.high?.["@_value"])}}mapGenderCode(e){return e?{F:"female",M:"male",UN:"unknown"}[e]:void 0}getTelecomSystem(e){if(e)return e.startsWith("tel:")?"phone":e.startsWith("mailto:")?"email":"other"}getTelecomValue(e){if(e)return e.replace(/^(tel:|mailto:)/,"")}mapCode(e){if(!e)return;let t={coding:[{system:$(e["@_codeSystem"]),code:e["@_code"],display:e["@_displayName"]}],text:e["@_displayName"]};if(e.translation)for(let n of e.translation)t.coding.push({system:$(n["@_codeSystem"]),code:n["@_code"],display:n["@_displayName"]});return t}mapCodeToCoding(e){if(e)return{system:$(e["@_codeSystem"]),code:e["@_code"],display:e["@_displayName"]}}createClinicalStatus(e){return{coding:[{system:me,code:De.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active")}]}}createVerificationStatus(){return{coding:[{system:nt,code:"confirmed"}]}}mapAuthorToReference(e){if(!e)return;let t={resourceType:"Practitioner",id:this.mapId(e.assignedAuthor?.id),identifier:this.mapIdentifiers(e.assignedAuthor?.id),name:this.mapCcdaNameArrayFhirHumanNameArray(e.assignedAuthor?.assignedPerson?.name),address:this.mapAddresses(e.assignedAuthor?.addr),telecom:this.mapTelecom(e.assignedAuthor?.telecom),qualification:e.assignedAuthor?.code?[this.mapCode(e.assignedAuthor?.code)]:void 0};return this.resources.push(t),f(t)}mapAssignedEntityToReference(e){if(!e)return;let t=e.assignedPerson,n=e.representedOrganization,r={resourceType:"Practitioner",id:this.mapId(e?.id),identifier:this.mapIdentifiers(e?.id),name:this.mapCcdaNameArrayFhirHumanNameArray(t?.name),address:this.mapAddresses(e?.addr),telecom:this.mapTelecom(e?.telecom)};this.resources.push(r);let o={resourceType:"Organization",id:this.mapId(e?.id),identifier:this.mapIdentifiers(n?.id),name:n?.name?.[0],address:this.mapAddresses(n?.addr)};this.resources.push(o);let s={resourceType:"PractitionerRole",id:this.mapId(e?.id),practitioner:f(r),organization:f(o)};return this.resources.push(s),f(s)}mapCustodianToReference(e){if(!e)return;let t={resourceType:"Organization",id:this.mapId(e.assignedCustodian.representedCustodianOrganization.id),identifier:this.mapIdentifiers(e.assignedCustodian.representedCustodianOrganization.id),name:e.assignedCustodian.representedCustodianOrganization.name?.[0],address:this.mapAddresses(e.assignedCustodian.representedCustodianOrganization.addr),telecom:this.mapTelecom(e.assignedCustodian.representedCustodianOrganization.telecom)};return this.resources.push(t),f(t)}mapDocumentationOfToEvent(e){if(!e)return;let t=e.serviceEvent;if(t)return[{code:t.code?[this.mapCode(t.code)]:void 0,period:this.mapEffectiveTimeToPeriod(t.effectiveTime?.[0])}]}concatArrays(e,t){return e?t?[...e,...t]:e:t}mapCcdaPerformerArrayToImmunizationPerformerArray(e){let t=[];for(let n of e){let r=n.assignedEntity,o=this.mapAssignedEntityToReference(r);o&&t.push({actor:o})}return t}processOrganizer(e,t){return e.templateId[0]["@_root"]===Xe?this.processCareTeamOrganizer(t):this.processVitalsOrganizer(t)}processCareTeamOrganizer(e){let t=[];if(e.component)for(let r of e.component){let o=this.processCareTeamMember(r);o&&t.push(o)}return{resourceType:"CareTeam",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),participant:t.length>0?t:void 0}}processCareTeamMember(e){let t=e.act?.[0];if(!t)return;let n=t.performer?.[0];if(n)return{role:n.functionCode?[this.mapCode(n.functionCode)]:void 0,member:this.mapAssignedEntityToReference(n.assignedEntity),period:this.mapEffectiveTimeToPeriod(t.effectiveTime?.[0])}}processVitalsOrganizer(e){let t={resourceType:"Observation",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"final",category:this.mapObservationTemplateIdToObservationCategory(e.templateId),code:this.mapCode(e.code),subject:f(this.patient)};if(e.effectiveTime?.[0]?.["@_value"]&&(t.effectiveDateTime=m(e.effectiveTime?.[0]?.["@_value"])),e.component){let n=[];for(let r of e.component)n.push(...this.processVitalsComponent(r));n.length>0&&(t.hasMember=n)}return t}processVitalsComponent(e){let t=[];if(e.observation)for(let n of e.observation){let r=this.processVitalsObservation(n);t.push(f(r)),this.resources.push(r)}return t}processObservation(e,t){let n=t.templateId[0]["@_root"];if(n===re||n===Je)return this.processGoalObservation(t);switch(e.templateId[0]["@_root"]){case V:case re:return this.processGoalObservation(t);default:return this.processVitalsObservation(t)}}processGoalObservation(e){let t={resourceType:"Goal",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),lifecycleStatus:this.mapGoalLifecycleStatus(e),description:this.mapCode(e.code),subject:f(this.patient),startDate:Ge(e.effectiveTime?.[0]?.["@_value"])};return t.target=e.entryRelationship?.map(n=>({measure:this.mapCode(n.act?.[0]?.code),detailCodeableConcept:this.mapCode(n.act?.[0]?.code),dueDate:m(n.act?.[0]?.effectiveTime?.[0]?.low?.["@_value"])})),t.extension=this.mapTextReference(e.text),t}mapGoalLifecycleStatus(e){return{active:"active",completed:"completed",cancelled:"cancelled",aborted:"cancelled"}[e.statusCode["@_code"]??"active"]}processVitalsObservation(e){let t={resourceType:"Observation",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"final",category:this.mapObservationTemplateIdToObservationCategory(e.templateId),code:this.mapCode(e.code),subject:f(this.patient),referenceRange:this.mapReferenceRangeArray(e.referenceRange),performer:e.author?.map(n=>this.mapAuthorToReference(n)).filter(Boolean)};if(e.value?.["@_xsi:type"])switch(e.value["@_xsi:type"]){case"PQ":case"CO":t.valueQuantity={value:e.value["@_value"]?parseFloat(e.value["@_value"]):void 0,unit:e.value["@_unit"],system:st,code:e.value["@_unit"]};break;case"CD":case"CE":t.valueCodeableConcept=this.mapCode(e.value);break;case"ST":t.valueString=e.value["#text"]??"";break;default:console.warn(`Unhandled observation value type: ${e.value["@_xsi:type"]}`)}return e.effectiveTime?.[0]?.["@_value"]&&(t.effectiveDateTime=m(e.effectiveTime?.[0]?.["@_value"])),t.extension=this.mapTextReference(e.text),t}mapObservationTemplateIdToObservationCategory(e){if(!e)return;let t=new Set,n=[];for(let r of e){let o=_i.mapCcdaToFhirCodeableConcept(r["@_root"]);o?.coding?.[0]?.code&&!t.has(o.coding[0].code)&&(t.add(o.coding[0].code),n.push(o))}return Array.from(n.values())}mapReferenceRangeArray(e){if(!(!e||e.length===0))return e.map(t=>this.mapReferenceRange(t)).filter(Boolean)}mapReferenceRange(e){if(!e)return;let t=e.observationRange;if(!t)return;let n={};return n.extension=this.mapTextReference(t.text),n}processEncounter(e,t){let n={resourceType:"Encounter",id:this.mapId(t.id),identifier:this.mapIdentifiers(t.id),status:hi.mapCcdaToFhirWithDefault(t.statusCode?.["@_code"],"unknown"),class:{system:wt,code:t.code?.["@_code"]??"AMB",display:t.code?.["@_displayName"]??"Ambulatory"},type:t.code?[this.mapCode(t.code)]:void 0,subject:f(this.patient),period:this.mapEffectiveTimeToPeriod(t.effectiveTime?.[0])};if(t.performer&&(n.participant=t.performer.map(r=>({type:[{coding:[{system:Bt,code:r["@_typeCode"]??"PPRF",display:"Primary Performer"}]}],individual:this.mapAssignedEntityToReference(r.assignedEntity)}))),t.entryRelationship){let r=t.entryRelationship.filter(o=>o["@_typeCode"]==="RSON").map(o=>{let s=o.observation?.[0];if(!s)return;let a={resourceType:"Condition",id:this.mapId(s.id),identifier:this.mapIdentifiers(s.id),clinicalStatus:{coding:[{system:tt,code:"active"}]},verificationStatus:{coding:[{system:it,code:"confirmed"}]},code:this.mapCode(s.value),subject:f(this.patient),onsetDateTime:m(s.effectiveTime?.[0]?.low?.["@_value"])};return this.resources.push(a),{condition:f(a),use:{coding:[{system:kt,code:"AD",display:"Admission diagnosis"}]}}}).filter(Boolean);r.length>0&&(n.diagnosis=r)}return n.extension=this.mapTextReference(t.text),n}processProcedure(e,t){return{resourceType:"Procedure",id:this.mapId(t.id),identifier:this.mapIdentifiers(t.id),status:fi.mapCcdaToFhirWithDefault(t.statusCode?.["@_code"],"completed"),code:this.mapCode(t.code),subject:f(this.patient),performedPeriod:this.mapEffectiveTimeToPeriod(t.effectiveTime?.[0]),bodySite:t.targetSiteCode?[this.mapCode(t.targetSiteCode)]:void 0,extension:this.mapTextReference(t.text)}}mapTextReference(e){if(!(!e||typeof e!="object")&&e?.reference?.["@_value"])return[{url:Ie,valueString:e.reference?.["@_value"]}]}};function be(i){if(i){if(typeof i=="string")return i;if(typeof i=="object"&&"#text"in i)return i["#text"]}}var Ti=[{"@_root":ft,"@_extension":"2015-08-01"},{"@_root":ft},{"@_root":_t,"@_extension":"2015-08-01"},{"@_root":_t}],sr=[{"@_root":ne,"@_extension":"2015-08-01"},{"@_root":ne}],ar=[{"@_root":qe,"@_extension":"2014-06-09"}],cr=[{"@_root":ie,"@_extension":"2015-08-01"},{"@_root":ie}],ur=[{"@_root":ee},{"@_root":ee,"@_extension":"2015-08-01"},{"@_root":te},{"@_root":te,"@_extension":"2015-08-01"}],dr=[{"@_root":rn,"@_extension":"2015-08-01"}],lr=[{"@_root":Et},{"@_root":Et,"@_extension":"2015-08-01"}],pr=[{"@_root":F,"@_extension":"2014-06-09"}],Zo=[{"@_root":V,"@_extension":"2014-06-09"}],Xo=[{"@_root":mt,"@_extension":"2015-08-01"}],hr=[{"@_root":mt,"@_extension":"2015-08-01"}],fr=[{"@_root":sn,"@_extension":"2015-08-01"}],_r=[{"@_root":We}],mr=[{"@_root":V},{"@_root":V,"@_extension":"2014-06-09"}],Er=[{"@_root":on,"@_extension":"2015-08-01"}],Ir=[{"@_root":re}],Tr=[{"@_root":ze,"@_extension":"2015-08-01"}],Or=[{"@_root":Ye,"@_extension":"2014-06-09"}],Sr=[{"@_root":an,"@_extension":"2015-08-01"}],yr=[{"@_root":Ze,"@_extension":"2016-11-01"}],Cr=[{"@_root":Xe,"@_extension":"2022-06-01"}],gr=[{"@_root":Qe,"@_extension":"2015-08-01"}],Oi=Object.fromEntries([[Ht,sr],[jt,ar],[Te,cr],[$t,ur],[Qt,dr],[Wt,lr],[zt,pr],[qt,hr],[Se,_r],[Oe,mr],[Xt,Er],[Y,Ir],[H,Tr],[Jt,Or],[Kt,Sr],[ye,yr],[ei,Cr],[ti,gr],[Zt,fr]]);function Jo(i){return new Si(i).convert()}var Si=class{constructor(e){this.bundle=e;let t=this.findResource("Composition");if(!t)throw new Error("Composition not found");let n=this.findResource("Patient");if(!n)throw new Error("Patient not found");this.composition=t,this.patient=n}convert(){let e=this.createSections();return{realmCode:{"@_code":"US"},typeId:{"@_root":Yi,"@_extension":"POCD_HD000040"},templateId:Ti,id:this.mapIdentifiers(this.composition.id,void 0),code:{"@_code":Ce,"@_displayName":"Summarization of Episode Note","@_codeSystem":b,"@_codeSystemName":"LOINC"},title:this.composition.title,effectiveTime:this.mapEffectiveTime(this.composition.date,void 0),confidentialityCode:this.composition.confidentiality?di.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),documentationOf:this.mapDocumentationOf(this.composition.event),component:e.length>0?{structuredBody:{component:e.map(t=>({section:[t]}))}}:void 0}}findResource(e){return this.bundle.entry?.find(t=>t.resource?.resourceType===e)?.resource}findResourceByReference(e){if(!e?.reference)return;let[t,n]=e.reference.split("/");if(!(!t||!n))return this.bundle.entry?.find(r=>r.resource?.resourceType===t&&r.resource?.id===n)?.resource}findResourcesByReferences(e){return e?e.map(t=>this.findResourceByReference(t)).filter(t=>!!t):[]}createRecordTarget(){if(!this.patient)throw new Error("Patient not found");return[{patientRole:{id:this.mapIdentifiers(this.patient.id,this.patient.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(this.patient.address),telecom:this.mapTelecom(this.patient.telecom),patient:this.mapPatient(this.patient)}}]}mapPatient(e){return{name:this.mapNames(e.name),administrativeGenderCode:this.mapGender(e.gender),birthTime:this.mapBirthDate(e.birthDate),raceCode:this.mapRace(e),"sdtc:raceCode":this.mapDetailedRace(e),ethnicGroupCode:this.mapEthnicity(e.extension),languageCommunication:this.mapLanguageCommunication(e.communication)}}mapNames(e){return e?.map(t=>({"@_use":t.use?Ae.mapFhirToCcdaWithDefault(t.use,"L"):void 0,prefix:t.prefix,family:t.family,given:t.given,suffix:t.suffix}))}mapGender(e){if(e)return{"@_code":li.mapFhirToCcda(e),"@_displayName":e?J(e):"Unknown","@_codeSystem":He,"@_codeSystemName":"AdministrativeGender"}}mapBirthDate(e){if(e)return{"@_value":e.replace(/-/g,"")}}mapFhirAddressArrayToCcdaAddressArray(e){return!e||e.length===0?[{"@_nullFlavor":"UNK"}]:e.map(t=>this.mapFhirAddressToCcdaAddress(t)).filter(Boolean)}mapFhirAddressToCcdaAddress(e){return e?{"@_use":e.use?Ne.mapFhirToCcda(e.use):void 0,streetAddressLine:e.line||[],city:e.city,state:e.state,postalCode:e.postalCode,country:e.country}:void 0}mapRace(e){let t=ke(e,G,"ombCategory")?.valueCoding;return t?[{"@_code":t.code,"@_displayName":t.display,"@_codeSystem":je,"@_codeSystemName":"CDC Race and Ethnicity"}]:[{"@_nullFlavor":"UNK"}]}mapDetailedRace(e){let t=ke(e,G,"detailed")?.valueCoding;if(t)return[{"@_code":t.code,"@_displayName":t.display,"@_codeSystem":je,"@_codeSystemName":"CDC Race and Ethnicity"}]}mapEthnicity(e){let n=e?.find(r=>r.url===Ee)?.extension?.find(r=>r.url==="ombCategory")?.valueCoding;return n?[{"@_code":n.code,"@_displayName":n.display,"@_codeSystem":je,"@_codeSystemName":"CDC Race and Ethnicity"}]:[{"@_nullFlavor":"UNK"}]}mapLanguageCommunication(e){if(e?.length)return[{languageCode:{"@_code":e[0].language?.coding?.[0]?.code}}]}createSections(){let e=[];if(this.composition.section)for(let t of this.composition.section)e.push(this.createSection(t));return e}createSection(e){let t=e.code?.coding?.[0]?.code;if(!t)throw new Error(`Missing section code: ${JSON.stringify(e.code)}`);let n=Oi[t];if(!n)throw new Error(`Unknown section code: ${t}`);let r=this.findResourcesByReferences(e.entry);return t===Se&&r.length===1&&r[0].resourceType==="ClinicalImpression"?this.createClinicalImpressionSection(e,r[0]):{templateId:n,code:p(e.code),title:e.title,text:this.mapFhirTextDivToCcdaSectionText(e.text),entry:r.map(o=>this.createEntry(e,o)).filter(Boolean),"@_nullFlavor":r.length===0?"NI":void 0}}createEntry(e,t){switch(t.resourceType){case"AllergyIntolerance":return this.createAllergyEntry(t);case"CarePlan":return this.createPlanOfTreatmentCarePlanEntry(t);case"CareTeam":return this.createCareTeamEntry(t);case"ClinicalImpression":return this.createClinicalImpressionEntry(t);case"Condition":return this.createConditionEntry(e,t);case"DeviceUseStatement":return this.createDeviceUseStatementEntry(t);case"DiagnosticReport":return this.createDiagnosticReportEntry(t);case"Encounter":return this.createEncounterEntry(t);case"Goal":return this.createGoalEntry(e,t);case"Immunization":return this.createImmunizationEntry(t);case"MedicationRequest":return this.createMedicationEntry(t);case"Procedure":return this.createHistoryOfProceduresEntry(t);case"Observation":return this.createObservationEntry(t);case"ServiceRequest":return this.createPlanOfTreatmentServiceRequestEntry(t);default:return}}mapFhirTextDivToCcdaSectionText(e){if(!e)return;let t=mi(e.div)?.div;return t?.["@_xmlns"]&&delete t["@_xmlns"],t}createAllergyEntry(e){let t=e.reaction?.[0];return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":gt},{"@_root":gt,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"CONC","@_codeSystem":pt},statusCode:{"@_code":De.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:this.mapEffectivePeriod(e.recordedDate,void 0),author:this.mapAuthor(e.recorder,e.recordedDate),text:this.createTextFromExtensions(e.extension),entryRelationship:[{"@_typeCode":"SUBJ",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":Tt},{"@_root":Tt,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"ASSERTION","@_codeSystem":$e},statusCode:{"@_code":"completed"},author:this.mapAuthor(e.asserter,e.recordedDate),effectiveTime:this.mapEffectivePeriod(e.onsetPeriod?.start??e.onsetDateTime,e.onsetPeriod?.end,!0),value:this.mapAllergyCategory(e.category),text:this.createTextFromExtensions(e.extension),participant:[{"@_typeCode":"CSM",participantRole:{"@_classCode":"MANU",playingEntity:{"@_classCode":"MMAT",code:e.code?.coding?.[0]?.code==="716186003"?{"@_nullFlavor":"NA"}:{...p(e.code),originalText:e.code?.extension?{reference:this.getNarrativeReference(e.code?.extension)}:void 0}}}}],entryRelationship:t?[{"@_typeCode":"MFST","@_inversionInd":"true",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":St},{"@_root":St,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(t.id,void 0),code:{"@_code":"ASSERTION","@_codeSystem":$e},statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveDate(e.onsetDateTime,e.onsetPeriod),value:j(t.manifestation?.[0]),text:this.createTextFromExtensions(t.manifestation?.[0]?.extension),entryRelationship:[{"@_typeCode":"SUBJ","@_inversionInd":"true",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":Ot},{"@_root":Ot,"@_extension":"2014-06-09"}],code:{"@_code":"SEV","@_codeSystem":$e,"@_codeSystemName":"ActCode"},statusCode:{"@_code":"completed"},value:{"@_xsi:type":"CD","@_code":ve.mapFhirToCcdaWithDefault(t.severity,"M"),"@_displayName":t.severity?J(t.severity):void 0,"@_codeSystem":U,"@_codeSystemName":"SNOMED CT"},text:this.createTextFromExtensions(t.extension)}]}]}]}]:[]}]}]}]}}mapAllergyCategory(e){let t=pi.mapFhirToCcdaCode(e?.[0]);return t||(t={"@_code":"419199007","@_displayName":"Allergy to substance (disorder)","@_codeSystem":U,"@_codeSystemName":"SNOMED CT"}),{"@_xsi:type":"CD",...t}}mapAuthor(e,t,n){if(!e)return;let r=this.findResourceByReference(e);if(!r)return;let o;if(r.resourceType==="Organization"?o=r:r.resourceType==="PractitionerRole"&&(o=this.findResourceByReference(r.organization),r=this.findResourceByReference(r.practitioner)),!r)return;let s;"address"in r&&(s=r.address);let a;"telecom"in r&&(a=r.telecom);let h;"qualification"in r&&(h=r.qualification?.[0]);let S;return["Patient","Practitioner","RelatedPerson"].includes(r.resourceType)&&(S=r.name),[{templateId:[{"@_root":Nn}],time:t?{"@_value":O(t)}:void 0,assignedAuthor:{id:this.mapIdentifiers(r.id,r.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(s),telecom:this.mapTelecom(a),code:p(h),assignedPerson:S?{name:this.mapNames(S)}:void 0,assignedAuthoringDevice:!S&&n?{manufacturerModelName:"Medplum",softwareName:"Medplum"}:void 0,representedOrganization:o?.name?{name:[o.name]}:void 0}}]}mapCustodian(e){if(!e)return;let t=this.findResourceByReference(e);if(t)return{assignedCustodian:{representedCustodianOrganization:{id:this.mapIdentifiers(t.id,t.identifier),name:t.name?[t.name]:void 0,telecom:this.mapTelecom(t.telecom),addr:this.mapFhirAddressArrayToCcdaAddressArray(t.address)}}}}mapDocumentationOf(e){if(!e||e.length===0)return;let t=e[0];if(!(!t||!t.code&&!t.period))return{serviceEvent:{"@_classCode":"PCPR",code:p(t.code?.[0]),effectiveTime:this.mapEffectiveDate(void 0,t.period)}}}createMedicationEntry(e){let t=e.contained?.find(s=>s.resourceType==="Medication"),n=t?.code||e.medicationCodeableConcept,r=t?.manufacturer,o=[];if(e.dispenseRequest?.validityPeriod){let s=this.mapEffectiveDate(void 0,e.dispenseRequest.validityPeriod);s&&o.push(...s)}return e.dosageInstruction?.[0]?.timing?.repeat?.period&&o.push({"@_xsi:type":"PIVL_TS","@_institutionSpecified":"true","@_operator":"A",period:{"@_value":e.dosageInstruction[0].timing.repeat.period.toString(),"@_unit":e.dosageInstruction[0].timing.repeat.periodUnit}}),{substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN",templateId:[{"@_root":yt,"@_extension":"2014-06-09"},{"@_root":yt}],id:[{"@_root":e.id||crypto.randomUUID()}],text:this.createTextFromExtensions(e.extension),statusCode:{"@_code":Pe.mapFhirToCcdaWithDefault(e.status,"active")},effectiveTime:o,routeCode:this.mapMedicationRoute(e.dosageInstruction?.[0]?.route),doseQuantity:this.mapDoseQuantity(e.dosageInstruction?.[0]?.doseAndRate?.[0]),consumable:{"@_typeCode":"CSM",manufacturedProduct:[{"@_classCode":"MANU",templateId:[{"@_root":Ct,"@_extension":"2014-06-09"},{"@_root":Ct}],manufacturedMaterial:[{code:[{...p(n),originalText:this.createTextFromExtensions(t?.extension)}]}],manufacturerOrganization:r?[{id:this.mapIdentifiers(r.id,r.identifier?[r.identifier]:void 0),name:[r.display]}]:void 0}]},entryRelationship:e.dosageInstruction?.filter(s=>!!s.extension)?.map(s=>({"@_typeCode":"COMP",substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN",templateId:[{"@_root":Ke}],code:{"@_code":ii,"@_codeSystem":b,"@_codeSystemName":"LOINC","@_displayName":"Medication Instructions"},text:this.createTextFromExtensions(s.extension),consumable:{manufacturedProduct:[{manufacturedLabeledDrug:[{"@_nullFlavor":"NA"}]}]}}]}))}]}}mapMedicationRoute(e){if(e)return p(e)}mapDoseQuantity(e){if(e?.doseQuantity)return{"@_value":e.doseQuantity.value?.toString(),"@_unit":e.doseQuantity.unit}}mapTelecom(e){return!e||e.length===0?[{"@_nullFlavor":"UNK"}]:e?.map(t=>({"@_use":t.use?Re.mapFhirToCcda(t.use):void 0,"@_value":`${this.mapTelecomSystemToPrefix(t.system)}${t.value}`}))}mapTelecomSystemToPrefix(e){return e==="email"?"mailto:":e==="phone"?"tel:":e==="fax"?"fax:":""}mapIdentifiers(e,t){let n=[];if(e&&n.push({"@_root":e}),t)for(let r of t){let o=ui(r.system);o&&n.push({"@_root":o,"@_extension":r.value})}return n}getNarrativeReference(e){let t=e?.find(n=>n.url===Ie)?.valueString;return t?{"@_value":t}:void 0}createTextFromExtensions(e){let t=this.getNarrativeReference(e);return t?{reference:t}:void 0}createConditionEntry(e,t){let n=e.code?.coding?.[0]?.code;if(n===Te)return this.createProblemEntry(t);if(n===H)return this.createHealthConcernEntry(t)}createProblemEntry(e){return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":It},{"@_root":It,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,void 0),code:{"@_code":"CONC","@_codeSystem":pt},statusCode:{"@_code":q.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:this.mapEffectivePeriod(e.recordedDate,void 0),entryRelationship:[{"@_typeCode":"SUBJ",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":ae},{"@_root":ae,"@_extension":"2015-08-01"}],id:e.identifier?this.mapIdentifiers(void 0,e.identifier):[{"@_root":Fe()}],text:this.createTextFromExtensions(e.extension),code:{"@_code":"55607006","@_codeSystem":U,"@_codeSystemName":"SNOMED CT","@_displayName":"Problem",translation:[{"@_code":ni,"@_codeSystem":b,"@_codeSystemName":"LOINC","@_displayName":"Condition"}]},statusCode:{"@_code":"completed"},effectiveTime:[{low:e.onsetDateTime?{"@_value":L(e.onsetDateTime)}:void 0,high:e.abatementDateTime?{"@_value":O(e.abatementDateTime)}:void 0}],value:j(e.code),author:this.mapAuthor(e.asserter,e.recordedDate)}]}]}]}}createHealthConcernEntry(e){return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":xt,"@_extension":"2015-08-01"},{"@_root":xt,"@_extension":"2022-06-01"}],id:this.mapIdentifiers(e.id,void 0),code:{"@_code":H,"@_codeSystem":b,"@_codeSystemName":"LOINC","@_displayName":"Health Concern"},statusCode:{"@_code":q.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:this.mapEffectivePeriod(e.recordedDate,void 0)}]}}createImmunizationEntry(e){let t=e?.manufacturer,n={substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN","@_negationInd":"false",templateId:[{"@_root":Dt},{"@_root":Dt,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),text:this.createTextFromExtensions(e.extension),statusCode:{"@_code":xe.mapFhirToCcdaWithDefault(e.status,"completed")},effectiveTime:[{"@_value":L(e.occurrenceDateTime)}],consumable:{manufacturedProduct:[{"@_classCode":"MANU",templateId:[{"@_root":vt},{"@_root":vt,"@_extension":"2014-06-09"}],manufacturedMaterial:[{code:[p(e.vaccineCode)],lotNumberText:e.lotNumber?[e.lotNumber]:void 0}],manufacturerOrganization:t?[{id:this.mapIdentifiers(t.id,t.identifier?[t.identifier]:void 0),name:[t.display]}]:void 0}]}}]};return e.performer&&(n.substanceAdministration[0].performer=e.performer.map(r=>this.mapImmunizationPerformerToCcdaPerformer(r)).filter(Boolean)),n}mapImmunizationPerformerToCcdaPerformer(e){if(!e)return;let t=this.findResourceByReference(e.actor);if(!t)return;let n,r;return t.resourceType==="PractitionerRole"?(n=this.findResourceByReference(t.practitioner),r=this.findResourceByReference(t.organization)):t.resourceType==="Practitioner"?n=t:t.resourceType==="Organization"&&(r=t),{assignedEntity:{id:this.mapIdentifiers(t.id,t.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(n?.address),telecom:this.mapTelecom(t.telecom),assignedPerson:n?{id:this.mapIdentifiers(n.id,n.identifier),name:this.mapNames(n.name)}:void 0,representedOrganization:r?{id:this.mapIdentifiers(r.id,r.identifier),name:r.name?[r.name]:void 0,addr:this.mapFhirAddressArrayToCcdaAddressArray(r.address),telecom:this.mapTelecom(r.telecom)}:void 0}}}createObservationEntry(e){return e.hasMember?{organizer:[this.createVitalSignsOrganizer(e)]}:{observation:[this.createVitalSignObservation(e)]}}createPlanOfTreatmentCarePlanEntry(e){if(e.status==="completed")return{act:[{"@_classCode":"ACT","@_moodCode":"INT",templateId:[{"@_root":ln}],id:this.mapIdentifiers(e.id,e.identifier),code:j(e.category?.[0]),text:e.description?{"#text":e.description}:this.createTextFromExtensions(e.extension),statusCode:{"@_code":e.status}}]}}createGoalEntry(e,t){let n=e.code?.coding?.[0]?.code,r;if(n===Oe)r=[{"@_root":Nt}];else if(n===Y)r=[{"@_root":Je}];else return;let o;if(n===Y)o={"@_code":ri,"@_codeSystem":b,"@_codeSystemName":"LOINC","@_displayName":"Resident's overall goal established during assessment process"};else if(t.description)o=p(t.description);else return;return{observation:[{"@_classCode":"OBS","@_moodCode":"GOL",templateId:r,id:this.mapIdentifiers(t.id,t.identifier),code:o,statusCode:{"@_code":this.mapPlanOfTreatmentStatus(t.lifecycleStatus)},effectiveTime:[{"@_value":O(t.startDate)}],value:t.description?.text?{"@_xsi:type":"ST","#text":t.description.text}:void 0,text:this.createTextFromExtensions(t.extension),entryRelationship:t.target?.map(s=>({"@_typeCode":"RSON","@_inversionInd":"true",act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":ce},{"@_root":ce,"@_extension":"2014-06-09"}],code:p(s.measure),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":O(t.startDate)}]}]}))}]}}mapPlanOfTreatmentStatus(e){switch(e){case"achieved":return"completed";case"cancelled":return"cancelled";default:return"active"}}createVitalSignsOrganizer(e){let t=[];if(e.hasMember)for(let r of e.hasMember){let o=this.findResourceByReference(r);if(!(!o||o.resourceType!=="Observation"))if(o.component)for(let s of o.component)t.push({observation:[this.createVitalSignComponentObservation(o,s)]});else t.push({observation:[this.createVitalSignObservation(o)]})}return{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":le},{"@_root":le,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":O(e.effectiveDateTime)}],component:t}}createVitalSignObservation(e){return{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":O(e.effectiveDateTime)}],value:this.mapObservationValue(e),referenceRange:this.mapReferenceRangeArray(e.referenceRange),text:this.createTextFromExtensions(e.extension),author:this.mapAuthor(e.performer?.[0],e.effectiveDateTime)}}createVitalSignComponentObservation(e,t){return{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:p(t.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":O(e.effectiveDateTime)}],value:this.mapObservationValue(t),referenceRange:this.mapReferenceRangeArray(t.referenceRange),text:this.createTextFromExtensions(t.extension),author:this.mapAuthor(e.performer?.[0],e.effectiveDateTime)}}mapObservationTemplateId(e){let t=e.code?.coding?.[0]?.code,n=e.category?.[0]?.coding?.[0]?.code;return t===oi?[{"@_root":he},{"@_root":he,"@_extension":"2014-06-09"}]:t===si?[{"@_root":fe},{"@_root":fe,"@_extension":"2014-06-09"}]:t===ai?[{"@_root":et,"@_extension":"2023-06-28"}]:t===ci?[{"@_root":_e},{"@_root":_e,"@_extension":"2016-06-01"}]:n==="exam"?[{"@_root":ue},{"@_root":ue,"@_extension":"2014-06-09"}]:n==="laboratory"?[{"@_root":se},{"@_root":se,"@_extension":"2015-08-01"}]:[{"@_root":pe},{"@_root":pe,"@_extension":"2014-06-09"}]}mapObservationValue(e){if(e.valueQuantity)return{"@_xsi:type":"PQ","@_unit":e.valueQuantity.unit,"@_value":e.valueQuantity.value?.toString()};if(e.valueCodeableConcept)return j(e.valueCodeableConcept);if(e.valueString)return{"@_xsi:type":"ST","#text":e.valueString}}mapReferenceRangeArray(e){if(!(!e||e.length===0))return e.map(t=>this.mapReferenceRange(t)).filter(Boolean)}mapReferenceRange(e){if(!e)return;let t=this.getNarrativeReference(e.extension);return t?{observationRange:{text:{reference:t},value:{"@_xsi:type":"ED",reference:t}}}:{observationRange:{text:this.createTextFromExtensions(e.extension)}}}createHistoryOfProceduresEntry(e){if(e.resourceType==="Procedure"){let t=["183948003","409063005","311331002","61310001","183945009","309814009","278373008","410606002","183933003","24642003","225338006","128939004"],n=e.code?.coding?.[0]?.code;return n&&t.includes(n)?{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":ce},{"@_root":ce,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.performedDateTime,e.performedPeriod),text:this.createTextFromExtensions(e.extension)}]}:{procedure:[{"@_classCode":"PROC","@_moodCode":"EVN",templateId:[{"@_root":de},{"@_root":de,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.performedDateTime,e.performedPeriod),text:this.createTextFromExtensions(e.extension),targetSiteCode:p(e.bodySite?.[0]),participant:[this.mapLocationToParticipant(e.location)].filter(Boolean)}]}}if(e.resourceType==="Observation")return{observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:p(e.code),value:this.mapObservationValue(e),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.effectiveDateTime,e.effectivePeriod),text:this.createTextFromExtensions(e.extension)}]};throw new Error(`Unknown history of procedures resource type: ${e.resourceType}`)}mapLocationToParticipant(e){if(!e)return;let t=this.findResourceByReference(e);if(t)return{"@_typeCode":"LOC",participantRole:{"@_classCode":"SDLOC",templateId:[{"@_root":At}],id:this.mapIdentifiers(t.id,t.identifier),code:p(t.type?.[0]),addr:t.address?this.mapFhirAddressArrayToCcdaAddressArray([t.address]):void 0,telecom:this.mapTelecom(t.telecom),playingEntity:{"@_classCode":"PLC",name:t.name?[t.name]:void 0}}}}mapEffectiveTime(e,t){if(t)return[{low:{"@_value":O(t.start)},high:{"@_value":O(t.end)}}];if(e)return[{"@_value":O(e)}]}mapEffectiveDate(e,t){if(t)return[{"@_xsi:type":"IVL_TS",low:t.start?{"@_value":L(t.start)}:void 0,high:t.end?{"@_value":L(t.end)}:void 0}];if(e)return[{"@_value":L(e)}]}mapEffectivePeriod(e,t,n=!1){if(!e&&!t)return;let r={};return e?r.low={"@_value":O(e)}:n&&(r.low={"@_nullFlavor":"NI"}),t?r.high={"@_value":O(t)}:n&&(r.high={"@_nullFlavor":"NI"}),[r]}createEncounterEntry(e){return{encounter:[{"@_classCode":"ENC","@_moodCode":"EVN",templateId:[{"@_root":Rt},{"@_root":Rt,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:p(e.type?.[0]),text:this.createTextFromExtensions(e.extension),effectiveTime:this.mapEffectiveTime(void 0,e.period),entryRelationship:e.participant?.map(t=>({"@_typeCode":"LOC",participantRole:{"@_classCode":"SDLOC",templateId:[{"@_root":At}],code:p(t.type?.[0])}}))}]}}createCareTeamEntry(e){return{organizer:[{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":Pt,"@_extension":"2022-07-01"},{"@_root":Pt,"@_extension":"2022-06-01"}],id:this.mapIdentifiers(e.id,e.identifier),component:e.participant?.map(t=>({"@_typeCode":"PRF",role:t.role}))}]}}createClinicalImpressionSection(e,t){return{templateId:[{"@_root":We}],code:p(e.code),title:e.title,text:t.summary,author:this.mapAuthor(t.assessor,t.date)}}createPlanOfTreatmentServiceRequestEntry(e){return{observation:[{"@_classCode":"OBS","@_moodCode":"RQO",templateId:[{"@_root":Nt}],id:this.mapIdentifiers(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":this.mapPlanOfTreatmentStatus(e.status)},effectiveTime:[{"@_value":O(e.occurrenceDateTime)}],text:this.createTextFromExtensions(e.extension)}]}}createDiagnosticReportEntry(e){let t=[];if(e.result)for(let n of e.result){let r=this.findResourceByReference(n);!r||r.resourceType!=="Observation"||t.push({observation:[this.createVitalSignObservation(r)]})}return{organizer:[{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":oe},{"@_root":oe,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:p(e.code),statusCode:{"@_code":"completed"},component:t}]}}createDeviceUseStatementEntry(e){let t=this.findResourceByReference(e.device);if(!t)return;let n=[],r=this.mapIdentifiers(t.id,t.identifier);return r&&n.push(...r),t.udiCarrier?.[0]?.deviceIdentifier&&n.push({"@_root":Lt,"@_extension":t.udiCarrier[0].carrierHRF,"@_assigningAuthorityName":"FDA"}),{procedure:[{"@_classCode":"PROC","@_moodCode":"EVN",templateId:[{"@_root":de,"@_extension":"2014-06-09"},{"@_root":de}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"360030002","@_codeSystem":U,"@_codeSystemName":"SNOMED CT","@_displayName":"Application of medical device"},statusCode:{"@_code":"completed"},participant:[{"@_typeCode":"DEV",participantRole:{"@_classCode":"MANU",templateId:[{"@_root":fn}],id:n,playingDevice:{"@_classCode":"DEV",code:p(t.type)},scopingEntity:{id:[{"@_root":Lt}]}}}]}]}}createClinicalImpressionEntry(e){return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":xn,"@_extension":"2016-11-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:p(e.code)??{"@_code":ye,"@_codeSystem":b,"@_codeSystemName":"LOINC","@_displayName":"Note"},text:e.summary?{"#text":e.summary}:this.createTextFromExtensions(e.extension),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":L(e.date)}],author:this.mapAuthor(e.assessor,e.date)}]}}};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,GENDER_MAPPER,GOALS_SECTION_TEMPLATE_IDS,HEALTH_CONCERNS_SECTION_TEMPLATE_IDS,HTTP,HUMAN_NAME_USE_MAPPER,IMMUNIZATIONS_SECTION_TEMPLATE_IDS,IMMUNIZATION_STATUS_MAPPER,INSURANCE_SECTION_TEMPLATE_IDS,LAB_TESTS_SECTION_TEMPLATE_IDS,LANGUAGE_MODE_CODE_SYSTEM,LANGUAGE_MODE_URL,LANGUAGE_PROFICIENCY_CODE_SYSTEM,LANGUAGE_PROFICIENCY_URL,LOINC_ADMINISTRATIVE_SEX,LOINC_ALLERGIES_SECTION,LOINC_ASSESSMENTS_SECTION,LOINC_BIRTH_SEX,LOINC_CARE_TEAM_SECTION,LOINC_CONDITION,LOINC_DEVICES_SECTION,LOINC_ENCOUNTERS_SECTION,LOINC_GOALS_SECTION,LOINC_HEALTH_CONCERNS_SECTION,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_PROBLEMS_SECTION,LOINC_PROCEDURES_SECTION,LOINC_REASON_FOR_REFERRAL_SECTION,LOINC_RESULTS_SECTION,LOINC_SOCIAL_HISTORY_SECTION,LOINC_SUMMARY_OF_EPISODE_NOTE,LOINC_TOBACCO_SMOKING_STATUS,LOINC_TO_TEMPLATE_IDS,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,RESULTS_SECTION_TEMPLATE_IDS,SOCIAL_HISTORY_SECTION_TEMPLATE_IDS,SYSTEM_MAPPER,TELECOM_USE_MAPPER,UNII_URL,US_CORE_CONDITION_URL,US_CORE_ETHNICITY_URL,US_CORE_MEDICATION_REQUEST_URL,US_CORE_PATIENT_URL,US_CORE_RACE_URL,US_DRIVER_LICENSE_URL,US_NPI_URL,US_SSN_URL,VA_MEDRT_URL,VITAL_SIGNS_SECTION_TEMPLATE_IDS,XSI_URL,convertCcdaToFhir,convertCcdaToXml,convertFhirToCcda,convertToCompactXml,convertXmlToCcda,mapCcdaSystemToFhir,mapCcdaToFhirDate,mapCcdaToFhirDateTime,mapCodeableConceptToCcdaCode,mapCodeableConceptToCcdaValue,mapCodingToCcdaCode,mapFhirSystemToCcda,mapFhirToCcdaDate,mapFhirToCcdaDateTime,parseXml});
|
|
3
3
|
/*!
|
|
4
4
|
* Reconnecting WebSocket
|
|
5
5
|
* by Pedro Ladaria <pedro.ladaria@gmail.com>
|