Skip to content

Commit

Permalink
feat(ihe): fix ihe gw results are incomplete for dr
Browse files Browse the repository at this point in the history
Refs: #1667
Signed-off-by: Jonah Kaye <[email protected]>
  • Loading branch information
jonahkaye committed Jun 20, 2024
1 parent 70f6898 commit 4eb3b3d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import { makeOrganization } from "../../../../domain/medical/__tests__/organizat
import { makePatient } from "../../../../domain/medical/__tests__/patient";
import { Facility, FacilityType } from "../../../../domain/medical/facility";
import { HieInitiator } from "../../../hie/get-hie-initiator";
import {
createOutboundDocumentRetrievalReqs,
maxDocRefsPerDocRetrievalRequest,
} from "../create-outbound-document-retrieval-req";
import { createOutboundDocumentRetrievalReqs } from "../create-outbound-document-retrieval-req";
import { defaultDocRefsPerRequest } from "@metriport/core/external/carequality/ihe-gateway-v2/gateways";
import { makeDocumentReferenceWithMetriportId } from "./make-document-reference-with-metriport-id";
import { makeOutboundDocumentQueryResp, makeXcaGateway } from "./shared";
import {
epicOidPrefix,
surescriptsOid,
} from "@metriport/core/external/carequality/ihe-gateway-v2/gateways";

