@medplum/health-gorilla-core 4.5.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var index_exports={};__export(index_exports,{BillToOptions:()=>BillToOptions,HEALTH_GORILLA_AUTHORIZED_BY_EXT:()=>HEALTH_GORILLA_AUTHORIZED_BY_EXT,HEALTH_GORILLA_ENVIRONMENT:()=>HEALTH_GORILLA_ENVIRONMENT,HEALTH_GORILLA_SYSTEM:()=>HEALTH_GORILLA_SYSTEM,LabOrderValidationError:()=>LabOrderValidationError,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO:()=>MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN:()=>MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE:()=>MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE,MEDPLUM_HEALTH_GORILLA_TENANT_PROFILE:()=>MEDPLUM_HEALTH_GORILLA_TENANT_PROFILE,NPI_SYSTEM:()=>NPI_SYSTEM,PRIORITY_VALUES:()=>PRIORITY_VALUES,assertLabOrderInputs:()=>assertLabOrderInputs,assertReferenceOfType:()=>assertReferenceOfType,createLabOrderBundle:()=>createLabOrderBundle,getMissingRequiredQuestionnaireItems:()=>getMissingRequiredQuestionnaireItems,isBillTo:()=>isBillTo,isPriority:()=>isPriority,isReferenceOfType:()=>isReferenceOfType,isValidLabOrderInputs:()=>isValidLabOrderInputs,normalizeAoeQuestionnaire:()=>normalizeAoeQuestionnaire,questionnaireItemIterator:()=>questionnaireItemIterator,validateLabOrderInputs:()=>validateLabOrderInputs});module.exports=__toCommonJS(index_exports);var import_core=require("@medplum/core");function normalizeAoeQuestionnaire(aoe){if(aoe.item)for(let item of aoe.item)item.linkId=item.linkId??item.id,item.initial=item.answerOption?void 0:item.initial;return aoe}function getMissingRequiredQuestionnaireItems(q,qr,includeRequiredWhenSpecimenCollected){let missing=[],answersByLinkId=qr&&(0,import_core.getAllQuestionnaireAnswers)(qr);for(let item of questionnaireItemIterator(normalizeAoeQuestionnaire(q).item))if(item.required||includeRequiredWhenSpecimenCollected&&(0,import_core.getExtensionValue)(item,"https://www.healthgorilla.com/fhir/StructureDefinition/questionnaire-requiredwhenspecimen")===!0){let answers=answersByLinkId?.[item.linkId];if(answers&&answers.length>0){let hasValue=!1;for(let answer of answers)if((0,import_core.arrayify)((0,import_core.getTypedPropertyValue)({type:"QuestionnaireResponseItemAnswer",value:answer},"value[x]"))?.some(v=>v.value)){hasValue=!0;continue}if(hasValue)continue}missing.push(item.linkId)}return missing}function*questionnaireItemIterator(item){if(item)for(let i of item)yield i,i.item&&(yield*questionnaireItemIterator(i.item))}var import_core2=require("@medplum/core"),MEDPLUM_HEALTH_GORILLA_TENANT_PROFILE="https://medplum.com/profiles/integrations/health-gorilla/StructureDefinition/MedplumHealthGorillaTenant",MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE="https://medplum.com/profiles/integrations/health-gorilla/StructureDefinition/MedplumHealthGorillaOrder",MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO="billTo",MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN="performingLabAccountNumber",HEALTH_GORILLA_SYSTEM="https://www.healthgorilla.com",HEALTH_GORILLA_ENVIRONMENT=HEALTH_GORILLA_SYSTEM+"/environment",HEALTH_GORILLA_AUTHORIZED_BY_EXT=HEALTH_GORILLA_SYSTEM+"/fhir/StructureDefinition/requestgroup-authorizedBy",NPI_SYSTEM=import_core2.HTTP_HL7_ORG+"/fhir/sid/us-npi";var import_core4=require("@medplum/core");var import_core3=require("@medplum/core"),BillToOptions=["patient","insurance","customer-account","self"];function isBillTo(value){return value==="patient"||value==="insurance"||value==="customer-account"||value==="self"}var PRIORITY_VALUES=["routine","urgent","asap","stat"];function isPriority(value){return PRIORITY_VALUES.includes(value)}function isReferenceOfType(resourceType,value){return(0,import_core3.isReference)(value)&&value.reference.startsWith(resourceType+"/")}function assertReferenceOfType(resourceType,value){if(!isReferenceOfType(resourceType,value))throw new Error(`Expected reference to be of type ${resourceType}`)}function tempId(){return"urn:uuid:"+(0,import_core4.generateId)()}function assertLabOrderInputs(args){let errors=validateLabOrderInputs(args);if(errors)throw new LabOrderValidationError(errors)}function isValidLabOrderInputs(args){return!validateLabOrderInputs(args)}function validateLabOrderInputs(args){let errors={};if(args.patient||(errors.patient={message:"Patient is required"}),args.requester||(errors.requester={message:"Requesting Practitioner is required"}),args.performingLab||(errors.performingLab={message:"Performing Lab is required"}),!args.selectedTests||args.selectedTests.length===0)errors.selectedTests={message:"At least one test must be selected"};else for(let test of args.selectedTests){let meta=args.testMetadata?.[test.code];meta?.priority&&!isPriority(meta.priority)&&(errors.testMetadata??={},errors.testMetadata[test.code]??={},errors.testMetadata[test.code].priority={message:`Priority for ${(0,import_core4.formatCoding)(test,!0)} must be one of ${PRIORITY_VALUES.join(", ")}`});let q=meta?.aoeQuestionnaire;if(q){let missing=getMissingRequiredQuestionnaireItems(q,meta.aoeResponses,!!args.specimenCollectedDateTime);missing.length>0&&(errors.testMetadata??={},errors.testMetadata[test.code]??={},errors.testMetadata[test.code].aoeResponses={message:`Missing required AOE responses for ${(0,import_core4.formatCoding)(test,!0)}: ${missing.join(", ")}`})}}if(!isBillTo(args.billingInformation?.billTo))errors.billingInformation??={},args.billingInformation?.billTo?errors.billingInformation.billTo={message:`Bill to must be one of: ${BillToOptions.join(", ")}`}:errors.billingInformation.billTo={message:"Bill to is required"};else if(args.billingInformation.billTo==="insurance"){let coverageCount=args.billingInformation.patientCoverage?.length??0;(coverageCount<1||coverageCount>3)&&(errors.billingInformation??={},errors.billingInformation.patientCoverage={message:"BillingInformation.patientCoverage must contain 1-3 Coverage resources when billing to insurance"})}if(Object.keys(errors).length>0)return errors}var LabOrderValidationError=class extends Error{constructor(errors){super(`Invalid lab order inputs: ${JSON.stringify(errors)}`),this.errors=errors}};function createLabOrderBundle(inputs){assertLabOrderInputs(inputs);let{patient,requester,requestingLocation,performingLab,performingLabAccountNumber,selectedTests,testMetadata,diagnoses,specimenCollectedDateTime,billingInformation,orderNotes}=inputs,bundle={resourceType:"Bundle",type:"transaction"},labOrderTempId=tempId(),labOrderExtension=[],bundleEntry=[],subjectReference=(0,import_core4.isReference)(patient)?patient:(0,import_core4.createReference)(patient),requesterReference=(0,import_core4.isReference)(requester)?requester:(0,import_core4.createReference)(requester),performerReference=(0,import_core4.createReference)(performingLab),testEntries=[];for(let test of selectedTests){let metadata=testMetadata[test.code],qr;metadata?.aoeResponses&&(qr=(0,import_core4.deepClone)(metadata.aoeResponses),qr.id=tempId(),bundleEntry.push({fullUrl:qr.id,resource:qr,request:{method:"POST",url:"QuestionnaireResponse"}}));let testSR={resourceType:"ServiceRequest",id:tempId(),status:"draft",intent:"order",basedOn:[{reference:labOrderTempId}],subject:subjectReference,requester:requesterReference,performer:[performerReference],category:[{coding:[{system:import_core4.SNOMED,code:"103693007",display:"Diagnostic procedure"}]}],code:{coding:[test]},priority:metadata?.priority??"routine",note:metadata?.notes?[{authorReference:requesterReference,time:new Date().toISOString(),text:metadata.notes}]:void 0,supportingInfo:qr?[{reference:qr.id}]:void 0};testEntries.push({fullUrl:testSR.id,resource:testSR,request:{method:"POST",url:"ServiceRequest"}})}let specimen;if(specimenCollectedDateTime&&(specimen={resourceType:"Specimen",id:tempId(),subject:subjectReference,collection:{collectedDateTime:specimenCollectedDateTime.toISOString()}},bundleEntry.push({fullUrl:specimen.id,resource:specimen,request:{method:"POST",url:"Specimen"}})),labOrderExtension.push({url:MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO,valueString:billingInformation.billTo}),performingLabAccountNumber&&labOrderExtension.push({url:MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN,valueString:performingLabAccountNumber}),requestingLocation){let requestingLocationRef=(0,import_core4.isReference)(requestingLocation)?requestingLocation:(0,import_core4.createReference)(requestingLocation);labOrderExtension.push({url:HEALTH_GORILLA_AUTHORIZED_BY_EXT,valueReference:requestingLocationRef})}let insurance;billingInformation.billTo==="insurance"&&(insurance=(billingInformation.patientCoverage??[]).map(coverage=>(0,import_core4.createReference)(coverage)));let labOrder={resourceType:"ServiceRequest",id:labOrderTempId,meta:{profile:[MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE]},extension:labOrderExtension,status:"draft",intent:"order",subject:subjectReference,requester:requesterReference,performer:[performerReference],reasonCode:diagnoses,category:[{coding:[{system:import_core4.SNOMED,code:"108252007",display:"Laboratory procedure"}]}],code:{coding:selectedTests},insurance,specimen:specimen?[{reference:specimen.id}]:void 0,note:orderNotes?[{authorReference:requesterReference,time:new Date().toISOString(),text:orderNotes}]:void 0};bundleEntry.push({fullUrl:labOrder.id,resource:labOrder,request:{method:"POST",url:"ServiceRequest"}}),bundleEntry.push(...testEntries);for(let entry of bundleEntry)entry.resource&&delete entry.resource.id;return bundle.entry=bundleEntry,bundle}0&&(module.exports={BillToOptions,HEALTH_GORILLA_AUTHORIZED_BY_EXT,HEALTH_GORILLA_ENVIRONMENT,HEALTH_GORILLA_SYSTEM,LabOrderValidationError,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE,MEDPLUM_HEALTH_GORILLA_TENANT_PROFILE,NPI_SYSTEM,PRIORITY_VALUES,assertLabOrderInputs,assertReferenceOfType,createLabOrderBundle,getMissingRequiredQuestionnaireItems,isBillTo,isPriority,isReferenceOfType,isValidLabOrderInputs,normalizeAoeQuestionnaire,questionnaireItemIterator,validateLabOrderInputs});
1
+ "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var index_exports={};__export(index_exports,{BillToOptions:()=>BillToOptions,HEALTH_GORILLA_AUTHORIZED_BY_EXT:()=>HEALTH_GORILLA_AUTHORIZED_BY_EXT,HEALTH_GORILLA_ENVIRONMENT:()=>HEALTH_GORILLA_ENVIRONMENT,HEALTH_GORILLA_SYSTEM:()=>HEALTH_GORILLA_SYSTEM,LabOrderValidationError:()=>LabOrderValidationError,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO:()=>MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN:()=>MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE:()=>MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE,MEDPLUM_HEALTH_GORILLA_TENANT_PROFILE:()=>MEDPLUM_HEALTH_GORILLA_TENANT_PROFILE,NPI_SYSTEM:()=>NPI_SYSTEM,PRIORITY_VALUES:()=>PRIORITY_VALUES,assertLabOrderInputs:()=>assertLabOrderInputs,assertReferenceOfType:()=>assertReferenceOfType,createLabOrderBundle:()=>createLabOrderBundle,getMissingRequiredQuestionnaireItems:()=>getMissingRequiredQuestionnaireItems,isBillTo:()=>isBillTo,isPriority:()=>isPriority,isReferenceOfType:()=>isReferenceOfType,isValidLabOrderInputs:()=>isValidLabOrderInputs,normalizeAoeQuestionnaire:()=>normalizeAoeQuestionnaire,questionnaireItemIterator:()=>questionnaireItemIterator,validateLabOrderInputs:()=>validateLabOrderInputs});module.exports=__toCommonJS(index_exports);var import_core=require("@medplum/core");function normalizeAoeQuestionnaire(aoe){if(aoe.item)for(let item of aoe.item)item.linkId=item.linkId??item.id,item.initial=item.answerOption?void 0:item.initial;return aoe}function getMissingRequiredQuestionnaireItems(q,qr,includeRequiredWhenSpecimenCollected){let missing=[],answersByLinkId=qr&&(0,import_core.getAllQuestionnaireAnswers)(qr);for(let item of questionnaireItemIterator(normalizeAoeQuestionnaire(q).item))if(item.required||includeRequiredWhenSpecimenCollected&&(0,import_core.getExtensionValue)(item,"https://www.healthgorilla.com/fhir/StructureDefinition/questionnaire-requiredwhenspecimen")===!0){let answers=answersByLinkId?.[item.linkId];if(answers&&answers.length>0){let hasValue=!1;for(let answer of answers)if((0,import_core.arrayify)((0,import_core.getTypedPropertyValue)({type:"QuestionnaireResponseItemAnswer",value:answer},"value[x]"))?.some(v=>v.value)){hasValue=!0;continue}if(hasValue)continue}missing.push(item.linkId)}return missing}function*questionnaireItemIterator(item){if(item)for(let i of item)yield i,i.item&&(yield*questionnaireItemIterator(i.item))}var import_core2=require("@medplum/core"),MEDPLUM_HEALTH_GORILLA_TENANT_PROFILE="https://medplum.com/profiles/integrations/health-gorilla/StructureDefinition/MedplumHealthGorillaTenant",MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE="https://medplum.com/profiles/integrations/health-gorilla/StructureDefinition/MedplumHealthGorillaOrder",MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO="billTo",MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN="performingLabAccountNumber",HEALTH_GORILLA_SYSTEM="https://www.healthgorilla.com",HEALTH_GORILLA_ENVIRONMENT=HEALTH_GORILLA_SYSTEM+"/environment",HEALTH_GORILLA_AUTHORIZED_BY_EXT=HEALTH_GORILLA_SYSTEM+"/fhir/StructureDefinition/requestgroup-authorizedBy",NPI_SYSTEM=import_core2.HTTP_HL7_ORG+"/fhir/sid/us-npi";var import_core4=require("@medplum/core");var import_core3=require("@medplum/core"),BillToOptions=["patient","insurance","customer-account","self"];function isBillTo(value){return value==="patient"||value==="insurance"||value==="customer-account"||value==="self"}var PRIORITY_VALUES=["routine","urgent","asap","stat"];function isPriority(value){return PRIORITY_VALUES.includes(value)}function isReferenceOfType(resourceType,value){return(0,import_core3.isReference)(value)&&value.reference.startsWith(resourceType+"/")}function assertReferenceOfType(resourceType,value){if(!isReferenceOfType(resourceType,value))throw new Error(`Expected reference to be of type ${resourceType}`)}function tempId(){return"urn:uuid:"+(0,import_core4.generateId)()}function assertLabOrderInputs(args){let errors=validateLabOrderInputs(args);if(errors)throw new LabOrderValidationError(errors)}function isValidLabOrderInputs(args){return!validateLabOrderInputs(args)}function validateLabOrderInputs(args){let errors={};if(args.patient||(errors.patient={message:"Patient is required"}),args.requester||(errors.requester={message:"Requesting Practitioner is required"}),args.performingLab||(errors.performingLab={message:"Performing Lab is required"}),!args.selectedTests||args.selectedTests.length===0)errors.selectedTests={message:"At least one test must be selected"};else for(let test of args.selectedTests){let meta=args.testMetadata?.[test.code];meta?.priority&&!isPriority(meta.priority)&&(errors.testMetadata??={},errors.testMetadata[test.code]??={},errors.testMetadata[test.code].priority={message:`Priority for ${(0,import_core4.formatCoding)(test,!0)} must be one of ${PRIORITY_VALUES.join(", ")}`});let q=meta?.aoeQuestionnaire;if(q){let missing=getMissingRequiredQuestionnaireItems(q,meta.aoeResponses,!!args.specimenCollectedDateTime);missing.length>0&&(errors.testMetadata??={},errors.testMetadata[test.code]??={},errors.testMetadata[test.code].aoeResponses={message:`Missing required AOE responses for ${(0,import_core4.formatCoding)(test,!0)}: ${missing.join(", ")}`})}}if(!isBillTo(args.billingInformation?.billTo))errors.billingInformation??={},args.billingInformation?.billTo?errors.billingInformation.billTo={message:`Bill to must be one of: ${BillToOptions.join(", ")}`}:errors.billingInformation.billTo={message:"Bill to is required"};else if(args.billingInformation.billTo==="insurance"){let coverageCount=args.billingInformation.patientCoverage?.length??0;(coverageCount<1||coverageCount>3)&&(errors.billingInformation??={},errors.billingInformation.patientCoverage={message:"BillingInformation.patientCoverage must contain 1-3 Coverage resources when billing to insurance"})}if(Object.keys(errors).length>0)return errors}var LabOrderValidationError=class extends Error{constructor(errors){super(`Invalid lab order inputs: ${JSON.stringify(errors)}`);__publicField(this,"errors");this.errors=errors}};function createLabOrderBundle(inputs){assertLabOrderInputs(inputs);let{patient,requester,requestingLocation,performingLab,performingLabAccountNumber,selectedTests,testMetadata,diagnoses,specimenCollectedDateTime,billingInformation,orderNotes}=inputs,bundle={resourceType:"Bundle",type:"transaction"},labOrderTempId=tempId(),labOrderExtension=[],bundleEntry=[],subjectReference=(0,import_core4.isReference)(patient)?patient:(0,import_core4.createReference)(patient),requesterReference=(0,import_core4.isReference)(requester)?requester:(0,import_core4.createReference)(requester),performerReference=(0,import_core4.createReference)(performingLab),testEntries=[];for(let test of selectedTests){let metadata=testMetadata[test.code],qr;metadata?.aoeResponses&&(qr=(0,import_core4.deepClone)(metadata.aoeResponses),qr.id=tempId(),bundleEntry.push({fullUrl:qr.id,resource:qr,request:{method:"POST",url:"QuestionnaireResponse"}}));let testSR={resourceType:"ServiceRequest",id:tempId(),status:"draft",intent:"order",basedOn:[{reference:labOrderTempId}],subject:subjectReference,requester:requesterReference,performer:[performerReference],category:[{coding:[{system:import_core4.SNOMED,code:"103693007",display:"Diagnostic procedure"}]}],code:{coding:[test]},priority:metadata?.priority??"routine",note:metadata?.notes?[{authorReference:requesterReference,time:new Date().toISOString(),text:metadata.notes}]:void 0,supportingInfo:qr?[{reference:qr.id}]:void 0};testEntries.push({fullUrl:testSR.id,resource:testSR,request:{method:"POST",url:"ServiceRequest"}})}let specimen;if(specimenCollectedDateTime&&(specimen={resourceType:"Specimen",id:tempId(),subject:subjectReference,collection:{collectedDateTime:specimenCollectedDateTime.toISOString()}},bundleEntry.push({fullUrl:specimen.id,resource:specimen,request:{method:"POST",url:"Specimen"}})),labOrderExtension.push({url:MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO,valueString:billingInformation.billTo}),performingLabAccountNumber&&labOrderExtension.push({url:MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN,valueString:performingLabAccountNumber}),requestingLocation){let requestingLocationRef=(0,import_core4.isReference)(requestingLocation)?requestingLocation:(0,import_core4.createReference)(requestingLocation);labOrderExtension.push({url:HEALTH_GORILLA_AUTHORIZED_BY_EXT,valueReference:requestingLocationRef})}let insurance;billingInformation.billTo==="insurance"&&(insurance=(billingInformation.patientCoverage??[]).map(coverage=>(0,import_core4.createReference)(coverage)));let labOrder={resourceType:"ServiceRequest",id:labOrderTempId,meta:{profile:[MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE]},extension:labOrderExtension,status:"draft",intent:"order",subject:subjectReference,requester:requesterReference,performer:[performerReference],reasonCode:diagnoses,category:[{coding:[{system:import_core4.SNOMED,code:"108252007",display:"Laboratory procedure"}]}],code:{coding:selectedTests},insurance,specimen:specimen?[{reference:specimen.id}]:void 0,note:orderNotes?[{authorReference:requesterReference,time:new Date().toISOString(),text:orderNotes}]:void 0};bundleEntry.push({fullUrl:labOrder.id,resource:labOrder,request:{method:"POST",url:"ServiceRequest"}}),bundleEntry.push(...testEntries);for(let entry of bundleEntry)entry.resource&&delete entry.resource.id;return bundle.entry=bundleEntry,bundle}0&&(module.exports={BillToOptions,HEALTH_GORILLA_AUTHORIZED_BY_EXT,HEALTH_GORILLA_ENVIRONMENT,HEALTH_GORILLA_SYSTEM,LabOrderValidationError,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE,MEDPLUM_HEALTH_GORILLA_TENANT_PROFILE,NPI_SYSTEM,PRIORITY_VALUES,assertLabOrderInputs,assertReferenceOfType,createLabOrderBundle,getMissingRequiredQuestionnaireItems,isBillTo,isPriority,isReferenceOfType,isValidLabOrderInputs,normalizeAoeQuestionnaire,questionnaireItemIterator,validateLabOrderInputs});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts", "../../src/aoe.ts", "../../src/constants.ts", "../../src/lab-order.ts", "../../src/types.ts"],
4
4
  "sourcesContent": ["// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nexport * from './aoe';\nexport * from './constants';\nexport * from './lab-order';\nexport * from './types';\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { arrayify, getAllQuestionnaireAnswers, getExtensionValue, getTypedPropertyValue } from '@medplum/core';\nimport type {\n Questionnaire,\n QuestionnaireItem,\n QuestionnaireResponse,\n QuestionnaireResponseItemAnswer,\n} from '@medplum/fhirtypes';\n\n/**\n * Edits an AOE Questionnaire from Health Gorilla to make it a valid Questionnaire;\n * most importantly, it sets the linkId to the id if it is not already set.\n * @param aoe - The AOE Questionnaire to normalize.\n * @returns - The normalized input Questionnaire.\n */\nexport function normalizeAoeQuestionnaire(aoe: Questionnaire): Questionnaire {\n if (aoe.item) {\n for (const item of aoe.item) {\n item.linkId = item.linkId ?? item.id;\n item.initial = item.answerOption ? undefined : item.initial;\n }\n }\n\n return aoe;\n}\n\n/**\n * Checks which required items are missing from a QuestionnaireResponse.\n * @param q - The Questionnaire to check against.\n * @param qr - The QuestionnaireResponse to check.\n * @param includeRequiredWhenSpecimenCollected - Whether to require AOE answers when a specimen is collected.\n * @returns An array of linkIds of missing required items.\n */\nexport function getMissingRequiredQuestionnaireItems(\n q: Questionnaire,\n qr: QuestionnaireResponse | undefined,\n includeRequiredWhenSpecimenCollected: boolean\n): string[] {\n const missing: string[] = [];\n const answersByLinkId: Record<string, QuestionnaireResponseItemAnswer[] | undefined> | undefined =\n qr && getAllQuestionnaireAnswers(qr);\n\n //TODO it might be better to make NormalizedAoeQuestionnaire a branded type\n // and specify that as the input type to this function\n for (const item of questionnaireItemIterator(normalizeAoeQuestionnaire(q).item)) {\n if (\n item.required ||\n (includeRequiredWhenSpecimenCollected &&\n getExtensionValue(\n item,\n 'https://www.healthgorilla.com/fhir/StructureDefinition/questionnaire-requiredwhenspecimen'\n ) === true)\n ) {\n const answers = answersByLinkId?.[item.linkId];\n if (answers && answers.length > 0) {\n let hasValue = false;\n for (const answer of answers) {\n const values = arrayify(\n getTypedPropertyValue({ type: 'QuestionnaireResponseItemAnswer', value: answer }, 'value[x]')\n );\n if (values?.some((v) => v.value)) {\n hasValue = true;\n continue;\n }\n }\n\n if (hasValue) {\n continue;\n }\n }\n\n missing.push(item.linkId);\n }\n }\n\n return missing;\n}\n\nexport function* questionnaireItemIterator(item: QuestionnaireItem[] | undefined): Generator<QuestionnaireItem> {\n if (!item) {\n return;\n }\n\n for (const i of item) {\n yield i;\n if (i.item) {\n yield* questionnaireItemIterator(i.item);\n }\n }\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { HTTP_HL7_ORG } from '@medplum/core';\n\nexport const MEDPLUM_HEALTH_GORILLA_TENANT_PROFILE =\n 'https://medplum.com/profiles/integrations/health-gorilla/StructureDefinition/MedplumHealthGorillaTenant';\nexport const MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE =\n 'https://medplum.com/profiles/integrations/health-gorilla/StructureDefinition/MedplumHealthGorillaOrder';\n\nexport const MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO = 'billTo';\nexport const MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN = 'performingLabAccountNumber';\n\nexport const HEALTH_GORILLA_SYSTEM = 'https://www.healthgorilla.com';\nexport const HEALTH_GORILLA_ENVIRONMENT = HEALTH_GORILLA_SYSTEM + '/environment';\nexport const HEALTH_GORILLA_AUTHORIZED_BY_EXT =\n HEALTH_GORILLA_SYSTEM + '/fhir/StructureDefinition/requestgroup-authorizedBy';\n\nexport const NPI_SYSTEM = HTTP_HL7_ORG + '/fhir/sid/us-npi';\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { createReference, deepClone, formatCoding, generateId, isReference, SNOMED } from '@medplum/core';\nimport type {\n Bundle,\n Coverage,\n Extension,\n Location,\n Organization,\n Patient,\n Practitioner,\n QuestionnaireResponse,\n Reference,\n Resource,\n ResourceType,\n ServiceRequest,\n Specimen,\n} from '@medplum/fhirtypes';\nimport { getMissingRequiredQuestionnaireItems } from './aoe';\nimport {\n HEALTH_GORILLA_AUTHORIZED_BY_EXT,\n MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO,\n MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN,\n MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE,\n} from './constants';\nimport type {\n BillingInformation,\n DiagnosisCodeableConcept,\n LabOrderServiceRequest,\n LabOrderTestMetadata,\n LabOrganization,\n TestCoding,\n} from './types';\nimport { BillToOptions, isBillTo, isPriority, PRIORITY_VALUES } from './types';\n\nexport type LabOrderInputs = {\n /** `Patient` the tests are ordered for. This must be a reference to an existing `Patient` resource. */\n patient: Patient | (Reference<Patient> & { reference: string });\n /** The physician who requests diagnostic procedures for the patient and responsible for the order. */\n requester: Practitioner | (Reference<Practitioner> & { reference: string });\n /** For multi-location practices, optionally specify the location from which the order is being placed */\n requestingLocation?: Location | Organization | (Reference<Location | Organization> & { reference: string });\n /** The desired performer for doing the diagnostic testing - laboratory, radiology imaging center, etc. */\n performingLab: LabOrganization;\n /**\n * (optional) Account Number for the performing lab. If not provided, the `HEALTH_GORILLA_SUBTENANT_ACCOUNT_NUMBER`\n * `Project.secret` is used.\n */\n performingLabAccountNumber?: string;\n /** The list of tests ordered within the given order. */\n selectedTests: TestCoding[];\n /** An object mapping the `Coding.code` of each selected test to an `LabOrderTestMetadata` object. */\n testMetadata: Record<string, LabOrderTestMetadata | undefined>;\n /** An explanation or justification for why this diagnostic investigation is being requested in coded or textual form. */\n diagnoses: DiagnosisCodeableConcept[];\n /** (optional) The collection date of the lab order. */\n specimenCollectedDateTime?: Date;\n /** The billing preferences for the order. */\n billingInformation: BillingInformation;\n /** (optional) An order note - any comments that should be included in the requisition. */\n orderNotes?: string;\n};\n\nfunction tempId(): string {\n return 'urn:uuid:' + generateId();\n}\n\n/**\n * A modified type of `LabOrderInputs` that makes every field and sub-field optional and loosens\n * cardinality checks to facilitate typical type signatures of hooks and other state used in\n * React components that call `createLabOrderBundle`. This type is used in conjunction\n * with `validateLabOrderInputs`\n */\nexport type PartialLabOrderInputs = Partial<\n Omit<LabOrderInputs, 'billingInformation' | 'testMetadata'> & {\n testMetadata: Record<string, LabOrderTestMetadata | undefined>;\n billingInformation: Partial<\n Omit<BillingInformation, 'patientCoverage'> & {\n patientCoverage?: Coverage[];\n }\n >;\n }\n>;\n\nexport type InputError = { message: string };\n\nexport type LabOrderInputErrors = {\n patient?: InputError;\n requester?: InputError;\n performingLab?: InputError;\n selectedTests?: InputError;\n testMetadata?: {\n [testCode: string]: {\n priority?: InputError;\n notes?: InputError;\n aoeResponses?: InputError;\n };\n };\n billingInformation?: {\n billTo?: InputError;\n patientCoverage?: InputError;\n };\n};\n\nexport function assertLabOrderInputs(args: PartialLabOrderInputs): asserts args is LabOrderInputs {\n const errors = validateLabOrderInputs(args);\n if (errors) {\n throw new LabOrderValidationError(errors);\n }\n}\n\nexport function isValidLabOrderInputs(args: PartialLabOrderInputs): args is LabOrderInputs {\n return !validateLabOrderInputs(args);\n}\n\nexport function validateLabOrderInputs(args: PartialLabOrderInputs): LabOrderInputErrors | undefined {\n const errors: LabOrderInputErrors = {};\n\n if (!args.patient) {\n errors.patient = { message: 'Patient is required' };\n }\n\n if (!args.requester) {\n errors.requester = { message: 'Requesting Practitioner is required' };\n }\n\n if (!args.performingLab) {\n errors.performingLab = { message: 'Performing Lab is required' };\n }\n\n if (!args.selectedTests || args.selectedTests.length === 0) {\n errors.selectedTests = { message: 'At least one test must be selected' };\n } else {\n for (const test of args.selectedTests) {\n const meta = args.testMetadata?.[test.code];\n\n // priority\n if (meta?.priority && !isPriority(meta.priority)) {\n errors.testMetadata ??= {};\n errors.testMetadata[test.code] ??= {};\n errors.testMetadata[test.code].priority = {\n message: `Priority for ${formatCoding(test, true)} must be one of ${PRIORITY_VALUES.join(', ')}`,\n };\n }\n\n // AOE responses\n const q = meta?.aoeQuestionnaire;\n if (q) {\n const missing = getMissingRequiredQuestionnaireItems(\n q,\n meta.aoeResponses,\n Boolean(args.specimenCollectedDateTime)\n );\n if (missing.length > 0) {\n errors.testMetadata ??= {};\n errors.testMetadata[test.code] ??= {};\n errors.testMetadata[test.code].aoeResponses = {\n message: `Missing required AOE responses for ${formatCoding(test, true)}: ${missing.join(', ')}`,\n };\n }\n }\n }\n }\n\n if (!isBillTo(args.billingInformation?.billTo)) {\n errors.billingInformation ??= {};\n if (!args.billingInformation?.billTo) {\n errors.billingInformation.billTo = { message: 'Bill to is required' };\n } else {\n errors.billingInformation.billTo = { message: `Bill to must be one of: ${BillToOptions.join(', ')}` };\n }\n } else if (args.billingInformation.billTo === 'insurance') {\n const coverageCount = args.billingInformation.patientCoverage?.length ?? 0;\n if (coverageCount < 1 || coverageCount > 3) {\n errors.billingInformation ??= {};\n errors.billingInformation.patientCoverage = {\n message: 'BillingInformation.patientCoverage must contain 1-3 Coverage resources when billing to insurance',\n };\n }\n }\n\n if (Object.keys(errors).length > 0) {\n return errors;\n }\n return undefined;\n}\n\nexport class LabOrderValidationError extends Error {\n readonly errors: LabOrderInputErrors;\n\n constructor(errors: LabOrderInputErrors) {\n super(`Invalid lab order inputs: ${JSON.stringify(errors)}`);\n this.errors = errors;\n }\n}\n\ntype PopulatedBundleEntry = NonNullable<Bundle['entry']> &\n {\n fullUrl: string;\n resource: Resource;\n request: { method: 'POST'; url: ResourceType };\n }[];\n\n/**\n * Prepares a Bundle containing the resources necessary to create a `ServiceRequest` representing\n * a Health Gorilla lab order.\n * @param inputs - An object containing the required fields for creating a lab order bundle\n * @returns A transaction `Bundle` containing the resources necessary to create\n * a `ServiceRequest` representing the Health Gorilla lab order.\n */\nexport function createLabOrderBundle(inputs: PartialLabOrderInputs): Bundle {\n assertLabOrderInputs(inputs);\n\n inputs satisfies LabOrderInputs;\n\n const {\n patient,\n requester,\n requestingLocation,\n performingLab,\n performingLabAccountNumber,\n selectedTests,\n testMetadata,\n diagnoses,\n specimenCollectedDateTime,\n billingInformation,\n orderNotes,\n } = inputs;\n\n const bundle: Bundle = {\n resourceType: 'Bundle',\n type: 'transaction',\n };\n\n const labOrderTempId = tempId();\n const labOrderExtension: Extension[] = [];\n const bundleEntry: PopulatedBundleEntry = [];\n\n const subjectReference = isReference(patient) ? patient : createReference(patient);\n const requesterReference = isReference(requester) ? requester : createReference(requester);\n const performerReference = createReference(performingLab);\n\n const testEntries: PopulatedBundleEntry = [];\n for (const test of selectedTests) {\n const metadata = testMetadata[test.code];\n\n let qr: QuestionnaireResponse | undefined;\n if (metadata?.aoeResponses) {\n qr = deepClone(metadata.aoeResponses);\n qr.id = tempId();\n bundleEntry.push({\n fullUrl: qr.id,\n resource: qr,\n request: { method: 'POST', url: 'QuestionnaireResponse' },\n });\n }\n\n const testSR: ServiceRequest = {\n resourceType: 'ServiceRequest',\n id: tempId(),\n status: 'draft',\n intent: 'order',\n basedOn: [{ reference: labOrderTempId }],\n subject: subjectReference,\n requester: requesterReference,\n performer: [performerReference],\n category: [{ coding: [{ system: SNOMED, code: '103693007', display: 'Diagnostic procedure' }] }],\n code: { coding: [test] },\n priority: metadata?.priority ?? 'routine',\n note: metadata?.notes\n ? [{ authorReference: requesterReference, time: new Date().toISOString(), text: metadata.notes }]\n : undefined,\n supportingInfo: qr ? [{ reference: qr.id }] : undefined,\n };\n\n testEntries.push({\n fullUrl: testSR.id,\n resource: testSR,\n request: { method: 'POST', url: 'ServiceRequest' },\n });\n }\n\n let specimen: Specimen | undefined;\n if (specimenCollectedDateTime) {\n specimen = {\n resourceType: 'Specimen',\n id: tempId(),\n subject: subjectReference,\n collection: { collectedDateTime: specimenCollectedDateTime.toISOString() },\n };\n bundleEntry.push({\n fullUrl: specimen.id,\n resource: specimen,\n request: { method: 'POST', url: 'Specimen' },\n });\n }\n\n labOrderExtension.push({\n url: MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO,\n valueString: billingInformation.billTo,\n });\n\n if (performingLabAccountNumber) {\n labOrderExtension.push({\n url: MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN,\n valueString: performingLabAccountNumber,\n });\n }\n\n if (requestingLocation) {\n const requestingLocationRef = isReference(requestingLocation)\n ? requestingLocation\n : createReference(requestingLocation);\n\n labOrderExtension.push({\n url: HEALTH_GORILLA_AUTHORIZED_BY_EXT,\n valueReference: requestingLocationRef,\n });\n }\n\n let insurance: Reference<Coverage>[] | undefined;\n if (billingInformation.billTo === 'insurance') {\n insurance = (billingInformation.patientCoverage ?? []).map((coverage) => {\n return createReference(coverage);\n });\n }\n\n const labOrder: LabOrderServiceRequest = {\n resourceType: 'ServiceRequest',\n id: labOrderTempId,\n meta: { profile: [MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE] },\n extension: labOrderExtension,\n status: 'draft',\n intent: 'order',\n subject: subjectReference,\n requester: requesterReference,\n performer: [performerReference],\n reasonCode: diagnoses,\n category: [{ coding: [{ system: SNOMED, code: '108252007', display: 'Laboratory procedure' }] }],\n // individual test codes are included in the ServcieRequest referenced in supporting Info.\n // TBD what should go in the `code` field of the lab order. Leaving the tests there for now\n // since code is required.\n code: { coding: selectedTests },\n insurance,\n specimen: specimen ? [{ reference: specimen.id }] : undefined,\n note: orderNotes\n ? [{ authorReference: requesterReference, time: new Date().toISOString(), text: orderNotes }]\n : undefined,\n };\n\n bundleEntry.push({\n fullUrl: labOrder.id,\n resource: labOrder,\n request: { method: 'POST', url: 'ServiceRequest' },\n });\n\n bundleEntry.push(...testEntries);\n\n // Remove resource.id to avoid breaking the transaction processing of the urn:uuid:<uuid> temp IDs.\n for (const entry of bundleEntry) {\n if (entry.resource) {\n delete entry.resource.id;\n }\n }\n\n bundle.entry = bundleEntry;\n\n return bundle;\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { isReference } from '@medplum/core';\nimport type {\n CodeableConcept,\n Coding,\n Coverage,\n ExtractResource,\n OperationOutcome,\n Organization,\n Questionnaire,\n QuestionnaireResponse,\n Reference,\n ResourceType,\n ServiceRequest,\n} from '@medplum/fhirtypes';\n\nexport type LabOrderServiceRequest = ServiceRequest & {\n performer: [Reference<LabOrganization>];\n code: CodeableConcept;\n};\n\nexport interface LabOrderTestMetadata {\n /** (optional) This attribute allows to set priority for the given test within the order. Defaults to 'routine' */\n priority?: 'routine' | 'urgent' | 'asap' | 'stat';\n /** (optional) Any notes and comments related to the given test. */\n notes?: string;\n /** The AOE `Questionnaire`, if any, containing Ask at Order Entry (AOE) questions for the test. */\n readonly aoeQuestionnaire?: Questionnaire;\n /**\n * The `QuestionnaireResponse` resource containing answers related to the given diagnostic procedure.\n * If AOE is required for the specified configuration (performer, test, specimen), but missed in the\n * request, then the whole order will be rejected. Only answered AOEs should be included into request.\n */\n aoeResponses?: QuestionnaireResponse;\n}\n\nexport const BillToOptions = ['patient', 'insurance', 'customer-account', 'self'] as const;\nexport type BillTo = (typeof BillToOptions)[number];\n\nexport function isBillTo(value: unknown): value is BillTo {\n if (value === 'patient' || value === 'insurance' || value === 'customer-account' || value === 'self') {\n value satisfies BillTo;\n return true;\n }\n return false;\n}\n\nexport type LabOrganization = Organization & { id: string };\n\nexport type TestCoding = Coding & { code: string };\n\nexport type DiagnosisCodeableConcept = CodeableConcept & {\n coding: (Coding & Required<Pick<Coding, 'system' | 'code'>>)[];\n};\n\nexport type BillingInformation = {\n billTo?: BillTo;\n patientCoverage?: [] | [Coverage] | [Coverage, Coverage] | [Coverage, Coverage, Coverage];\n};\n\nexport const PRIORITY_VALUES = ['routine', 'urgent', 'asap', 'stat'] as const;\n\nexport function isPriority(value: unknown): value is NonNullable<ServiceRequest['priority']> {\n return PRIORITY_VALUES.includes(value as any);\n}\n\nexport type HGAutocompleteBotInput =\n | {\n type: 'lab';\n query: string;\n }\n | {\n type: 'test';\n query: string;\n labId: string;\n }\n | {\n type: 'aoe';\n testCode: Coding;\n };\n\nexport type HGAutocompleteBotResponse =\n | {\n outcome: OperationOutcome;\n type: 'lab';\n result: Organization[];\n }\n | {\n outcome: OperationOutcome;\n type: 'test';\n result: Coding[];\n }\n | {\n outcome: OperationOutcome;\n type: 'aoe';\n result: Questionnaire | undefined;\n }\n | {\n outcome: OperationOutcome;\n type: 'error';\n args: any;\n };\n\nexport function isReferenceOfType<T extends ResourceType>(\n resourceType: T,\n value: unknown\n): value is Reference<ExtractResource<T>> & { reference: string } {\n return isReference(value) && value.reference.startsWith(resourceType + '/');\n}\n\nexport function assertReferenceOfType<T extends ResourceType>(\n resourceType: T,\n value: unknown\n): asserts value is Reference<ExtractResource<T>> {\n if (!isReferenceOfType(resourceType, value)) {\n throw new Error(`Expected reference to be of type ${resourceType}`);\n }\n}\n\nexport type WithId<T> = T & { id: string };\n"],
