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