Skip to content

Commit

Permalink
Merge pull request #2297 from metriport/fix-dqs-missing-creation-date
Browse files Browse the repository at this point in the history
fix(ihe): catch missing dates in dq + dont overwrite stored dr response
  • Loading branch information
jonahkaye committed Jun 19, 2024
2 parents f3a0ae3 + 0aad5ef commit 0447f9d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { buildIheResponseKey } from "../store";

it("should construct the correct file path and upload the file", async () => {
it("should construct the correct file path for type 'xcpd'", async () => {
const cxId = "cxId";
const patientId = "patientId";
const requestId = "requestId";
Expand All @@ -16,3 +16,22 @@ it("should construct the correct file path and upload the file", async () => {
});
expect(key).toEqual(`${cxId}/${patientId}/xcpd/${requestId}_2024-05-01/${oid}.xml`);
});

it("should construct the correct file path for type 'dr' with index", async () => {
const cxId = "cxId";
const patientId = "patientId";
const requestId = "requestId";
const oid = "oid";
const timestamp = "2024-05-01T00:00:00";
const index = 1;
const key = buildIheResponseKey({
type: "dr",
cxId,
patientId,
requestId,
oid,
timestamp,
index,
});
expect(key).toEqual(`${cxId}/${patientId}/dr/${requestId}_2024-05-01/${oid}_1.xml`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ export async function storeDrResponse({
response,
outboundRequest,
gateway,
index,
}: {
response: Buffer;
outboundRequest: OutboundDocumentRetrievalReq;
gateway: XCAGateway;
index: number;
}) {
try {
if (!bucket) {
Expand All @@ -112,6 +114,7 @@ export async function storeDrResponse({
requestId,
oid: gateway.homeCommunityId,
timestamp,
index,
});
await s3Utils.uploadFile({ bucket, key, file: response, contentType: "application/xml" });
} catch (error) {
Expand All @@ -126,14 +129,17 @@ export function buildIheResponseKey({
requestId,
oid,
timestamp,
index,
}: {
type: "xcpd" | "dq" | "dr";
cxId: string;
patientId: string;
requestId: string;
oid: string;
timestamp: string;
index?: number;
}) {
const date = dayjs(timestamp).format("YYYY-MM-DD");
return `${cxId}/${patientId}/${type}/${requestId}_${date}/${oid}.xml`;
const indexPart = index ? `_${index}` : "";
return `${cxId}/${patientId}/${type}/${requestId}_${date}/${oid}${indexPart}.xml`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ function getHomeCommunityIdForDr(extrinsicObject: ExtrinsicObject): string {
return getResponseHomeCommunityId(extrinsicObject);
}

function getCreationTime(time: string | undefined): string | undefined {
function getCreationTime({
creationTimeValue,
serviceStartTimeValue,
serviceStopTimeValue,
}: {
creationTimeValue: string | undefined;
serviceStartTimeValue: string | undefined;
serviceStopTimeValue: string | undefined;
}): string | undefined {
const time = creationTimeValue ?? serviceStartTimeValue ?? serviceStopTimeValue;

try {
return time ? dayjs.utc(time).toISOString() : undefined;
} catch (error) {
Expand Down Expand Up @@ -116,7 +126,8 @@ function parseDocumentReference({
}

const creationTimeValue = findSlotValue("creationTime");
const creationTime = creationTimeValue ? String(creationTimeValue) : undefined;
const serviceStartTimeValue = findSlotValue("serviceStartTime");
const serviceStopTimeValue = findSlotValue("serviceStopTime");

const documentReference: DocumentReference = {
homeCommunityId: getHomeCommunityIdForDr(extrinsicObject),
Expand All @@ -126,7 +137,7 @@ function parseDocumentReference({
language: findSlotValue("languageCode"),
size: sizeValue ? parseInt(sizeValue) : undefined,
title: findClassificationName(XDSDocumentEntryClassCode),
creation: getCreationTime(creationTime),
creation: getCreationTime({ creationTimeValue, serviceStartTimeValue, serviceStopTimeValue }),
authorInstitution: findClassificationSlotValue(XDSDocumentEntryAuthor, "authorInstitution"),
};
return documentReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export async function sendSignedDrRequest({
response: rawResponse,
outboundRequest: request.outboundRequest,
gateway: request.gateway,
index,
});
return {
gateway: request.gateway,
Expand Down

0 comments on commit 0447f9d

Please sign in to comment.