5
- "mappings": "wpBAAA,8zCCEA,gBAA+F,yBAcxF,SAAS,0BAA0B,IAAmC,CAC3E,GAAI,IAAI,KACN,QAAW,QAAQ,IAAI,KACrB,KAAK,OAAS,KAAK,QAAU,KAAK,GAClC,KAAK,QAAU,KAAK,aAAe,OAAY,KAAK,QAIxD,OAAO,GACT,CASO,SAAS,qCACd,EACA,GACA,qCACU,CACV,IAAM,QAAoB,CAAC,EACrB,gBACJ,OAAM,wCAA2B,EAAE,EAIrC,QAAW,QAAQ,0BAA0B,0BAA0B,CAAC,EAAE,IAAI,EAC5E,GACE,KAAK,UACJ,yCACC,+BACE,KACA,2FACF,IAAM,GACR,CACA,IAAM,QAAU,kBAAkB,KAAK,MAAM,EAC7C,GAAI,SAAW,QAAQ,OAAS,EAAG,CACjC,IAAI,SAAW,GACf,QAAW,UAAU,QAInB,MAHe,yBACb,mCAAsB,CAAE,KAAM,kCAAmC,MAAO,MAAO,EAAG,UAAU,CAC9F,GACY,KAAM,GAAM,EAAE,KAAK,EAAG,CAChC,SAAW,GACX,QACF,CAGF,GAAI,SACF,QAEJ,CAEA,QAAQ,KAAK,KAAK,MAAM,CA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SAAS,GAI1B,cAAO,MAAQ,YAER,MACT",
6
6
  "names": ["import_core", "import_core", "import_core"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{arrayify,getAllQuestionnaireAnswers,getExtensionValue,getTypedPropertyValue}from"@medplum/core";function normalizeAoeQuestionnaire(aoe){if(aoe.item)for(let item of aoe.item)item.linkId=item.linkId??item.id,item.initial=item.answerOption?void 0:item.initial;return aoe}function getMissingRequiredQuestionnaireItems(q,qr,includeRequiredWhenSpecimenCollected){let missing=[],answersByLinkId=qr&&getAllQuestionnaireAnswers(qr);for(let item of questionnaireItemIterator(normalizeAoeQuestionnaire(q).item))if(item.required||includeRequiredWhenSpecimenCollected&&getExtensionValue(item,"https://www.healthgorilla.com/fhir/StructureDefinition/questionnaire-requiredwhenspecimen")===!0){let answers=answersByLinkId?.[item.linkId];if(answers&&answers.length>0){let hasValue=!1;for(let answer of answers)if(arrayify(getTypedPropertyValue({type:"QuestionnaireResponseItemAnswer",value:answer},"value[x]"))?.some(v=>v.value)){hasValue=!0;continue}if(hasValue)continue}missing.push(item.linkId)}return missing}function*questionnaireItemIterator(item){if(item)for(let i of item)yield i,i.item&&(yield*questionnaireItemIterator(i.item))}import{HTTP_HL7_ORG}from"@medplum/core";var MEDPLUM_HEALTH_GORILLA_TENANT_PROFILE="https://medplum.com/profiles/integrations/health-gorilla/StructureDefinition/MedplumHealthGorillaTenant",MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE="https://medplum.com/profiles/integrations/health-gorilla/StructureDefinition/MedplumHealthGorillaOrder",MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO="billTo",MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN="performingLabAccountNumber",HEALTH_GORILLA_SYSTEM="https://www.healthgorilla.com",HEALTH_GORILLA_ENVIRONMENT=HEALTH_GORILLA_SYSTEM+"/environment",HEALTH_GORILLA_AUTHORIZED_BY_EXT=HEALTH_GORILLA_SYSTEM+"/fhir/StructureDefinition/requestgroup-authorizedBy",NPI_SYSTEM=HTTP_HL7_ORG+"/fhir/sid/us-npi";import{createReference,deepClone,formatCoding,generateId,isReference as isReference2,SNOMED}from"@medplum/core";import{isReference}from"@medplum/core";var BillToOptions=["patient","insurance","customer-account","self"];function isBillTo(value){return value==="patient"||value==="insurance"||value==="customer-account"||value==="self"}var PRIORITY_VALUES=["routine","urgent","asap","stat"];function isPriority(value){return PRIORITY_VALUES.includes(value)}function isReferenceOfType(resourceType,value){return isReference(value)&&value.reference.startsWith(resourceType+"/")}function assertReferenceOfType(resourceType,value){if(!isReferenceOfType(resourceType,value))throw new Error(`Expected reference to be of type ${resourceType}`)}function tempId(){return"urn:uuid:"+generateId()}function assertLabOrderInputs(args){let errors=validateLabOrderInputs(args);if(errors)throw new LabOrderValidationError(errors)}function isValidLabOrderInputs(args){return!validateLabOrderInputs(args)}function validateLabOrderInputs(args){let errors={};if(args.patient||(errors.patient={message:"Patient is required"}),args.requester||(errors.requester={message:"Requesting Practitioner is required"}),args.performingLab||(errors.performingLab={message:"Performing Lab is required"}),!args.selectedTests||args.selectedTests.length===0)errors.selectedTests={message:"At least one test must be selected"};else for(let test of args.selectedTests){let meta=args.testMetadata?.[test.code];meta?.priority&&!isPriority(meta.priority)&&(errors.testMetadata??={},errors.testMetadata[test.code]??={},errors.testMetadata[test.code].priority={message:`Priority for ${formatCoding(test,!0)} must be one of ${PRIORITY_VALUES.join(", ")}`});let q=meta?.aoeQuestionnaire;if(q){let missing=getMissingRequiredQuestionnaireItems(q,meta.aoeResponses,!!args.specimenCollectedDateTime);missing.length>0&&(errors.testMetadata??={},errors.testMetadata[test.code]??={},errors.testMetadata[test.code].aoeResponses={message:`Missing required AOE responses for ${formatCoding(test,!0)}: ${missing.join(", ")}`})}}if(!isBillTo(args.billingInformation?.billTo))errors.billingInformation??={},args.billingInformation?.billTo?errors.billingInformation.billTo={message:`Bill to must be one of: ${BillToOptions.join(", ")}`}:errors.billingInformation.billTo={message:"Bill to is required"};else if(args.billingInformation.billTo==="insurance"){let coverageCount=args.billingInformation.patientCoverage?.length??0;(coverageCount<1||coverageCount>3)&&(errors.billingInformation??={},errors.billingInformation.patientCoverage={message:"BillingInformation.patientCoverage must contain 1-3 Coverage resources when billing to insurance"})}if(Object.keys(errors).length>0)return errors}var LabOrderValidationError=class extends Error{constructor(errors){super(`Invalid lab order inputs: ${JSON.stringify(errors)}`),this.errors=errors}};function createLabOrderBundle(inputs){assertLabOrderInputs(inputs);let{patient,requester,requestingLocation,performingLab,performingLabAccountNumber,selectedTests,testMetadata,diagnoses,specimenCollectedDateTime,billingInformation,orderNotes}=inputs,bundle={resourceType:"Bundle",type:"transaction"},labOrderTempId=tempId(),labOrderExtension=[],bundleEntry=[],subjectReference=isReference2(patient)?patient:createReference(patient),requesterReference=isReference2(requester)?requester:createReference(requester),performerReference=createReference(performingLab),testEntries=[];for(let test of selectedTests){let metadata=testMetadata[test.code],qr;metadata?.aoeResponses&&(qr=deepClone(metadata.aoeResponses),qr.id=tempId(),bundleEntry.push({fullUrl:qr.id,resource:qr,request:{method:"POST",url:"QuestionnaireResponse"}}));let testSR={resourceType:"ServiceRequest",id:tempId(),status:"draft",intent:"order",basedOn:[{reference:labOrderTempId}],subject:subjectReference,requester:requesterReference,performer:[performerReference],category:[{coding:[{system:SNOMED,code:"103693007",display:"Diagnostic procedure"}]}],code:{coding:[test]},priority:metadata?.priority??"routine",note:metadata?.notes?[{authorReference:requesterReference,time:new Date().toISOString(),text:metadata.notes}]:void 0,supportingInfo:qr?[{reference:qr.id}]:void 0};testEntries.push({fullUrl:testSR.id,resource:testSR,request:{method:"POST",url:"ServiceRequest"}})}let specimen;if(specimenCollectedDateTime&&(specimen={resourceType:"Specimen",id:tempId(),subject:subjectReference,collection:{collectedDateTime:specimenCollectedDateTime.toISOString()}},bundleEntry.push({fullUrl:specimen.id,resource:specimen,request:{method:"POST",url:"Specimen"}})),labOrderExtension.push({url:MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO,valueString:billingInformation.billTo}),performingLabAccountNumber&&labOrderExtension.push({url:MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN,valueString:performingLabAccountNumber}),requestingLocation){let requestingLocationRef=isReference2(requestingLocation)?requestingLocation:createReference(requestingLocation);labOrderExtension.push({url:HEALTH_GORILLA_AUTHORIZED_BY_EXT,valueReference:requestingLocationRef})}let insurance;billingInformation.billTo==="insurance"&&(insurance=(billingInformation.patientCoverage??[]).map(coverage=>createReference(coverage)));let labOrder={resourceType:"ServiceRequest",id:labOrderTempId,meta:{profile:[MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE]},extension:labOrderExtension,status:"draft",intent:"order",subject:subjectReference,requester:requesterReference,performer:[performerReference],reasonCode:diagnoses,category:[{coding:[{system:SNOMED,code:"108252007",display:"Laboratory procedure"}]}],code:{coding:selectedTests},insurance,specimen:specimen?[{reference:specimen.id}]:void 0,note:orderNotes?[{authorReference:requesterReference,time:new Date().toISOString(),text:orderNotes}]:void 0};bundleEntry.push({fullUrl:labOrder.id,resource:labOrder,request:{method:"POST",url:"ServiceRequest"}}),bundleEntry.push(...testEntries);for(let entry of bundleEntry)entry.resource&&delete entry.resource.id;return bundle.entry=bundleEntry,bundle}export{BillToOptions,HEALTH_GORILLA_AUTHORIZED_BY_EXT,HEALTH_GORILLA_ENVIRONMENT,HEALTH_GORILLA_SYSTEM,LabOrderValidationError,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE,MEDPLUM_HEALTH_GORILLA_TENANT_PROFILE,NPI_SYSTEM,PRIORITY_VALUES,assertLabOrderInputs,assertReferenceOfType,createLabOrderBundle,getMissingRequiredQuestionnaireItems,isBillTo,isPriority,isReferenceOfType,isValidLabOrderInputs,normalizeAoeQuestionnaire,questionnaireItemIterator,validateLabOrderInputs};
1
+ var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);import{arrayify,getAllQuestionnaireAnswers,getExtensionValue,getTypedPropertyValue}from"@medplum/core";function normalizeAoeQuestionnaire(aoe){if(aoe.item)for(let item of aoe.item)item.linkId=item.linkId??item.id,item.initial=item.answerOption?void 0:item.initial;return aoe}function getMissingRequiredQuestionnaireItems(q,qr,includeRequiredWhenSpecimenCollected){let missing=[],answersByLinkId=qr&&getAllQuestionnaireAnswers(qr);for(let item of questionnaireItemIterator(normalizeAoeQuestionnaire(q).item))if(item.required||includeRequiredWhenSpecimenCollected&&getExtensionValue(item,"https://www.healthgorilla.com/fhir/StructureDefinition/questionnaire-requiredwhenspecimen")===!0){let answers=answersByLinkId?.[item.linkId];if(answers&&answers.length>0){let hasValue=!1;for(let answer of answers)if(arrayify(getTypedPropertyValue({type:"QuestionnaireResponseItemAnswer",value:answer},"value[x]"))?.some(v=>v.value)){hasValue=!0;continue}if(hasValue)continue}missing.push(item.linkId)}return missing}function*questionnaireItemIterator(item){if(item)for(let i of item)yield i,i.item&&(yield*questionnaireItemIterator(i.item))}import{HTTP_HL7_ORG}from"@medplum/core";var MEDPLUM_HEALTH_GORILLA_TENANT_PROFILE="https://medplum.com/profiles/integrations/health-gorilla/StructureDefinition/MedplumHealthGorillaTenant",MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE="https://medplum.com/profiles/integrations/health-gorilla/StructureDefinition/MedplumHealthGorillaOrder",MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO="billTo",MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN="performingLabAccountNumber",HEALTH_GORILLA_SYSTEM="https://www.healthgorilla.com",HEALTH_GORILLA_ENVIRONMENT=HEALTH_GORILLA_SYSTEM+"/environment",HEALTH_GORILLA_AUTHORIZED_BY_EXT=HEALTH_GORILLA_SYSTEM+"/fhir/StructureDefinition/requestgroup-authorizedBy",NPI_SYSTEM=HTTP_HL7_ORG+"/fhir/sid/us-npi";import{createReference,deepClone,formatCoding,generateId,isReference as isReference2,SNOMED}from"@medplum/core";import{isReference}from"@medplum/core";var BillToOptions=["patient","insurance","customer-account","self"];function isBillTo(value){return value==="patient"||value==="insurance"||value==="customer-account"||value==="self"}var PRIORITY_VALUES=["routine","urgent","asap","stat"];function isPriority(value){return PRIORITY_VALUES.includes(value)}function isReferenceOfType(resourceType,value){return isReference(value)&&value.reference.startsWith(resourceType+"/")}function assertReferenceOfType(resourceType,value){if(!isReferenceOfType(resourceType,value))throw new Error(`Expected reference to be of type ${resourceType}`)}function tempId(){return"urn:uuid:"+generateId()}function assertLabOrderInputs(args){let errors=validateLabOrderInputs(args);if(errors)throw new LabOrderValidationError(errors)}function isValidLabOrderInputs(args){return!validateLabOrderInputs(args)}function validateLabOrderInputs(args){let errors={};if(args.patient||(errors.patient={message:"Patient is required"}),args.requester||(errors.requester={message:"Requesting Practitioner is required"}),args.performingLab||(errors.performingLab={message:"Performing Lab is required"}),!args.selectedTests||args.selectedTests.length===0)errors.selectedTests={message:"At least one test must be selected"};else for(let test of args.selectedTests){let meta=args.testMetadata?.[test.code];meta?.priority&&!isPriority(meta.priority)&&(errors.testMetadata??={},errors.testMetadata[test.code]??={},errors.testMetadata[test.code].priority={message:`Priority for ${formatCoding(test,!0)} must be one of ${PRIORITY_VALUES.join(", ")}`});let q=meta?.aoeQuestionnaire;if(q){let missing=getMissingRequiredQuestionnaireItems(q,meta.aoeResponses,!!args.specimenCollectedDateTime);missing.length>0&&(errors.testMetadata??={},errors.testMetadata[test.code]??={},errors.testMetadata[test.code].aoeResponses={message:`Missing required AOE responses for ${formatCoding(test,!0)}: ${missing.join(", ")}`})}}if(!isBillTo(args.billingInformation?.billTo))errors.billingInformation??={},args.billingInformation?.billTo?errors.billingInformation.billTo={message:`Bill to must be one of: ${BillToOptions.join(", ")}`}:errors.billingInformation.billTo={message:"Bill to is required"};else if(args.billingInformation.billTo==="insurance"){let coverageCount=args.billingInformation.patientCoverage?.length??0;(coverageCount<1||coverageCount>3)&&(errors.billingInformation??={},errors.billingInformation.patientCoverage={message:"BillingInformation.patientCoverage must contain 1-3 Coverage resources when billing to insurance"})}if(Object.keys(errors).length>0)return errors}var LabOrderValidationError=class extends Error{constructor(errors){super(`Invalid lab order inputs: ${JSON.stringify(errors)}`);__publicField(this,"errors");this.errors=errors}};function createLabOrderBundle(inputs){assertLabOrderInputs(inputs);let{patient,requester,requestingLocation,performingLab,performingLabAccountNumber,selectedTests,testMetadata,diagnoses,specimenCollectedDateTime,billingInformation,orderNotes}=inputs,bundle={resourceType:"Bundle",type:"transaction"},labOrderTempId=tempId(),labOrderExtension=[],bundleEntry=[],subjectReference=isReference2(patient)?patient:createReference(patient),requesterReference=isReference2(requester)?requester:createReference(requester),performerReference=createReference(performingLab),testEntries=[];for(let test of selectedTests){let metadata=testMetadata[test.code],qr;metadata?.aoeResponses&&(qr=deepClone(metadata.aoeResponses),qr.id=tempId(),bundleEntry.push({fullUrl:qr.id,resource:qr,request:{method:"POST",url:"QuestionnaireResponse"}}));let testSR={resourceType:"ServiceRequest",id:tempId(),status:"draft",intent:"order",basedOn:[{reference:labOrderTempId}],subject:subjectReference,requester:requesterReference,performer:[performerReference],category:[{coding:[{system:SNOMED,code:"103693007",display:"Diagnostic procedure"}]}],code:{coding:[test]},priority:metadata?.priority??"routine",note:metadata?.notes?[{authorReference:requesterReference,time:new Date().toISOString(),text:metadata.notes}]:void 0,supportingInfo:qr?[{reference:qr.id}]:void 0};testEntries.push({fullUrl:testSR.id,resource:testSR,request:{method:"POST",url:"ServiceRequest"}})}let specimen;if(specimenCollectedDateTime&&(specimen={resourceType:"Specimen",id:tempId(),subject:subjectReference,collection:{collectedDateTime:specimenCollectedDateTime.toISOString()}},bundleEntry.push({fullUrl:specimen.id,resource:specimen,request:{method:"POST",url:"Specimen"}})),labOrderExtension.push({url:MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO,valueString:billingInformation.billTo}),performingLabAccountNumber&&labOrderExtension.push({url:MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN,valueString:performingLabAccountNumber}),requestingLocation){let requestingLocationRef=isReference2(requestingLocation)?requestingLocation:createReference(requestingLocation);labOrderExtension.push({url:HEALTH_GORILLA_AUTHORIZED_BY_EXT,valueReference:requestingLocationRef})}let insurance;billingInformation.billTo==="insurance"&&(insurance=(billingInformation.patientCoverage??[]).map(coverage=>createReference(coverage)));let labOrder={resourceType:"ServiceRequest",id:labOrderTempId,meta:{profile:[MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE]},extension:labOrderExtension,status:"draft",intent:"order",subject:subjectReference,requester:requesterReference,performer:[performerReference],reasonCode:diagnoses,category:[{coding:[{system:SNOMED,code:"108252007",display:"Laboratory procedure"}]}],code:{coding:selectedTests},insurance,specimen:specimen?[{reference:specimen.id}]:void 0,note:orderNotes?[{authorReference:requesterReference,time:new Date().toISOString(),text:orderNotes}]:void 0};bundleEntry.push({fullUrl:labOrder.id,resource:labOrder,request:{method:"POST",url:"ServiceRequest"}}),bundleEntry.push(...testEntries);for(let entry of bundleEntry)entry.resource&&delete entry.resource.id;return bundle.entry=bundleEntry,bundle}export{BillToOptions,HEALTH_GORILLA_AUTHORIZED_BY_EXT,HEALTH_GORILLA_ENVIRONMENT,HEALTH_GORILLA_SYSTEM,LabOrderValidationError,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN,MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE,MEDPLUM_HEALTH_GORILLA_TENANT_PROFILE,NPI_SYSTEM,PRIORITY_VALUES,assertLabOrderInputs,assertReferenceOfType,createLabOrderBundle,getMissingRequiredQuestionnaireItems,isBillTo,isPriority,isReferenceOfType,isValidLabOrderInputs,normalizeAoeQuestionnaire,questionnaireItemIterator,validateLabOrderInputs};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/aoe.ts", "../../src/constants.ts", "../../src/lab-order.ts", "../../src/types.ts"],
4
4
  "sourcesContent": ["// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { arrayify, getAllQuestionnaireAnswers, getExtensionValue, getTypedPropertyValue } from '@medplum/core';\nimport type {\n Questionnaire,\n QuestionnaireItem,\n QuestionnaireResponse,\n QuestionnaireResponseItemAnswer,\n} from '@medplum/fhirtypes';\n\n/**\n * Edits an AOE Questionnaire from Health Gorilla to make it a valid Questionnaire;\n * most importantly, it sets the linkId to the id if it is not already set.\n * @param aoe - The AOE Questionnaire to normalize.\n * @returns - The normalized input Questionnaire.\n */\nexport function normalizeAoeQuestionnaire(aoe: Questionnaire): Questionnaire {\n if (aoe.item) {\n for (const item of aoe.item) {\n item.linkId = item.linkId ?? item.id;\n item.initial = item.answerOption ? undefined : item.initial;\n }\n }\n\n return aoe;\n}\n\n/**\n * Checks which required items are missing from a QuestionnaireResponse.\n * @param q - The Questionnaire to check against.\n * @param qr - The QuestionnaireResponse to check.\n * @param includeRequiredWhenSpecimenCollected - Whether to require AOE answers when a specimen is collected.\n * @returns An array of linkIds of missing required items.\n */\nexport function getMissingRequiredQuestionnaireItems(\n q: Questionnaire,\n qr: QuestionnaireResponse | undefined,\n includeRequiredWhenSpecimenCollected: boolean\n): string[] {\n const missing: string[] = [];\n const answersByLinkId: Record<string, QuestionnaireResponseItemAnswer[] | undefined> | undefined =\n qr && getAllQuestionnaireAnswers(qr);\n\n //TODO it might be better to make NormalizedAoeQuestionnaire a branded type\n // and specify that as the input type to this function\n for (const item of questionnaireItemIterator(normalizeAoeQuestionnaire(q).item)) {\n if (\n item.required ||\n (includeRequiredWhenSpecimenCollected &&\n getExtensionValue(\n item,\n 'https://www.healthgorilla.com/fhir/StructureDefinition/questionnaire-requiredwhenspecimen'\n ) === true)\n ) {\n const answers = answersByLinkId?.[item.linkId];\n if (answers && answers.length > 0) {\n let hasValue = false;\n for (const answer of answers) {\n const values = arrayify(\n getTypedPropertyValue({ type: 'QuestionnaireResponseItemAnswer', value: answer }, 'value[x]')\n );\n if (values?.some((v) => v.value)) {\n hasValue = true;\n continue;\n }\n }\n\n if (hasValue) {\n continue;\n }\n }\n\n missing.push(item.linkId);\n }\n }\n\n return missing;\n}\n\nexport function* questionnaireItemIterator(item: QuestionnaireItem[] | undefined): Generator<QuestionnaireItem> {\n if (!item) {\n return;\n }\n\n for (const i of item) {\n yield i;\n if (i.item) {\n yield* questionnaireItemIterator(i.item);\n }\n }\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { HTTP_HL7_ORG } from '@medplum/core';\n\nexport const MEDPLUM_HEALTH_GORILLA_TENANT_PROFILE =\n 'https://medplum.com/profiles/integrations/health-gorilla/StructureDefinition/MedplumHealthGorillaTenant';\nexport const MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE =\n 'https://medplum.com/profiles/integrations/health-gorilla/StructureDefinition/MedplumHealthGorillaOrder';\n\nexport const MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO = 'billTo';\nexport const MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN = 'performingLabAccountNumber';\n\nexport const HEALTH_GORILLA_SYSTEM = 'https://www.healthgorilla.com';\nexport const HEALTH_GORILLA_ENVIRONMENT = HEALTH_GORILLA_SYSTEM + '/environment';\nexport const HEALTH_GORILLA_AUTHORIZED_BY_EXT =\n HEALTH_GORILLA_SYSTEM + '/fhir/StructureDefinition/requestgroup-authorizedBy';\n\nexport const NPI_SYSTEM = HTTP_HL7_ORG + '/fhir/sid/us-npi';\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { createReference, deepClone, formatCoding, generateId, isReference, SNOMED } from '@medplum/core';\nimport type {\n Bundle,\n Coverage,\n Extension,\n Location,\n Organization,\n Patient,\n Practitioner,\n QuestionnaireResponse,\n Reference,\n Resource,\n ResourceType,\n ServiceRequest,\n Specimen,\n} from '@medplum/fhirtypes';\nimport { getMissingRequiredQuestionnaireItems } from './aoe';\nimport {\n HEALTH_GORILLA_AUTHORIZED_BY_EXT,\n MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO,\n MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN,\n MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE,\n} from './constants';\nimport type {\n BillingInformation,\n DiagnosisCodeableConcept,\n LabOrderServiceRequest,\n LabOrderTestMetadata,\n LabOrganization,\n TestCoding,\n} from './types';\nimport { BillToOptions, isBillTo, isPriority, PRIORITY_VALUES } from './types';\n\nexport type LabOrderInputs = {\n /** `Patient` the tests are ordered for. This must be a reference to an existing `Patient` resource. */\n patient: Patient | (Reference<Patient> & { reference: string });\n /** The physician who requests diagnostic procedures for the patient and responsible for the order. */\n requester: Practitioner | (Reference<Practitioner> & { reference: string });\n /** For multi-location practices, optionally specify the location from which the order is being placed */\n requestingLocation?: Location | Organization | (Reference<Location | Organization> & { reference: string });\n /** The desired performer for doing the diagnostic testing - laboratory, radiology imaging center, etc. */\n performingLab: LabOrganization;\n /**\n * (optional) Account Number for the performing lab. If not provided, the `HEALTH_GORILLA_SUBTENANT_ACCOUNT_NUMBER`\n * `Project.secret` is used.\n */\n performingLabAccountNumber?: string;\n /** The list of tests ordered within the given order. */\n selectedTests: TestCoding[];\n /** An object mapping the `Coding.code` of each selected test to an `LabOrderTestMetadata` object. */\n testMetadata: Record<string, LabOrderTestMetadata | undefined>;\n /** An explanation or justification for why this diagnostic investigation is being requested in coded or textual form. */\n diagnoses: DiagnosisCodeableConcept[];\n /** (optional) The collection date of the lab order. */\n specimenCollectedDateTime?: Date;\n /** The billing preferences for the order. */\n billingInformation: BillingInformation;\n /** (optional) An order note - any comments that should be included in the requisition. */\n orderNotes?: string;\n};\n\nfunction tempId(): string {\n return 'urn:uuid:' + generateId();\n}\n\n/**\n * A modified type of `LabOrderInputs` that makes every field and sub-field optional and loosens\n * cardinality checks to facilitate typical type signatures of hooks and other state used in\n * React components that call `createLabOrderBundle`. This type is used in conjunction\n * with `validateLabOrderInputs`\n */\nexport type PartialLabOrderInputs = Partial<\n Omit<LabOrderInputs, 'billingInformation' | 'testMetadata'> & {\n testMetadata: Record<string, LabOrderTestMetadata | undefined>;\n billingInformation: Partial<\n Omit<BillingInformation, 'patientCoverage'> & {\n patientCoverage?: Coverage[];\n }\n >;\n }\n>;\n\nexport type InputError = { message: string };\n\nexport type LabOrderInputErrors = {\n patient?: InputError;\n requester?: InputError;\n performingLab?: InputError;\n selectedTests?: InputError;\n testMetadata?: {\n [testCode: string]: {\n priority?: InputError;\n notes?: InputError;\n aoeResponses?: InputError;\n };\n };\n billingInformation?: {\n billTo?: InputError;\n patientCoverage?: InputError;\n };\n};\n\nexport function assertLabOrderInputs(args: PartialLabOrderInputs): asserts args is LabOrderInputs {\n const errors = validateLabOrderInputs(args);\n if (errors) {\n throw new LabOrderValidationError(errors);\n }\n}\n\nexport function isValidLabOrderInputs(args: PartialLabOrderInputs): args is LabOrderInputs {\n return !validateLabOrderInputs(args);\n}\n\nexport function validateLabOrderInputs(args: PartialLabOrderInputs): LabOrderInputErrors | undefined {\n const errors: LabOrderInputErrors = {};\n\n if (!args.patient) {\n errors.patient = { message: 'Patient is required' };\n }\n\n if (!args.requester) {\n errors.requester = { message: 'Requesting Practitioner is required' };\n }\n\n if (!args.performingLab) {\n errors.performingLab = { message: 'Performing Lab is required' };\n }\n\n if (!args.selectedTests || args.selectedTests.length === 0) {\n errors.selectedTests = { message: 'At least one test must be selected' };\n } else {\n for (const test of args.selectedTests) {\n const meta = args.testMetadata?.[test.code];\n\n // priority\n if (meta?.priority && !isPriority(meta.priority)) {\n errors.testMetadata ??= {};\n errors.testMetadata[test.code] ??= {};\n errors.testMetadata[test.code].priority = {\n message: `Priority for ${formatCoding(test, true)} must be one of ${PRIORITY_VALUES.join(', ')}`,\n };\n }\n\n // AOE responses\n const q = meta?.aoeQuestionnaire;\n if (q) {\n const missing = getMissingRequiredQuestionnaireItems(\n q,\n meta.aoeResponses,\n Boolean(args.specimenCollectedDateTime)\n );\n if (missing.length > 0) {\n errors.testMetadata ??= {};\n errors.testMetadata[test.code] ??= {};\n errors.testMetadata[test.code].aoeResponses = {\n message: `Missing required AOE responses for ${formatCoding(test, true)}: ${missing.join(', ')}`,\n };\n }\n }\n }\n }\n\n if (!isBillTo(args.billingInformation?.billTo)) {\n errors.billingInformation ??= {};\n if (!args.billingInformation?.billTo) {\n errors.billingInformation.billTo = { message: 'Bill to is required' };\n } else {\n errors.billingInformation.billTo = { message: `Bill to must be one of: ${BillToOptions.join(', ')}` };\n }\n } else if (args.billingInformation.billTo === 'insurance') {\n const coverageCount = args.billingInformation.patientCoverage?.length ?? 0;\n if (coverageCount < 1 || coverageCount > 3) {\n errors.billingInformation ??= {};\n errors.billingInformation.patientCoverage = {\n message: 'BillingInformation.patientCoverage must contain 1-3 Coverage resources when billing to insurance',\n };\n }\n }\n\n if (Object.keys(errors).length > 0) {\n return errors;\n }\n return undefined;\n}\n\nexport class LabOrderValidationError extends Error {\n readonly errors: LabOrderInputErrors;\n\n constructor(errors: LabOrderInputErrors) {\n super(`Invalid lab order inputs: ${JSON.stringify(errors)}`);\n this.errors = errors;\n }\n}\n\ntype PopulatedBundleEntry = NonNullable<Bundle['entry']> &\n {\n fullUrl: string;\n resource: Resource;\n request: { method: 'POST'; url: ResourceType };\n }[];\n\n/**\n * Prepares a Bundle containing the resources necessary to create a `ServiceRequest` representing\n * a Health Gorilla lab order.\n * @param inputs - An object containing the required fields for creating a lab order bundle\n * @returns A transaction `Bundle` containing the resources necessary to create\n * a `ServiceRequest` representing the Health Gorilla lab order.\n */\nexport function createLabOrderBundle(inputs: PartialLabOrderInputs): Bundle {\n assertLabOrderInputs(inputs);\n\n inputs satisfies LabOrderInputs;\n\n const {\n patient,\n requester,\n requestingLocation,\n performingLab,\n performingLabAccountNumber,\n selectedTests,\n testMetadata,\n diagnoses,\n specimenCollectedDateTime,\n billingInformation,\n orderNotes,\n } = inputs;\n\n const bundle: Bundle = {\n resourceType: 'Bundle',\n type: 'transaction',\n };\n\n const labOrderTempId = tempId();\n const labOrderExtension: Extension[] = [];\n const bundleEntry: PopulatedBundleEntry = [];\n\n const subjectReference = isReference(patient) ? patient : createReference(patient);\n const requesterReference = isReference(requester) ? requester : createReference(requester);\n const performerReference = createReference(performingLab);\n\n const testEntries: PopulatedBundleEntry = [];\n for (const test of selectedTests) {\n const metadata = testMetadata[test.code];\n\n let qr: QuestionnaireResponse | undefined;\n if (metadata?.aoeResponses) {\n qr = deepClone(metadata.aoeResponses);\n qr.id = tempId();\n bundleEntry.push({\n fullUrl: qr.id,\n resource: qr,\n request: { method: 'POST', url: 'QuestionnaireResponse' },\n });\n }\n\n const testSR: ServiceRequest = {\n resourceType: 'ServiceRequest',\n id: tempId(),\n status: 'draft',\n intent: 'order',\n basedOn: [{ reference: labOrderTempId }],\n subject: subjectReference,\n requester: requesterReference,\n performer: [performerReference],\n category: [{ coding: [{ system: SNOMED, code: '103693007', display: 'Diagnostic procedure' }] }],\n code: { coding: [test] },\n priority: metadata?.priority ?? 'routine',\n note: metadata?.notes\n ? [{ authorReference: requesterReference, time: new Date().toISOString(), text: metadata.notes }]\n : undefined,\n supportingInfo: qr ? [{ reference: qr.id }] : undefined,\n };\n\n testEntries.push({\n fullUrl: testSR.id,\n resource: testSR,\n request: { method: 'POST', url: 'ServiceRequest' },\n });\n }\n\n let specimen: Specimen | undefined;\n if (specimenCollectedDateTime) {\n specimen = {\n resourceType: 'Specimen',\n id: tempId(),\n subject: subjectReference,\n collection: { collectedDateTime: specimenCollectedDateTime.toISOString() },\n };\n bundleEntry.push({\n fullUrl: specimen.id,\n resource: specimen,\n request: { method: 'POST', url: 'Specimen' },\n });\n }\n\n labOrderExtension.push({\n url: MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_BILL_TO,\n valueString: billingInformation.billTo,\n });\n\n if (performingLabAccountNumber) {\n labOrderExtension.push({\n url: MEDPLUM_HEALTH_GORILLA_LAB_ORDER_EXTENSION_URL_PERFORMING_LAB_AN,\n valueString: performingLabAccountNumber,\n });\n }\n\n if (requestingLocation) {\n const requestingLocationRef = isReference(requestingLocation)\n ? requestingLocation\n : createReference(requestingLocation);\n\n labOrderExtension.push({\n url: HEALTH_GORILLA_AUTHORIZED_BY_EXT,\n valueReference: requestingLocationRef,\n });\n }\n\n let insurance: Reference<Coverage>[] | undefined;\n if (billingInformation.billTo === 'insurance') {\n insurance = (billingInformation.patientCoverage ?? []).map((coverage) => {\n return createReference(coverage);\n });\n }\n\n const labOrder: LabOrderServiceRequest = {\n resourceType: 'ServiceRequest',\n id: labOrderTempId,\n meta: { profile: [MEDPLUM_HEALTH_GORILLA_LAB_ORDER_PROFILE] },\n extension: labOrderExtension,\n status: 'draft',\n intent: 'order',\n subject: subjectReference,\n requester: requesterReference,\n performer: [performerReference],\n reasonCode: diagnoses,\n category: [{ coding: [{ system: SNOMED, code: '108252007', display: 'Laboratory procedure' }] }],\n // individual test codes are included in the ServcieRequest referenced in supporting Info.\n // TBD what should go in the `code` field of the lab order. Leaving the tests there for now\n // since code is required.\n code: { coding: selectedTests },\n insurance,\n specimen: specimen ? [{ reference: specimen.id }] : undefined,\n note: orderNotes\n ? [{ authorReference: requesterReference, time: new Date().toISOString(), text: orderNotes }]\n : undefined,\n };\n\n bundleEntry.push({\n fullUrl: labOrder.id,\n resource: labOrder,\n request: { method: 'POST', url: 'ServiceRequest' },\n });\n\n bundleEntry.push(...testEntries);\n\n // Remove resource.id to avoid breaking the transaction processing of the urn:uuid:<uuid> temp IDs.\n for (const entry of bundleEntry) {\n if (entry.resource) {\n delete entry.resource.id;\n }\n }\n\n bundle.entry = bundleEntry;\n\n return bundle;\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { isReference } from '@medplum/core';\nimport type {\n CodeableConcept,\n Coding,\n Coverage,\n ExtractResource,\n OperationOutcome,\n Organization,\n Questionnaire,\n QuestionnaireResponse,\n Reference,\n ResourceType,\n ServiceRequest,\n} from '@medplum/fhirtypes';\n\nexport type LabOrderServiceRequest = ServiceRequest & {\n performer: [Reference<LabOrganization>];\n code: CodeableConcept;\n};\n\nexport interface LabOrderTestMetadata {\n /** (optional) This attribute allows to set priority for the given test within the order. Defaults to 'routine' */\n priority?: 'routine' | 'urgent' | 'asap' | 'stat';\n /** (optional) Any notes and comments related to the given test. */\n notes?: string;\n /** The AOE `Questionnaire`, if any, containing Ask at Order Entry (AOE) questions for the test. */\n readonly aoeQuestionnaire?: Questionnaire;\n /**\n * The `QuestionnaireResponse` resource containing answers related to the given diagnostic procedure.\n * If AOE is required for the specified configuration (performer, test, specimen), but missed in the\n * request, then the whole order will be rejected. Only answered AOEs should be included into request.\n */\n aoeResponses?: QuestionnaireResponse;\n}\n\nexport const BillToOptions = ['patient', 'insurance', 'customer-account', 'self'] as const;\nexport type BillTo = (typeof BillToOptions)[number];\n\nexport function isBillTo(value: unknown): value is BillTo {\n if (value === 'patient' || value === 'insurance' || value === 'customer-account' || value === 'self') {\n value satisfies BillTo;\n return true;\n }\n return false;\n}\n\nexport type LabOrganization = Organization & { id: string };\n\nexport type TestCoding = Coding & { code: string };\n\nexport type DiagnosisCodeableConcept = CodeableConcept & {\n coding: (Coding & Required<Pick<Coding, 'system' | 'code'>>)[];\n};\n\nexport type BillingInformation = {\n billTo?: BillTo;\n patientCoverage?: [] | [Coverage] | [Coverage, Coverage] | [Coverage, Coverage, Coverage];\n};\n\nexport const PRIORITY_VALUES = ['routine', 'urgent', 'asap', 'stat'] as const;\n\nexport function isPriority(value: unknown): value is NonNullable<ServiceRequest['priority']> {\n return PRIORITY_VALUES.includes(value as any);\n}\n\nexport type HGAutocompleteBotInput =\n | {\n type: 'lab';\n query: string;\n }\n | {\n type: 'test';\n query: string;\n labId: string;\n }\n | {\n type: 'aoe';\n testCode: Coding;\n };\n\nexport type HGAutocompleteBotResponse =\n | {\n outcome: OperationOutcome;\n type: 'lab';\n result: Organization[];\n }\n | {\n outcome: OperationOutcome;\n type: 'test';\n result: Coding[];\n }\n | {\n outcome: OperationOutcome;\n type: 'aoe';\n result: Questionnaire | undefined;\n }\n | {\n outcome: OperationOutcome;\n type: 'error';\n args: any;\n };\n\nexport function isReferenceOfType<T extends ResourceType>(\n resourceType: T,\n value: unknown\n): value is Reference<ExtractResource<T>> & { reference: string } {\n return isReference(value) && value.reference.startsWith(resourceType + '/');\n}\n\nexport function assertReferenceOfType<T extends ResourceType>(\n resourceType: T,\n value: unknown\n): asserts value is Reference<ExtractResource<T>> {\n if (!isReferenceOfType(resourceType, value)) {\n throw new Error(`Expected reference to be of type ${resourceType}`);\n }\n}\n\nexport type WithId<T> = T & { id: string };\n"],
