@medplum/ccda 3.3.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- var cn=class{constructor(t,e){this.operator=t,this.child=e}toString(){return`${this.operator}(${this.child.toString()})`}},Y=class{constructor(t,e,i){this.operator=t,this.left=e,this.right=i}toString(){return`${this.left.toString()} ${this.operator} ${this.right.toString()}`}},un=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 ln(t,this.prefixParselets,this.infixParselets)}},ln=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]}},Re="http://unitsofmeasure.org",re="http://loinc.org",Ne="http://snomed.info/sct",dt="http://www.nlm.nih.gov/research/umls/rxnorm",pt="http://www.ama-assn.org/go/cpt";var ht="http://hl7.org/fhir/sid/ndc",f="http://hl7.org",E="http://terminology.hl7.org";var dn="unauthorized";var ie={resourceType:"OperationOutcome",id:dn,issue:[{severity:"error",code:"login",details:{text:"Unauthorized"}}]},to={...ie,issue:[...ie.issue,{severity:"error",code:"expired",details:{text:"Token expired"}}]},io={...ie,issue:[...ie.issue,{severity:"error",code:"invalid",details:{text:"Token not issued for this audience"}}]};function pn(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 hn(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,pn(r,o)])),constraints:[],innerTypes:[]};return e}var fn={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 _n=hn(fn);var ot=Object.create(null);function mn(t){let e;return e=ot[t],e||(e=ot[t]=Object.create(null)),e}function En(t,e){if(e){let i=mn(e)[t];if(i)return i}return _n[t]}var ft={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:/^[\s\S]+$/,oid:/^urn:oid:[0-2](\.(0|[1-9]\d*))+$/,string:/^[\s\S]+$/,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 b(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}:S(t)?{type:u.Quantity,value:t}:oe(t)?{type:t.resourceType,value:t}:St(t)?{type:u.CodeableConcept,value:t}:Ot(t)?{type:u.Coding,value:t}:{type:u.BackboneElement,value:t}}function D(t){return t.length===0?!1:!!t[0].value}function x(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 In(t,e,i){if(!t.value)return;let n=Fn(t.type,e,i?.profileUrl);return n?Tn(t,e,n):On(t,e)}function Tn(t,e,i){let n=t.value,r=i.type;if(!r||r.length===0)return;let o,s="undefined",a,d=i.path.lastIndexOf("."),L=i.path.substring(d+1);for(let m of r){let B=L.replace("[x]",$(m.code));if(o=n[B],a=n["_"+B],o!==void 0||a!==void 0){s=m.code;break}}if(a)if(Array.isArray(o)){o=o.slice();for(let m=0;m<Math.max(o.length,a.length);m++)o[m]=ut(o[m],a[m])}else o=ut(o,a);if(!G(o))return(s==="Element"||s==="BackboneElement")&&(s=i.type[0].code),Array.isArray(o)?o.map(m=>st(m,s)):st(o,s)}function st(t,e){return e==="Resource"&&oe(t)&&(e=t.resourceType),{type:e,value:t}}function On(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(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+$(o);if(s in i){let a=i[s];Array.isArray(a)?n=a.map(d=>({type:o,value:d})):n={type:o,value:a};break}}}if(Array.isArray(n)){if(n.length===0||G(n[0]))return}else if(G(n))return;return n}function _t(t){let e=[];for(let i of t){let n=!1;for(let r of e)if(D(De(i,r))){n=!0;break}n||e.push(i)}return e}function Sn(t){return c(!D(t))}function yn(t,e){return t.length===0||e.length===0?[]:t.length!==e.length?c(!1):c(t.every((i,n)=>D(De(i,e[n]))))}function Cn(t,e){return t.length===0||e.length===0?[]:t.length!==e.length?c(!0):c(t.some((i,n)=>!D(De(i,e[n]))))}function De(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):S(i)&&S(n)?c(It(i,n)):c(typeof i=="object"&&typeof n=="object"?xe(t,e):i===n)}function mt(t,e){return t.length===0&&e.length===0?c(!0):t.length!==e.length?c(!1):(t.sort(at),e.sort(at),c(t.every((i,n)=>D(gn(i,e[n])))))}function gn(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):S(s)&&S(a)?c(It(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"?xe({...s,id:void 0},{...a,id:void 0}):typeof s=="string"&&typeof a=="string"?s.toLowerCase()===a.toLowerCase():s===a)}function at(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 Et(t,e){let{value:i}=t;if(i==null)return!1;switch(e){case"Boolean":return typeof i=="boolean";case"Decimal":case"Integer":return typeof i=="number";case"Date":return An(i);case"DateTime":return Ae(i);case"Time":return typeof i=="string"&&!!/^T\d/.exec(i);case"Period":return Rn(i);case"Quantity":return S(i);default:return t.type===e||typeof i=="object"&&i?.resourceType===e}}function An(t){return typeof t=="string"&&!!ft.date.exec(t)}function Ae(t){return typeof t=="string"&&!!ft.dateTime.exec(t)}function Rn(t){return!!(t&&typeof t=="object"&&("start"in t&&Ae(t.start)||"end"in t&&Ae(t.end)))}function S(t){return!!(t&&typeof t=="object"&&"value"in t&&typeof t.value=="number")}function It(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 xe(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(ct(o)&&ct(s)){if(!xe(o,s))return!1}else if(o!==s)return!1}return!0}function ct(t){return t!==null&&typeof t=="object"}function ut(t,e){if(e){if(typeof e!="object")throw new Error("Primitive extension must be an object");return Nn(t??{},e)}return t}function Nn(t,e){return delete e.__proto__,delete e.constructor,Object.assign(t,e)}function p(t){let e=Tt(t),i=vn(t);return i===e?{reference:e}:{reference:e,display:i}}function Tt(t){return yt(t)?t.reference:`${t.resourceType}/${t.id}`}function Dn(t){if(t)return yt(t)?t.reference.split("/")[1]:t.id}function xn(t){return t.resourceType==="Patient"||t.resourceType==="Practitioner"||t.resourceType==="RelatedPerson"}function vn(t){if(xn(t)){let e=Pn(t);if(e)return e}if(t.resourceType==="Device"){let e=bn(t);if(e)return e}if(t.resourceType==="MedicationRequest"&&t.medicationCodeableConcept)return lt(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]),St(e))return lt(e);if(Vn(e))return e.text}return Tt(t)}function Pn(t){let e=t.name;if(e&&e.length>0)return kn(e[0])}function bn(t){let e=t.deviceName;if(e&&e.length>0)return e[0].name}function Un(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(),d=n.getUTCMonth(),L=n.getUTCDate(),m=a-r;(d<o||d===o&&L<s)&&m--;let B=a*12+d-(r*12+o);L<s&&B--;let an=Math.floor((n.getTime()-i.getTime())/(1e3*60*60*24));return{years:m,months:B,days:an}}function Ln(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 G(t){if(t==null)return!0;let e=typeof t;return e==="string"||e==="object"?!wn(t):!1}function wn(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 ve(t){return!!/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i.exec(t)}function Pe(t){return t!==null&&typeof t=="object"}function Ot(t){return Pe(t)&&"code"in t&&typeof t.code=="string"}function St(t){return Pe(t)&&"coding"in t&&Array.isArray(t.coding)&&t.coding.every(Ot)}function Vn(t){return Pe(t)&&"text"in t&&typeof t.text=="string"}var Mn=[];for(let t=0;t<256;t++)Mn.push(t.toString(16).padStart(2,"0"));function $(t){return t?t.charAt(0).toUpperCase()+t.substring(1):""}function kn(t,e){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=F(t.text);if(n)return n}return i.join(" ").trim()}function lt(t){return t?F(t.text)||(t.coding?t.coding.map(i=>Bn(i)).join(", "):""):""}function Bn(t,e){let i=F(t?.display);if(i){let n=e?F(t?.code):void 0;return`${i}${n?" ("+n+")":""}`}return F(t?.code)??""}function F(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 Fn(t,e,i){let n=En(t,i);if(n)return Gn(n.elements,e)}function Gn(t,e){let i=t[e]??t[e+"[x]"];if(i)return i;for(let n=0;n<e.length;n++){let r=e[n];if(r>="A"&&r<="Z"){let o=e.slice(0,n)+"[x]",s=t[o];if(s)return s}}}function oe(t){return!!(t&&typeof t=="object"&&"resourceType"in t)}function yt(t){return!!(t&&typeof t=="object"&&"reference"in t&&typeof t.reference=="string")}function te(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 N=()=>[],T={empty:(t,e)=>c(e.length===0||e.every(i=>G(i.value))),hasValue:(t,e)=>c(e.length!==0),exists:(t,e,i)=>c(i?e.filter(n=>D(i.eval(t,[n]))).length>0:e.length>0&&e.every(n=>!G(n.value))),all:(t,e,i)=>c(e.every(n=>D(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,P(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,P(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===T.distinct(t,e).length),where:(t,e,i)=>e.filter(n=>D(i.eval(t,[n]))),select:(t,e,i)=>e.map(n=>i.eval({parent:t,variables:{$this:n}},[n])).flat(),repeat:N,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,P(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,P(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,P(t));return _t([...e,...n])},combine:(t,e,i)=>{if(!i)return e;let n=i.eval(t,P(t));return[...e,...n]},htmlChecks:(t,e,i)=>[b(!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 D(o)?n.eval(t,e):r?r.eval(t,e):[]},toBoolean:(t,e)=>{if(e.length===0)return[];let[{value:i}]=A(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(T.toBoolean(t,e).length===1),toInteger:(t,e)=>{if(e.length===0)return[];let[{value:i}]=A(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(T.toInteger(t,e).length===1),toDate:(t,e)=>{if(e.length===0)return[];let[{value:i}]=A(e,1);return typeof i=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(i)?[{type:u.date,value:te(i)}]:[]},convertsToDate:(t,e)=>e.length===0?[]:c(T.toDate(t,e).length===1),toDateTime:(t,e)=>{if(e.length===0)return[];let[{value:i}]=A(e,1);return typeof i=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(i)?[{type:u.dateTime,value:te(i)}]:[]},convertsToDateTime:(t,e)=>e.length===0?[]:c(T.toDateTime(t,e).length===1),toDecimal:(t,e)=>{if(e.length===0)return[];let[{value:i}]=A(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(T.toDecimal(t,e).length===1),toQuantity:(t,e)=>{if(e.length===0)return[];let[{value:i}]=A(e,1);return S(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(T.toQuantity(t,e).length===1),toString:(t,e)=>{if(e.length===0)return[];let[{value:i}]=A(e,1);return i==null?[]:S(i)?[{type:u.string,value:`${i.value} '${i.unit}'`}]:[{type:u.string,value:i.toString()}]},convertsToString:(t,e)=>e.length===0?[]:c(T.toString(t,e).length===1),toTime:(t,e)=>{if(e.length===0)return[];let[{value:i}]=A(e,1);if(typeof i=="string"){let n=/^T?(\d{2}(:\d{2}(:\d{2})?)?)/.exec(i);if(n)return[{type:u.time,value:te("T"+n[1])}]}return[]},convertsToTime:(t,e)=>e.length===0?[]:c(T.toTime(t,e).length===1),indexOf:(t,e,i)=>O((n,r)=>n.indexOf(r),t,e,i),substring:(t,e,i,n)=>O((r,o,s)=>{let a=o,d=s?a+s:r.length;return a<0||a>=r.length?void 0:r.substring(a,d)},t,e,i,n),startsWith:(t,e,i)=>O((n,r)=>n.startsWith(r),t,e,i),endsWith:(t,e,i)=>O((n,r)=>n.endsWith(r),t,e,i),contains:(t,e,i)=>O((n,r)=>n.includes(r),t,e,i),upper:(t,e)=>O(i=>i.toUpperCase(),t,e),lower:(t,e)=>O(i=>i.toLowerCase(),t,e),replace:(t,e,i,n)=>O((r,o,s)=>r.replaceAll(o,s),t,e,i,n),matches:(t,e,i)=>O((n,r)=>!!new RegExp(r).exec(n),t,e,i),replaceMatches:(t,e,i,n)=>O((r,o,s)=>r.replaceAll(o,s),t,e,i,n),length:(t,e)=>O(i=>i.length,t,e),toChars:(t,e)=>O(i=>i?i.split(""):void 0,t,e),encode:N,decode:N,escape:N,unescape:N,trim:N,split:N,join:(t,e,i)=>{let n=i?.eval(t,P(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)=>g(Math.abs,t,e),ceiling:(t,e)=>g(Math.ceil,t,e),exp:(t,e)=>g(Math.exp,t,e),floor:(t,e)=>g(Math.floor,t,e),ln:(t,e)=>g(Math.log,t,e),log:(t,e,i)=>g((n,r)=>Math.log(n)/Math.log(r),t,e,i),power:(t,e,i)=>g(Math.pow,t,e,i),round:(t,e)=>g(Math.round,t,e),sqrt:(t,e)=>g(Math.sqrt,t,e),truncate:(t,e)=>g(i=>i|0,t,e),children:N,descendants:N,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=T.toDateTime(t,i.eval(t,e));if(o.length===0)throw new Error("Invalid start date");let s=T.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 d=Un(o[0].value,s[0].value);return[{type:u.Quantity,value:{value:d[a],unit:a}}]},is:(t,e,i)=>{let n="";return i instanceof ne?n=i.name:i instanceof Ct&&(n=i.left.name+"."+i.right.name),n?e.map(r=>({type:u.boolean,value:Et(r,n)})):[]},not:(t,e)=>T.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 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(i=>!!i.value),as:(t,e)=>e,type:(t,e)=>e.map(({value:i})=>typeof i=="boolean"?{type:u.BackboneElement,value:{namespace:"System",name:"Boolean"}}:typeof i=="number"?{type:u.BackboneElement,value:{namespace:"System",name:"Integer"}}:oe(i)?{type:u.BackboneElement,value:{namespace:"FHIR",name:i.resourceType}}:{type:u.BackboneElement,value:null}),conformsTo:(t,e,i)=>{let n=i.eval(t,e)[0].value;if(!n.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");let r=n.replace("http://hl7.org/fhir/StructureDefinition/","");return e.map(o=>({type:u.boolean,value:o.value?.resourceType===r}))},getResourceKey:(t,e)=>{let i=e[0].value;return i?.id?[{type:u.id,value:i.id}]:[]},getReferenceKey:(t,e,i)=>{let n=e[0].value;if(!n?.reference)return[];let r="";return i instanceof ne&&(r=i.name),r&&!n.reference.startsWith(r+"/")?[]:[{type:u.id,value:Dn(n)}]},extension:(t,e,i)=>{let n=i.eval(t,e)[0].value,r=e?.[0]?.value;if(r){let o=Ln(r,n);if(o)return[{type:u.Extension,value:o}]}return[]}};function O(t,e,i,...n){if(i.length===0)return[];let[{value:r}]=A(i,1);if(typeof r!="string")throw new Error("String function cannot be called with non-string");let o=t(r,...n.map(s=>s?.eval(e,i)[0]?.value));return o===void 0?[]:Array.isArray(o)?o.map(b):[b(o)]}function g(t,e,i,...n){if(i.length===0)return[];let[{value:r}]=A(i,1),o=S(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(m=>m.eval(e,i)[0]?.value)),d=o?u.Quantity:i[0].type,L=o?{...r,value:a}:a;return[{type:d,value:L}]}function A(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 P(t){let e=t;for(;e.parent?.variables.$this;)e=e.parent;return[e.variables.$this]}var w=class{constructor(t){this.value=t}eval(){return[this.value]}toString(){let t=this.value.value;return typeof t=="string"?`'${t}'`:t.toString()}},ne=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 oe(e)&&e.resourceType===this.name?t:In(t,this.name)}toString(){return this.name}},Yn=class{eval(){return[]}toString(){return"{}"}},$n=class extends cn{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()}},Hn=class extends Y{constructor(t,e){super("as",t,e)}eval(t,e){return T.ofType(t,this.left.eval(t,e),this.right)}},y=class extends Y{},C=class extends y{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=S(r)?r.value:r,a=S(o)?o.value:o,d=this.impl(s,a);return typeof d=="boolean"?c(d):S(r)?[{type:u.Quantity,value:{...r,value:d}}]:[b(d)]}},jn=class extends Y{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}},qn=class extends y{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))}},Wn=class extends y{constructor(t,e){super("in",t,e)}eval(t,e){let i=x(this.left.eval(t,e)),n=this.right.eval(t,e);return i?c(n.some(r=>r.value===i.value)):[]}},Ct=class extends Y{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()}`}},Qn=class extends Y{constructor(t,e){super("|",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return _t([...i,...n])}},zn=class extends y{constructor(t,e){super("=",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return yn(i,n)}},Zn=class extends y{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)}},Xn=class extends y{constructor(t,e){super("~",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return mt(i,n)}},Jn=class extends y{constructor(t,e){super("!~",t,e)}eval(t,e){let i=this.left.eval(t,e),n=this.right.eval(t,e);return Sn(mt(i,n))}},Kn=class extends y{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(Et(i[0],n))}},er=class extends y{constructor(t,e){super("and",t,e)}eval(t,e){let i=x(this.left.eval(t,e),"boolean"),n=x(this.right.eval(t,e),"boolean");return i?.value===!0&&n?.value===!0?c(!0):i?.value===!1||n?.value===!1?c(!1):[]}},tr=class extends y{constructor(t,e){super("or",t,e)}eval(t,e){let i=x(this.left.eval(t,e),"boolean"),n=x(this.right.eval(t,e),"boolean");return i?.value===!1&&n?.value===!1?c(!1):i?.value||n?.value?c(!0):[]}},ir=class extends y{constructor(t,e){super("xor",t,e)}eval(t,e){let i=x(this.left.eval(t,e),"boolean"),n=x(this.right.eval(t,e),"boolean");return!i||!n?[]:c(i.value!==n.value)}},nr=class extends y{constructor(t,e){super("implies",t,e)}eval(t,e){let i=x(this.left.eval(t,e),"boolean"),n=x(this.right.eval(t,e),"boolean");return n?.value===!0||i?.value===!1?c(!0):!i||!n?[]:c(!1)}},rr=class{constructor(t,e){this.name=t,this.args=e}eval(t,e){let i=T[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(", ")})`}},or=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 gt=["!=","!~","<=",">=","{}","->"];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},sr={parse(t){let e=t.consumeAndParse();if(!t.match(")"))throw new Error("Parse error: expected `)` got `"+t.peek()?.value+"`");return e}},ar={parse(t,e){let i=t.consumeAndParse();if(!t.match("]"))throw new Error("Parse error: expected `]`");return new or(e,i)},precedence:l.Indexer},cr={parse(t,e){if(!(e instanceof ne))throw new Error("Unexpected parentheses");let i=[];for(;!t.match(")");)i.push(t.consumeAndParse()),t.match(",");return new rr(e.name,i)},precedence:l.FunctionCall};function ur(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 be(){return new un().registerPrefix("String",{parse:(t,e)=>new w({type:u.string,value:e.value})}).registerPrefix("DateTime",{parse:(t,e)=>new w({type:u.dateTime,value:te(e.value)})}).registerPrefix("Quantity",{parse:(t,e)=>new w({type:u.Quantity,value:ur(e.value)})}).registerPrefix("Number",{parse:(t,e)=>new w({type:e.value.includes(".")?u.decimal:u.integer,value:parseFloat(e.value)})}).registerPrefix("true",{parse:()=>new w({type:u.boolean,value:!0})}).registerPrefix("false",{parse:()=>new w({type:u.boolean,value:!1})}).registerPrefix("Symbol",{parse:(t,e)=>new ne(e.value)}).registerPrefix("{}",{parse:()=>new Yn}).registerPrefix("(",sr).registerInfix("[",ar).registerInfix("(",cr).prefix("+",l.UnaryAdd,(t,e)=>new $n("+",e,i=>i)).prefix("-",l.UnarySubtract,(t,e)=>new C("-",e,e,(i,n)=>-n)).infixLeft(".",l.Dot,(t,e,i)=>new Ct(t,i)).infixLeft("/",l.Divide,(t,e,i)=>new C("/",t,i,(n,r)=>n/r)).infixLeft("*",l.Multiply,(t,e,i)=>new C("*",t,i,(n,r)=>n*r)).infixLeft("+",l.Add,(t,e,i)=>new C("+",t,i,(n,r)=>n+r)).infixLeft("-",l.Subtract,(t,e,i)=>new C("-",t,i,(n,r)=>n-r)).infixLeft("|",l.Union,(t,e,i)=>new Qn(t,i)).infixLeft("=",l.Equals,(t,e,i)=>new zn(t,i)).infixLeft("!=",l.NotEquals,(t,e,i)=>new Zn(t,i)).infixLeft("~",l.Equivalent,(t,e,i)=>new Xn(t,i)).infixLeft("!~",l.NotEquivalent,(t,e,i)=>new Jn(t,i)).infixLeft("<",l.LessThan,(t,e,i)=>new C("<",t,i,(n,r)=>n<r)).infixLeft("<=",l.LessThanOrEquals,(t,e,i)=>new C("<=",t,i,(n,r)=>n<=r)).infixLeft(">",l.GreaterThan,(t,e,i)=>new C(">",t,i,(n,r)=>n>r)).infixLeft(">=",l.GreaterThanOrEquals,(t,e,i)=>new C(">=",t,i,(n,r)=>n>=r)).infixLeft("&",l.Ampersand,(t,e,i)=>new jn(t,i)).infixLeft("and",l.And,(t,e,i)=>new er(t,i)).infixLeft("as",l.As,(t,e,i)=>new Hn(t,i)).infixLeft("contains",l.Contains,(t,e,i)=>new qn(t,i)).infixLeft("div",l.Divide,(t,e,i)=>new C("div",t,i,(n,r)=>n/r|0)).infixLeft("in",l.In,(t,e,i)=>new Wn(t,i)).infixLeft("is",l.Is,(t,e,i)=>new Kn(t,i)).infixLeft("mod",l.Modulo,(t,e,i)=>new C("mod",t,i,(n,r)=>n%r)).infixLeft("or",l.Or,(t,e,i)=>new tr(t,i)).infixLeft("xor",l.Xor,(t,e,i)=>new ir(t,i)).infixLeft("implies",l.Implies,(t,e,i)=>new nr(t,i))}var no=be();var lr=(t=>(t.BOOLEAN="BOOLEAN",t.NUMBER="NUMBER",t.QUANTITY="QUANTITY",t.TEXT="TEXT",t.REFERENCE="REFERENCE",t.CANONICAL="CANONICAL",t.DATE="DATE",t.DATETIME="DATETIME",t.PERIOD="PERIOD",t.UUID="UUID",t))(lr||{});var dr=(t=>(t.EQUALS="eq",t.NOT_EQUALS="ne",t.GREATER_THAN="gt",t.LESS_THAN="lt",t.GREATER_THAN_OR_EQUALS="ge",t.LESS_THAN_OR_EQUALS="le",t.STARTS_AFTER="sa",t.ENDS_BEFORE="eb",t.APPROXIMATELY="ap",t.CONTAINS="contains",t.STARTS_WITH="sw",t.EXACT="exact",t.TEXT="text",t.NOT="not",t.ABOVE="above",t.BELOW="below",t.IN="in",t.NOT_IN="not-in",t.OF_TYPE="of-type",t.MISSING="missing",t.PRESENT="present",t.IDENTIFIER="identifier",t.ITERATE="iterate",t))(dr||{});var pr=(t=>(t.READ="read",t.VREAD="vread",t.UPDATE="update",t.PATCH="patch",t.DELETE="delete",t.HISTORY="history",t.HISTORY_INSTANCE="history-instance",t.HISTORY_TYPE="history-type",t.HISTORY_SYSTEM="history-system",t.CREATE="create",t.SEARCH="search",t.SEARCH_TYPE="search-type",t.SEARCH_SYSTEM="search-system",t.SEARCH_COMPARTMENT="search-compartment",t.CAPABILITIES="capabilities",t.TRANSACTION="transaction",t.BATCH="batch",t.OPERATION="operation",t))(pr||{});function At(){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 hr={CSS:"text/css",DICOM:"application/dicom",FAVICON:"image/vnd.microsoft.icon",FHIR_JSON:"application/fhir+json",FORM_URL_ENCODED:"application/x-www-form-urlencoded",HL7_V2:"x-application/hl7-v2+er7",HTML:"text/html",JAVASCRIPT:"text/javascript",JSON:"application/json",JSON_PATCH:"application/json-patch+json",PNG:"image/png",SCIM_JSON:"application/scim+json",SVG:"image/svg+xml",TEXT:"text/plain",TYPESCRIPT:"text/typescript",PING:"x-application/ping",XML:"text/xml",CDA_XML:"application/cda+xml"};var fr;fr=Symbol.toStringTag;var ro={Event:typeof globalThis.Event<"u"?globalThis.Event:void 0,ErrorEvent:void 0,CloseEvent:void 0};var oo={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 so=hr.FHIR_JSON+", */*; q=0.1";var _r=(t=>(t.ClientCredentials="client_credentials",t.AuthorizationCode="authorization_code",t.RefreshToken="refresh_token",t.JwtBearer="urn:ietf:params:oauth:grant-type:jwt-bearer",t.TokenExchange="urn:ietf:params:oauth:grant-type:token-exchange",t))(_r||{}),mr=(t=>(t.AccessToken="urn:ietf:params:oauth:token-type:access_token",t.RefreshToken="urn:ietf:params:oauth:token-type:refresh_token",t.IdToken="urn:ietf:params:oauth:token-type:id_token",t.Saml1Token="urn:ietf:params:oauth:token-type:saml1",t.Saml2Token="urn:ietf:params:oauth:token-type:saml2",t))(mr||{}),Er=(t=>(t.ClientSecretBasic="client_secret_basic",t.ClientSecretPost="client_secret_post",t.ClientSecretJwt="client_secret_jwt",t.PrivateKeyJwt="private_key_jwt",t.None="none",t))(Er||{}),Ir=(t=>(t.JwtBearer="urn:ietf:params:oauth:client-assertion-type:jwt-bearer",t))(Ir||{});var ao=[...gt,"->","<<",">>","=="];var co=be().registerInfix("->",{precedence:l.Arrow}).registerInfix(";",{precedence:l.Semicolon});var uo=" ".repeat(2);var lo=[...gt,"eq","ne","co"];var po=be();var Tr=(t=>(t[t.NONE=0]="NONE",t[t.ERROR=1]="ERROR",t[t.WARN=2]="WARN",t[t.INFO=3]="INFO",t[t.DEBUG=4]="DEBUG",t))(Tr||{});function Ue(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 _(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)),`${e}-${i}-${n}T${r}:${o}:${s}${a}`}function V(t){if(t)return t.substring(0,10).replace(/-/g,"")}function R(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}`}var se="1.3.6.1.4.1.19376.1.5.3.1.3.1";var Rt="2.16.840.1.113883.1.3";var Nt="2.16.840.1.113883.2.20.5.1",Dt="2.16.840.1.113883.3.26.1.1";var xt="2.16.840.1.113883.4.1",vt="2.16.840.1.113883.4.3",Pt="2.16.840.1.113883.4.6",bt="2.16.840.1.113883.4.9",Ut="2.16.840.1.113883.5.1",ae="2.16.840.1.113883.5.4",Le="2.16.840.1.113883.5.6",Lt="2.16.840.1.113883.5.25",H="2.16.840.1.113883.6.1",wt="2.16.840.1.113883.6.12",Vt="2.16.840.1.113883.6.24",Mt="2.16.840.1.113883.6.69",kt="2.16.840.1.113883.6.88",M="2.16.840.1.113883.6.96",Bt="2.16.840.1.113883.6.101",Ft="2.16.840.1.113883.6.209",we="2.16.840.1.113883.6.238",Gt="2.16.840.1.113883.6.345";var Yt="2.16.840.1.113883.10.20.15.3.8";var Ve="2.16.840.1.113883.10.20.22.1.1";var Me="2.16.840.1.113883.10.20.22.1.2";var ce="2.16.840.1.113883.10.20.22.2.1.1";var j="2.16.840.1.113883.10.20.22.2.2",q="2.16.840.1.113883.10.20.22.2.2.1";var ke="2.16.840.1.113883.10.20.22.2.3.1";var $t="2.16.840.1.113883.10.20.22.2.4.1";var ue="2.16.840.1.113883.10.20.22.2.5.1";var le="2.16.840.1.113883.10.20.22.2.6.1";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 v="2.16.840.1.113883.10.20.22.2.10";var Be="2.16.840.1.113883.10.20.22.2.17";var de="2.16.840.1.113883.10.20.22.2.18";var jt="2.16.840.1.113883.10.20.22.2.22.1";var qt="2.16.840.1.113883.10.20.22.2.23";var Wt="2.16.840.1.113883.10.20.22.2.56";var pe="2.16.840.1.113883.10.20.22.2.58";var W="2.16.840.1.113883.10.20.22.2.60";var he="2.16.840.1.113883.10.20.22.2.65";var fe="2.16.840.1.113883.10.20.22.2.500",Qt="2.16.840.1.113883.10.20.22.4.1",zt="2.16.840.1.113883.10.20.22.4.1.2",Zt="2.16.840.1.113883.10.20.22.4.2",Xt="2.16.840.1.113883.10.20.22.4.2.2",Fe="2.16.840.1.113883.10.20.22.4.3";var Q="2.16.840.1.113883.10.20.22.4.4",Jt="2.16.840.1.113883.10.20.22.4.4.2";var Ge="2.16.840.1.113883.10.20.22.4.7";var Ye="2.16.840.1.113883.10.20.22.4.8";var $e="2.16.840.1.113883.10.20.22.4.9";var z="2.16.840.1.113883.10.20.22.4.12";var Kt="2.16.840.1.113883.10.20.22.4.13";var He="2.16.840.1.113883.10.20.22.4.14";var ei="2.16.840.1.113883.10.20.22.4.16";var ti="2.16.840.1.113883.10.20.22.4.20";var ii="2.16.840.1.113883.10.20.22.4.23";var Z="2.16.840.1.113883.10.20.22.4.26",ni="2.16.840.1.113883.10.20.22.4.26.2",X="2.16.840.1.113883.10.20.22.4.27",ri="2.16.840.1.113883.10.20.22.4.27.2";var je="2.16.840.1.113883.10.20.22.4.30";var oi="2.16.840.1.113883.10.20.22.4.32";var si="2.16.840.1.113883.10.20.22.4.38",ai="2.16.840.1.113883.10.20.22.4.38.1";var ci="2.16.840.1.113883.10.20.22.4.44";var qe="2.16.840.1.113883.10.20.22.4.49";var We="2.16.840.1.113883.10.20.22.4.52";var Qe="2.16.840.1.113883.10.20.22.4.54";var ui="2.16.840.1.113883.10.20.22.4.66";var li="2.16.840.1.113883.10.20.22.4.67";var di="2.16.840.1.113883.10.20.22.4.69",pi="2.16.840.1.113883.10.20.22.4.70";var hi="2.16.840.1.113883.10.20.22.4.74";var fi="2.16.840.1.113883.10.20.22.4.75";var _i="2.16.840.1.113883.10.20.22.4.78",mi="2.16.840.1.113883.10.20.22.4.78.2";var Ei="2.16.840.1.113883.10.20.22.4.85";var Ii="2.16.840.1.113883.10.20.22.4.86";var Ti="2.16.840.1.113883.10.20.22.4.114";var Oi="2.16.840.1.113883.10.20.22.4.119";var Si="2.16.840.1.113883.10.20.22.4.121";var yi="2.16.840.1.113883.10.20.22.4.130";var Ci="2.16.840.1.113883.10.20.22.4.133";var gi="2.16.840.1.113883.10.20.22.4.147",Ai="2.16.840.1.113883.10.20.22.4.200",Ri="2.16.840.1.113883.10.20.22.4.201";var Ni="2.16.840.1.113883.10.20.22.4.244";var Di="2.16.840.1.113883.10.20.22.4.250";var xi="2.16.840.1.113883.10.20.22.4.406",vi="2.16.840.1.113883.10.20.22.4.407";var Pi="2.16.840.1.113883.10.20.22.4.416";var ze="2.16.840.1.113883.10.20.22.4.500",bi="2.16.840.1.113883.10.20.22.4.501";var Ui="2.16.840.1.113883.10.20.22.4.503",Li="2.16.840.1.113883.10.20.22.4.504";var wi="2.16.840.1.113883.10.20.22.4.506",Vi="2.16.840.1.113883.10.20.22.4.507",Mi="2.16.840.1.113883.10.20.22.4.508";var ki="2.16.840.1.113883.10.20.22.4.512";var Ze="2.16.840.1.113883.12.292";var I=class{constructor(e,i,n,r){this.systemName=e,this.ccdaSystemOid=i,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]}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.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.ccdaSystemOid,"@_codeSystemName":this.systemName}}},U="http:",Xe=`${E}/CodeSystem/condition-clinical`,Bi=`${E}/CodeSystem/condition-verification`,jo=`${E}/CodeSystem/v3-LanguageAbilityMode`,qo=`${E}/CodeSystem/v3-LanguageAbilityProficiency`,Wo=`${E}/CodeSystem/v3-Race`,Fi=`${E}/CodeSystem/condition-category`,Je=`${E}/CodeSystem/condition-ver-status`,Ke=`${E}/CodeSystem/allergyintolerance-clinical`,et=`${E}/CodeSystem/allergyintolerance-verification`,Gi=`${E}/CodeSystem/v3-ActCode`,Yi=`${E}/CodeSystem/v3-ParticipationType`,$i=`${E}/CodeSystem/diagnosis-role`,Or=`${E}/CodeSystem/v3-Confidentiality`,Sr=`${E}/CodeSystem/observation-category`,yr=`${f}/fhir/ValueSet/address-use`,Cr=`${f}/fhir/ValueSet/name-use`,gr=`${f}/fhir/ValueSet/administrative-gender`,Ar=`${f}/fhir/ValueSet/contactentity-use`,Rr=`${f}/fhir/ValueSet/medicationrequest-status`,Qo=`${f}/fhir/StructureDefinition/language-mode`,zo=`${f}/fhir/StructureDefinition/language-proficiency`,Zo=`${f}/fhir/us/core/StructureDefinition/us-core-patient`,_e=`${f}/fhir/us/core/StructureDefinition/us-core-race`,me=`${f}/fhir/us/core/StructureDefinition/us-core-ethnicity`,Hi=`${f}/fhir/us/core/StructureDefinition/us-core-condition`,ji=`${f}/fhir/us/core/StructureDefinition/us-core-medicationrequest`,J=`${f}/cda/template`,Nr=`${U}//ncithesaurus-stage.nci.nih.gov`,Dr=`${f}/fhir/sid/us-ssn`,xr=`${f}/fhir/sid/us-dln`,vr=`${f}/fhir/sid/us-npi`,Pr=`${U}//fdasis.nlm.nih.gov`,br=`${U}//nucc.org/provider-taxonomy`,Ur=`${U}//va.gov/terminology/medrt`,Lr=`${U}//hl7.org/fhir/ndfrt`,wr=`${U}//nucc.org/cvx`,Vr=`${f}/fhir/sid/cvx`,qi=`${U}//www.w3.org/2001/XMLSchema-instance`,Ee="https://medplum.com/fhir/StructureDefinition/ccda-narrative-reference",tt=new I("System","","",[{ccdaValue:Nt,fhirValue:"https://fhir.infoway-inforoute.ca/CodeSystem/pCLOCD",displayName:"pan-Canadian LOINC Observation Code Database (pCLOCD)"},{ccdaValue:Dt,fhirValue:Nr,displayName:"NCI Thesaurus"},{ccdaValue:xt,fhirValue:Dr,displayName:"SSN"},{ccdaValue:vt,fhirValue:xr,displayName:"DLN"},{ccdaValue:Pt,fhirValue:vr,displayName:"NPI"},{ccdaValue:bt,fhirValue:Pr,displayName:"Unique Ingredient Identifier (UNII)"},{ccdaValue:H,fhirValue:re,displayName:"LOINC"},{ccdaValue:wt,fhirValue:pt,displayName:"Current Procedural Terminology (CPT)"},{ccdaValue:Vt,fhirValue:"urn:iso:std:iso:11073:10101",displayName:"Medical Device Communications (MDC)"},{ccdaValue:Mt,fhirValue:ht,displayName:"National Drug Code (NDC)"},{ccdaValue:kt,fhirValue:dt,displayName:"RxNorm"},{ccdaValue:M,fhirValue:Ne,displayName:"SNOMED CT"},{ccdaValue:Bt,fhirValue:br,displayName:"NUCC Health Care Provider Taxonomy"},{ccdaValue:Gt,fhirValue:Ur,displayName:"Medication Reference Terminology (MED-RT)"},{ccdaValue:Ft,fhirValue:Lr,displayName:"National Drug File Reference Terminology (NDF-RT)"},{ccdaValue:Ze,fhirValue:wr,displayName:"CVX"},{ccdaValue:Ze,fhirValue:Vr,displayName:"Vaccine Administered Code Set (CVX)"}]);function Ie(t){if(t)return tt.mapCcdaToFhir(t)??`urn:oid:${t}`}function Wi(t){if(t)return t.startsWith("urn:oid:")?t.replace("urn:oid:",""):tt.mapFhirToCcda(t)}function h(t){if(!t)return;let e=t.coding?.[0]?.system?tt.getEntryByFhir(t.coding[0].system):void 0,i=e?.ccdaValue,n=e?.displayName;return{"@_code":t?.coding?.[0]?.code,"@_displayName":t?.coding?.[0]?.display,"@_codeSystem":i,"@_codeSystemName":n}}function K(t){let e=h(t);if(e)return{"@_xsi:type":"CD",...e}}var Qi=new I("Confidentiality",Lt,Or,[{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"}]),Te=new I("HumanNameUse","",Cr,[{ccdaValue:"C",fhirValue:"usual",displayName:"Common/Called by"},{ccdaValue:"L",fhirValue:"official",displayName:"Legal"},{ccdaValue:"TEMP",fhirValue:"temp",displayName:"Temporary"},{ccdaValue:"N",fhirValue:"nickname",displayName:"Nickname"},{ccdaValue:"ANON",fhirValue:"anonymous",displayName:"Anonymous"},{ccdaValue:"M",fhirValue:"maiden",displayName:"Maiden"},{ccdaValue:"M",fhirValue:"old",displayName:"Old"}]),zi=new I("Gender","",gr,[{ccdaValue:"F",fhirValue:"female",displayName:"Female"},{ccdaValue:"M",fhirValue:"male",displayName:"Male"},{ccdaValue:"UN",fhirValue:"unknown",displayName:"Unknown"},{ccdaValue:"UN",fhirValue:"other",displayName:"Other"}]),Oe=new I("AddressUse","",yr,[{ccdaValue:"HP",fhirValue:"home",displayName:"Home"},{ccdaValue:"WP",fhirValue:"work",displayName:"Work"}]),Se=new I("TelecomUse","",Ar,[{ccdaValue:"WP",fhirValue:"work",displayName:"Work"},{ccdaValue:"HP",fhirValue:"home",displayName:"Home"}]),Zi=new I("AllergyStatus","",et,[{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"}]),ye=new I("AllergySeverity",Ne,Ke,[{ccdaValue:"255604002",fhirValue:"mild",displayName:"Mild"},{ccdaValue:"6736007",fhirValue:"moderate",displayName:"Moderate"},{ccdaValue:"24484000",fhirValue:"severe",displayName:"Severe"}]),Xi=new I("ProblemStatus","",Je,[{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"}]),Ji=new I("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"}]),Ki=new I("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"}]),Ce=new I("MedicationStatus","",Rr,[{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"}]),ge=new I("ObservationCategory","",Sr,[{ccdaValue:si,fhirValue:"social-history",displayName:"Social History"},{ccdaValue:ai,fhirValue:"social-history",displayName:"Social History V2"},{ccdaValue:_i,fhirValue:"social-history",displayName:"Smoking Status"},{ccdaValue:mi,fhirValue:"social-history",displayName:"Current Smoking Status"},{ccdaValue:Ei,fhirValue:"social-history",displayName:"Tobacco Use"},{ccdaValue:Ui,fhirValue:"social-history",displayName:"Basic Occupation"},{ccdaValue:Li,fhirValue:"social-history",displayName:"Basic Industry"},{ccdaValue:bi,fhirValue:"social-history",displayName:"Sexual Orientation"},{ccdaValue:Vi,fhirValue:"social-history",displayName:"Sex Observation"},{ccdaValue:Ai,fhirValue:"social-history",displayName:"Gender Identity"},{ccdaValue:Ri,fhirValue:"social-history",displayName:"Gender Identity V2"},{ccdaValue:Yt,fhirValue:"social-history",displayName:"Pregnancy Status"},{ccdaValue:wi,fhirValue:"social-history",displayName:"Tribal Affiliation"},{ccdaValue:Z,fhirValue:"vital-signs",displayName:"Vital Signs Organizer"},{ccdaValue:ni,fhirValue:"vital-signs",displayName:"Vital Signs Organizer V2"},{ccdaValue:X,fhirValue:"vital-signs",displayName:"Vital Signs Observation"},{ccdaValue:ri,fhirValue:"vital-signs",displayName:"Vital Signs Observation V2"},{ccdaValue:ki,fhirValue:"vital-signs",displayName:"Average Blood Pressure Organizer"},{ccdaValue:Qt,fhirValue:"laboratory",displayName:"Result Organizer"},{ccdaValue:zt,fhirValue:"laboratory",displayName:"Result Organizer V2"},{ccdaValue:Zt,fhirValue:"laboratory",displayName:"Result Observation"},{ccdaValue:Xt,fhirValue:"laboratory",displayName:"Result Observation V2"},{ccdaValue:xi,fhirValue:"laboratory",displayName:"Laboratory Battery (ID)"},{ccdaValue:vi,fhirValue:"laboratory",displayName:"Laboratory Observation (ID)"},{ccdaValue:Pi,fhirValue:"laboratory",displayName:"Laboratory Result Organizer (ID)"},{ccdaValue:di,fhirValue:"survey",displayName:"Assessment Scale Observation"},{ccdaValue:Ii,fhirValue:"survey",displayName:"Assessment Scale Supporting Observation"},{ccdaValue:hi,fhirValue:"survey",displayName:"Cognitive Status Result Observation"},{ccdaValue:fi,fhirValue:"survey",displayName:"Cognitive Status Result Organizer"},{ccdaValue:li,fhirValue:"survey",displayName:"Functional Status Result Observation"},{ccdaValue:ui,fhirValue:"survey",displayName:"Functional Status Result Organizer"},{ccdaValue:Q,fhirValue:"exam",displayName:"Problem Observation"},{ccdaValue:Jt,fhirValue:"exam",displayName:"Problem Observation V2"},{ccdaValue:pi,fhirValue:"exam",displayName:"Pressure Ulcer Observation"},{ccdaValue:Ti,fhirValue:"exam",displayName:"Wound Observation"},{ccdaValue:Ci,fhirValue:"exam",displayName:"Wound Measurements Observation"},{ccdaValue:k,fhirValue:"exam",displayName:"Procedure Section"},{ccdaValue:Kt,fhirValue:"exam",displayName:"Procedure Activity Observation"},{ccdaValue:Mi,fhirValue:"therapy",displayName:"Medication Adherence"},{ccdaValue:yi,fhirValue:"therapy",displayName:"Nutrition Recommendations"},{ccdaValue:Ni,fhirValue:"therapy",displayName:"Diet Statement (Nutrition)"},{ccdaValue:Di,fhirValue:"therapy",displayName:"Monitoring, Evaluation and Outcome (Nutrition)"}]);import{XMLBuilder as en,XMLParser as tn}from"fast-xml-parser";var Mr=["ClinicalDocument.recordTarget",".id",".templateId",".name",".addr",".telecom",".streetAddressLine",".author",".effectiveTime","name.given","name.suffix","name.prefix","patient.raceCode","patient.ethnicGroupCode","patient.languageCommunication","component.structuredBody.component","component.structuredBody.component.section","component.section","component.observation","component.act","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 es(t){return new tn({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1,isArray:(n,r,o,s)=>Mr.some(a=>r.endsWith(a))}).parse(t).ClinicalDocument}function ts(t){return new en({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":qi,"@_xmlns:voc":"urn:hl7-org:v3/voc","@_xmlns:sdtc":"urn:hl7-org:sdtc",...t}})}function nn(t){return new tn({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1}).parse(t)}function rn(t){return t?typeof t=="string"?t:new en({ignoreAttributes:!1,attributeNamePrefix:"@_",format:!1,suppressBooleanAttributes:!1,suppressEmptyNode:!0}).build(t).split(`
2
- `).map(n=>n.trim()).join(""):""}function cs(t){return new it(t).convert()}var it=class{constructor(e){this.resources=[];this.ccda=e}convert(){return this.processHeader(),{resourceType:"Bundle",type:"document",entry:[{resource:this.createComposition()},...this.patient?[{resource:this.patient}]:[],...this.resources.map(i=>({resource:i}))]}}processHeader(){let e=this.ccda.recordTarget?.[0]?.patientRole;e&&(this.patient=this.createPatient(e))}createPatient(e){let i=e.patient,n=[];return i.raceCode&&i.raceCode.length>0&&n.push({url:_e,extension:i.raceCode.map(r=>({url:"ombCategory",valueCoding:this.mapCodeToCoding(r)}))}),i.ethnicGroupCode&&i.ethnicGroupCode.length>0&&n.push({url:me,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:Ue(i.birthTime?.["@_value"]),address:this.mapAddresses(e.addr),telecom:this.mapTelecom(e.telecom),extension:n.length>0?n:void 0}}mapId(e){let i=e?.find(n=>!n["@_extension"]&&n["@_root"]&&ve(n["@_root"]));return i?i["@_root"]:At()}mapIdentifiers(e){if(!e)return;let i=[];for(let n of e)!n["@_extension"]&&n["@_root"]&&ve(n["@_root"])||i.push({system:Ie(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"]?Te.mapCcdaToFhir(e["@_use"]):void 0;return n&&(i.use=n),e.prefix&&(i.prefix=e.prefix.map(ee)?.filter(Boolean)),e.family&&(i.family=ee(e.family)),e.given&&(i.given=e.given.map(ee)?.filter(Boolean)),e.suffix&&(i.suffix=e.suffix.map(ee)?.filter(Boolean)),i}mapAddresses(e){if(!(!e||e.length===0||e.every(i=>i["@_nullFlavor"]==="UNK")))return e?.map(i=>({"@_use":i["@_use"]?Oe.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"]?Se.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">${rn(r.text)}</div>`},entry:o.map(p)}),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:re,code:"34133-9"}]},confidentiality:this.ccda.confidentialityCode?.["@_code"],author:this.ccda.author?.[0]?[this.mapAuthorToReference(this.ccda.author?.[0])]:[{display:"Medplum"}],custodian:this.mapCustodianToReference(this.ccda.custodian),event:this.mapDocumentationOfToEvent(this.ccda.documentationOf),date:_(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 le:return this.processAllergyIntoleranceAct(i);case ue:return this.processConditionAct(i);case v:return this.processCarePlanAct(i);case pe:return this.processConditionAct(i);case k:return this.processProcedureAct(i);case se:return;case he:return;case de:return;default: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:p(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:[Hi]},clinicalStatus:{coding:[{system:Xe,code:this.mapStatus(e.statusCode["@_code"])}]},verificationStatus:{coding:[{system:Bi,code:"confirmed"}]},category:[{coding:[{system:Fi,code:"problem-list-item",display:"Problem List Item"}]}],code:this.mapCode(i.value),subject:p(this.patient),onsetDateTime:_(i.effectiveTime?.[0]?.low?.["@_value"]),abatementDateTime:_(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:"active",intent:"plan",title:"CARE PLAN",category:e.code?[this.mapCode(e.code)]:void 0,subject:p(this.patient),description:ee(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:p(this.patient),performedDateTime:_(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 ce:case v:return this.processMedicationSubstanceAdministration(i);case j:case q:return this.processImmunizationSubstanceAdministration(i);default: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,d;return s?a={resourceType:"Medication",id:"med-"+i,code:this.mapCode(n),extension:this.mapTextReference(n?.originalText),manufacturer:s?{identifier:{value:s.id?.[0]?.["@_root"]},display:s.name?.[0]}:void 0}:d={...this.mapCode(n),extension:this.mapTextReference(n?.originalText)},{resourceType:"MedicationRequest",id:i,contained:a?[a]:void 0,meta:{profile:[ji]},status:Ce.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active"),intent:"order",medicationReference:a?{reference:"#med-"+i}:void 0,medicationCodeableConcept:d,subject:p(this.patient),authoredOn:_(e.author?.[0]?.time?.["@_value"]),dispenseRequest:e.effectiveTime?.[0]?{validityPeriod:{start:_(e.effectiveTime?.[0]?.low?.["@_value"]),end:_(e.effectiveTime?.[0]?.high?.["@_value"])}}:void 0,dosageInstruction:[{text:e.text?.reference?.["@_value"],extension:this.mapTextReference(e.text),route:r?this.mapCode(r):void 0,timing:{repeat:{when:["HS"]}},doseAndRate:o?[{doseQuantity:{system:Re,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:"completed",vaccineCode:this.mapCode(i.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.code?.[0]),patient:p(this.patient),occurrenceDateTime:_(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:_(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=ye.mapCcdaToFhir(r)),i.extension=this.mapTextReference(n.text)}mapEffectiveTimeToDateTime(e){if(e?.["@_value"])return _(e["@_value"])}mapEffectiveTimeToPeriod(e){if(!e?.["@_value"]&&(e?.low||e?.high))return{start:_(e?.low?.["@_value"]),end:_(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:)/,"")}mapStatus(e){return{active:"active",suspended:"inactive",aborted:"inactive",completed:"resolved"}[e]??"active"}mapCode(e){if(e)return{coding:[{system:Ie(e["@_codeSystem"]),code:e["@_code"],display:e["@_displayName"]}],text:e["@_displayName"]}}mapCodeToCoding(e){if(e)return{system:Ie(e["@_codeSystem"]),code:e["@_code"],display:e["@_displayName"]}}createClinicalStatus(e){return{coding:[{system:Ke,code:this.mapStatus(e.statusCode["@_code"])}]}}createVerificationStatus(){return{coding:[{system:et,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),p(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:p(r),organization:p(o)};return this.resources.push(s),p(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),p(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"]===fe?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:p(this.patient)};if(e.effectiveTime?.[0]?.["@_value"]&&(i.effectiveDateTime=_(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(p(r)),this.resources.push(r)}return i}processObservation(e,i){let n=i.templateId[0]["@_root"];if(n===W||n===Si)return this.processGoalObservation(i);switch(e.templateId[0]["@_root"]){case v:case W:return this.processGoalObservation(i);default:return this.processVitalsObservation(i)}}processGoalObservation(e){let i={resourceType:"Goal",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),lifecycleStatus:this.mapGoalLifecycleStatus(e),description:this.mapCode(e.code),subject:p(this.patient),startDate:Ue(e.effectiveTime?.[0]?.["@_value"])};return i.target=e.entryRelationship?.map(n=>({measure:this.mapCode(n.act?.[0]?.code),detailCodeableConcept:this.mapCode(n.act?.[0]?.code),dueDate:_(n.act?.[0]?.effectiveTime?.[0]?.low?.["@_value"])})),i.extension=this.mapTextReference(e.text),i}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:p(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":i.valueQuantity={value:e.value["@_value"]?parseFloat(e.value["@_value"]):void 0,unit:e.value["@_unit"],system:Re,code:e.value["@_unit"]};break;case"CD":case"CE":i.valueCodeableConcept=this.mapCode(e.value);break;case"ST":i.valueString=e.value["#text"]??"";break;default:console.warn(`Unhandled observation value type: ${e.value["@_xsi:type"]}`)}return e.effectiveTime?.[0]?.["@_value"]&&(i.effectiveDateTime=_(e.effectiveTime?.[0]?.["@_value"])),i.extension=this.mapTextReference(e.text),i}mapObservationTemplateIdToObservationCategory(e){if(!e)return;let i=new Set,n=[];for(let r of e){let o=ge.mapCcdaToFhirCodeableConcept(r["@_root"]);o?.coding?.[0]?.code&&!i.has(o.coding[0].code)&&(i.add(o.coding[0].code),n.push(o))}for(let r of e)n.push({coding:[{system:J,code:r["@_root"],version:r["@_extension"]}]});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:Ji.mapCcdaToFhirWithDefault(i.statusCode?.["@_code"],"unknown"),class:{system:Gi,code:i.code?.["@_code"]??"AMB",display:i.code?.["@_displayName"]??"Ambulatory"},type:i.code?[this.mapCode(i.code)]:void 0,subject:p(this.patient),period:this.mapEffectiveTimeToPeriod(i.effectiveTime?.[0])};if(i.performer&&(n.participant=i.performer.map(r=>({type:[{coding:[{system:Yi,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:Xe,code:"active"}]},verificationStatus:{coding:[{system:Je,code:"confirmed"}]},code:this.mapCode(s.value),subject:p(this.patient),onsetDateTime:_(s.effectiveTime?.[0]?.low?.["@_value"])};return this.resources.push(a),{condition:p(a),use:{coding:[{system:$i,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:Ki.mapCcdaToFhirWithDefault(i.statusCode?.["@_code"],"completed"),code:this.mapCode(i.code),subject:p(this.patient),performedDateTime:this.mapEffectiveTimeToDateTime(i.effectiveTime?.[0]),performedPeriod:this.mapEffectiveTimeToPeriod(i.effectiveTime?.[0]),bodySite:i.targetSiteCode?[this.mapCode(i.targetSiteCode)]:void 0,extension:this.mapTextReference(i.text)}}mapTextReference(e){if(e?.reference?.["@_value"])return[{url:Ee,valueString:e.reference?.["@_value"]}]}};function ee(t){if(t){if(typeof t=="string")return t;if(typeof t=="object"&&"#text"in t)return t["#text"]}}var on=[{"@_root":Ve,"@_extension":"2015-08-01"},{"@_root":Ve},{"@_root":Me,"@_extension":"2015-08-01"},{"@_root":Me}],kr=[{"@_root":le,"@_extension":"2015-08-01"}],Br=[{"@_root":ce,"@_extension":"2014-06-09"}],Fr=[{"@_root":ue,"@_extension":"2015-08-01"}],nt=[{"@_root":j},{"@_root":j,"@_extension":"2015-08-01"},{"@_root":q},{"@_root":q,"@_extension":"2015-08-01"}],Gr=[{"@_root":$t,"@_extension":"2015-08-01"}],Yr=[{"@_root":Be},{"@_root":Be,"@_extension":"2015-08-01"}],$r=[{"@_root":k,"@_extension":"2014-06-09"}],ds=[{"@_root":v,"@_extension":"2014-06-09"}],ps=[{"@_root":ke,"@_extension":"2015-08-01"}],Hr=[{"@_root":ke,"@_extension":"2015-08-01"}],hs=[{"@_root":qt,"@_extension":"2015-08-01"}],jr=[{"@_root":Ht}],qr=[{"@_root":v},{"@_root":v,"@_extension":"2014-06-09"}],Wr=[{"@_root":jt,"@_extension":"2015-08-01"}],Qr=[{"@_root":W}],zr=[{"@_root":pe,"@_extension":"2015-08-01"}],Zr=[{"@_root":se,"@_extension":"2014-06-09"}],Xr=[{"@_root":Wt,"@_extension":"2015-08-01"}],Jr=[{"@_root":he,"@_extension":"2016-11-01"}],Kr=[{"@_root":fe,"@_extension":"2022-06-01"}],eo=[{"@_root":de,"@_extension":"2015-08-01"}],sn={"48765-2":kr,"10160-0":Br,"11450-4":Fr,"11369-6":nt,"11348-0":nt,"9176-8":nt,"8716-3":Gr,"29762-2":Yr,"47519-4":$r,"30954-2":Hr,"51848-0":jr,"18776-5":qr,"46240-8":Wr,"61146-7":Qr,"75310-3":zr,"42349-1":Zr,"10190-7":Xr,"11488-4":Jr,"85847-2":Kr,"48768-6":eo};function Ss(t){return new rt(t).convert()}var rt=class{constructor(e){this.bundle=e;let i=this.findResource("Composition");if(!i)throw new Error("Composition not found");let n=this.findResource("Patient");if(!n)throw new Error("Patient not found");this.composition=i,this.patient=n}convert(){let e=this.createSections();return{realmCode:{"@_code":"US"},typeId:{"@_root":Rt,"@_extension":"POCD_HD000040"},templateId:on,id:this.mapIdentifiers(this.composition.id,void 0),code:{"@_code":"34133-9","@_displayName":"Summarization of Episode Note","@_codeSystem":H,"@_codeSystemName":"LOINC"},title:this.composition.title,effectiveTime:this.mapEffectiveTime(this.composition.date,void 0),confidentialityCode:this.composition.confidentiality?Qi.mapFhirToCcdaCode(this.composition.confidentiality):void 0,languageCode:{"@_code":this.composition.language??"en-US"},recordTarget:this.createRecordTarget(),author:this.mapAuthor(this.composition.author?.[0],this.composition.date),custodian:this.mapCustodian(this.composition.custodian),documentationOf:this.mapDocumentationOf(this.composition.event),component:e.length>0?{structuredBody:{component:e.map(i=>({section:[i]}))}}: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:this.mapIdentifiers(this.patient.id,this.patient.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(this.patient.address),telecom:this.mapTelecom(this.patient.telecom),patient:this.mapPatient(this.patient)}}]}mapPatient(e){return{name:this.mapNames(e.name),administrativeGenderCode:this.mapGender(e.gender),birthTime:this.mapBirthDate(e.birthDate),raceCode:this.mapRace(e.extension),ethnicGroupCode:this.mapEthnicity(e.extension),languageCommunication:this.mapLanguageCommunication(e.communication)}}mapNames(e){return e?.map(i=>({"@_use":i.use?Te.mapFhirToCcdaWithDefault(i.use,"L"):void 0,prefix:i.prefix,family:i.family,given:i.given,suffix:i.suffix}))}mapGender(e){if(e)return{"@_xsi:type":"CE","@_code":zi.mapFhirToCcda(e),"@_displayName":e?$(e):"Unknown","@_codeSystem":Ut,"@_codeSystemName":"AdministrativeGender"}}mapBirthDate(e){if(e)return{"@_value":e.replace(/-/g,"")}}mapFhirAddressArrayToCcdaAddressArray(e){return!e||e.length===0?[{"@_nullFlavor":"UNK"}]:e.map(i=>this.mapFhirAddressToCcdaAddress(i)).filter(Boolean)}mapFhirAddressToCcdaAddress(e){return e?{"@_use":e.use?Oe.mapFhirToCcda(e.use):void 0,streetAddressLine:e.line||[],city:e.city,state:e.state,postalCode:e.postalCode,country:e.country}:void 0}mapRace(e){let n=e?.find(r=>r.url===_e)?.extension?.find(r=>r.url==="ombCategory")?.valueCoding;if(n)return[{"@_code":n.code,"@_displayName":n.display,"@_codeSystem":we,"@_codeSystemName":"CDC Race and Ethnicity"}]}mapEthnicity(e){let n=e?.find(r=>r.url===me)?.extension?.find(r=>r.url==="ombCategory")?.valueCoding;if(n)return[{"@_code":n.code,"@_displayName":n.display,"@_codeSystem":we,"@_codeSystemName":"CDC Race and Ethnicity"}]}mapLanguageCommunication(e){if(e?.length)return[{"@_languageCode":e[0].language?.coding?.[0]?.code}]}createSections(){let e=[];if(this.composition.section)for(let 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=sn[i];if(!n)throw new Error(`Unknown section code: ${i}`);let r=this.findResourcesByReferences(e.entry);return{templateId:n,code:h(e.code),title:e.title,text:this.mapFhirTextDivToCcdaSectionText(e.text),entry:r.map(o=>this.createEntry(e,o)),"@_nullFlavor":r.length===0?"NI":void 0}}createEntry(e,i){switch(i.resourceType){case"AllergyIntolerance":return this.createAllergyEntry(i);case"CarePlan":return this.createPlanOfTreatmentCarePlanEntry(i);case"CareTeam":return this.createCareTeamEntry(i);case"Condition":return this.createProblemEntry(i);case"Encounter":return this.createEncounterEntry(i);case"Goal":return this.createPlanOfTreatmentGoalEntry(i);case"Immunization":return this.createImmunizationEntry(i);case"MedicationRequest":return this.createMedicationEntry(i);case"Procedure":return this.createHistoryOfProceduresEntry(i);case"Observation":return this.createObservationEntry(i);default:throw new Error(`Unknown resource type: ${i.resourceType}`)}}mapFhirTextDivToCcdaSectionText(e){if(!e)return;let i=nn(e.div)?.div;return i?.["@_xmlns"]&&delete i["@_xmlns"],i}createAllergyEntry(e){let i=e.reaction?.[0];return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":je},{"@_root":je,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"CONC","@_codeSystem":Le},statusCode:{"@_code":Zi.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:this.mapEffectiveTime(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":Ge},{"@_root":Ge,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"ASSERTION","@_codeSystem":ae},statusCode:{"@_code":"completed"},author:this.mapAuthor(e.asserter,e.recordedDate),effectiveTime:this.mapEffectiveDate(e.onsetDateTime,void 0),value:this.mapAllergyCategory(e.category),text:this.createTextFromExtensions(e.extension),participant:[{"@_typeCode":"CSM",participantRole:{"@_classCode":"MANU",playingEntity:{"@_classCode":"MMAT",code:{...h(e.code),originalText:{reference:this.getNarrativeReference(e.code?.extension)}}}}}],entryRelationship:i?[{"@_typeCode":"MFST","@_inversionInd":"true",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":$e},{"@_root":$e,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(i.id,void 0),code:{"@_code":"ASSERTION","@_codeSystem":ae},statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveDate(e.onsetDateTime,e.onsetPeriod),value:K(i.manifestation?.[0]),text:this.createTextFromExtensions(i.manifestation?.[0]?.extension),entryRelationship:[{"@_typeCode":"SUBJ","@_inversionInd":"true",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":Ye},{"@_root":Ye,"@_extension":"2014-06-09"}],code:{"@_code":"SEV","@_codeSystem":ae,"@_codeSystemName":"ActCode"},statusCode:{"@_code":"completed"},value:{"@_xsi:type":"CD","@_code":ye.mapFhirToCcdaWithDefault(i.severity,"M"),"@_displayName":i.severity?$(i.severity):void 0,"@_codeSystem":M,"@_codeSystemName":"SNOMED CT"},text:this.createTextFromExtensions(i.extension)}]}]}]}]:[]}]}]}]}}mapAllergyCategory(e){if(e&&e.length===1&&e[0]==="food")return{"@_xsi:type":"CD","@_code":"414285001","@_displayName":"Allergy to food (finding)","@_codeSystem":M,"@_codeSystemName":"SNOMED CT"}}mapAuthor(e,i){if(!e)return;let n=this.findResourceByReference(e);if(n?.resourceType==="Practitioner")return[{templateId:[{"@_root":Oi}],time:i?{"@_value":R(i)}:void 0,assignedAuthor:{id:this.mapIdentifiers(n.id,n.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(n.address),telecom:this.mapTelecom(n.telecom),code:h(n.qualification?.[0]),assignedPerson:{name:this.mapNames(n.name)}}}]}mapCustodian(e){if(!e)return;let i=this.findResourceByReference(e);if(i)return{assignedCustodian:{representedCustodianOrganization:{id:this.mapIdentifiers(i.id,i.identifier),name:i.name?[i.name]:void 0,telecom:this.mapTelecom(i.telecom),addr:this.mapFhirAddressArrayToCcdaAddressArray(i.address)}}}}mapDocumentationOf(e){if(!e||e.length===0)return;let i=e[0];if(!(!i||!i.code&&!i.period))return{serviceEvent:{"@_classCode":"PCPR",code:h(i.code?.[0]),effectiveTime:this.mapEffectiveDate(void 0,i.period)}}}createMedicationEntry(e){let i=e.contained?.find(d=>d.resourceType==="Medication"),n=i?.code||e.medicationCodeableConcept,r=i?.manufacturer;return{substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN",templateId:[{"@_root":ei,"@_extension":"2014-06-09"}],id:[{"@_root":e.id||crypto.randomUUID()}],text:{reference:{"@_value":"#Medication_6"}},statusCode:{"@_code":Ce.mapFhirToCcdaWithDefault(e.status,"active")},effectiveTime:this.mapEffectiveDate(void 0,e.dispenseRequest?.validityPeriod),routeCode:this.mapMedicationRoute(e.dosageInstruction?.[0]?.route),doseQuantity:this.mapDoseQuantity(e.dosageInstruction?.[0]?.doseAndRate?.[0]),consumable:{"@_typeCode":"CSM",manufacturedProduct:[{"@_classCode":"MANU",templateId:[{"@_root":ii,"@_extension":"2014-06-09"}],manufacturedMaterial:[{code:[{...h(n),originalText:{reference:{"@_value":"#MedicationName_6"}}}]}],manufacturerOrganization:r?[{id:this.mapIdentifiers(r.id,r.identifier?[r.identifier]:void 0),name:[r.display]}]:void 0}]},entryRelationship:[{"@_typeCode":"COMP",substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN",templateId:[{"@_root":gi}],code:{"@_code":"76662-6","@_codeSystem":H,"@_codeSystemName":"LOINC","@_displayName":"Medication Instructions"},text:{reference:{"@_value":"#MedicationSig_6"}},consumable:{manufacturedProduct:[{manufacturedLabeledDrug:[{"@_nullFlavor":"NA"}]}]}}]}]}]}}mapMedicationRoute(e){if(e)return h(e)}mapDoseQuantity(e){if(e?.doseQuantity)return{"@_xsi:type":"PQ","@_value":e.doseQuantity.value?.toString(),"@_unit":e.doseQuantity.unit}}mapTelecom(e){return!e||e.length===0?[{"@_nullFlavor":"UNK"}]:e?.map(i=>({"@_use":i.use?Se.mapFhirToCcda(i.use):void 0,"@_value":`${this.mapTelecomSystemToPrefix(i.system)}${i.value}`}))}mapTelecomSystemToPrefix(e){return e==="email"?"mailto:":e==="phone"?"tel:":e==="fax"?"fax:":""}mapIdentifiers(e,i){let n=[];if(e&&n.push({"@_root":e}),i)for(let r of i){let o=Wi(r.system);o&&n.push({"@_root":o,"@_extension":r.value})}return n}getNarrativeReference(e){let i=e?.find(n=>n.url===Ee)?.valueString;return i?{"@_value":i}:void 0}createTextFromExtensions(e){let i=this.getNarrativeReference(e);return i?{reference:i}:void 0}createProblemEntry(e){return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":Fe},{"@_root":Fe,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,void 0),code:{"@_code":"CONC","@_codeSystem":Le},statusCode:{"@_code":Xi.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:this.mapEffectiveTime(e.recordedDate,void 0),entryRelationship:[{"@_typeCode":"SUBJ",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":Q},{"@_root":Q,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(void 0,e.identifier),text:this.createTextFromExtensions(e.extension),code:{"@_code":"55607006","@_codeSystem":M,"@_codeSystemName":"SNOMED CT","@_displayName":"Problem"},statusCode:{"@_code":"completed"},effectiveTime:[{low:e.onsetDateTime?{"@_value":V(e.onsetDateTime)}:void 0,high:e.abatementDateTime?{"@_value":R(e.abatementDateTime)}:void 0}],value:K(e.code),author:this.mapAuthor(e.asserter,e.recordedDate)}]}]}]}}createImmunizationEntry(e){let i=e?.manufacturer,n={substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN","@_negationInd":"false",templateId:[{"@_root":We},{"@_root":We,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),text:this.createTextFromExtensions(e.extension),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":V(e.occurrenceDateTime)}],consumable:{manufacturedProduct:[{"@_classCode":"MANU",templateId:[{"@_root":Qe},{"@_root":Qe,"@_extension":"2014-06-09"}],manufacturedMaterial:[{code:[h(e.vaccineCode)],lotNumberText:e.lotNumber?[e.lotNumber]:void 0}],manufacturerOrganization:i?[{id:this.mapIdentifiers(i.id,i.identifier?[i.identifier]:void 0),name:[i.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 i=this.findResourceByReference(e.actor);if(!i)return;let n,r;return i.resourceType==="PractitionerRole"?(n=this.findResourceByReference(i.practitioner),r=this.findResourceByReference(i.organization)):i.resourceType==="Practitioner"?n=i:i.resourceType==="Organization"&&(r=i),{assignedEntity:{id:this.mapIdentifiers(i.id,i.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(n?.address),telecom:this.mapTelecom(i.telecom),assignedPerson:n?{id:this.mapIdentifiers(n.id,n.identifier),name:this.mapNames(n.name)}:void 0,representedOrganization:r?{id:this.mapIdentifiers(r.id,r.identifier),name:r.name?[r.name]:void 0,addr:this.mapFhirAddressArrayToCcdaAddressArray(r.address),telecom:this.mapTelecom(r.telecom)}:void 0}}}createObservationEntry(e){return e.hasMember?{organizer:[this.createVitalSignsOrganizer(e)]}:{observation:[this.createVitalSignObservation(e)]}}createPlanOfTreatmentCarePlanEntry(e){return{act:[{"@_classCode":"ACT","@_moodCode":"INT",id:this.mapIdentifiers(e.id,e.identifier),code:K(e.category?.[0]),templateId:[{"@_root":ti}],statusCode:{"@_code":"completed"},text:e.description?{"#text":e.description}:this.createTextFromExtensions(e.extension)}]}}createPlanOfTreatmentGoalEntry(e){return{observation:[{"@_classCode":"OBS","@_moodCode":"GOL",templateId:[{"@_root":ci}],id:this.mapIdentifiers(e.id,e.identifier),code:h(e.description),statusCode:{"@_code":this.mapGoalStatus(e.lifecycleStatus)},effectiveTime:[{"@_value":R(e.startDate)}],text:this.createTextFromExtensions(e.extension),entryRelationship:e.target?.map(n=>({"@_typeCode":"RSON","@_inversionInd":"true",act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":z},{"@_root":z,"@_extension":"2014-06-09"}],code:h(n.measure),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":R(e.startDate)}]}]}))}]}}mapGoalStatus(e){switch(e){case"achieved":return"completed";case"cancelled":return"cancelled";default:return"active"}}createVitalSignsOrganizer(e){let i=[];if(e.hasMember)for(let r of e.hasMember){let o=this.findResourceByReference(r);o&&i.push({observation:[this.createVitalSignObservation(o)]})}return{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":Z},{"@_root":Z,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:h(e.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":R(e.effectiveDateTime)}],component:i}}createVitalSignObservation(e){return{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:h(e.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":R(e.effectiveDateTime)}],value:this.mapObservationValue(e),referenceRange:this.mapReferenceRangeArray(e.referenceRange),text:this.createTextFromExtensions(e.extension),author:this.mapAuthor(e.performer?.[0],e.effectiveDateTime)}}mapObservationTemplateId(e){let i=e.category?.filter(n=>n.coding?.some(r=>r.system===J)).map(n=>n.coding?.find(r=>r.system===J)).filter(n=>n?.code);if(i&&i.length>0)return i.map(n=>n.version?{"@_root":n.code,"@_extension":n.version}:{"@_root":n.code});if(e.category?.[0]?.coding?.[0]?.code){let n=ge.getEntryByFhir(e.category?.[0]?.coding?.[0]?.code);if(n)return[{"@_root":n.ccdaValue},{"@_root":n.ccdaValue,"@_extension":"2014-06-09"}]}return[{"@_root":X},{"@_root":X,"@_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 K(e.valueCodeableConcept)}mapReferenceRangeArray(e){if(!(!e||e.length===0))return e.map(i=>this.mapReferenceRange(i)).filter(Boolean)}mapReferenceRange(e){if(!e)return;let i=this.getNarrativeReference(e.extension);return i?{observationRange:{text:{reference:i},value:{"@_xsi:type":"ED",reference:i}}}:{observationRange:{text:this.createTextFromExtensions(e.extension)}}}createHistoryOfProceduresEntry(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":z},{"@_root":z,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:h(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:h(e.code),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.performedDateTime,e.performedPeriod),text:this.createTextFromExtensions(e.extension),targetSiteCode:h(e.bodySite?.[0])}]}}if(e.resourceType==="Observation")return{observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:h(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}`)}mapEffectiveTime(e,i){if(i)return[{"@_xsi:type":"IVL_TS",low:{"@_value":R(i.start)},high:{"@_value":R(i.end)}}];if(e)return[{"@_xsi:type":"TS","@_value":R(e)}]}mapEffectiveDate(e,i){if(i)return[{"@_xsi:type":"IVL_TS",low:i.start?{"@_value":V(i.start)}:void 0,high:i.end?{"@_value":V(i.end)}:void 0}];if(e)return[{"@_xsi:type":"TS","@_value":V(e)}]}createEncounterEntry(e){return{encounter:[{"@_classCode":"ENC","@_moodCode":"EVN",templateId:[{"@_root":qe},{"@_root":qe,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:h(e.type?.[0]),text:this.createTextFromExtensions(e.extension),effectiveTime:this.mapEffectiveTime(void 0,e.period),entryRelationship:e.participant?.map(i=>({"@_typeCode":"LOC",participantRole:{"@_classCode":"SDLOC",templateId:[{"@_root":oi}],code:h(i.type?.[0])}}))}]}}createCareTeamEntry(e){return{organizer:[{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":ze,"@_extension":"2022-07-01"},{"@_root":ze,"@_extension":"2022-06-01"}],id:this.mapIdentifiers(e.id,e.identifier),component:e.participant?.map(i=>({"@_typeCode":"PRF",role:i.role}))}]}}};export{Gi as ACT_CODE_SYSTEM,Oe as ADDRESS_USE_MAPPER,yr as ADDRESS_USE_VALUE_SET,gr as ADMINISTRATIVE_GENDER_VALUE_SET,kr as ALLERGIES_SECTION_TEMPLATE_IDS,Ke as ALLERGY_CLINICAL_CODE_SYSTEM,ye as ALLERGY_SEVERITY_MAPPER,Zi as ALLERGY_STATUS_MAPPER,et as ALLERGY_VERIFICATION_CODE_SYSTEM,jr as ASSESSMENTS_SECTION_TEMPLATE_IDS,Kr as CARE_TEAM_SECTION_TEMPLATE_IDS,Ee as CCDA_NARRATIVE_REFERENCE_URL,J as CCDA_TEMPLATE_CODE_SYSTEM,on as CCDA_TEMPLATE_IDS,Xe as CLINICAL_CONDITION_CODE_SYSTEM,ds as CLINICAL_NOTES_SECTION_TEMPLATE_IDS,Fi as CONDITION_CATEGORY_CODE_SYSTEM,Bi as CONDITION_VERIFICATION_CODE_SYSTEM,Je as CONDITION_VER_STATUS_CODE_SYSTEM,Or as CONFIDENTIALITY_CODE_SYSTEM,Qi as CONFIDENTIALITY_MAPPER,Ar as CONTACT_ENTITY_USE_VALUE_SET,wr as CVX_URL,hs as DEVICES_SECTION_TEMPLATE_IDS,$i as DIAGNOSIS_ROLE_CODE_SYSTEM,Wr as ENCOUNTERS_SECTION_TEMPLATE_IDS,Ji as ENCOUNTER_STATUS_MAPPER,I as EnumMapper,Vr as FHIR_CVX_URL,zi as GENDER_MAPPER,Qr as GOALS_SECTION_TEMPLATE_IDS,zr as HEALTH_CONCERNS_SECTION_TEMPLATE_IDS,U as HTTP,Te as HUMAN_NAME_USE_MAPPER,nt as IMMUNIZATIONS_SECTION_TEMPLATE_IDS,eo as INSURANCE_SECTION_TEMPLATE_IDS,ps as LAB_TESTS_SECTION_TEMPLATE_IDS,jo as LANGUAGE_MODE_CODE_SYSTEM,Qo as LANGUAGE_MODE_URL,qo as LANGUAGE_PROFICIENCY_CODE_SYSTEM,zo as LANGUAGE_PROFICIENCY_URL,sn as LOINC_TO_TEMPLATE_IDS,Br as MEDICATIONS_SECTION_TEMPLATE_IDS,Rr as MEDICATION_REQUEST_STATUS_VALUE_SET,Ce as MEDICATION_STATUS_MAPPER,Xr as MENTAL_STATUS_SECTION_TEMPLATE_IDS,Cr as NAME_USE_VALUE_SET,Nr as NCI_THESAURUS_URL,Lr as NDFRT_URL,br as NUCC_TAXONOMY_URL,Sr as OBSERVATION_CATEGORY_CODE_SYSTEM,ge as OBSERVATION_CATEGORY_MAPPER,Yi as PARTICIPATION_CODE_SYSTEM,Jr as PATIENT_NOTES_SECTION_TEMPLATE_IDS,qr as PLAN_OF_TREATMENT_SECTION_TEMPLATE_IDS,Fr as PROBLEMS_SECTION_TEMPLATE_IDS,Xi as PROBLEM_STATUS_MAPPER,$r as PROCEDURES_SECTION_TEMPLATE_IDS,Ki as PROCEDURE_STATUS_MAPPER,Wo as RACE_CODE_SYSTEM,Zr as REASON_FOR_REFERRAL_SECTION_TEMPLATE_IDS,Hr as RESULTS_SECTION_TEMPLATE_IDS,Yr as SOCIAL_HISTORY_SECTION_TEMPLATE_IDS,tt as SYSTEM_MAPPER,Se as TELECOM_USE_MAPPER,Pr as UNII_URL,Hi as US_CORE_CONDITION_URL,me as US_CORE_ETHNICITY_URL,ji as US_CORE_MEDICATION_REQUEST_URL,Zo as US_CORE_PATIENT_URL,_e as US_CORE_RACE_URL,xr as US_DRIVER_LICENSE_URL,vr as US_NPI_URL,Dr as US_SSN_URL,Ur as VA_MEDRT_URL,Gr as VITAL_SIGNS_SECTION_TEMPLATE_IDS,qi as XSI_URL,cs as convertCcdaToFhir,ts as convertCcdaToXml,Ss as convertFhirToCcda,rn as convertToCompactXml,es as convertXmlToCcda,Ie as mapCcdaSystemToFhir,Ue as mapCcdaToFhirDate,_ as mapCcdaToFhirDateTime,h as mapCodeableConceptToCcdaCode,K as mapCodeableConceptToCcdaValue,Wi as mapFhirSystemToCcda,V as mapFhirToCcdaDate,R as mapFhirToCcdaDateTime,nn as parseXml};
1
+ var ln=class{constructor(i,e){this.operator=i,this.child=e}toString(){return`${this.operator}(${this.child.toString()})`}},$=class{constructor(i,e,t){this.operator=i,this.left=e,this.right=t}toString(){return`${this.left.toString()} ${this.operator} ${this.right.toString()}`}},dn=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 pn(i,this.prefixParselets,this.infixParselets)}},pn=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]}},Le="http://unitsofmeasure.org",ae="http://loinc.org",Ve="http://snomed.info/sct",St="http://www.nlm.nih.gov/research/umls/rxnorm",yt="http://www.ama-assn.org/go/cpt";var Ct="http://hl7.org/fhir/sid/ndc",f="http://hl7.org",I="http://terminology.hl7.org";var hn="unauthorized";var oe={resourceType:"OperationOutcome",id:hn,issue:[{severity:"error",code:"login",details:{text:"Unauthorized"}}]},ro={...oe,issue:[...oe.issue,{severity:"error",code:"expired",details:{text:"Token expired"}}]},oo={...oe,issue:[...oe.issue,{severity:"error",code:"invalid",details:{text:"Token not issued for this audience"}}]};function fn(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 _n(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,fn(r,o)])),constraints:[],innerTypes:[]};return e}var mn={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 En=_n(mn);var _t=Object.create(null);function In(i){let e;return e=_t[i],e||(e=_t[i]=Object.create(null)),e}function Tn(i,e){if(e){let t=In(e)[i];if(t)return t}return En[i]}var gt={base64Binary:/^([A-Za-z\d+/]{4})*([A-Za-z\d+/]{2}==|[A-Za-z\d+/]{3}=)?$/,canonical:/^\S*$/,code:/^[^\s]+( [^\s]+)*$/,date:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1]))?)?$/,dateTime:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1])(T([01]\d|2[0-3])(:[0-5]\d:([0-5]\d|60)(\.\d{1,9})?)?)?)?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00)?)?)?$/,id:/^[A-Za-z0-9\-.]{1,64}$/,instant:/^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])T([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00))$/,markdown:/^[\r\n\t\u0020-\uFFFF]+$/,oid:/^urn:oid:[0-2](\.(0|[1-9]\d*))+$/,string:/^[\r\n\t\u0020-\uFFFF]+$/,time:/^([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?$/,uri:/^\S*$/,url:/^\S*$/,uuid:/^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,xhtml:/.*/};function a(i){return[{type:u.boolean,value:i}]}function U(i){return i==null?{type:"undefined",value:void 0}:Number.isSafeInteger(i)?{type:u.integer,value:i}:typeof i=="number"?{type:u.decimal,value:i}:typeof i=="boolean"?{type:u.boolean,value:i}:typeof i=="string"?{type:u.string,value:i}:y(i)?{type:u.Quantity,value:i}:j(i)?{type:i.resourceType,value:i}:Pt(i)?{type:u.CodeableConcept,value:i}:vt(i)?{type:u.Coding,value:i}:{type:u.BackboneElement,value:i}}function x(i){return i.length===0?!1:!!i[0].value}function v(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 On(i,e,t){if(!i.value)return;let n=$n(i.type,e,t?.profileUrl);return n?Sn(i,e,n):yn(i,e)}function Sn(i,e,t){let n=i.value,r=t.type;if(!r||r.length===0)return;let o,s="undefined",c,d=t.path.lastIndexOf("."),N=t.path.substring(d+1);for(let m of r){let F=N.replace("[x]",H(m.code));if(o=n[F],c=n["_"+F],o!==void 0||c!==void 0){s=m.code;break}}if(c)if(Array.isArray(o)){o=o.slice();for(let m=0;m<Math.max(o.length,c.length);m++)o[m]=Tt(o[m],c[m])}else o=Tt(o,c);if(!Y(o))return(s==="Element"||s==="BackboneElement")&&(s=t.type[0].code),Array.isArray(o)?o.map(m=>mt(m,s)):mt(o,s)}function mt(i,e){return e==="Resource"&&j(i)&&(e=i.resourceType),{type:e,value:i}}function yn(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(U):n=U(r)}else{let r=e.endsWith("[x]")?e.substring(0,e.length-3):e;for(let o of Object.values(u)){let s=r+H(o);if(s in t){let c=t[s];Array.isArray(c)?n=c.map(d=>({type:o,value:d})):n={type:o,value:c};break}}}if(Array.isArray(n)){if(n.length===0||Y(n[0]))return}else if(Y(n))return;return n}function At(i){let e=[];for(let t of i){let n=!1;for(let r of e)if(x(we(t,r))){n=!0;break}n||e.push(t)}return e}function Cn(i){return a(!x(i))}function gn(i,e){return i.length===0||e.length===0?[]:i.length!==e.length?a(!1):a(i.every((t,n)=>x(we(t,e[n]))))}function An(i,e){return i.length===0||e.length===0?[]:i.length!==e.length?a(!0):a(i.some((t,n)=>!x(we(t,e[n]))))}function we(i,e){let t=i.value?.valueOf(),n=e.value?.valueOf();return typeof t=="number"&&typeof n=="number"?a(Math.abs(t-n)<1e-8):y(t)&&y(n)?a(Dt(t,n)):a(typeof t=="object"&&typeof n=="object"?Me(i,e):t===n)}function Rt(i,e){return i.length===0&&e.length===0?a(!0):i.length!==e.length?a(!1):(i.sort(Et),e.sort(Et),a(i.every((t,n)=>x(Rn(t,e[n])))))}function Rn(i,e){let{type:t,value:n}=i,{type:r,value:o}=e,s=n?.valueOf(),c=o?.valueOf();return typeof s=="number"&&typeof c=="number"?a(Math.abs(s-c)<.01):y(s)&&y(c)?a(Dt(s,c)):a(t==="Coding"&&r==="Coding"?typeof s!="object"||typeof c!="object"?!1:s.code===c.code&&s.system===c.system:typeof s=="object"&&typeof c=="object"?Me({...s,id:void 0},{...c,id:void 0}):typeof s=="string"&&typeof c=="string"?s.toLowerCase()===c.toLowerCase():s===c)}function Et(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 Nt(i,e){let{value:t}=i;if(t==null)return!1;switch(e){case"Boolean":return typeof t=="boolean";case"Decimal":case"Integer":return typeof t=="number";case"Date":return Nn(t);case"DateTime":return Ue(t);case"Time":return typeof t=="string"&&!!/^T\d/.exec(t);case"Period":return Dn(t);case"Quantity":return y(t);default:return i.type===e||typeof t=="object"&&t?.resourceType===e}}function Nn(i){return typeof i=="string"&&!!gt.date.exec(i)}function Ue(i){return typeof i=="string"&&!!gt.dateTime.exec(i)}function Dn(i){return!!(i&&typeof i=="object"&&("start"in i&&Ue(i.start)||"end"in i&&Ue(i.end)))}function y(i){return!!(i&&typeof i=="object"&&"value"in i&&typeof i.value=="number")}function Dt(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 Me(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(It(o)&&It(s)){if(!Me(o,s))return!1}else if(o!==s)return!1}return!0}function It(i){return i!==null&&typeof i=="object"}function Tt(i,e){if(e){if(typeof e!="object")throw new Error("Primitive extension must be an object");return xn(i??{},e)}return i}function xn(i,e){return delete e.__proto__,delete e.constructor,Object.assign(i,e)}function vn(i,e){return j(i,e)&&"id"in i&&typeof i.id=="string"}function p(i){let e=xt(i)??"undefined/undefined",t=Un(i);return t===e?{reference:e}:{reference:e,display:t}}function xt(i){if(bt(i))return i.reference;if(vn(i))return`${i.resourceType}/${i.id}`}function Pn(i){if(i)return bt(i)?i.reference.split("/")[1]:i.id}function bn(i){return i.resourceType==="Patient"||i.resourceType==="Practitioner"||i.resourceType==="RelatedPerson"}function Un(i){if(bn(i)){let e=Ln(i);if(e)return e}if(i.resourceType==="Device"){let e=Vn(i);if(e)return e}if(i.resourceType==="MedicationRequest"&&i.medicationCodeableConcept)return Ot(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]),Pt(e))return Ot(e);if(Bn(e))return e.text}return xt(i)??""}function Ln(i){let e=i.name;if(e&&e.length>0)return Gn(e[0])}function Vn(i){let e=i.deviceName;if(e&&e.length>0)return e[0].name}function wn(i,e){let t=new Date(i);t.setUTCHours(0,0,0,0);let n=e?new Date(e):new Date;n.setUTCHours(0,0,0,0);let r=t.getUTCFullYear(),o=t.getUTCMonth(),s=t.getUTCDate(),c=n.getUTCFullYear(),d=n.getUTCMonth(),N=n.getUTCDate(),m=c-r;(d<o||d===o&&N<s)&&m--;let F=c*12+d-(r*12+o);N<s&&F--;let un=Math.floor((n.getTime()-t.getTime())/(1e3*60*60*24));return{years:m,months:F,days:un}}function Mn(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 Y(i){if(i==null)return!0;let e=typeof i;return e==="string"||e==="object"?!kn(i):!1}function kn(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 ke(i){return!!/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i.exec(i)}function Be(i){return i!==null&&typeof i=="object"}function vt(i){return Be(i)&&"code"in i&&typeof i.code=="string"}function Pt(i){return Be(i)&&"coding"in i&&Array.isArray(i.coding)&&i.coding.every(vt)}function Bn(i){return Be(i)&&"text"in i&&typeof i.text=="string"}var Fn=[];for(let i=0;i<256;i++)Fn.push(i.toString(16).padStart(2,"0"));function H(i){return i?i.charAt(0).toUpperCase()+i.substring(1):""}function Gn(i,e){let t=[];if(i.prefix&&e?.prefix!==!1&&t.push(...i.prefix),i.given&&t.push(...i.given),i.family&&t.push(i.family),i.suffix&&e?.suffix!==!1&&t.push(...i.suffix),i.use&&(e?.all||e?.use)&&t.push("["+i.use+"]"),t.length===0){let n=G(i.text);if(n)return n}return t.join(" ").trim()}function Ot(i){return i?G(i.text)||(i.coding?i.coding.map(t=>Yn(t)).join(", "):""):""}function Yn(i,e){let t=G(i?.display);if(t){let n=e?G(i?.code):void 0;return`${t}${n?" ("+n+")":""}`}return G(i?.code)??""}function G(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 $n(i,e,t){let n=Tn(i,t);if(n)return Hn(n.elements,e)}function Hn(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 j(i,e){return!(!i||typeof i!="object"||!("resourceType"in i)||e&&i.resourceType!==e)}function bt(i){return!!(i&&typeof i=="object"&&"reference"in i&&typeof i.reference=="string")}function re(i){if(i.startsWith("T"))return i+"T00:00:00.000Z".substring(i.length);if(i.length<=10)return i;try{return new Date(i).toISOString()}catch{return i}}var D=()=>[],T={empty:(i,e)=>a(e.length===0||e.every(t=>Y(t.value))),hasValue:(i,e)=>a(e.length!==0),exists:(i,e,t)=>a(t?e.filter(n=>x(t.eval(i,[n]))).length>0:e.length>0&&e.every(n=>!Y(n.value))),all:(i,e,t)=>a(e.every(n=>x(t.eval(i,[n])))),allTrue:(i,e)=>{for(let t of e)if(!t.value)return a(!1);return a(!0)},anyTrue:(i,e)=>{for(let t of e)if(t.value)return a(!0);return a(!1)},allFalse:(i,e)=>{for(let t of e)if(t.value)return a(!1);return a(!0)},anyFalse:(i,e)=>{for(let t of e)if(!t.value)return a(!0);return a(!1)},subsetOf:(i,e,t)=>{if(e.length===0)return a(!0);let n=t.eval(i,b(i));return n.length===0?a(!1):a(e.every(r=>n.some(o=>o.value===r.value)))},supersetOf:(i,e,t)=>{let n=t.eval(i,b(i));return n.length===0?a(!0):e.length===0?a(!1):a(n.every(r=>e.some(o=>o.value===r.value)))},count:(i,e)=>[{type:u.integer,value:e.length}],distinct:(i,e)=>{let t=[];for(let n of e)t.some(r=>r.value===n.value)||t.push(n);return t},isDistinct:(i,e)=>a(e.length===T.distinct(i,e).length),where:(i,e,t)=>e.filter(n=>x(t.eval(i,[n]))),select:(i,e,t)=>e.map(n=>t.eval({parent:i,variables:{$this:n}},[n])).flat(),repeat:D,ofType:(i,e,t)=>e.filter(n=>n.type===t.name),single:(i,e)=>{if(e.length>1)throw new Error("Expected input length one for single()");return e.length===0?[]:e.slice(0,1)},first:(i,e)=>e.length===0?[]:e.slice(0,1),last:(i,e)=>e.length===0?[]:e.slice(e.length-1,e.length),tail:(i,e)=>e.length===0?[]:e.slice(1,e.length),skip:(i,e,t)=>{let n=t.eval(i,e)[0]?.value;if(typeof n!="number")throw new Error("Expected a number for skip(num)");return n>=e.length?[]:n<=0?e:e.slice(n,e.length)},take:(i,e,t)=>{let n=t.eval(i,e)[0]?.value;if(typeof n!="number")throw new Error("Expected a number for take(num)");return n>=e.length?e:n<=0?[]:e.slice(0,n)},intersect:(i,e,t)=>{if(!t)return e;let n=t.eval(i,b(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,b(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,b(i));return At([...e,...n])},combine:(i,e,t)=>{if(!t)return e;let n=t.eval(i,b(i));return[...e,...n]},htmlChecks:(i,e,t)=>[U(!0)],iif:(i,e,t,n,r)=>{let o=t.eval(i,e);if(o.length>1||o.length===1&&typeof o[0].value!="boolean")throw new Error("Expected criterion to evaluate to a Boolean");return x(o)?n.eval(i,e):r?r.eval(i,e):[]},toBoolean:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);if(typeof t=="boolean")return[{type:u.boolean,value:t}];if(typeof t=="number"&&(t===0||t===1))return a(!!t);if(typeof t=="string"){let n=t.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(n))return a(!0);if(["false","f","no","n","0","0.0"].includes(n))return a(!1)}return[]},convertsToBoolean:(i,e)=>e.length===0?[]:a(T.toBoolean(i,e).length===1),toInteger:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return typeof t=="number"?[{type:u.integer,value:t}]:typeof t=="string"&&/^[+-]?\d+$/.exec(t)?[{type:u.integer,value:parseInt(t,10)}]:typeof t=="boolean"?[{type:u.integer,value:t?1:0}]:[]},convertsToInteger:(i,e)=>e.length===0?[]:a(T.toInteger(i,e).length===1),toDate:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return typeof t=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(t)?[{type:u.date,value:re(t)}]:[]},convertsToDate:(i,e)=>e.length===0?[]:a(T.toDate(i,e).length===1),toDateTime:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return typeof t=="string"&&/^\d{4}(-\d{2}(-\d{2})?)?/.exec(t)?[{type:u.dateTime,value:re(t)}]:[]},convertsToDateTime:(i,e)=>e.length===0?[]:a(T.toDateTime(i,e).length===1),toDecimal:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return typeof t=="number"?[{type:u.decimal,value:t}]:typeof t=="string"&&/^-?\d{1,9}(\.\d{1,9})?$/.exec(t)?[{type:u.decimal,value:parseFloat(t)}]:typeof t=="boolean"?[{type:u.decimal,value:t?1:0}]:[]},convertsToDecimal:(i,e)=>e.length===0?[]:a(T.toDecimal(i,e).length===1),toQuantity:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return y(t)?[{type:u.Quantity,value:t}]:typeof t=="number"?[{type:u.Quantity,value:{value:t,unit:"1"}}]:typeof t=="string"&&/^-?\d{1,9}(\.\d{1,9})?/.exec(t)?[{type:u.Quantity,value:{value:parseFloat(t),unit:"1"}}]:typeof t=="boolean"?[{type:u.Quantity,value:{value:t?1:0,unit:"1"}}]:[]},convertsToQuantity:(i,e)=>e.length===0?[]:a(T.toQuantity(i,e).length===1),toString:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);return t==null?[]:y(t)?[{type:u.string,value:`${t.value} '${t.unit}'`}]:[{type:u.string,value:t.toString()}]},convertsToString:(i,e)=>e.length===0?[]:a(T.toString(i,e).length===1),toTime:(i,e)=>{if(e.length===0)return[];let[{value:t}]=R(e,1);if(typeof t=="string"){let n=/^T?(\d{2}(:\d{2}(:\d{2})?)?)/.exec(t);if(n)return[{type:u.time,value:re("T"+n[1])}]}return[]},convertsToTime:(i,e)=>e.length===0?[]:a(T.toTime(i,e).length===1),indexOf:(i,e,t)=>S((n,r)=>n.indexOf(r),i,e,t),substring:(i,e,t,n)=>S((r,o,s)=>{let c=o,d=s?c+s:r.length;return c<0||c>=r.length?void 0:r.substring(c,d)},i,e,t,n),startsWith:(i,e,t)=>S((n,r)=>n.startsWith(r),i,e,t),endsWith:(i,e,t)=>S((n,r)=>n.endsWith(r),i,e,t),contains:(i,e,t)=>S((n,r)=>n.includes(r),i,e,t),upper:(i,e)=>S(t=>t.toUpperCase(),i,e),lower:(i,e)=>S(t=>t.toLowerCase(),i,e),replace:(i,e,t,n)=>S((r,o,s)=>r.replaceAll(o,s),i,e,t,n),matches:(i,e,t)=>S((n,r)=>!!new RegExp(r).exec(n),i,e,t),replaceMatches:(i,e,t,n)=>S((r,o,s)=>r.replaceAll(o,s),i,e,t,n),length:(i,e)=>S(t=>t.length,i,e),toChars:(i,e)=>S(t=>t?t.split(""):void 0,i,e),encode:D,decode:D,escape:D,unescape:D,trim:D,split:D,join:(i,e,t)=>{let n=t?.eval(i,b(i))[0]?.value??"";if(typeof n!="string")throw new Error("Separator must be a string.");return[{type:u.string,value:e.map(r=>r.value?.toString()??"").join(n)}]},abs:(i,e)=>A(Math.abs,i,e),ceiling:(i,e)=>A(Math.ceil,i,e),exp:(i,e)=>A(Math.exp,i,e),floor:(i,e)=>A(Math.floor,i,e),ln:(i,e)=>A(Math.log,i,e),log:(i,e,t)=>A((n,r)=>Math.log(n)/Math.log(r),i,e,t),power:(i,e,t)=>A(Math.pow,i,e,t),round:(i,e)=>A(Math.round,i,e),sqrt:(i,e)=>A(Math.sqrt,i,e),truncate:(i,e)=>A(t=>t|0,i,e),children:D,descendants:D,trace:(i,e,t)=>e,now:()=>[{type:u.dateTime,value:new Date().toISOString()}],timeOfDay:()=>[{type:u.time,value:new Date().toISOString().substring(11)}],today:()=>[{type:u.date,value:new Date().toISOString().substring(0,10)}],between:(i,e,t,n,r)=>{let o=T.toDateTime(i,t.eval(i,e));if(o.length===0)throw new Error("Invalid start date");let s=T.toDateTime(i,n.eval(i,e));if(s.length===0)throw new Error("Invalid end date");let c=r.eval(i,e)[0]?.value;if(c!=="years"&&c!=="months"&&c!=="days")throw new Error("Invalid units");let d=wn(o[0].value,s[0].value);return[{type:u.Quantity,value:{value:d[c],unit:c}}]},is:(i,e,t)=>{let n="";return t instanceof se?n=t.name:t instanceof Ut&&(n=t.left.name+"."+t.right.name),n?e.map(r=>({type:u.boolean,value:Nt(r,n)})):[]},not:(i,e)=>T.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 U(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"}}:j(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 se&&(r=t.name),r&&!n.reference.startsWith(r+"/")?[]:[{type:u.id,value:Pn(n)}]},extension:(i,e,t)=>{let n=t.eval(i,e)[0].value,r=e?.[0]?.value;if(r){let o=Mn(r,n);if(o)return[{type:u.Extension,value:o}]}return[]}};function S(i,e,t,...n){if(t.length===0)return[];let[{value:r}]=R(t,1);if(typeof r!="string")throw new Error("String function cannot be called with non-string");let o=i(r,...n.map(s=>s?.eval(e,t)[0]?.value));return o===void 0?[]:Array.isArray(o)?o.map(U):[U(o)]}function A(i,e,t,...n){if(t.length===0)return[];let[{value:r}]=R(t,1),o=y(r),s=o?r.value:r;if(typeof s!="number")throw new Error("Math function cannot be called with non-number");let c=i(s,...n.map(m=>m.eval(e,t)[0]?.value)),d=o?u.Quantity:t[0].type,N=o?{...r,value:c}:c;return[{type:d,value:N}]}function R(i,e){if(i.length!==e)throw new Error(`Expected ${e} arguments`);for(let t of i)if(t==null)throw new Error("Expected non-null argument");return i}function b(i){let e=i;for(;e.parent?.variables.$this;)e=e.parent;return[e.variables.$this]}var V=class{constructor(i){this.value=i}eval(){return[this.value]}toString(){let i=this.value.value;return typeof i=="string"?`'${i}'`:i.toString()}},se=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 j(e,this.name)?i:On(i,this.name)}toString(){return this.name}},jn=class{eval(){return[]}toString(){return"{}"}},qn=class extends ln{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()}},Wn=class extends ${constructor(i,e){super("as",i,e)}eval(i,e){return T.ofType(i,this.left.eval(i,e),this.right)}},C=class extends ${},g=class extends C{constructor(i,e,t,n){super(i,e,t),this.impl=n}eval(i,e){let t=this.left.eval(i,e);if(t.length!==1)return[];let n=this.right.eval(i,e);if(n.length!==1)return[];let r=t[0].value,o=n[0].value,s=y(r)?r.value:r,c=y(o)?o.value:o,d=this.impl(s,c);return typeof d=="boolean"?a(d):y(r)?[{type:u.Quantity,value:{...r,value:d}}]:[U(d)]}},Qn=class extends ${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}},zn=class extends C{constructor(i,e){super("contains",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return a(t.some(r=>r.value===n[0].value))}},Zn=class extends C{constructor(i,e){super("in",i,e)}eval(i,e){let t=v(this.left.eval(i,e)),n=this.right.eval(i,e);return t?a(n.some(r=>r.value===t.value)):[]}},Ut=class extends ${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()}`}},Xn=class extends ${constructor(i,e){super("|",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return At([...t,...n])}},Jn=class extends C{constructor(i,e){super("=",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return gn(t,n)}},Kn=class extends C{constructor(i,e){super("!=",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return An(t,n)}},er=class extends C{constructor(i,e){super("~",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return Rt(t,n)}},tr=class extends C{constructor(i,e){super("!~",i,e)}eval(i,e){let t=this.left.eval(i,e),n=this.right.eval(i,e);return Cn(Rt(t,n))}},ir=class extends C{constructor(i,e){super("is",i,e)}eval(i,e){let t=this.left.eval(i,e);if(t.length!==1)return[];let n=this.right.name;return a(Nt(t[0],n))}},nr=class extends C{constructor(i,e){super("and",i,e)}eval(i,e){let t=v(this.left.eval(i,e),"boolean"),n=v(this.right.eval(i,e),"boolean");return t?.value===!0&&n?.value===!0?a(!0):t?.value===!1||n?.value===!1?a(!1):[]}},rr=class extends C{constructor(i,e){super("or",i,e)}eval(i,e){let t=v(this.left.eval(i,e),"boolean"),n=v(this.right.eval(i,e),"boolean");return t?.value===!1&&n?.value===!1?a(!1):t?.value||n?.value?a(!0):[]}},or=class extends C{constructor(i,e){super("xor",i,e)}eval(i,e){let t=v(this.left.eval(i,e),"boolean"),n=v(this.right.eval(i,e),"boolean");return!t||!n?[]:a(t.value!==n.value)}},sr=class extends C{constructor(i,e){super("implies",i,e)}eval(i,e){let t=v(this.left.eval(i,e),"boolean"),n=v(this.right.eval(i,e),"boolean");return n?.value===!0||t?.value===!1?a(!0):!t||!n?[]:a(!1)}},ar=class{constructor(i,e){this.name=i,this.args=e}eval(i,e){let t=T[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(", ")})`}},cr=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 Lt=["!=","!~","<=",">=","{}","->"];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},ur={parse(i){let e=i.consumeAndParse();if(!i.match(")"))throw new Error("Parse error: expected `)` got `"+i.peek()?.value+"`");return e}},lr={parse(i,e){let t=i.consumeAndParse();if(!i.match("]"))throw new Error("Parse error: expected `]`");return new cr(e,t)},precedence:l.Indexer},dr={parse(i,e){if(!(e instanceof se))throw new Error("Unexpected parentheses");let t=[];for(;!i.match(")");)t.push(i.consumeAndParse()),i.match(",");return new ar(e.name,t)},precedence:l.FunctionCall};function pr(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 Fe(){return new dn().registerPrefix("String",{parse:(i,e)=>new V({type:u.string,value:e.value})}).registerPrefix("DateTime",{parse:(i,e)=>new V({type:u.dateTime,value:re(e.value)})}).registerPrefix("Quantity",{parse:(i,e)=>new V({type:u.Quantity,value:pr(e.value)})}).registerPrefix("Number",{parse:(i,e)=>new V({type:e.value.includes(".")?u.decimal:u.integer,value:parseFloat(e.value)})}).registerPrefix("true",{parse:()=>new V({type:u.boolean,value:!0})}).registerPrefix("false",{parse:()=>new V({type:u.boolean,value:!1})}).registerPrefix("Symbol",{parse:(i,e)=>new se(e.value)}).registerPrefix("{}",{parse:()=>new jn}).registerPrefix("(",ur).registerInfix("[",lr).registerInfix("(",dr).prefix("+",l.UnaryAdd,(i,e)=>new qn("+",e,t=>t)).prefix("-",l.UnarySubtract,(i,e)=>new g("-",e,e,(t,n)=>-n)).infixLeft(".",l.Dot,(i,e,t)=>new Ut(i,t)).infixLeft("/",l.Divide,(i,e,t)=>new g("/",i,t,(n,r)=>n/r)).infixLeft("*",l.Multiply,(i,e,t)=>new g("*",i,t,(n,r)=>n*r)).infixLeft("+",l.Add,(i,e,t)=>new g("+",i,t,(n,r)=>n+r)).infixLeft("-",l.Subtract,(i,e,t)=>new g("-",i,t,(n,r)=>n-r)).infixLeft("|",l.Union,(i,e,t)=>new Xn(i,t)).infixLeft("=",l.Equals,(i,e,t)=>new Jn(i,t)).infixLeft("!=",l.NotEquals,(i,e,t)=>new Kn(i,t)).infixLeft("~",l.Equivalent,(i,e,t)=>new er(i,t)).infixLeft("!~",l.NotEquivalent,(i,e,t)=>new tr(i,t)).infixLeft("<",l.LessThan,(i,e,t)=>new g("<",i,t,(n,r)=>n<r)).infixLeft("<=",l.LessThanOrEquals,(i,e,t)=>new g("<=",i,t,(n,r)=>n<=r)).infixLeft(">",l.GreaterThan,(i,e,t)=>new g(">",i,t,(n,r)=>n>r)).infixLeft(">=",l.GreaterThanOrEquals,(i,e,t)=>new g(">=",i,t,(n,r)=>n>=r)).infixLeft("&",l.Ampersand,(i,e,t)=>new Qn(i,t)).infixLeft("and",l.And,(i,e,t)=>new nr(i,t)).infixLeft("as",l.As,(i,e,t)=>new Wn(i,t)).infixLeft("contains",l.Contains,(i,e,t)=>new zn(i,t)).infixLeft("div",l.Divide,(i,e,t)=>new g("div",i,t,(n,r)=>n/r|0)).infixLeft("in",l.In,(i,e,t)=>new Zn(i,t)).infixLeft("is",l.Is,(i,e,t)=>new ir(i,t)).infixLeft("mod",l.Modulo,(i,e,t)=>new g("mod",i,t,(n,r)=>n%r)).infixLeft("or",l.Or,(i,e,t)=>new rr(i,t)).infixLeft("xor",l.Xor,(i,e,t)=>new or(i,t)).infixLeft("implies",l.Implies,(i,e,t)=>new sr(i,t))}var so=Fe();var hr=(i=>(i.BOOLEAN="BOOLEAN",i.NUMBER="NUMBER",i.QUANTITY="QUANTITY",i.TEXT="TEXT",i.REFERENCE="REFERENCE",i.CANONICAL="CANONICAL",i.DATE="DATE",i.DATETIME="DATETIME",i.PERIOD="PERIOD",i.UUID="UUID",i))(hr||{});var fr=(i=>(i.EQUALS="eq",i.NOT_EQUALS="ne",i.GREATER_THAN="gt",i.LESS_THAN="lt",i.GREATER_THAN_OR_EQUALS="ge",i.LESS_THAN_OR_EQUALS="le",i.STARTS_AFTER="sa",i.ENDS_BEFORE="eb",i.APPROXIMATELY="ap",i.CONTAINS="contains",i.STARTS_WITH="sw",i.EXACT="exact",i.TEXT="text",i.NOT="not",i.ABOVE="above",i.BELOW="below",i.IN="in",i.NOT_IN="not-in",i.OF_TYPE="of-type",i.MISSING="missing",i.PRESENT="present",i.IDENTIFIER="identifier",i.ITERATE="iterate",i))(fr||{});var _r=(i=>(i.READ="read",i.VREAD="vread",i.UPDATE="update",i.PATCH="patch",i.DELETE="delete",i.HISTORY="history",i.HISTORY_INSTANCE="history-instance",i.HISTORY_TYPE="history-type",i.HISTORY_SYSTEM="history-system",i.CREATE="create",i.SEARCH="search",i.SEARCH_TYPE="search-type",i.SEARCH_SYSTEM="search-system",i.SEARCH_COMPARTMENT="search-compartment",i.CAPABILITIES="capabilities",i.TRANSACTION="transaction",i.BATCH="batch",i.OPERATION="operation",i))(_r||{});function ce(){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 mr={CSS:"text/css",DICOM:"application/dicom",FAVICON:"image/vnd.microsoft.icon",FHIR_JSON:"application/fhir+json",FORM_URL_ENCODED:"application/x-www-form-urlencoded",HL7_V2:"x-application/hl7-v2+er7",HTML:"text/html",JAVASCRIPT:"text/javascript",JSON:"application/json",JSON_PATCH:"application/json-patch+json",PNG:"image/png",SCIM_JSON:"application/scim+json",SVG:"image/svg+xml",TEXT:"text/plain",TYPESCRIPT:"text/typescript",PING:"x-application/ping",XML:"text/xml",CDA_XML:"application/cda+xml"};var Er;Er=Symbol.toStringTag;var ao={Event:typeof globalThis.Event<"u"?globalThis.Event:void 0,ErrorEvent:void 0,CloseEvent:void 0};var co={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 uo=mr.FHIR_JSON+", */*; q=0.1";var Ir=(i=>(i.ClientCredentials="client_credentials",i.AuthorizationCode="authorization_code",i.RefreshToken="refresh_token",i.JwtBearer="urn:ietf:params:oauth:grant-type:jwt-bearer",i.TokenExchange="urn:ietf:params:oauth:grant-type:token-exchange",i))(Ir||{}),Tr=(i=>(i.AccessToken="urn:ietf:params:oauth:token-type:access_token",i.RefreshToken="urn:ietf:params:oauth:token-type:refresh_token",i.IdToken="urn:ietf:params:oauth:token-type:id_token",i.Saml1Token="urn:ietf:params:oauth:token-type:saml1",i.Saml2Token="urn:ietf:params:oauth:token-type:saml2",i))(Tr||{}),Or=(i=>(i.ClientSecretBasic="client_secret_basic",i.ClientSecretPost="client_secret_post",i.ClientSecretJwt="client_secret_jwt",i.PrivateKeyJwt="private_key_jwt",i.None="none",i))(Or||{}),Sr=(i=>(i.JwtBearer="urn:ietf:params:oauth:client-assertion-type:jwt-bearer",i))(Sr||{});var lo=[...Lt,"->","<<",">>","=="];var po=Fe().registerInfix("->",{precedence:l.Arrow}).registerInfix(";",{precedence:l.Semicolon});var ho=" ".repeat(2);var fo=[...Lt,"eq","ne","co"];var _o=Fe();var yr=(i=>(i[i.NONE=0]="NONE",i[i.ERROR=1]="ERROR",i[i.WARN=2]="WARN",i[i.INFO=3]="INFO",i[i.DEBUG=4]="DEBUG",i))(yr||{});function Ge(i){if(!i)return;let e=i.substring(0,4),t="01",n="01";return i.length>=8&&(t=i.substring(4,6),n=i.substring(6,8)),`${e}-${t}-${n}`}function _(i){if(!i)return;let e=i.substring(0,4),t="01",n="01",r="00",o="00",s="00",c="Z";return i.length>=8&&(t=i.substring(4,6),n=i.substring(6,8)),i.length>=12&&(r=i.substring(8,10),o=i.substring(10,12)),i.length>=14&&(s=i.substring(12,14)),i.length>14&&(c=i.substring(14),c==="+0000"&&(c="Z")),`${e}-${t}-${n}T${r}:${o}:${s}${c}`}function w(i){if(i)return i.substring(0,10).replace(/-/g,"")}function O(i){if(!i)return;let[e,t]=i.split("T"),n=e.replaceAll("-",""),r=(t??"").replaceAll(/\.\d+/g,"").replaceAll(/:/g,"").replaceAll(/Z/g,"+0000");return`${n}${r}`}var ue="1.3.6.1.4.1.19376.1.5.3.1.3.1";var Vt="2.16.840.1.113883.1.3";var wt="2.16.840.1.113883.2.20.5.1",Mt="2.16.840.1.113883.3.26.1.1";var kt="2.16.840.1.113883.4.1",Bt="2.16.840.1.113883.4.3",Ft="2.16.840.1.113883.4.6",Gt="2.16.840.1.113883.4.9",Yt="2.16.840.1.113883.5.1",le="2.16.840.1.113883.5.4",Ye="2.16.840.1.113883.5.6",$e="2.16.840.1.113883.5.25",M="2.16.840.1.113883.6.1",$t="2.16.840.1.113883.6.12",Ht="2.16.840.1.113883.6.24",jt="2.16.840.1.113883.6.69",qt="2.16.840.1.113883.6.88",k="2.16.840.1.113883.6.96",Wt="2.16.840.1.113883.6.101",Qt="2.16.840.1.113883.6.209",He="2.16.840.1.113883.6.238",zt="2.16.840.1.113883.6.345";var Zt="2.16.840.1.113883.10.20.15.3.8";var je="2.16.840.1.113883.10.20.22.1.1";var qe="2.16.840.1.113883.10.20.22.1.2";var de="2.16.840.1.113883.10.20.22.2.1.1";var q="2.16.840.1.113883.10.20.22.2.2",W="2.16.840.1.113883.10.20.22.2.2.1";var We="2.16.840.1.113883.10.20.22.2.3.1";var Xt="2.16.840.1.113883.10.20.22.2.4.1";var pe="2.16.840.1.113883.10.20.22.2.5.1";var he="2.16.840.1.113883.10.20.22.2.6.1";var B="2.16.840.1.113883.10.20.22.2.7.1";var Jt="2.16.840.1.113883.10.20.22.2.8";var P="2.16.840.1.113883.10.20.22.2.10";var Qe="2.16.840.1.113883.10.20.22.2.17";var fe="2.16.840.1.113883.10.20.22.2.18";var Kt="2.16.840.1.113883.10.20.22.2.22.1";var ei="2.16.840.1.113883.10.20.22.2.23";var ti="2.16.840.1.113883.10.20.22.2.56";var _e="2.16.840.1.113883.10.20.22.2.58";var Q="2.16.840.1.113883.10.20.22.2.60";var me="2.16.840.1.113883.10.20.22.2.65";var Ee="2.16.840.1.113883.10.20.22.2.500",ii="2.16.840.1.113883.10.20.22.4.1",ni="2.16.840.1.113883.10.20.22.4.1.2",ri="2.16.840.1.113883.10.20.22.4.2",oi="2.16.840.1.113883.10.20.22.4.2.2",ze="2.16.840.1.113883.10.20.22.4.3";var z="2.16.840.1.113883.10.20.22.4.4",si="2.16.840.1.113883.10.20.22.4.4.2";var Ze="2.16.840.1.113883.10.20.22.4.7";var Xe="2.16.840.1.113883.10.20.22.4.8";var Je="2.16.840.1.113883.10.20.22.4.9";var Z="2.16.840.1.113883.10.20.22.4.12";var ai="2.16.840.1.113883.10.20.22.4.13";var Ke="2.16.840.1.113883.10.20.22.4.14";var et="2.16.840.1.113883.10.20.22.4.16";var ci="2.16.840.1.113883.10.20.22.4.20";var tt="2.16.840.1.113883.10.20.22.4.23";var X="2.16.840.1.113883.10.20.22.4.26",ui="2.16.840.1.113883.10.20.22.4.26.2",J="2.16.840.1.113883.10.20.22.4.27",li="2.16.840.1.113883.10.20.22.4.27.2";var it="2.16.840.1.113883.10.20.22.4.30";var nt="2.16.840.1.113883.10.20.22.4.32";var di="2.16.840.1.113883.10.20.22.4.38",pi="2.16.840.1.113883.10.20.22.4.38.1";var hi="2.16.840.1.113883.10.20.22.4.44";var rt="2.16.840.1.113883.10.20.22.4.49";var ot="2.16.840.1.113883.10.20.22.4.52";var st="2.16.840.1.113883.10.20.22.4.54";var fi="2.16.840.1.113883.10.20.22.4.66";var _i="2.16.840.1.113883.10.20.22.4.67";var mi="2.16.840.1.113883.10.20.22.4.69",Ei="2.16.840.1.113883.10.20.22.4.70";var Ii="2.16.840.1.113883.10.20.22.4.74";var Ti="2.16.840.1.113883.10.20.22.4.75";var K="2.16.840.1.113883.10.20.22.4.78",Oi="2.16.840.1.113883.10.20.22.4.78.2";var ee="2.16.840.1.113883.10.20.22.4.85";var Si="2.16.840.1.113883.10.20.22.4.86";var yi="2.16.840.1.113883.10.20.22.4.114";var Ci="2.16.840.1.113883.10.20.22.4.119";var gi="2.16.840.1.113883.10.20.22.4.121";var Ai="2.16.840.1.113883.10.20.22.4.130";var Ri="2.16.840.1.113883.10.20.22.4.133";var Ie="2.16.840.1.113883.10.20.22.4.147",Ni="2.16.840.1.113883.10.20.22.4.200",Di="2.16.840.1.113883.10.20.22.4.201";var xi="2.16.840.1.113883.10.20.22.4.244";var vi="2.16.840.1.113883.10.20.22.4.250";var Pi="2.16.840.1.113883.10.20.22.4.406",bi="2.16.840.1.113883.10.20.22.4.407";var Ui="2.16.840.1.113883.10.20.22.4.416";var at="2.16.840.1.113883.10.20.22.4.500",Li="2.16.840.1.113883.10.20.22.4.501";var Vi="2.16.840.1.113883.10.20.22.4.503",wi="2.16.840.1.113883.10.20.22.4.504";var Mi="2.16.840.1.113883.10.20.22.4.506",ki="2.16.840.1.113883.10.20.22.4.507",Bi="2.16.840.1.113883.10.20.22.4.508";var Fi="2.16.840.1.113883.10.20.22.4.512";var ct="2.16.840.1.113883.12.292";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":Ce.getEntryByCcda(this.ccdaSystemOid)?.displayName}}},L="http:",ut=`${I}/CodeSystem/condition-clinical`,Yi=`${I}/CodeSystem/condition-verification`,Qo=`${I}/CodeSystem/v3-LanguageAbilityMode`,zo=`${I}/CodeSystem/v3-LanguageAbilityProficiency`,Zo=`${I}/CodeSystem/v3-Race`,$i=`${I}/CodeSystem/condition-category`,lt=`${I}/CodeSystem/condition-ver-status`,Te=`${I}/CodeSystem/allergyintolerance-clinical`,dt=`${I}/CodeSystem/allergyintolerance-verification`,Hi=`${I}/CodeSystem/v3-ActCode`,ji=`${I}/CodeSystem/v3-ParticipationType`,qi=`${I}/CodeSystem/diagnosis-role`,Cr=`${I}/CodeSystem/v3-Confidentiality`,gr=`${I}/CodeSystem/observation-category`,Ar=`${f}/fhir/ValueSet/address-use`,Rr=`${f}/fhir/ValueSet/name-use`,Nr=`${f}/fhir/ValueSet/administrative-gender`,Dr=`${f}/fhir/ValueSet/contactentity-use`,xr=`${f}/fhir/ValueSet/medicationrequest-status`,Xo=`${f}/fhir/StructureDefinition/language-mode`,Jo=`${f}/fhir/StructureDefinition/language-proficiency`,Ko=`${f}/fhir/us/core/StructureDefinition/us-core-patient`,Oe=`${f}/fhir/us/core/StructureDefinition/us-core-race`,Se=`${f}/fhir/us/core/StructureDefinition/us-core-ethnicity`,Wi=`${f}/fhir/us/core/StructureDefinition/us-core-condition`,Qi=`${f}/fhir/us/core/StructureDefinition/us-core-medicationrequest`,es=`${f}/cda/template`,vr=`${L}//ncithesaurus-stage.nci.nih.gov`,Pr=`${f}/fhir/sid/us-ssn`,br=`${f}/fhir/sid/us-dln`,Ur=`${f}/fhir/sid/us-npi`,Lr=`${L}//fdasis.nlm.nih.gov`,Vr=`${L}//nucc.org/provider-taxonomy`,wr=`${L}//va.gov/terminology/medrt`,Mr=`${L}//hl7.org/fhir/ndfrt`,kr=`${L}//nucc.org/cvx`,Br=`${f}/fhir/sid/cvx`,zi=`${L}//www.w3.org/2001/XMLSchema-instance`,ye="https://medplum.com/fhir/StructureDefinition/ccda-narrative-reference",Ce=new E("System","","",[{ccdaValue:wt,fhirValue:"https://fhir.infoway-inforoute.ca/CodeSystem/pCLOCD",displayName:"pan-Canadian LOINC Observation Code Database (pCLOCD)"},{ccdaValue:Mt,fhirValue:vr,displayName:"NCI Thesaurus"},{ccdaValue:kt,fhirValue:Pr,displayName:"SSN"},{ccdaValue:Bt,fhirValue:br,displayName:"DLN"},{ccdaValue:Ft,fhirValue:Ur,displayName:"NPI"},{ccdaValue:Gt,fhirValue:Lr,displayName:"Unique Ingredient Identifier (UNII)"},{ccdaValue:M,fhirValue:ae,displayName:"LOINC"},{ccdaValue:$t,fhirValue:yt,displayName:"Current Procedural Terminology (CPT)"},{ccdaValue:Ht,fhirValue:"urn:iso:std:iso:11073:10101",displayName:"Medical Device Communications (MDC)"},{ccdaValue:jt,fhirValue:Ct,displayName:"National Drug Code (NDC)"},{ccdaValue:qt,fhirValue:St,displayName:"RxNorm"},{ccdaValue:k,fhirValue:Ve,displayName:"SNOMED CT"},{ccdaValue:Wt,fhirValue:Vr,displayName:"NUCC Health Care Provider Taxonomy"},{ccdaValue:zt,fhirValue:wr,displayName:"Medication Reference Terminology (MED-RT)"},{ccdaValue:Qt,fhirValue:Mr,displayName:"National Drug File Reference Terminology (NDF-RT)"},{ccdaValue:ct,fhirValue:kr,displayName:"CVX"},{ccdaValue:$e,fhirValue:"Confidentiality",displayName:"Confidentiality"},{ccdaValue:ct,fhirValue:Br,displayName:"Vaccine Administered Code Set (CVX)"}]);function te(i){if(i)return Ce.mapCcdaToFhir(i)??`urn:oid:${i}`}function Zi(i){if(i)return i.startsWith("urn:oid:")?i.replace("urn:oid:",""):Ce.mapFhirToCcda(i)}function h(i){if(!i?.coding)return;let e=Gi(i.coding[0]);if(i.coding.length>1){e.translation=[];for(let t=1;t<i.coding.length;t++)e.translation.push(Gi(i.coding[t]))}return e}function Gi(i){let e=i?.system?Ce.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 ie(i){let e=h(i);if(e)return{"@_xsi:type":"CD",...e}}var Xi=new E("Confidentiality",$e,Cr,[{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"}]),ge=new E("HumanNameUse","",Rr,[{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"}]),Ji=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"}]),Ae=new E("AddressUse","",Ar,[{ccdaValue:"HP",fhirValue:"home",displayName:"Home"},{ccdaValue:"WP",fhirValue:"work",displayName:"Work"}]),Re=new E("TelecomUse","",Dr,[{ccdaValue:"WP",fhirValue:"work",displayName:"Work"},{ccdaValue:"HP",fhirValue:"home",displayName:"Home"}]),Ne=new E("AllergyStatus","",dt,[{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"}]),Ki=new E("AllergyCategory",k,Te,[{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)"}]),De=new E("AllergySeverity",Ve,Te,[{ccdaValue:"255604002",fhirValue:"mild",displayName:"Mild"},{ccdaValue:"6736007",fhirValue:"moderate",displayName:"Moderate"},{ccdaValue:"24484000",fhirValue:"severe",displayName:"Severe"}]),xe=new E("ProblemStatus","",lt,[{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"}]),ve=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"}]),en=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"}]),tn=new E("ProcedureStatus","","",[{ccdaValue:"completed",fhirValue:"completed",displayName:"Completed"},{ccdaValue:"aborted",fhirValue:"stopped",displayName:"Stopped"},{ccdaValue:"cancelled",fhirValue:"not-done",displayName:"Not Done"},{ccdaValue:"new",fhirValue:"not-done",displayName:"Draft"},{ccdaValue:"unknown",fhirValue:"unknown",displayName:"Unknown"}]),Pe=new E("MedicationStatus","",xr,[{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"}]),be=new E("ObservationCategory","",gr,[{ccdaValue:di,fhirValue:"social-history",displayName:"Social History"},{ccdaValue:pi,fhirValue:"social-history",displayName:"Social History V2"},{ccdaValue:K,fhirValue:"social-history",displayName:"Smoking Status"},{ccdaValue:Oi,fhirValue:"social-history",displayName:"Current Smoking Status"},{ccdaValue:ee,fhirValue:"social-history",displayName:"Tobacco Use"},{ccdaValue:Vi,fhirValue:"social-history",displayName:"Basic Occupation"},{ccdaValue:wi,fhirValue:"social-history",displayName:"Basic Industry"},{ccdaValue:Li,fhirValue:"social-history",displayName:"Sexual Orientation"},{ccdaValue:ki,fhirValue:"social-history",displayName:"Sex Observation"},{ccdaValue:Ni,fhirValue:"social-history",displayName:"Gender Identity"},{ccdaValue:Di,fhirValue:"social-history",displayName:"Gender Identity V2"},{ccdaValue:Zt,fhirValue:"social-history",displayName:"Pregnancy Status"},{ccdaValue:Mi,fhirValue:"social-history",displayName:"Tribal Affiliation"},{ccdaValue:J,fhirValue:"vital-signs",displayName:"Vital Signs Observation"},{ccdaValue:li,fhirValue:"vital-signs",displayName:"Vital Signs Observation V2"},{ccdaValue:X,fhirValue:"vital-signs",displayName:"Vital Signs Organizer"},{ccdaValue:ui,fhirValue:"vital-signs",displayName:"Vital Signs Organizer V2"},{ccdaValue:Fi,fhirValue:"vital-signs",displayName:"Average Blood Pressure Organizer"},{ccdaValue:ii,fhirValue:"laboratory",displayName:"Result Organizer"},{ccdaValue:ni,fhirValue:"laboratory",displayName:"Result Organizer V2"},{ccdaValue:ri,fhirValue:"laboratory",displayName:"Result Observation"},{ccdaValue:oi,fhirValue:"laboratory",displayName:"Result Observation V2"},{ccdaValue:Pi,fhirValue:"laboratory",displayName:"Laboratory Battery (ID)"},{ccdaValue:bi,fhirValue:"laboratory",displayName:"Laboratory Observation (ID)"},{ccdaValue:Ui,fhirValue:"laboratory",displayName:"Laboratory Result Organizer (ID)"},{ccdaValue:mi,fhirValue:"survey",displayName:"Assessment Scale Observation"},{ccdaValue:Si,fhirValue:"survey",displayName:"Assessment Scale Supporting Observation"},{ccdaValue:Ii,fhirValue:"survey",displayName:"Cognitive Status Result Observation"},{ccdaValue:Ti,fhirValue:"survey",displayName:"Cognitive Status Result Organizer"},{ccdaValue:_i,fhirValue:"survey",displayName:"Functional Status Result Observation"},{ccdaValue:fi,fhirValue:"survey",displayName:"Functional Status Result Organizer"},{ccdaValue:ai,fhirValue:"exam",displayName:"Procedure Activity Observation"},{ccdaValue:z,fhirValue:"exam",displayName:"Problem Observation"},{ccdaValue:si,fhirValue:"exam",displayName:"Problem Observation V2"},{ccdaValue:Ei,fhirValue:"exam",displayName:"Pressure Ulcer Observation"},{ccdaValue:yi,fhirValue:"exam",displayName:"Wound Observation"},{ccdaValue:Ri,fhirValue:"exam",displayName:"Wound Measurements Observation"},{ccdaValue:B,fhirValue:"exam",displayName:"Procedure Section"},{ccdaValue:Bi,fhirValue:"therapy",displayName:"Medication Adherence"},{ccdaValue:Ai,fhirValue:"therapy",displayName:"Nutrition Recommendations"},{ccdaValue:xi,fhirValue:"therapy",displayName:"Diet Statement (Nutrition)"},{ccdaValue:vi,fhirValue:"therapy",displayName:"Monitoring, Evaluation and Outcome (Nutrition)"}]);import{XMLBuilder as nn,XMLParser as rn}from"fast-xml-parser";var Fr=["ClinicalDocument.recordTarget",".id",".templateId",".name",".addr",".telecom",".streetAddressLine",".author",".effectiveTime","name.given","name.suffix","name.prefix","patient.raceCode","patient.ethnicGroupCode","patient.languageCommunication","component.structuredBody.component","component.structuredBody.component.section","component.section","component.observation","component.act","code.translation","section.entry","entry.act","entry.organizer","entry.substanceAdministration","entry.observation","entry.encounter","entry.procedure","encounter.performer","encounter.participant","encounter.entryRelationship","entryRelationship.observation","entryRelationship.substanceAdministration","entryRelationship.act","organizer.component","substanceAdministration.consumable.manufacturedProduct","substanceAdministration.entryRelationship","substanceAdministration.performer","act.entryRelationship","act.performer","observation.participant","observation.entryRelationship","observation.referenceRange","consumable.manufacturedProduct","manufacturedProduct.manufacturedMaterial","manufacturedProduct.manufacturerOrganization","manufacturedProduct.manufacturedLabeledDrug","manufacturedMaterial.code","manufacturedMaterial.lotNumberText"];function rs(i){return new rn({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1,isArray:(n,r,o,s)=>Fr.some(c=>r.endsWith(c))}).parse(i).ClinicalDocument}function os(i){return new nn({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":zi,"@_xmlns:voc":"urn:hl7-org:v3/voc","@_xmlns:sdtc":"urn:hl7-org:sdtc",...i}})}function on(i){return new rn({ignoreAttributes:!1,attributeNamePrefix:"@_",parseAttributeValue:!1,parseTagValue:!1}).parse(i)}function sn(i){return i?typeof i=="string"?i:new nn({ignoreAttributes:!1,attributeNamePrefix:"@_",format:!1,suppressBooleanAttributes:!1,suppressEmptyNode:!0}).build(i).split(`
2
+ `).map(n=>n.trim()).join(""):""}function ps(i){return new pt(i).convert()}var pt=class{constructor(e){this.resources=[];this.ccda=e}convert(){return this.processHeader(),{resourceType:"Bundle",type:"document",entry:[{resource:this.createComposition()},...this.patient?[{resource:this.patient}]:[],...this.resources.map(t=>({resource:t}))]}}processHeader(){let e=this.ccda.recordTarget?.[0]?.patientRole;e&&(this.patient=this.createPatient(e))}createPatient(e){let t=e.patient,n=[];return t.raceCode&&t.raceCode.length>0&&n.push({url:Oe,extension:t.raceCode.map(r=>({url:"ombCategory",valueCoding:this.mapCodeToCoding(r)}))}),t.ethnicGroupCode&&t.ethnicGroupCode.length>0&&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:Ge(t.birthTime?.["@_value"]),address:this.mapAddresses(e.addr),telecom:this.mapTelecom(e.telecom),extension:n.length>0?n:void 0}}mapId(e){let t=e?.find(n=>!n["@_extension"]&&n["@_root"]&&ke(n["@_root"]));return t?t["@_root"]:ce()}mapIdentifiers(e){if(!e)return;let t=[];for(let n of e)!n["@_extension"]&&n["@_root"]&&ke(n["@_root"])||t.push({system:te(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"]?ge.mapCcdaToFhir(e["@_use"]):void 0;return n&&(t.use=n),e.prefix&&(t.prefix=e.prefix.map(ne)?.filter(Boolean)),e.family&&(t.family=ne(e.family)),e.given&&(t.given=e.given.map(ne)?.filter(Boolean)),e.suffix&&(t.suffix=e.suffix.map(ne)?.filter(Boolean)),t}mapAddresses(e){if(!(!e||e.length===0||e.every(t=>t["@_nullFlavor"]==="UNK")))return e?.map(t=>({"@_use":t["@_use"]?Ae.mapCcdaToFhir(t["@_use"]):void 0,line:t.streetAddressLine,city:t.city,state:t.state,postalCode:t.postalCode,country:t.country}))}mapTelecom(e){if(!(!e||e.length===0||e.every(t=>t["@_nullFlavor"]==="UNK")))return e?.map(t=>({"@_use":t["@_use"]?Re.mapCcdaToFhir(t["@_use"]):void 0,system:this.getTelecomSystem(t["@_value"]),value:this.getTelecomValue(t["@_value"])}))}createComposition(){let e=this.ccda.component?.structuredBody?.component||[],t=[];for(let n of e)for(let r of n.section){let o=this.processSection(r);t.push({title:r.title,code:this.mapCode(r.code),text:{status:"generated",div:`<div xmlns="http://www.w3.org/1999/xhtml">${sn(r.text)}</div>`},entry:o.map(p)}),this.resources.push(...o)}return{resourceType:"Composition",id:this.mapId(this.ccda.id),language:this.ccda.languageCode?.["@_code"],status:"final",type:this.ccda.code?this.mapCode(this.ccda.code):{coding:[{system:ae,code:"34133-9"}]},confidentiality:this.ccda.confidentialityCode?.["@_code"],author:this.ccda.author?.[0]?[this.mapAuthorToReference(this.ccda.author?.[0])]:[{display:"Medplum"}],custodian:this.mapCustodianToReference(this.ccda.custodian),event:this.mapDocumentationOfToEvent(this.ccda.documentationOf),date:_(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 he:return this.processAllergyIntoleranceAct(t);case pe:return this.processConditionAct(t);case P:return this.processCarePlanAct(t);case _e:return this.processConditionAct(t);case B:return this.processProcedureAct(t);case ue:return;case me:return;case fe:return;default:throw new Error("Unhandled act templateId: "+n)}}processAllergyIntoleranceAct(e){let t=e.entryRelationship?.find(s=>s["@_typeCode"]==="SUBJ")?.observation?.[0];if(!t)return;let n={resourceType:"AllergyIntolerance",id:this.mapId(e.id),clinicalStatus:this.createClinicalStatus(e),verificationStatus:this.createVerificationStatus(),type:"allergy",category:["food"],patient:p(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:[Wi]},clinicalStatus:{coding:[{system:ut,code:xe.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active")}]},verificationStatus:{coding:[{system:Yi,code:"confirmed"}]},category:[{coding:[{system:$i,code:"problem-list-item",display:"Problem List Item"}]}],code:this.mapCode(t.value),subject:p(this.patient),onsetDateTime:_(t.effectiveTime?.[0]?.low?.["@_value"]),abatementDateTime:_(t.effectiveTime?.[0]?.high?.["@_value"]),recordedDate:this.mapEffectiveTimeToDateTime(e.effectiveTime?.[0]),recorder:this.mapAuthorToReference(t.author?.[0]),asserter:this.mapAuthorToReference(t.author?.[0])};return n.extension=this.mapTextReference(t.text),n}processCarePlanAct(e){return{resourceType:"CarePlan",id:this.mapId(e.id),identifier:this.mapIdentifiers(e.id),status:"active",intent:"plan",title:"CARE PLAN",category:e.code?[this.mapCode(e.code)]:void 0,subject:p(this.patient),description:ne(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:p(this.patient),performedDateTime:_(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 de:case P:return this.processMedicationSubstanceAdministration(t);case q:case W:return this.processImmunizationSubstanceAdministration(t);default:throw new Error("Unhandled substance administration templateId: "+n)}}processMedicationSubstanceAdministration(e){let t=this.mapId(e.id),n=e.consumable?.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.code?.[0],r=e.routeCode,o=e.doseQuantity,s=e.consumable?.manufacturedProduct?.[0]?.manufacturerOrganization?.[0],c=e.entryRelationship?.find(m=>m.substanceAdministration?.[0]?.templateId?.[0]?.["@_root"]===Ie)?.substanceAdministration?.[0],d,N;return s?d={resourceType:"Medication",id:"med-"+t,code:this.mapCode(n),extension:this.mapTextReference(n?.originalText),manufacturer:s?{identifier:{value:s.id?.[0]?.["@_root"]},display:s.name?.[0]}:void 0}:N={...this.mapCode(n),extension:this.mapTextReference(n?.originalText)},{resourceType:"MedicationRequest",id:t,contained:d?[d]:void 0,meta:{profile:[Qi]},extension:this.mapTextReference(e.text),status:Pe.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active"),intent:"order",medicationReference:d?{reference:"#med-"+t}:void 0,medicationCodeableConcept:N,subject:p(this.patient),authoredOn:_(e.author?.[0]?.time?.["@_value"]),dispenseRequest:e.effectiveTime?.[0]?{validityPeriod:{start:_(e.effectiveTime?.[0]?.low?.["@_value"]),end:_(e.effectiveTime?.[0]?.high?.["@_value"])}}:void 0,dosageInstruction:[{text:typeof e.text=="string"?e.text:void 0,extension:this.mapTextReference(c?.text),route:r?this.mapCode(r):void 0,timing:{repeat:e.effectiveTime?.[1]?.period?{period:Number(e.effectiveTime?.[1]?.period["@_value"]),periodUnit:e.effectiveTime?.[1]?.period["@_unit"]}:void 0},doseAndRate:o?[{doseQuantity:{system:Le,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:ve.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"completed"),vaccineCode:this.mapCode(t.manufacturedProduct?.[0]?.manufacturedMaterial?.[0]?.code?.[0]),patient:p(this.patient),occurrenceDateTime:_(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:_(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=De.mapCcdaToFhir(r)),t.extension=this.mapTextReference(n.text)}mapEffectiveTimeToDateTime(e){if(e?.["@_value"])return _(e["@_value"]);if(e?.low?.["@_value"])return _(e.low["@_value"])}mapEffectiveTimeToPeriod(e){if(!e?.["@_value"]&&(e?.low||e?.high))return{start:_(e?.low?.["@_value"]),end:_(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:te(e["@_codeSystem"]),code:e["@_code"],display:e["@_displayName"]}],text:e["@_displayName"]};if(e.translation)for(let n of e.translation)t.coding.push({system:te(n["@_codeSystem"]),code:n["@_code"],display:n["@_displayName"]});return t}mapCodeToCoding(e){if(e)return{system:te(e["@_codeSystem"]),code:e["@_code"],display:e["@_displayName"]}}createClinicalStatus(e){return{coding:[{system:Te,code:Ne.mapCcdaToFhirWithDefault(e.statusCode?.["@_code"],"active")}]}}createVerificationStatus(){return{coding:[{system:dt,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),p(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:p(r),organization:p(o)};return this.resources.push(s),p(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),p(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"]===Ee?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:p(this.patient)};if(e.effectiveTime?.[0]?.["@_value"]&&(t.effectiveDateTime=_(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(p(r)),this.resources.push(r)}return t}processObservation(e,t){let n=t.templateId[0]["@_root"];if(n===Q||n===gi)return this.processGoalObservation(t);switch(e.templateId[0]["@_root"]){case P:case Q: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:p(this.patient),startDate:Ge(e.effectiveTime?.[0]?.["@_value"])};return t.target=e.entryRelationship?.map(n=>({measure:this.mapCode(n.act?.[0]?.code),detailCodeableConcept:this.mapCode(n.act?.[0]?.code),dueDate:_(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:p(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:Le,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=_(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=be.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:en.mapCcdaToFhirWithDefault(t.statusCode?.["@_code"],"unknown"),class:{system:Hi,code:t.code?.["@_code"]??"AMB",display:t.code?.["@_displayName"]??"Ambulatory"},type:t.code?[this.mapCode(t.code)]:void 0,subject:p(this.patient),period:this.mapEffectiveTimeToPeriod(t.effectiveTime?.[0])};if(t.performer&&(n.participant=t.performer.map(r=>({type:[{coding:[{system:ji,code:r["@_typeCode"]??"PPRF",display:"Primary Performer"}]}],individual:this.mapAssignedEntityToReference(r.assignedEntity)}))),t.entryRelationship){let r=t.entryRelationship.filter(o=>o["@_typeCode"]==="RSON").map(o=>{let s=o.observation?.[0];if(!s)return;let c={resourceType:"Condition",id:this.mapId(s.id),identifier:this.mapIdentifiers(s.id),clinicalStatus:{coding:[{system:ut,code:"active"}]},verificationStatus:{coding:[{system:lt,code:"confirmed"}]},code:this.mapCode(s.value),subject:p(this.patient),onsetDateTime:_(s.effectiveTime?.[0]?.low?.["@_value"])};return this.resources.push(c),{condition:p(c),use:{coding:[{system:qi,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:tn.mapCcdaToFhirWithDefault(t.statusCode?.["@_code"],"completed"),code:this.mapCode(t.code),subject:p(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 ne(i){if(i){if(typeof i=="string")return i;if(typeof i=="object"&&"#text"in i)return i["#text"]}}var an=[{"@_root":je,"@_extension":"2015-08-01"},{"@_root":je},{"@_root":qe,"@_extension":"2015-08-01"},{"@_root":qe}],Gr=[{"@_root":he,"@_extension":"2015-08-01"}],Yr=[{"@_root":de,"@_extension":"2014-06-09"}],$r=[{"@_root":pe,"@_extension":"2015-08-01"}],ht=[{"@_root":q},{"@_root":q,"@_extension":"2015-08-01"},{"@_root":W},{"@_root":W,"@_extension":"2015-08-01"}],Hr=[{"@_root":Xt,"@_extension":"2015-08-01"}],jr=[{"@_root":Qe},{"@_root":Qe,"@_extension":"2015-08-01"}],qr=[{"@_root":B,"@_extension":"2014-06-09"}],_s=[{"@_root":P,"@_extension":"2014-06-09"}],ms=[{"@_root":We,"@_extension":"2015-08-01"}],Wr=[{"@_root":We,"@_extension":"2015-08-01"}],Es=[{"@_root":ei,"@_extension":"2015-08-01"}],Qr=[{"@_root":Jt}],zr=[{"@_root":P},{"@_root":P,"@_extension":"2014-06-09"}],Zr=[{"@_root":Kt,"@_extension":"2015-08-01"}],Xr=[{"@_root":Q}],Jr=[{"@_root":_e,"@_extension":"2015-08-01"}],Kr=[{"@_root":ue,"@_extension":"2014-06-09"}],eo=[{"@_root":ti,"@_extension":"2015-08-01"}],to=[{"@_root":me,"@_extension":"2016-11-01"}],io=[{"@_root":Ee,"@_extension":"2022-06-01"}],no=[{"@_root":fe,"@_extension":"2015-08-01"}],cn={"48765-2":Gr,"10160-0":Yr,"11450-4":$r,"11369-6":ht,"11348-0":ht,"9176-8":ht,"8716-3":Hr,"29762-2":jr,"47519-4":qr,"30954-2":Wr,"51848-0":Qr,"18776-5":zr,"46240-8":Zr,"61146-7":Xr,"75310-3":Jr,"42349-1":Kr,"10190-7":eo,"11488-4":to,"85847-2":io,"48768-6":no};function As(i){return new ft(i).convert()}var ft=class{constructor(e){this.bundle=e;let t=this.findResource("Composition");if(!t)throw new Error("Composition not found");let n=this.findResource("Patient");if(!n)throw new Error("Patient not found");this.composition=t,this.patient=n}convert(){let e=this.createSections();return{realmCode:{"@_code":"US"},typeId:{"@_root":Vt,"@_extension":"POCD_HD000040"},templateId:an,id:this.mapIdentifiers(this.composition.id,void 0),code:{"@_code":"34133-9","@_displayName":"Summarization of Episode Note","@_codeSystem":M,"@_codeSystemName":"LOINC"},title:this.composition.title,effectiveTime:this.mapEffectiveTime(this.composition.date,void 0),confidentialityCode:this.composition.confidentiality?Xi.mapFhirToCcdaCode(this.composition.confidentiality):void 0,languageCode:{"@_code":this.composition.language??"en-US"},recordTarget:this.createRecordTarget(),author:this.mapAuthor(this.composition.author?.[0],this.composition.date),custodian:this.mapCustodian(this.composition.custodian),documentationOf:this.mapDocumentationOf(this.composition.event),component:e.length>0?{structuredBody:{component:e.map(t=>({section:[t]}))}}:void 0}}findResource(e){return this.bundle.entry?.find(t=>t.resource?.resourceType===e)?.resource}findResourceByReference(e){if(!e?.reference)return;let[t,n]=e.reference.split("/");if(!(!t||!n))return this.bundle.entry?.find(r=>r.resource?.resourceType===t&&r.resource?.id===n)?.resource}findResourcesByReferences(e){return e?e.map(t=>this.findResourceByReference(t)).filter(t=>!!t):[]}createRecordTarget(){if(!this.patient)throw new Error("Patient not found");return[{patientRole:{id:this.mapIdentifiers(this.patient.id,this.patient.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(this.patient.address),telecom:this.mapTelecom(this.patient.telecom),patient:this.mapPatient(this.patient)}}]}mapPatient(e){return{name:this.mapNames(e.name),administrativeGenderCode:this.mapGender(e.gender),birthTime:this.mapBirthDate(e.birthDate),raceCode:this.mapRace(e.extension),ethnicGroupCode:this.mapEthnicity(e.extension),languageCommunication:this.mapLanguageCommunication(e.communication)}}mapNames(e){return e?.map(t=>({"@_use":t.use?ge.mapFhirToCcdaWithDefault(t.use,"L"):void 0,prefix:t.prefix,family:t.family,given:t.given,suffix:t.suffix}))}mapGender(e){if(e)return{"@_code":Ji.mapFhirToCcda(e),"@_displayName":e?H(e):"Unknown","@_codeSystem":Yt,"@_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?Ae.mapFhirToCcda(e.use):void 0,streetAddressLine:e.line||[],city:e.city,state:e.state,postalCode:e.postalCode,country:e.country}:void 0}mapRace(e){let n=e?.find(r=>r.url===Oe)?.extension?.find(r=>r.url==="ombCategory")?.valueCoding;if(n)return[{"@_code":n.code,"@_displayName":n.display,"@_codeSystem":He,"@_codeSystemName":"CDC Race and Ethnicity"}]}mapEthnicity(e){let n=e?.find(r=>r.url===Se)?.extension?.find(r=>r.url==="ombCategory")?.valueCoding;if(n)return[{"@_code":n.code,"@_displayName":n.display,"@_codeSystem":He,"@_codeSystemName":"CDC Race and Ethnicity"}]}mapLanguageCommunication(e){if(e?.length)return[{"@_languageCode":e[0].language?.coding?.[0]?.code}]}createSections(){let e=[];if(this.composition.section)for(let t of this.composition.section)e.push(this.createSection(t));return e}createSection(e){let t=e.code?.coding?.[0]?.code;if(!t)throw new Error(`Missing section code: ${JSON.stringify(e.code)}`);let n=cn[t];if(!n)throw new Error(`Unknown section code: ${t}`);let r=this.findResourcesByReferences(e.entry);return{templateId:n,code:h(e.code),title:e.title,text:this.mapFhirTextDivToCcdaSectionText(e.text),entry:r.map(o=>this.createEntry(e,o)),"@_nullFlavor":r.length===0?"NI":void 0}}createEntry(e,t){switch(t.resourceType){case"AllergyIntolerance":return this.createAllergyEntry(t);case"CarePlan":return this.createPlanOfTreatmentCarePlanEntry(t);case"CareTeam":return this.createCareTeamEntry(t);case"Condition":return this.createProblemEntry(t);case"Encounter":return this.createEncounterEntry(t);case"Goal":return this.createPlanOfTreatmentGoalEntry(t);case"Immunization":return this.createImmunizationEntry(t);case"MedicationRequest":return this.createMedicationEntry(t);case"Procedure":return this.createHistoryOfProceduresEntry(t);case"Observation":return this.createObservationEntry(t);default:throw new Error(`Unknown resource type: ${t.resourceType}`)}}mapFhirTextDivToCcdaSectionText(e){if(!e)return;let t=on(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":it},{"@_root":it,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"CONC","@_codeSystem":Ye},statusCode:{"@_code":Ne.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":Ze},{"@_root":Ze,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:{"@_code":"ASSERTION","@_codeSystem":le},statusCode:{"@_code":"completed"},author:this.mapAuthor(e.asserter,e.recordedDate),effectiveTime:this.mapEffectivePeriod(e.onsetPeriod?.start??e.onsetDateTime,e.onsetPeriod?.end,!0),value:this.mapAllergyCategory(e.category),text:this.createTextFromExtensions(e.extension),participant:[{"@_typeCode":"CSM",participantRole:{"@_classCode":"MANU",playingEntity:{"@_classCode":"MMAT",code:{...h(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":Je},{"@_root":Je,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(t.id,void 0),code:{"@_code":"ASSERTION","@_codeSystem":le},statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveDate(e.onsetDateTime,e.onsetPeriod),value:ie(t.manifestation?.[0]),text:this.createTextFromExtensions(t.manifestation?.[0]?.extension),entryRelationship:[{"@_typeCode":"SUBJ","@_inversionInd":"true",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":Xe},{"@_root":Xe,"@_extension":"2014-06-09"}],code:{"@_code":"SEV","@_codeSystem":le,"@_codeSystemName":"ActCode"},statusCode:{"@_code":"completed"},value:{"@_xsi:type":"CD","@_code":De.mapFhirToCcdaWithDefault(t.severity,"M"),"@_displayName":t.severity?H(t.severity):void 0,"@_codeSystem":k,"@_codeSystemName":"SNOMED CT"},text:this.createTextFromExtensions(t.extension)}]}]}]}]:[]}]}]}]}}mapAllergyCategory(e){if(!e||e.length===0)return;let t=Ki.mapFhirToCcdaCode(e[0]);if(t)return{"@_xsi:type":"CD",...t}}mapAuthor(e,t){if(!e)return;let n=this.findResourceByReference(e);if(n?.resourceType==="Practitioner")return[{templateId:[{"@_root":Ci}],time:t?{"@_value":O(t)}:void 0,assignedAuthor:{id:this.mapIdentifiers(n.id,n.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(n.address),telecom:this.mapTelecom(n.telecom),code:h(n.qualification?.[0]),assignedPerson:{name:this.mapNames(n.name)}}}]}mapCustodian(e){if(!e)return;let t=this.findResourceByReference(e);if(t)return{assignedCustodian:{representedCustodianOrganization:{id:this.mapIdentifiers(t.id,t.identifier),name:t.name?[t.name]:void 0,telecom:this.mapTelecom(t.telecom),addr:this.mapFhirAddressArrayToCcdaAddressArray(t.address)}}}}mapDocumentationOf(e){if(!e||e.length===0)return;let t=e[0];if(!(!t||!t.code&&!t.period))return{serviceEvent:{"@_classCode":"PCPR",code:h(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":et,"@_extension":"2014-06-09"},{"@_root":et}],id:[{"@_root":e.id||crypto.randomUUID()}],text:this.createTextFromExtensions(e.extension),statusCode:{"@_code":Pe.mapFhirToCcdaWithDefault(e.status,"active")},effectiveTime:o,routeCode:this.mapMedicationRoute(e.dosageInstruction?.[0]?.route),doseQuantity:this.mapDoseQuantity(e.dosageInstruction?.[0]?.doseAndRate?.[0]),consumable:{"@_typeCode":"CSM",manufacturedProduct:[{"@_classCode":"MANU",templateId:[{"@_root":tt,"@_extension":"2014-06-09"},{"@_root":tt}],manufacturedMaterial:[{code:[{...h(n),originalText:this.createTextFromExtensions(t?.extension)}]}],manufacturerOrganization:r?[{id:this.mapIdentifiers(r.id,r.identifier?[r.identifier]:void 0),name:[r.display]}]:void 0}]},entryRelationship:e.dosageInstruction?.filter(s=>!!s.extension)?.map(s=>({"@_typeCode":"COMP",substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN",templateId:[{"@_root":Ie}],code:{"@_code":"76662-6","@_codeSystem":M,"@_codeSystemName":"LOINC","@_displayName":"Medication Instructions"},text:this.createTextFromExtensions(s.extension),consumable:{manufacturedProduct:[{manufacturedLabeledDrug:[{"@_nullFlavor":"NA"}]}]}}]}))}]}}mapMedicationRoute(e){if(e)return h(e)}mapDoseQuantity(e){if(e?.doseQuantity)return{"@_value":e.doseQuantity.value?.toString(),"@_unit":e.doseQuantity.unit}}mapTelecom(e){return!e||e.length===0?[{"@_nullFlavor":"UNK"}]:e?.map(t=>({"@_use":t.use?Re.mapFhirToCcda(t.use):void 0,"@_value":`${this.mapTelecomSystemToPrefix(t.system)}${t.value}`}))}mapTelecomSystemToPrefix(e){return e==="email"?"mailto:":e==="phone"?"tel:":e==="fax"?"fax:":""}mapIdentifiers(e,t){let n=[];if(e&&n.push({"@_root":e}),t)for(let r of t){let o=Zi(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}createProblemEntry(e){return{act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":ze},{"@_root":ze,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,void 0),code:{"@_code":"CONC","@_codeSystem":Ye},statusCode:{"@_code":xe.mapFhirToCcdaWithDefault(e.clinicalStatus?.coding?.[0]?.code,"active")},effectiveTime:this.mapEffectivePeriod(e.recordedDate,void 0),entryRelationship:[{"@_typeCode":"SUBJ",observation:[{"@_classCode":"OBS","@_moodCode":"EVN",templateId:[{"@_root":z},{"@_root":z,"@_extension":"2015-08-01"}],id:e.identifier?this.mapIdentifiers(void 0,e.identifier):[{"@_root":ce()}],text:this.createTextFromExtensions(e.extension),code:{"@_code":"55607006","@_codeSystem":k,"@_codeSystemName":"SNOMED CT","@_displayName":"Problem",translation:[{"@_code":"75323-6","@_codeSystem":M,"@_codeSystemName":"LOINC","@_displayName":"Condition"}]},statusCode:{"@_code":"completed"},effectiveTime:[{low:e.onsetDateTime?{"@_value":w(e.onsetDateTime)}:void 0,high:e.abatementDateTime?{"@_value":O(e.abatementDateTime)}:void 0}],value:ie(e.code),author:this.mapAuthor(e.asserter,e.recordedDate)}]}]}]}}createImmunizationEntry(e){let t=e?.manufacturer,n={substanceAdministration:[{"@_classCode":"SBADM","@_moodCode":"EVN","@_negationInd":"false",templateId:[{"@_root":ot},{"@_root":ot,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),text:this.createTextFromExtensions(e.extension),statusCode:{"@_code":ve.mapFhirToCcdaWithDefault(e.status,"completed")},effectiveTime:[{"@_value":w(e.occurrenceDateTime)}],consumable:{manufacturedProduct:[{"@_classCode":"MANU",templateId:[{"@_root":st},{"@_root":st,"@_extension":"2014-06-09"}],manufacturedMaterial:[{code:[h(e.vaccineCode)],lotNumberText:e.lotNumber?[e.lotNumber]:void 0}],manufacturerOrganization:t?[{id:this.mapIdentifiers(t.id,t.identifier?[t.identifier]:void 0),name:[t.display]}]:void 0}]}}]};return e.performer&&(n.substanceAdministration[0].performer=e.performer.map(r=>this.mapImmunizationPerformerToCcdaPerformer(r)).filter(Boolean)),n}mapImmunizationPerformerToCcdaPerformer(e){if(!e)return;let t=this.findResourceByReference(e.actor);if(!t)return;let n,r;return t.resourceType==="PractitionerRole"?(n=this.findResourceByReference(t.practitioner),r=this.findResourceByReference(t.organization)):t.resourceType==="Practitioner"?n=t:t.resourceType==="Organization"&&(r=t),{assignedEntity:{id:this.mapIdentifiers(t.id,t.identifier),addr:this.mapFhirAddressArrayToCcdaAddressArray(n?.address),telecom:this.mapTelecom(t.telecom),assignedPerson:n?{id:this.mapIdentifiers(n.id,n.identifier),name:this.mapNames(n.name)}:void 0,representedOrganization:r?{id:this.mapIdentifiers(r.id,r.identifier),name:r.name?[r.name]:void 0,addr:this.mapFhirAddressArrayToCcdaAddressArray(r.address),telecom:this.mapTelecom(r.telecom)}:void 0}}}createObservationEntry(e){return e.hasMember?{organizer:[this.createVitalSignsOrganizer(e)]}:{observation:[this.createVitalSignObservation(e)]}}createPlanOfTreatmentCarePlanEntry(e){return{act:[{"@_classCode":"ACT","@_moodCode":"INT",id:this.mapIdentifiers(e.id,e.identifier),code:ie(e.category?.[0]),templateId:[{"@_root":ci}],statusCode:{"@_code":"completed"},text:e.description?{"#text":e.description}:this.createTextFromExtensions(e.extension)}]}}createPlanOfTreatmentGoalEntry(e){return{observation:[{"@_classCode":"OBS","@_moodCode":"GOL",templateId:[{"@_root":hi}],id:this.mapIdentifiers(e.id,e.identifier),code:h(e.description),statusCode:{"@_code":this.mapGoalStatus(e.lifecycleStatus)},effectiveTime:[{"@_value":O(e.startDate)}],text:this.createTextFromExtensions(e.extension),entryRelationship:e.target?.map(n=>({"@_typeCode":"RSON","@_inversionInd":"true",act:[{"@_classCode":"ACT","@_moodCode":"EVN",templateId:[{"@_root":Z},{"@_root":Z,"@_extension":"2014-06-09"}],code:h(n.measure),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":O(e.startDate)}]}]}))}]}}mapGoalStatus(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":X},{"@_root":X,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:h(e.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":O(e.effectiveDateTime)}],component:t}}createVitalSignObservation(e){return{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:h(e.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":O(e.effectiveDateTime)}],value:this.mapObservationValue(e),referenceRange:this.mapReferenceRangeArray(e.referenceRange),text:this.createTextFromExtensions(e.extension),author:this.mapAuthor(e.performer?.[0],e.effectiveDateTime)}}createVitalSignComponentObservation(e,t){return{"@_classCode":"OBS","@_moodCode":"EVN",templateId:this.mapObservationTemplateId(e),id:this.mapIdentifiers(e.id,e.identifier),code:h(t.code),statusCode:{"@_code":"completed"},effectiveTime:[{"@_value":O(e.effectiveDateTime)}],value:this.mapObservationValue(t),referenceRange:this.mapReferenceRangeArray(t.referenceRange),text:this.createTextFromExtensions(t.extension),author:this.mapAuthor(e.performer?.[0],e.effectiveDateTime)}}mapObservationTemplateId(e){if(e.code?.coding?.[0]?.code==="72166-2")return[{"@_root":K},{"@_root":K,"@_extension":"2014-06-09"}];if(e.code?.coding?.[0]?.code==="11367-0")return[{"@_root":ee},{"@_root":ee,"@_extension":"2014-06-09"}];if(e.category?.[0]?.coding?.[0]?.code){let t=be.getEntryByFhir(e.category?.[0]?.coding?.[0]?.code);if(t)return[{"@_root":t.ccdaValue},{"@_root":t.ccdaValue,"@_extension":"2014-06-09"}]}return[{"@_root":J},{"@_root":J,"@_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 ie(e.valueCodeableConcept)}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":Z},{"@_root":Z,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:h(e.code),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.performedDateTime,e.performedPeriod),text:this.createTextFromExtensions(e.extension)}]}:{procedure:[{"@_classCode":"PROC","@_moodCode":"EVN",templateId:[{"@_root":Ke},{"@_root":Ke,"@_extension":"2014-06-09"}],id:this.mapIdentifiers(e.id,e.identifier),code:h(e.code),statusCode:{"@_code":"completed"},effectiveTime:this.mapEffectiveTime(e.performedDateTime,e.performedPeriod),text:this.createTextFromExtensions(e.extension),targetSiteCode:h(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:h(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":nt}],id:this.mapIdentifiers(t.id,t.identifier),code:h(t.type?.[0]),addr:t.address?this.mapFhirAddressArrayToCcdaAddressArray([t.address]):void 0,telecom:this.mapTelecom(t.telecom),playingEntity:{"@_classCode":"PLC",name:t.name?[t.name]:void 0}}}}mapEffectiveTime(e,t){if(t)return[{low:{"@_value":O(t.start)},high:{"@_value":O(t.end)}}];if(e)return[{"@_value":O(e)}]}mapEffectiveDate(e,t){if(t)return[{"@_xsi:type":"IVL_TS",low:t.start?{"@_value":w(t.start)}:void 0,high:t.end?{"@_value":w(t.end)}:void 0}];if(e)return[{"@_value":w(e)}]}mapEffectivePeriod(e,t,n=!1){if(!e&&!t)return;let r={};return e?r.low={"@_value":O(e)}:n&&(r.low={"@_nullFlavor":"NI"}),t?r.high={"@_value":O(t)}:n&&(r.high={"@_nullFlavor":"NI"}),[r]}createEncounterEntry(e){return{encounter:[{"@_classCode":"ENC","@_moodCode":"EVN",templateId:[{"@_root":rt},{"@_root":rt,"@_extension":"2015-08-01"}],id:this.mapIdentifiers(e.id,e.identifier),code:h(e.type?.[0]),text:this.createTextFromExtensions(e.extension),effectiveTime:this.mapEffectiveTime(void 0,e.period),entryRelationship:e.participant?.map(t=>({"@_typeCode":"LOC",participantRole:{"@_classCode":"SDLOC",templateId:[{"@_root":nt}],code:h(t.type?.[0])}}))}]}}createCareTeamEntry(e){return{organizer:[{"@_classCode":"CLUSTER","@_moodCode":"EVN",templateId:[{"@_root":at,"@_extension":"2022-07-01"},{"@_root":at,"@_extension":"2022-06-01"}],id:this.mapIdentifiers(e.id,e.identifier),component:e.participant?.map(t=>({"@_typeCode":"PRF",role:t.role}))}]}}};export{Hi as ACT_CODE_SYSTEM,Ae as ADDRESS_USE_MAPPER,Ar as ADDRESS_USE_VALUE_SET,Nr as ADMINISTRATIVE_GENDER_VALUE_SET,Gr as ALLERGIES_SECTION_TEMPLATE_IDS,Ki as ALLERGY_CATEGORY_MAPPER,Te as ALLERGY_CLINICAL_CODE_SYSTEM,De as ALLERGY_SEVERITY_MAPPER,Ne as ALLERGY_STATUS_MAPPER,dt as ALLERGY_VERIFICATION_CODE_SYSTEM,Qr as ASSESSMENTS_SECTION_TEMPLATE_IDS,io as CARE_TEAM_SECTION_TEMPLATE_IDS,ye as CCDA_NARRATIVE_REFERENCE_URL,es as CCDA_TEMPLATE_CODE_SYSTEM,an as CCDA_TEMPLATE_IDS,ut as CLINICAL_CONDITION_CODE_SYSTEM,_s as CLINICAL_NOTES_SECTION_TEMPLATE_IDS,$i as CONDITION_CATEGORY_CODE_SYSTEM,Yi as CONDITION_VERIFICATION_CODE_SYSTEM,lt as CONDITION_VER_STATUS_CODE_SYSTEM,Cr as CONFIDENTIALITY_CODE_SYSTEM,Xi as CONFIDENTIALITY_MAPPER,Dr as CONTACT_ENTITY_USE_VALUE_SET,kr as CVX_URL,Es as DEVICES_SECTION_TEMPLATE_IDS,qi as DIAGNOSIS_ROLE_CODE_SYSTEM,Zr as ENCOUNTERS_SECTION_TEMPLATE_IDS,en as ENCOUNTER_STATUS_MAPPER,E as EnumMapper,Br as FHIR_CVX_URL,Ji as GENDER_MAPPER,Xr as GOALS_SECTION_TEMPLATE_IDS,Jr as HEALTH_CONCERNS_SECTION_TEMPLATE_IDS,L as HTTP,ge as HUMAN_NAME_USE_MAPPER,ht as IMMUNIZATIONS_SECTION_TEMPLATE_IDS,ve as IMMUNIZATION_STATUS_MAPPER,no as INSURANCE_SECTION_TEMPLATE_IDS,ms as LAB_TESTS_SECTION_TEMPLATE_IDS,Qo as LANGUAGE_MODE_CODE_SYSTEM,Xo as LANGUAGE_MODE_URL,zo as LANGUAGE_PROFICIENCY_CODE_SYSTEM,Jo as LANGUAGE_PROFICIENCY_URL,cn as LOINC_TO_TEMPLATE_IDS,Yr as MEDICATIONS_SECTION_TEMPLATE_IDS,xr as MEDICATION_REQUEST_STATUS_VALUE_SET,Pe as MEDICATION_STATUS_MAPPER,eo as MENTAL_STATUS_SECTION_TEMPLATE_IDS,Rr as NAME_USE_VALUE_SET,vr as NCI_THESAURUS_URL,Mr as NDFRT_URL,Vr as NUCC_TAXONOMY_URL,gr as OBSERVATION_CATEGORY_CODE_SYSTEM,be as OBSERVATION_CATEGORY_MAPPER,ji as PARTICIPATION_CODE_SYSTEM,to as PATIENT_NOTES_SECTION_TEMPLATE_IDS,zr as PLAN_OF_TREATMENT_SECTION_TEMPLATE_IDS,$r as PROBLEMS_SECTION_TEMPLATE_IDS,xe as PROBLEM_STATUS_MAPPER,qr as PROCEDURES_SECTION_TEMPLATE_IDS,tn as PROCEDURE_STATUS_MAPPER,Zo as RACE_CODE_SYSTEM,Kr as REASON_FOR_REFERRAL_SECTION_TEMPLATE_IDS,Wr as RESULTS_SECTION_TEMPLATE_IDS,jr as SOCIAL_HISTORY_SECTION_TEMPLATE_IDS,Ce as SYSTEM_MAPPER,Re as TELECOM_USE_MAPPER,Lr as UNII_URL,Wi as US_CORE_CONDITION_URL,Se as US_CORE_ETHNICITY_URL,Qi as US_CORE_MEDICATION_REQUEST_URL,Ko as US_CORE_PATIENT_URL,Oe as US_CORE_RACE_URL,br as US_DRIVER_LICENSE_URL,Ur as US_NPI_URL,Pr as US_SSN_URL,wr as VA_MEDRT_URL,Hr as VITAL_SIGNS_SECTION_TEMPLATE_IDS,zi as XSI_URL,ps as convertCcdaToFhir,os as convertCcdaToXml,As as convertFhirToCcda,sn as convertToCompactXml,rs as convertXmlToCcda,te as mapCcdaSystemToFhir,Ge as mapCcdaToFhirDate,_ as mapCcdaToFhirDateTime,h as mapCodeableConceptToCcdaCode,ie as mapCodeableConceptToCcdaValue,Gi as mapCodingToCcdaCode,Zi as mapFhirSystemToCcda,w as mapFhirToCcdaDate,O as mapFhirToCcdaDateTime,on as parseXml};
3
3
  /*!
4
4
  * Reconnecting WebSocket
5
5
  * by Pedro Ladaria <pedro.ladaria@gmail.com>