@medplum/health-gorilla-core 3.2.27 → 3.2.28

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,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts", "../../src/aoe.ts", "../../src/constants.ts", "../../src/lab-order.ts", "../../src/types.ts"],
4
- "sourcesContent": ["export * from './aoe';\nexport * from './constants';\nexport * from './lab-order';\nexport * from './types';\n", "import { arrayify, getAllQuestionnaireAnswers, getExtensionValue, getTypedPropertyValue } from '@medplum/core';\nimport {\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 required: 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 required.push(item.linkId);\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", "import { 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", "import { createReference, deepClone, formatCoding, generateId, isReference, SNOMED } from '@medplum/core';\nimport {\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 {\n BillingInformation,\n BillToOptions,\n DiagnosisCodeableConcept,\n isBillTo,\n isPriority,\n LabOrderServiceRequest,\n LabOrderTestMetadata,\n LabOrganization,\n PRIORITY_VALUES,\n TestCoding,\n} 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 constructor(readonly errors: LabOrderInputErrors) {\n super(`Invalid lab order inputs: ${JSON.stringify(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", "import { isReference } from '@medplum/core';\nimport {\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\ndeclare const __brand: unique symbol;\nexport type Branded<T, B> = T & { [__brand]: B };\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'] 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') {\n value satisfies BillTo;\n return true;\n }\n return false;\n}\n\nexport type LabOrganization = Organization & { id: string };\n\nexport type TestCoding = Branded<Coding & { code: string }, 'TestCoding'>;\n\nexport type DiagnosisCodeableConcept = Branded<\n CodeableConcept & { coding: (Coding & Required<Pick<Coding, 'system' | 'code'>>)[] },\n 'DiagnosisCodeableConcept'\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,8zCCAA,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,SAAqB,CAAC,EACtB,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,SAAS,KAAK,KAAK,MAAM,EAEzB,IAAM,QAAU,kBAAkB,KAAK,MAAM,EAC7C,GAAI,SAAW,QAAQ,OAAS,EAAG,CACjC,IAAI,SAAW,GACf,QAAW,UAAU,QAInB,MAH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/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",
4
+ "sourcesContent": ["export * from './aoe';\nexport * from './constants';\nexport * from './lab-order';\nexport * from './types';\n", "import { arrayify, getAllQuestionnaireAnswers, getExtensionValue, getTypedPropertyValue } from '@medplum/core';\nimport {\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 required: 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 required.push(item.linkId);\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", "import { 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", "import { createReference, deepClone, formatCoding, generateId, isReference, SNOMED } from '@medplum/core';\nimport {\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 {\n BillingInformation,\n BillToOptions,\n DiagnosisCodeableConcept,\n isBillTo,\n isPriority,\n LabOrderServiceRequest,\n LabOrderTestMetadata,\n LabOrganization,\n PRIORITY_VALUES,\n TestCoding,\n} 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 constructor(readonly errors: LabOrderInputErrors) {\n super(`Invalid lab order inputs: ${JSON.stringify(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", "import { isReference } from '@medplum/core';\nimport {\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'] 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') {\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,8zCCAA,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,SAAqB,CAAC,EACtB,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,SAAS,KAAK,KAAK,MAAM,EAEzB,IAAM,QAAU,kBAAkB,KAAK,MA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E,OAAQ,CAAC,CAAE,OAAQ,oBAAQ,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": ["import_core", "import_core", "import_core"]
7
7
  }
@@ -15,8 +15,6 @@ import { Reference } from '@medplum/fhirtypes';
15
15
  import { ResourceType } from '@medplum/fhirtypes';
16
16
  import { ServiceRequest } from '@medplum/fhirtypes';
17
17
 
18
- declare const __brand: unique symbol;
19
-
20
18
  export declare function assertLabOrderInputs(args: PartialLabOrderInputs): asserts args is LabOrderInputs;
21
19
 
22
20
  export declare function assertReferenceOfType<T extends ResourceType>(resourceType: T, value: unknown): asserts value is Reference<ExtractResource<T>>;
@@ -30,10 +28,6 @@ export declare type BillTo = (typeof BillToOptions)[number];
30
28
 
31
29
  export declare const BillToOptions: readonly ["patient", "insurance", "customer-account"];
32
30
 
33
- export declare type Branded<T, B> = T & {
34
- [__brand]: B;
35
- };
36
-
37
31
  /**
38
32
  * Prepares a Bundle containing the resources necessary to create a `ServiceRequest` representing
39
33
  * a Health Gorilla lab order.
@@ -43,9 +37,9 @@ export declare type Branded<T, B> = T & {
43
37
  */
44
38
  export declare function createLabOrderBundle(inputs: PartialLabOrderInputs): Bundle;
45
39
 
46
- export declare type DiagnosisCodeableConcept = Branded<CodeableConcept & {
40
+ export declare type DiagnosisCodeableConcept = CodeableConcept & {
47
41
  coding: (Coding & Required<Pick<Coding, 'system' | 'code'>>)[];
48
- }, 'DiagnosisCodeableConcept'>;
42
+ };
49
43
 
50
44
  /**
51
45
  * Checks which required items are missing from a QuestionnaireResponse.
@@ -222,9 +216,9 @@ export declare const PRIORITY_VALUES: readonly ["routine", "urgent", "asap", "st
222
216
 
223
217
  export declare function questionnaireItemIterator(item: QuestionnaireItem[] | undefined): Generator<QuestionnaireItem>;
224
218
 
225
- export declare type TestCoding = Branded<Coding & {
219
+ export declare type TestCoding = Coding & {
226
220
  code: string;
227
- }, 'TestCoding'>;
221
+ };
228
222
 
229
223
  export declare function validateLabOrderInputs(args: PartialLabOrderInputs): LabOrderInputErrors | undefined;
230
224
 
@@ -15,8 +15,6 @@ import { Reference } from '@medplum/fhirtypes';
15
15
  import { ResourceType } from '@medplum/fhirtypes';
16
16
  import { ServiceRequest } from '@medplum/fhirtypes';
17
17
 
18
- declare const __brand: unique symbol;
19
-
20
18
  export declare function assertLabOrderInputs(args: PartialLabOrderInputs): asserts args is LabOrderInputs;
21
19
 
22
20
  export declare function assertReferenceOfType<T extends ResourceType>(resourceType: T, value: unknown): asserts value is Reference<ExtractResource<T>>;
@@ -30,10 +28,6 @@ export declare type BillTo = (typeof BillToOptions)[number];
30
28
 
31
29
  export declare const BillToOptions: readonly ["patient", "insurance", "customer-account"];
32
30
 
33
- export declare type Branded<T, B> = T & {
34
- [__brand]: B;
35
- };
36
-
37
31
  /**
38
32
  * Prepares a Bundle containing the resources necessary to create a `ServiceRequest` representing
39
33
  * a Health Gorilla lab order.
@@ -43,9 +37,9 @@ export declare type Branded<T, B> = T & {
43
37
  */
44
38
  export declare function createLabOrderBundle(inputs: PartialLabOrderInputs): Bundle;
45
39
 
46
- export declare type DiagnosisCodeableConcept = Branded<CodeableConcept & {
40
+ export declare type DiagnosisCodeableConcept = CodeableConcept & {
47
41
  coding: (Coding & Required<Pick<Coding, 'system' | 'code'>>)[];
48
- }, 'DiagnosisCodeableConcept'>;
42
+ };
49
43
 
50
44
  /**
51
45
  * Checks which required items are missing from a QuestionnaireResponse.
@@ -222,9 +216,9 @@ export declare const PRIORITY_VALUES: readonly ["routine", "urgent", "asap", "st
222
216
 
223
217
  export declare function questionnaireItemIterator(item: QuestionnaireItem[] | undefined): Generator<QuestionnaireItem>;
224
218
 
225
- export declare type TestCoding = Branded<Coding & {
219
+ export declare type TestCoding = Coding & {
226
220
  code: string;
227
- }, 'TestCoding'>;
221
+ };
228
222
 
229
223
  export declare function validateLabOrderInputs(args: PartialLabOrderInputs): LabOrderInputErrors | undefined;
230
224
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/aoe.ts", "../../src/constants.ts", "../../src/lab-order.ts", "../../src/types.ts"],
4
- "sourcesContent": ["import { arrayify, getAllQuestionnaireAnswers, getExtensionValue, getTypedPropertyValue } from '@medplum/core';\nimport {\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 required: 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 required.push(item.linkId);\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", "import { 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", "import { createReference, deepClone, formatCoding, generateId, isReference, SNOMED } from '@medplum/core';\nimport {\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 {\n BillingInformation,\n BillToOptions,\n DiagnosisCodeableConcept,\n isBillTo,\n isPriority,\n LabOrderServiceRequest,\n LabOrderTestMetadata,\n LabOrganization,\n PRIORITY_VALUES,\n TestCoding,\n} 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 constructor(readonly errors: LabOrderInputErrors) {\n super(`Invalid lab order inputs: ${JSON.stringify(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", "import { isReference } from '@medplum/core';\nimport {\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\ndeclare const __brand: unique symbol;\nexport type Branded<T, B> = T & { [__brand]: B };\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'] 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') {\n value satisfies BillTo;\n return true;\n }\n return false;\n}\n\nexport type LabOrganization = Organization & { id: string };\n\nexport type TestCoding = Branded<Coding & { code: string }, 'TestCoding'>;\n\nexport type DiagnosisCodeableConcept = Branded<\n CodeableConcept & { coding: (Coding & Required<Pick<Coding, 'system' | 'code'>>)[] },\n 'DiagnosisCodeableConcept'\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": "AAAA,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,SAAqB,CAAC,EACtB,QAAoB,CAAC,EACrB,gBACJ,IAAM,2BAA2B,EAAE,EAIrC,QAAW,QAAQ,0BAA0B,0BAA0B,CAA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iBACd,GAAI,eACJ,KAAM,CAAE,QAAS,CAAC,wCAAwC,CAAE,EAC5D,UAAW,kBACX,OAAQ,QACR,OAAQ,QACR,QAAS,iBACT,UAAW,mBACX,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",
4
+ "sourcesContent": ["import { arrayify, getAllQuestionnaireAnswers, getExtensionValue, getTypedPropertyValue } from '@medplum/core';\nimport {\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 required: 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 required.push(item.linkId);\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", "import { 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", "import { createReference, deepClone, formatCoding, generateId, isReference, SNOMED } from '@medplum/core';\nimport {\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 {\n BillingInformation,\n BillToOptions,\n DiagnosisCodeableConcept,\n isBillTo,\n isPriority,\n LabOrderServiceRequest,\n LabOrderTestMetadata,\n LabOrganization,\n PRIORITY_VALUES,\n TestCoding,\n} 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 constructor(readonly errors: LabOrderInputErrors) {\n super(`Invalid lab order inputs: ${JSON.stringify(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", "import { isReference } from '@medplum/core';\nimport {\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'] 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') {\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": "AAAA,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,SAAqB,CAAC,E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AAmB,iBAAmB,CAAC,GAAG,IAAK,UACnD,gBAAgB,QAAQ,CAChC,GAGH,IAAM,SAAmC,CACvC,aAAc,iBACd,GAAI,eACJ,KAAM,CAAE,QAAS,CAAC,wCAAwC,CAAE,EAC5D,UAAW,kBACX,OAAQ,QACR,OAAQ,QACR,QAAS,iBACT,UAAW,mBACX,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": "3.2.27",
3
+ "version": "3.2.28",
4
4
  "description": "Medplum Health Gorilla SDK",
5
5
  "homepage": "https://www.medplum.com/",
6
6
  "bugs": {
@@ -41,16 +41,16 @@
41
41
  "test:watch": "vitest watch"
42
42
  },
43
43
  "devDependencies": {
44
- "@medplum/core": "3.2.27",
45
- "@medplum/definitions": "3.2.27",
46
- "@medplum/fhirtypes": "3.2.27",
47
- "@medplum/mock": "3.2.27",
48
- "@types/node": "22.10.2",
44
+ "@medplum/core": "3.2.28",
45
+ "@medplum/definitions": "3.2.28",
46
+ "@medplum/fhirtypes": "3.2.28",
47
+ "@medplum/mock": "3.2.28",
48
+ "@types/node": "22.10.6",
49
49
  "vitest": "2.1.8"
50
50
  },
51
51
  "peerDependencies": {
52
- "@medplum/core": "3.2.27",
53
- "@medplum/fhirtypes": "3.2.27"
52
+ "@medplum/core": "3.2.28",
53
+ "@medplum/fhirtypes": "3.2.28"
54
54
  },
55
55
  "engines": {
56
56
  "node": ">=18.0.0"