Skip to content

Commit

Permalink
feat(ihe): renaming subreqid, nano id
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 21, 2024
1 parent e2d12b4 commit 5a60435
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { nanoid } from "nanoid";
import { Patient } from "@metriport/core/domain/patient";
import { capture } from "@metriport/core/util/notifications";
import {
Expand All @@ -8,7 +9,6 @@ import {
isEpicGateway,
maxDocRefsPerEpicDocRetrievalRequest,
} from "@metriport/core/external/carequality/ihe-gateway-v2/gateways";
import { v4 as uuidv4 } from "uuid";

import dayjs from "dayjs";
import { chunk } from "lodash";
Expand Down Expand Up @@ -73,7 +73,7 @@ export function createOutboundDocumentRetrievalReqs({
const request: OutboundDocumentRetrievalReq[] = docRefChunks.map(chunk => {
return {
...baseRequest,
subRequestId: uuidv4(),
requestChunkId: nanoid(),
documentReference: chunk,
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export async function sendProcessRetryDrRequest({
response,
});
}

return await executeWithRetries(sendProcessDrRequest, {
initialDelay: 3000,
maxAttempts: 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ it("should construct the correct file path for type 'dr' with index", async () =
requestId,
oid,
timestamp,
subRequestId: "subRequestId",
requestChunkId: "requestChunkId",
});
expect(key).toEqual(`${cxId}/${patientId}/dr/${requestId}_2024-05-01/${oid}_subRequestId.xml`);
expect(key).toEqual(`${cxId}/${patientId}/dr/${requestId}_2024-05-01/${oid}_requestChunkId.xml`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ export async function storeDrResponse({
response,
outboundRequest,
gateway,
subRequestId,
requestChunkId,
}: {
response: Buffer;
outboundRequest: OutboundDocumentRetrievalReq;
gateway: XCAGateway;
subRequestId?: string | undefined;
requestChunkId?: string | undefined;
}) {
try {
if (!bucket) {
Expand All @@ -114,7 +114,7 @@ export async function storeDrResponse({
requestId,
oid: gateway.homeCommunityId,
timestamp,
subRequestId,
requestChunkId,
});
await s3Utils.uploadFile({ bucket, key, file: response, contentType: "application/xml" });
} catch (error) {
Expand All @@ -129,17 +129,17 @@ export function buildIheResponseKey({
requestId,
oid,
timestamp,
subRequestId,
requestChunkId,
}: {
type: "xcpd" | "dq" | "dr";
cxId: string;
patientId: string;
requestId: string;
oid: string;
timestamp: string;
subRequestId?: string | undefined;
requestChunkId?: string | undefined;
}) {
const date = dayjs(timestamp).format("YYYY-MM-DD");
const subRequestIdPart = subRequestId ? `_${subRequestId}` : "";
return `${cxId}/${patientId}/${type}/${requestId}_${date}/${oid}${subRequestIdPart}.xml`;
const requestChunkIdPart = requestChunkId ? `_${requestChunkId}` : "";
return `${cxId}/${patientId}/${type}/${requestId}_${date}/${oid}${requestChunkIdPart}.xml`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async function handleSuccessResponse({

const response: OutboundDocumentRetrievalResp = {
id: outboundRequest.id,
subRequestId: outboundRequest.subRequestId,
requestChunkId: outboundRequest.requestChunkId,
patientId: outboundRequest.patientId,
timestamp: outboundRequest.timestamp,
requestTimestamp: outboundRequest.timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function handleRegistryErrorResponse({
const operationOutcome = processRegistryErrorList(registryErrorList, outboundRequest);
return {
id: outboundRequest.id,
subRequestId: outboundRequest.subRequestId,
requestChunkId: outboundRequest.requestChunkId,
patientId: outboundRequest.patientId,
timestamp: outboundRequest.timestamp,
requestTimestamp: outboundRequest.timestamp,
Expand Down Expand Up @@ -111,7 +111,7 @@ export function handleHttpErrorResponse({
};
return {
id: outboundRequest.id,
subRequestId: outboundRequest.subRequestId,
requestChunkId: outboundRequest.requestChunkId,
timestamp: outboundRequest.timestamp,
requestTimestamp: outboundRequest.timestamp,
responseTimestamp: dayjs().toISOString(),
Expand Down Expand Up @@ -147,7 +147,7 @@ export function handleEmptyResponse({
};
return {
id: outboundRequest.id,
subRequestId: outboundRequest.subRequestId,
requestChunkId: outboundRequest.requestChunkId,
patientId: outboundRequest.patientId,
timestamp: outboundRequest.timestamp,
requestTimestamp: outboundRequest.timestamp,
Expand Down Expand Up @@ -182,7 +182,7 @@ export function handleSchemaErrorResponse({
};
return {
id: outboundRequest.id,
subRequestId: outboundRequest.subRequestId,
requestChunkId: outboundRequest.requestChunkId,
patientId: outboundRequest.patientId,
timestamp: outboundRequest.timestamp,
requestTimestamp: outboundRequest.timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function sendSignedDrRequest({
url: request.gateway.url,
samlCertsAndKeys,
oid: request.outboundRequest.gateway.homeCommunityId,
subRequestId: request.outboundRequest.subRequestId,
requestChunkId: request.outboundRequest.requestChunkId,
});
log(
`Request ${index + 1} sent successfully to: ${request.gateway.url} + oid: ${
Expand All @@ -48,7 +48,7 @@ export async function sendSignedDrRequest({
response: rawResponse,
outboundRequest: request.outboundRequest,
gateway: request.gateway,
subRequestId: request.outboundRequest.subRequestId,
requestChunkId: request.outboundRequest.requestChunkId,
});
return {
gateway: request.gateway,
Expand All @@ -59,14 +59,14 @@ export async function sendSignedDrRequest({
} catch (error: any) {
const msg = "HTTP/SSL Failure Sending Signed DR SAML Request";
log(
`${msg}, batchRequestId: ${request.outboundRequest.id}, subRequestId: ${request.outboundRequest.subRequestId}, cxId: ${cxId}, patientId: ${patientId}, gateway: ${request.gateway.homeCommunityId}, error: ${error}`
`${msg}, requestId ${request.outboundRequest.id}, requestChunkId: ${request.outboundRequest.requestChunkId}, cxId: ${cxId}, patientId: ${patientId}, gateway: ${request.gateway.homeCommunityId}, error: ${error}`
);
if (error?.response?.data) {
const errorDetails = Buffer.isBuffer(error?.response?.data)
? error.response.data.toString("utf-8")
: JSON.stringify(error?.response?.data);
log(
`batchRequestId: ${request.outboundRequest.id}, subRequestId: ${request.outboundRequest.subRequestId}, error details: ${errorDetails}`
`batchRequestId: ${request.outboundRequest.id}, requestChunkId: ${request.outboundRequest.requestChunkId}, error details: ${errorDetails}`
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ export async function sendSignedXmlMtom({
url,
samlCertsAndKeys,
oid,
subRequestId,
requestChunkId,
}: {
signedXml: string;
url: string;
samlCertsAndKeys: SamlCertsAndKeys;
oid: string;
subRequestId: string | undefined;
requestChunkId: string | undefined;
}): Promise<{ mtomParts: MtomAttachments; rawResponse: Buffer }> {
const trustedKeyStore = await getTrustedKeyStore();
const agent = new https.Agent({
Expand All @@ -157,7 +157,7 @@ export async function sendSignedXmlMtom({
secureOptions: constants.SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION,
});

const logger = getLog(`sendSignedXmlMtom, oid: ${oid}, SubRequestId: ${subRequestId}`);
const logger = getLog(`sendSignedXmlMtom, oid: ${oid}, requestChunkId: ${requestChunkId}`);
const { contentType, payload } = createMtomContentTypeAndPayload(signedXml);
const response = await executeWithNetworkRetries(
async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/ihe-gateway-sdk/src/models/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type SamlAttributes = z.infer<typeof SamlAttributesSchema>;

export const baseRequestSchema = z.object({
id: z.string(),
subRequestId: z.string().optional(),
requestChunkId: z.string().optional(),
cxId: z.string().optional(),
timestamp: z.string(),
samlAttributes: SamlAttributesSchema,
Expand Down Expand Up @@ -76,7 +76,7 @@ export type XCPDPatientId = z.infer<typeof externalGatewayPatientSchema>;

export const baseResponseSchema = z.object({
id: z.string(),
subRequestId: z.string().optional(),
requestChunkId: z.string().optional(),
timestamp: z.string(),
/** timestamp right after external gateway response */
responseTimestamp: z.string(),
Expand Down

0 comments on commit 5a60435

Please sign in to comment.