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