-
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 pull request #2232 from metriport/develop
RELEASE 2024_06_07 IHE V2
- Loading branch information
Showing
17 changed files
with
297 additions
and
62 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/core/src/external/carequality/ihe-gateway-v2/monitor/__tests__/store.test.ts
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { buildIheResponseKey } from "../store"; | ||
|
||
it("should construct the correct file path and upload the file", async () => { | ||
const cxId = "cxId"; | ||
const patientId = "patientId"; | ||
const requestId = "requestId"; | ||
const oid = "oid"; | ||
const timestamp = "2024-05-01T00:00:00"; | ||
const key = buildIheResponseKey({ | ||
type: "xcpd", | ||
cxId, | ||
patientId, | ||
requestId, | ||
oid, | ||
timestamp, | ||
}); | ||
expect(key).toEqual(`${cxId}/${patientId}/xcpd/${requestId}_2024-05-01/${oid}.xml`); | ||
}); |
139 changes: 139 additions & 0 deletions
139
packages/core/src/external/carequality/ihe-gateway-v2/monitor/store.ts
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 |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import dayjs from "dayjs"; | ||
import { | ||
OutboundPatientDiscoveryReq, | ||
OutboundDocumentQueryReq, | ||
OutboundDocumentRetrievalReq, | ||
XCPDGateway, | ||
XCAGateway, | ||
} from "@metriport/ihe-gateway-sdk"; | ||
import { S3Utils } from "../../../aws/s3"; | ||
import { Config } from "../../../../util/config"; | ||
import { out } from "../../../../util/log"; | ||
|
||
const { log } = out("Storing IHE Responses"); | ||
|
||
const bucket = Config.getIheResponsesBucketName(); | ||
let s3UtilsInstance = new S3Utils(Config.getAWSRegion()); | ||
|
||
function getS3UtilsInstance(): S3Utils { | ||
return s3UtilsInstance; | ||
} | ||
export function setS3UtilsInstance(s3Utils: S3Utils): void { | ||
s3UtilsInstance = s3Utils; | ||
} | ||
|
||
export async function storeXcpdResponses({ | ||
response, | ||
outboundRequest, | ||
gateway, | ||
}: { | ||
response: string; | ||
outboundRequest: OutboundPatientDiscoveryReq; | ||
gateway: XCPDGateway; | ||
}) { | ||
try { | ||
if (!bucket) { | ||
return; | ||
} | ||
const s3Utils = getS3UtilsInstance(); | ||
const { cxId, patientId, id: requestId, timestamp } = outboundRequest; | ||
const key = buildIheResponseKey({ | ||
type: "xcpd", | ||
cxId, | ||
patientId, | ||
requestId, | ||
oid: gateway.oid, | ||
timestamp, | ||
}); | ||
await s3Utils.uploadFile({ | ||
bucket, | ||
key, | ||
file: Buffer.from(response), | ||
contentType: "application/xml", | ||
}); | ||
} catch (error) { | ||
log(`Error storing XCPD response: ${error}`); | ||
} | ||
} | ||
|
||
export async function storeDqResponses({ | ||
response, | ||
outboundRequest, | ||
gateway, | ||
}: { | ||
response: string; | ||
outboundRequest: OutboundDocumentQueryReq; | ||
gateway: XCAGateway; | ||
}) { | ||
try { | ||
if (!bucket) { | ||
return; | ||
} | ||
const s3Utils = getS3UtilsInstance(); | ||
const { cxId, patientId, id: requestId, timestamp } = outboundRequest; | ||
const key = buildIheResponseKey({ | ||
type: "dq", | ||
cxId, | ||
patientId, | ||
requestId, | ||
oid: gateway.homeCommunityId, | ||
timestamp, | ||
}); | ||
await s3Utils.uploadFile({ | ||
bucket, | ||
key, | ||
file: Buffer.from(response), | ||
contentType: "application/xml", | ||
}); | ||
} catch (error) { | ||
log(`Error storing DQ response: ${error}`); | ||
} | ||
} | ||
|
||
export async function storeDrResponses({ | ||
response, | ||
outboundRequest, | ||
gateway, | ||
}: { | ||
response: Buffer; | ||
outboundRequest: OutboundDocumentRetrievalReq; | ||
gateway: XCAGateway; | ||
}) { | ||
try { | ||
if (!bucket) { | ||
return; | ||
} | ||
const s3Utils = getS3UtilsInstance(); | ||
const { cxId, patientId, id: requestId, timestamp } = outboundRequest; | ||
const key = buildIheResponseKey({ | ||
type: "dr", | ||
cxId, | ||
patientId, | ||
requestId, | ||
oid: gateway.homeCommunityId, | ||
timestamp, | ||
}); | ||
await s3Utils.uploadFile({ bucket, key, file: response, contentType: "application/xml" }); | ||
} catch (error) { | ||
log(`Error storing DR response: ${error}`); | ||
} | ||
} | ||
|
||
export function buildIheResponseKey({ | ||
type, | ||
cxId, | ||
patientId, | ||
requestId, | ||
oid, | ||
timestamp, | ||
}: { | ||
type: "xcpd" | "dq" | "dr"; | ||
cxId: string; | ||
patientId: string; | ||
requestId: string; | ||
oid: string; | ||
timestamp: string; | ||
}) { | ||
const date = dayjs(timestamp).format("YYYY-MM-DD"); | ||
return `${cxId}/${patientId}/${type}/${requestId}_${date}/${oid}.xml`; | ||
} |
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
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
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
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
Oops, something went wrong.