5
- "mappings": "AAEA,OAAS,SAAU,2BAA4B,kBAAmB,0BAA6B,gBAcxF,SAAS,0BAA0B,IAAmC,CAC3E,GAAI,IAAI,KACN,QAAW,QAAQ,IAAI,KACrB,KAAK,OAAS,KAAK,QAAU,KAAK,GAClC,KAAK,QAAU,KAAK,aAAe,OAAY,KAAK,QAIxD,OAAO,GACT,CASO,SAAS,qCACd,EACA,GACA,qCACU,CACV,IAAM,QAAoB,CAAC,EACrB,gBACJ,IAAM,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ACX,UAAW,CAAC,kBAAkB,EAC9B,WAAY,UACZ,SAAU,CAAC,CAAE,OAAQ,CAAC,CAAE,OAAQ,OAAQ,KAAM,YAAa,QAAS,sBAAuB,CAAC,CAAE,CAAC,EAI/F,KAAM,CAAE,OAAQ,aAAc,EAC9B,UACA,SAAU,SAAW,CAAC,CAAE,UAAW,SAAS,EAAG,CAAC,EAAI,OACpD,KAAM,WACF,CAAC,CAAE,gBAAiB,mBAAoB,KAAM,IAAI,KAAK,EAAE,YAAY,EAAG,KAAM,UAAW,CAAC,EAC1F,MACN,EAEA,YAAY,KAAK,CACf,QAAS,SAAS,GAClB,SAAU,SACV,QAAS,CAAE,OAAQ,OAAQ,IAAK,gBAAiB,CACnD,CAAC,EAED,YAAY,KAAK,GAAG,WAAW,EAG/B,QAAW,SAAS,YACd,MAAM,UACR,OAAO,MAAM,SAAS,GAI1B,cAAO,MAAQ,YAER,MACT",
6
6
  "names": ["isReference", "isReference"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medplum/health-gorilla-core",
3
- "version": "4.5.2",
3
+ "version": "5.0.0",
4
4
  "description": "Medplum Health Gorilla SDK",
5
5
  "homepage": "https://www.medplum.com/",
6
6
  "bugs": {
@@ -42,18 +42,18 @@
42
42
  "test:watch": "vitest watch"
43
43
  },
44
44
  "devDependencies": {
45
- "@medplum/core": "4.5.2",
46
- "@medplum/definitions": "4.5.2",
47
- "@medplum/fhirtypes": "4.5.2",
48
- "@medplum/mock": "4.5.2",
49
- "@types/node": "20.19.23",
50
- "vitest": "4.0.3"
45
+ "@medplum/core": "5.0.0",
46
+ "@medplum/definitions": "5.0.0",
47
+ "@medplum/fhirtypes": "5.0.0",
48
+ "@medplum/mock": "5.0.0",
49
+ "@types/node": "22.18.13",
50
+ "vitest": "4.0.6"
51
51
  },
52
52
  "peerDependencies": {
53
- "@medplum/core": "4.5.2",
54
- "@medplum/fhirtypes": "4.5.2"
53
+ "@medplum/core": "5.0.0",
54
+ "@medplum/fhirtypes": "5.0.0"
55
55
  },
56
56
  "engines": {
57
- "node": "^20.19.0 || >=22.12.0"
57
+ "node": "^22.18.0 || >=24.2.0"
58
58
  }
59
59
  }