@medplum/health-gorilla-core 4.4.0 → 4.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +176 -0
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/cjs/index.d.ts +16 -16
- package/dist/esm/index.d.ts +16 -16
- package/dist/esm/index.mjs.map +2 -2
- package/package.json +8 -8
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -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": ["// 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 {\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 {\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 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 {\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,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,CAC1B,CAGF,OAAO,OACT,CAEO,SAAU,0BAA0B,KAAqE,CAC9G,GAAK,KAIL,QAAW,KAAK,KACd,MAAM,EACF,EAAE,OACJ,MAAO,0BAA0B,EAAE,IAAI,EAG7C,CCxFA,IAAAA,aAA6B,yBAEhB,sCACX,0GACW,yCACX,yGAEW,uDAAyD,SACzD,iEAAmE,6BAEnE,sBAAwB,gCACxB,2BAA6B,sBAAwB,eACrD,iCACX,sBAAwB,sDAEb,WAAa,0BAAe,mBCfzC,IAAAC,aAA0F,yBCA1F,IAAAC,aAA4B,yBAmCf,cAAgB,CAAC,UAAW,YAAa,kBAAkB,EAGjE,SAAS,SAAS,MAAiC,CACxD,OAAI,QAAU,WAAa,QAAU,aAAe,QAAU,kBAKhE,CAeO,IAAM,gBAAkB,CAAC,UAAW,SAAU,OAAQ,MAAM,EAE5D,SAAS,WAAW,MAAkE,CAC3F,OAAO,gBAAgB,SAAS,KAAY,CAC9C,CAuCO,SAAS,kBACd,aACA,MACgE,CAChE,SAAO,0BAAY,KAAK,GAAK,MAAM,UAAU,WAAW,aAAe,GAAG,CAC5E,CAEO,SAAS,sBACd,aACA,MACgD,CAChD,GAAI,CAAC,kBAAkB,aAAc,KAAK,EACxC,MAAM,IAAI,MAAM,oCAAoC,YAAY,EAAE,CAEtE,
|
|
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'] 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,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,CAC1B,CAGF,OAAO,OACT,CAEO,SAAU,0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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
|
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { Bundle } from '@medplum/fhirtypes';
|
|
2
|
-
import { CodeableConcept } from '@medplum/fhirtypes';
|
|
3
|
-
import { Coding } from '@medplum/fhirtypes';
|
|
4
|
-
import { Coverage } from '@medplum/fhirtypes';
|
|
5
|
-
import { ExtractResource } from '@medplum/fhirtypes';
|
|
6
|
-
import { Location as Location_2 } from '@medplum/fhirtypes';
|
|
7
|
-
import { OperationOutcome } from '@medplum/fhirtypes';
|
|
8
|
-
import { Organization } from '@medplum/fhirtypes';
|
|
9
|
-
import { Patient } from '@medplum/fhirtypes';
|
|
10
|
-
import { Practitioner } from '@medplum/fhirtypes';
|
|
11
|
-
import { Questionnaire } from '@medplum/fhirtypes';
|
|
12
|
-
import { QuestionnaireItem } from '@medplum/fhirtypes';
|
|
13
|
-
import { QuestionnaireResponse } from '@medplum/fhirtypes';
|
|
14
|
-
import { Reference } from '@medplum/fhirtypes';
|
|
15
|
-
import { ResourceType } from '@medplum/fhirtypes';
|
|
16
|
-
import { ServiceRequest } from '@medplum/fhirtypes';
|
|
1
|
+
import type { Bundle } from '@medplum/fhirtypes';
|
|
2
|
+
import type { CodeableConcept } from '@medplum/fhirtypes';
|
|
3
|
+
import type { Coding } from '@medplum/fhirtypes';
|
|
4
|
+
import type { Coverage } from '@medplum/fhirtypes';
|
|
5
|
+
import type { ExtractResource } from '@medplum/fhirtypes';
|
|
6
|
+
import type { Location as Location_2 } from '@medplum/fhirtypes';
|
|
7
|
+
import type { OperationOutcome } from '@medplum/fhirtypes';
|
|
8
|
+
import type { Organization } from '@medplum/fhirtypes';
|
|
9
|
+
import type { Patient } from '@medplum/fhirtypes';
|
|
10
|
+
import type { Practitioner } from '@medplum/fhirtypes';
|
|
11
|
+
import type { Questionnaire } from '@medplum/fhirtypes';
|
|
12
|
+
import type { QuestionnaireItem } from '@medplum/fhirtypes';
|
|
13
|
+
import type { QuestionnaireResponse } from '@medplum/fhirtypes';
|
|
14
|
+
import type { Reference } from '@medplum/fhirtypes';
|
|
15
|
+
import type { ResourceType } from '@medplum/fhirtypes';
|
|
16
|
+
import type { ServiceRequest } from '@medplum/fhirtypes';
|
|
17
17
|
|
|
18
18
|
export declare function assertLabOrderInputs(args: PartialLabOrderInputs): asserts args is LabOrderInputs;
|
|
19
19
|
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { Bundle } from '@medplum/fhirtypes';
|
|
2
|
-
import { CodeableConcept } from '@medplum/fhirtypes';
|
|
3
|
-
import { Coding } from '@medplum/fhirtypes';
|
|
4
|
-
import { Coverage } from '@medplum/fhirtypes';
|
|
5
|
-
import { ExtractResource } from '@medplum/fhirtypes';
|
|
6
|
-
import { Location as Location_2 } from '@medplum/fhirtypes';
|
|
7
|
-
import { OperationOutcome } from '@medplum/fhirtypes';
|
|
8
|
-
import { Organization } from '@medplum/fhirtypes';
|
|
9
|
-
import { Patient } from '@medplum/fhirtypes';
|
|
10
|
-
import { Practitioner } from '@medplum/fhirtypes';
|
|
11
|
-
import { Questionnaire } from '@medplum/fhirtypes';
|
|
12
|
-
import { QuestionnaireItem } from '@medplum/fhirtypes';
|
|
13
|
-
import { QuestionnaireResponse } from '@medplum/fhirtypes';
|
|
14
|
-
import { Reference } from '@medplum/fhirtypes';
|
|
15
|
-
import { ResourceType } from '@medplum/fhirtypes';
|
|
16
|
-
import { ServiceRequest } from '@medplum/fhirtypes';
|
|
1
|
+
import type { Bundle } from '@medplum/fhirtypes';
|
|
2
|
+
import type { CodeableConcept } from '@medplum/fhirtypes';
|
|
3
|
+
import type { Coding } from '@medplum/fhirtypes';
|
|
4
|
+
import type { Coverage } from '@medplum/fhirtypes';
|
|
5
|
+
import type { ExtractResource } from '@medplum/fhirtypes';
|
|
6
|
+
import type { Location as Location_2 } from '@medplum/fhirtypes';
|
|
7
|
+
import type { OperationOutcome } from '@medplum/fhirtypes';
|
|
8
|
+
import type { Organization } from '@medplum/fhirtypes';
|
|
9
|
+
import type { Patient } from '@medplum/fhirtypes';
|
|
10
|
+
import type { Practitioner } from '@medplum/fhirtypes';
|
|
11
|
+
import type { Questionnaire } from '@medplum/fhirtypes';
|
|
12
|
+
import type { QuestionnaireItem } from '@medplum/fhirtypes';
|
|
13
|
+
import type { QuestionnaireResponse } from '@medplum/fhirtypes';
|
|
14
|
+
import type { Reference } from '@medplum/fhirtypes';
|
|
15
|
+
import type { ResourceType } from '@medplum/fhirtypes';
|
|
16
|
+
import type { ServiceRequest } from '@medplum/fhirtypes';
|
|
17
17
|
|
|
18
18
|
export declare function assertLabOrderInputs(args: PartialLabOrderInputs): asserts args is LabOrderInputs;
|
|
19
19
|
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -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": ["// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { 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 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 {\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 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 {\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": "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,2BAA2B,EAAE,EAIrC,QAAW,QAAQ,0BAA0B,0BAA0B,CAAC,EAAE,IAAI,EAC5E,GACE,KAAK,UACJ,sCACC,kBACE,KACA,2FACF,IAAM,GACR,CACA,IAAM,QAAU,kBAAkB,KAAK,MAAM,EAC7C,GAAI,SAAW,QAAQ,OAAS,EAAG,CACjC,IAAI,SAAW,GACf,QAAW,UAAU,QAInB,GAHe,SACb,sBAAsB,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,CAC1B,CAGF,OAAO,OACT,CAEO,SAAU,0BAA0B,KAAqE,CAC9G,GAAK,KAIL,QAAW,KAAK,KACd,MAAM,EACF,EAAE,OACJ,MAAO,0BAA0B,EAAE,IAAI,EAG7C,CCxFA,OAAS,iBAAoB,gBAEtB,IAAM,sCACX,0GACW,yCACX,yGAEW,uDAAyD,SACzD,iEAAmE,6BAEnE,sBAAwB,gCACxB,2BAA6B,sBAAwB,eACrD,iCACX,sBAAwB,sDAEb,WAAa,aAAe,mBCfzC,OAAS,gBAAiB,UAAW,aAAc,WAAY,eAAAA,aAAa,WAAc,gBCA1F,OAAS,gBAAmB,gBAmCrB,IAAM,cAAgB,CAAC,UAAW,YAAa,kBAAkB,EAGjE,SAAS,SAAS,MAAiC,CACxD,OAAI,QAAU,WAAa,QAAU,aAAe,QAAU,kBAKhE,CAeO,IAAM,gBAAkB,CAAC,UAAW,SAAU,OAAQ,MAAM,EAE5D,SAAS,WAAW,MAAkE,CAC3F,OAAO,gBAAgB,SAAS,KAAY,CAC9C,CAuCO,SAAS,kBACd,aACA,MACgE,CAChE,OAAO,YAAY,KAAK,GAAK,MAAM,UAAU,WAAW,aAAe,GAAG,CAC5E,CAEO,SAAS,sBACd,aACA,MACgD,CAChD,GAAI,CAAC,kBAAkB,aAAc,KAAK,EACxC,MAAM,IAAI,MAAM,oCAAoC,YAAY,EAAE,CAEtE,
|
|
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'] 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": "AAEA,OAAS,SAAU,2BAA4B,kBAAmB,0BAA6B,gBAcxF,SAA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,CACtB,IAAM,sBAAwBA,aAAY,kBAAkB,EACxD,mBACA,gBAAgB,kBAAkB,EAEtC,kBAAkB,KAAK,CACrB,IAAK,iCACL,eAAgB,qBAClB,CAAC,CACH,CAEA,IAAI,UACA,mBAAmB,SAAW,cAChC,WAAa,mBAAmB,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": "4.4.
|
|
3
|
+
"version": "4.4.2",
|
|
4
4
|
"description": "Medplum Health Gorilla SDK",
|
|
5
5
|
"homepage": "https://www.medplum.com/",
|
|
6
6
|
"bugs": {
|
|
@@ -42,16 +42,16 @@
|
|
|
42
42
|
"test:watch": "vitest watch"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@medplum/core": "4.4.
|
|
46
|
-
"@medplum/definitions": "4.4.
|
|
47
|
-
"@medplum/fhirtypes": "4.4.
|
|
48
|
-
"@medplum/mock": "4.4.
|
|
49
|
-
"@types/node": "20.19.
|
|
45
|
+
"@medplum/core": "4.4.2",
|
|
46
|
+
"@medplum/definitions": "4.4.2",
|
|
47
|
+
"@medplum/fhirtypes": "4.4.2",
|
|
48
|
+
"@medplum/mock": "4.4.2",
|
|
49
|
+
"@types/node": "20.19.19",
|
|
50
50
|
"vitest": "3.2.4"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@medplum/core": "4.4.
|
|
54
|
-
"@medplum/fhirtypes": "4.4.
|
|
53
|
+
"@medplum/core": "4.4.2",
|
|
54
|
+
"@medplum/fhirtypes": "4.4.2"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": "^20.19.0 || >=22.12.0"
|