-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into 1040-alb-behind-api-nlb_1
- Loading branch information
Showing
52 changed files
with
746 additions
and
628 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@metriport/api-sdk", | ||
"version": "9.0.1", | ||
"version": "9.0.2-alpha.0", | ||
"description": "Metriport helps you access and manage health and medical data, through a single open source API.", | ||
"author": "Metriport Inc. <[email protected]>", | ||
"homepage": "https://metriport.com/", | ||
|
@@ -57,9 +57,9 @@ | |
}, | ||
"dependencies": { | ||
"@medplum/fhirtypes": "^2.0.32", | ||
"@metriport/commonwell-sdk": "^4.15.14", | ||
"@metriport/shared": "^0.9.7", | ||
"axios": "^1.3.4", | ||
"@metriport/commonwell-sdk": "^4.15.15-alpha.0", | ||
"@metriport/shared": "^0.9.8-alpha.0", | ||
"axios": "^1.4.0", | ||
"dayjs": "^1.11.7", | ||
"dotenv": "^16.3.1", | ||
"zod": "^3.22.1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,11 @@ | ||
import { DocumentReference } from "@medplum/fhirtypes"; | ||
import { chunk } from "lodash"; | ||
import { capture } from "../../../shared/notifications"; | ||
import { makeFhirApi } from "../api/api-factory"; | ||
import { | ||
isoDateToFHIRDateQueryFrom, | ||
isoDateToFHIRDateQueryTo, | ||
} from "@metriport/core/external/fhir/shared/index"; | ||
import { getDocuments } from "@metriport/core/external/fhir/document/get-documents"; | ||
|
||
export async function getDocumentsFromFHIR({ | ||
cxId, | ||
patientId, | ||
from, | ||
to, | ||
documentIds, | ||
}: { | ||
cxId: string; | ||
patientId?: string | string[]; | ||
from?: string; | ||
to?: string; | ||
documentIds?: string[]; | ||
}): Promise<DocumentReference[]> { | ||
try { | ||
const api = makeFhirApi(cxId); | ||
const docs: DocumentReference[] = []; | ||
const chunksDocIds = documentIds && documentIds.length > 0 ? chunk(documentIds, 150) : [[]]; | ||
|
||
for (const docIds of chunksDocIds) { | ||
const filtersAsStr = getFilters({ patientId, documentIds: docIds, from, to }); | ||
for await (const page of api.searchResourcePages("DocumentReference", filtersAsStr)) { | ||
docs.push(...page); | ||
} | ||
} | ||
return docs; | ||
} catch (error) { | ||
const msg = `Error getting documents from FHIR server`; | ||
console.log(`${msg} - patientId: ${patientId}, error: ${error}`); | ||
capture.message(msg, { extra: { patientId, error }, level: "error" }); | ||
throw error; | ||
} | ||
} | ||
|
||
export function getFilters({ | ||
patientId: patientIdParam, | ||
documentIds = [], | ||
from, | ||
to, | ||
}: { | ||
patientId?: string | string[]; | ||
documentIds?: string[]; | ||
from?: string; | ||
to?: string; | ||
} = {}) { | ||
const filters = new URLSearchParams(); | ||
const patientIds = Array.isArray(patientIdParam) ? patientIdParam : [patientIdParam]; | ||
const patientIdsFiltered = patientIds.flatMap(id => | ||
id && id.trim().length > 0 ? id.trim() : [] | ||
); | ||
patientIdsFiltered.length && filters.append("patient", patientIdsFiltered.join(",")); | ||
documentIds.length && filters.append(`_id`, documentIds.join(",")); | ||
from && filters.append("date", isoDateToFHIRDateQueryFrom(from)); | ||
to && filters.append("date", isoDateToFHIRDateQueryTo(to)); | ||
const filtersAsStr = filters.toString(); | ||
return filtersAsStr; | ||
/** | ||
* @deprecated Use `getDocuments()` from `@metriport/core/external/fhir/document/get-documents` instead. | ||
*/ | ||
export async function getDocumentsFromFHIR( | ||
...params: Parameters<typeof getDocuments> | ||
): Promise<DocumentReference[]> { | ||
return getDocuments(...params); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.