let requestId: string;
let facilityId: string;
Expand Down Expand Up @@ -67,7 +69,7 @@ describe("outboundDocumentRetrievalRequest", () => {
it("returns 1 req with 6 doc refs when we have an epic gw", async () => {
const outboundDocumentQueryResps: OutboundDocumentQueryResp[] = [
makeOutboundDocumentQueryResp({
gateway: makeXcaGateway({ homeCommunityId: "1.2.840.114350.1.13" }),
gateway: makeXcaGateway({ homeCommunityId: epicOidPrefix }),
documentReference: [
makeDocumentReferenceWithMetriportId(),
makeDocumentReferenceWithMetriportId(),
Expand All @@ -92,7 +94,7 @@ describe("outboundDocumentRetrievalRequest", () => {
it("returns 2 req with 11 doc refs when we have an epic gw", async () => {
const outboundDocumentQueryResps: OutboundDocumentQueryResp[] = [
makeOutboundDocumentQueryResp({
gateway: makeXcaGateway({ homeCommunityId: "1.2.840.114350.1.13" }),
gateway: makeXcaGateway({ homeCommunityId: epicOidPrefix }),
documentReference: [
makeDocumentReferenceWithMetriportId(),
makeDocumentReferenceWithMetriportId(),
Expand Down Expand Up @@ -120,6 +122,28 @@ describe("outboundDocumentRetrievalRequest", () => {
expect(res[1].documentReference.length).toEqual(1);
});

it("returns 1 req with 6 doc refs when we have an epic gw", async () => {
const outboundDocumentQueryResps: OutboundDocumentQueryResp[] = [
makeOutboundDocumentQueryResp({
gateway: makeXcaGateway({ homeCommunityId: surescriptsOid }),
documentReference: [
makeDocumentReferenceWithMetriportId(),
makeDocumentReferenceWithMetriportId(),
],
}),
];
const res: OutboundDocumentRetrievalReq[] = createOutboundDocumentRetrievalReqs({
patient,
requestId,
initiator,
outboundDocumentQueryResults: outboundDocumentQueryResps,
});
expect(res).toBeTruthy();
expect(res.length).toEqual(2);
expect(res[0].documentReference.length).toEqual(1);
expect(res[1].documentReference.length).toEqual(1);
});

it("returns one req when doc refs within limit", async () => {
const outboundDocumentQueryResps: OutboundDocumentQueryResp[] = [
makeOutboundDocumentQueryResp({
Expand Down Expand Up @@ -150,7 +174,7 @@ describe("outboundDocumentRetrievalRequest", () => {
const outboundDocumentQueryResps: OutboundDocumentQueryResp[] = [
makeOutboundDocumentQueryResp({
gateway: makeXcaGateway({ homeCommunityId }),
documentReference: [...Array(maxDocRefsPerDocRetrievalRequest + 1).keys()].map(() =>
documentReference: [...Array(defaultDocRefsPerRequest + 1).keys()].map(() =>
makeDocumentReferenceWithMetriportId({ homeCommunityId })
),
}),
Expand All @@ -169,7 +193,7 @@ describe("outboundDocumentRetrievalRequest", () => {
const outboundDocumentQueryResps: OutboundDocumentQueryResp[] = [
makeOutboundDocumentQueryResp({
gateway: makeXcaGateway({ homeCommunityId }),
documentReference: [...Array(maxDocRefsPerDocRetrievalRequest * 2 + 1).keys()].map(() =>
documentReference: [...Array(defaultDocRefsPerRequest * 2 + 1).keys()].map(() =>
makeDocumentReferenceWithMetriportId({ homeCommunityId })
),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import {
OutboundDocumentQueryResp,
OutboundDocumentRetrievalReq,
} from "@metriport/ihe-gateway-sdk";
import {
isEpicGateway,
maxDocRefsPerEpicDocRetrievalRequest,
} from "@metriport/core/external/carequality/ihe-gateway-v2/gateways";
import { getGatewaySpecificDocRefsPerRequest } from "@metriport/core/external/carequality/ihe-gateway-v2/gateways";
import { v4 as uuidv4 } from "uuid";

import dayjs from "dayjs";
Expand All @@ -17,7 +14,6 @@ import { createPurposeOfUse, getSystemUserName, isGWValid } from "../shared";

const SUBJECT_ROLE_CODE = "106331006";
const SUBJECT_ROLE_DISPLAY = "Administrative AND/OR managerial worker";
export const maxDocRefsPerDocRetrievalRequest = 5;

export function createOutboundDocumentRetrievalReqs({
requestId,
Expand Down Expand Up @@ -66,9 +62,7 @@ export function createOutboundDocumentRetrievalReqs({
},
};

const docRefsPerRequest = isEpicGateway(gateway)
? maxDocRefsPerEpicDocRetrievalRequest
: maxDocRefsPerDocRetrievalRequest;
const docRefsPerRequest = getGatewaySpecificDocRefsPerRequest(gateway);
const docRefChunks = chunk(documentReference, docRefsPerRequest);
const request: OutboundDocumentRetrievalReq[] = docRefChunks.map(chunk => {
return {
Expand Down
22 changes: 15 additions & 7 deletions packages/core/src/external/carequality/ihe-gateway-v2/gateways.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const specialNamespaceRequiredUrl =
const pointClickCareOid = "2.16.840.1.113883.3.6448";
const redoxOid = "2.16.840.1.113883.3.6147.458";
const redoxGatewayOid = "2.16.840.1.113883.3.6147.458.2";
const surescriptsOid = "2.16.840.1.113883.3.2054.2.1.1";
export const surescriptsOid = "2.16.840.1.113883.3.2054.2.1.1";
export const epicOidPrefix = "1.2.840.114350.1.13";

/*
* These gateways only accept a single document reference per request.
Expand All @@ -33,8 +34,19 @@ const gatewaysThatAcceptOneDocRefPerRequest = [
surescriptsOid,
];

const epicOidPrefix = "1.2.840.114350.1.13";
export const maxDocRefsPerEpicDocRetrievalRequest = 10;
const docRefsPerRequestByGateway: Record<string, number> = {
[pointClickCareOid]: 1,
[redoxOid]: 1,
[redoxGatewayOid]: 1,
[surescriptsOid]: 1,
[epicOidPrefix]: 10,
};

export const defaultDocRefsPerRequest = 5;

export function getGatewaySpecificDocRefsPerRequest(gateway: XCAGateway): number {
return docRefsPerRequestByGateway[gateway.homeCommunityId] || defaultDocRefsPerRequest;
}

/*
* These gateways require a urn:uuid prefix before document Unique ids formatted as lowercase uuids
Expand Down Expand Up @@ -85,7 +97,3 @@ export function requiresUrnInSoapBody(gateway: XCPDGateway): boolean {
export function requiresOnlyOneDocRefPerRequest(gateway: XCAGateway): boolean {
return gatewaysThatAcceptOneDocRefPerRequest.includes(gateway.homeCommunityId);
}

export function isEpicGateway(gateway: XCAGateway): boolean {
return gateway.homeCommunityId.startsWith(epicOidPrefix);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dayjs from "dayjs";
import { chunk } from "lodash";
import { XMLBuilder } from "fast-xml-parser";
import { OutboundDocumentRetrievalReq, XCAGateway } from "@metriport/ihe-gateway-sdk";
import { createSecurityHeader } from "../../../saml/security/security-header";
Expand All @@ -8,17 +7,10 @@ import { SamlCertsAndKeys } from "../../../saml/security/types";
import { namespaces, expiresIn } from "../../../constants";
import { ORGANIZATION_NAME_DEFAULT as metriportOrganization, replyTo } from "../../../../shared";
import { wrapIdInUrnUuid, wrapIdInUrnOid } from "../../../../../../util/urn";
import {
requiresOnlyOneDocRefPerRequest,
getHomeCommunityId,
getDocumentUniqueIdFunctionByGateway,
} from "../../../gateways";
import { getHomeCommunityId, getDocumentUniqueIdFunctionByGateway } from "../../../gateways";

const action = "urn:ihe:iti:2007:CrossGatewayRetrieve";

const minDocumentReferencesPerDrRequest = 1;
const maxDocumentReferencesPerDrRequest = 10;

export type SignedDrRequest = {
gateway: XCAGateway;
signedRequest: string;
Expand Down Expand Up @@ -121,22 +113,11 @@ export function createAndSignBulkDRRequests({
const signedRequests: SignedDrRequest[] = [];

for (const bodyData of bulkBodyData) {
const documentReferencesPerRequest = requiresOnlyOneDocRefPerRequest(bodyData.gateway)
? minDocumentReferencesPerDrRequest
: maxDocumentReferencesPerDrRequest;
const documentReferences = bodyData.documentReference;
const chunks = chunk(documentReferences, documentReferencesPerRequest);
chunks.forEach(docRefs => {
const chunkedBodyData = {
...bodyData,
documentReference: docRefs,
};
const signedRequest = createAndSignDRRequest(chunkedBodyData, samlCertsAndKeys);
signedRequests.push({
gateway: bodyData.gateway,
signedRequest,
outboundRequest: chunkedBodyData,
});
const signedRequest = createAndSignDRRequest(bodyData, samlCertsAndKeys);
signedRequests.push({
gateway: bodyData.gateway,
signedRequest,
outboundRequest: bodyData,
});
}

Expand Down

0 comments on commit 4eb3b3d

Please sign in to comment.