Skip to content

Commit

Permalink
Merge pull request #2285 from metriport/1827-update-lambdas-to-retry
Browse files Browse the repository at this point in the history
1827 Apply executeWithRetries and the network one throughout
  • Loading branch information
leite08 committed Jun 19, 2024
2 parents ce53590 + 899a914 commit 056427f
Show file tree
Hide file tree
Showing 43 changed files with 625 additions and 417 deletions.
47 changes: 24 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/api-sdk/package.json
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/",
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api",
"version": "1.18.4",
"version": "1.18.5-alpha.0",
"description": "",
"main": "app.js",
"private": true,
Expand Down
22 changes: 15 additions & 7 deletions packages/api/src/external/commonwell/patient-external-data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Patient } from "@metriport/core/domain/patient";
import { DiscoveryParams } from "@metriport/core/domain/patient-discovery";
import { MetriportError } from "@metriport/core/util/error/metriport-error";
import { executeWithRetriesSafe } from "@metriport/shared";
import { executeWithRetriesSafe, MetriportError } from "@metriport/shared";
import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
import { getPatientOrFail } from "../../command/medical/patient/get-patient";
Expand All @@ -14,7 +13,7 @@ import { CQLinkStatus, PatientDataCommonwell } from "./patient-shared";
dayjs.extend(duration);

const maxAttemptsToGetPatientCWData = 5;
const waitTimeBetweenAttemptsToGetPatientCWData = dayjs.duration(2, "seconds");
const waitTimeBetweenAttemptsToGetPatientCWData = dayjs.duration(1, "seconds");

export type PatientWithCWData = Patient & {
data: { externalData: { COMMONWELL: PatientDataCommonwell } };
Expand All @@ -23,8 +22,8 @@ export type PatientWithCWData = Patient & {
const _getPatientWithCWData = async ({
id,
cxId,
}: Pick<Patient, "id" | "cxId">): Promise<PatientWithCWData | undefined> => {
const patientDB: Patient = await getPatientOrFail({
}: Pick<Patient, "id" | "cxId">): Promise<PatientWithCWData> => {
const patientDB = await getPatientOrFail({
id,
cxId,
});
Expand All @@ -33,7 +32,17 @@ const _getPatientWithCWData = async ({
if (!cwData) throw new MetriportError(`Missing CW data on patient`);
if (!cwData.patientId) throw new MetriportError(`Missing CW patientId`);

return patientDB as PatientWithCWData;
const patient = patientDB.dataValues;
return {
...patient,
data: {
...patient.data,
externalData: {
...patient.data.externalData,
COMMONWELL: cwData,
},
},
};
};

export async function getPatientWithCWData(
Expand All @@ -42,7 +51,6 @@ export async function getPatientWithCWData(
return executeWithRetriesSafe(() => _getPatientWithCWData(patient), {
maxAttempts: maxAttemptsToGetPatientCWData,
initialDelay: waitTimeBetweenAttemptsToGetPatientCWData.asMilliseconds(),
backoffMultiplier: 0, // no backoff
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Bundle, DocumentReference } from "@medplum/fhirtypes";
import { out } from "@metriport/core/util/log";
import { executeWithRetries } from "@metriport/shared";
import { executeWithNetworkRetries } from "@metriport/shared";
import { errorToString } from "../../../shared/log";
import { makeFhirApi } from "../api/api-factory";

Expand All @@ -14,10 +14,9 @@ export const upsertDocumentToFHIRServer = async (
): Promise<void> => {
const fhir = makeFhirApi(cxId);
try {
await executeWithRetries(async () => await fhir.updateResource(docRef), {
await executeWithNetworkRetries(async () => await fhir.updateResource(docRef), {
maxAttempts,
initialDelay: waitTimeBetweenAttemptsInMillis,
backoffMultiplier: 0, // no backoff
log,
});
} catch (err) {
Expand All @@ -33,10 +32,9 @@ export const upsertDocumentsToFHIRServer = async (
): Promise<void> => {
const fhir = makeFhirApi(cxId);
try {
await executeWithRetries(async () => await fhir.executeBatch(transactionBundle), {
await executeWithNetworkRetries(async () => await fhir.executeBatch(transactionBundle), {
maxAttempts,
initialDelay: waitTimeBetweenAttemptsInMillis,
backoffMultiplier: 0, // no backoff
log,
});
} catch (error) {
Expand Down
10 changes: 3 additions & 7 deletions packages/api/src/routes/medical/internal-docs.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { BulkGetDocUrlStatus } from "@metriport/core/domain/bulk-get-document-url";
import {
DocumentBulkSignerLambdaResponse,
documentBulkSignerLambdaResponseArraySchema,
} from "@metriport/core/external/aws/document-signing/document-bulk-signer-response";
import { convertResult } from "@metriport/core/domain/document-query";
import { createDocumentFilePath } from "@metriport/core/domain/document/filename";
import { documentBulkSignerLambdaResponseArraySchema } from "@metriport/core/external/aws/document-signing/document-bulk-signer-response";
import { S3Utils } from "@metriport/core/external/aws/s3";
import { isMedicalDataSource } from "@metriport/core/external/index";
import { uuidv7 } from "@metriport/core/util/uuid-v7";
Expand Down Expand Up @@ -387,8 +384,7 @@ router.post(
const patientId = getFrom("query").orFail("patientId", req);
const requestId = getFrom("query").orFail("requestId", req);
const status = getFrom("query").orFail("status", req);
const dtos: DocumentBulkSignerLambdaResponse[] =
documentBulkSignerLambdaResponseArraySchema.parse(req.body);
const docs = documentBulkSignerLambdaResponseArraySchema.parse(req.body);

const updatedPatient = await appendBulkGetDocUrlProgress({
patient: { id: patientId, cxId },
Expand All @@ -403,7 +399,7 @@ router.post(
"medical.document-bulk-download-urls",
status as MAPIWebhookStatus,
requestId,
dtos
docs
);

return res.status(httpStatus.OK).json(updatedPatient.data.bulkGetDocumentsUrlProgress);
Expand Down
4 changes: 2 additions & 2 deletions packages/carequality-cert-runner/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metriport/carequality-cert-runner",
"version": "1.8.5",
"version": "1.8.6-alpha.0",
"description": "Tool to run through Carequality certification test cases - by Metriport Inc.",
"author": "Metriport Inc. <[email protected]>",
"homepage": "https://metriport.com/",
Expand Down Expand Up @@ -41,7 +41,7 @@
"url": "https://github.com/metriport/metriport/issues"
},
"dependencies": {
"@metriport/ihe-gateway-sdk": "^0.9.5",
"@metriport/ihe-gateway-sdk": "^0.9.6-alpha.0",
"@metriport/shared": "^0.8.0"
}
}
2 changes: 1 addition & 1 deletion packages/carequality-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metriport/carequality-sdk",
"version": "0.10.5",
"version": "0.10.6-alpha.0",
"description": "SDK to interact with the Carequality directory - by Metriport Inc.",
"author": "Metriport Inc. <[email protected]>",
"homepage": "https://metriport.com/",
Expand Down
6 changes: 3 additions & 3 deletions packages/commonwell-cert-runner/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metriport/commonwell-cert-runner",
"version": "1.16.14",
"version": "1.16.15-alpha.0",
"description": "Tool to run through Edge System CommonWell certification test cases - by Metriport Inc.",
"author": "Metriport Inc. <[email protected]>",
"homepage": "https://metriport.com/",
Expand Down Expand Up @@ -42,8 +42,8 @@
"url": "https://github.com/metriport/metriport/issues"
},
"dependencies": {
"@metriport/commonwell-sdk": "^4.15.14",
"axios": "^1.3.5",
"@metriport/commonwell-sdk": "^4.15.15-alpha.0",
"axios": "^1.4.0",
"commander": "^9.5.0",
"dayjs": "^1.11.7",
"dotenv": "^16.0.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/commonwell-jwt-maker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metriport/commonwell-jwt-maker",
"version": "1.14.5",
"version": "1.14.6-alpha.0",
"description": "CLI to create a JWT for use in CommonWell queries - by Metriport Inc.",
"author": "Metriport Inc. <[email protected]>",
"homepage": "https://metriport.com/",
Expand Down Expand Up @@ -41,7 +41,7 @@
"url": "https://github.com/metriport/metriport/issues"
},
"dependencies": {
"@metriport/commonwell-sdk": "^4.15.14",
"@metriport/commonwell-sdk": "^4.15.15-alpha.0",
"commander": "^9.5.0"
},
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions packages/commonwell-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metriport/commonwell-sdk",
"version": "4.15.14",
"version": "4.15.15-alpha.0",
"description": "SDK to simplify CommonWell API integration - by Metriport Inc.",
"author": "Metriport Inc. <[email protected]>",
"homepage": "https://metriport.com/",
Expand Down Expand Up @@ -59,7 +59,8 @@
"url": "https://github.com/metriport/metriport/issues"
},
"dependencies": {
"axios": "^1.3.5",
"@metriport/shared": "^0.9.8-alpha.0",
"axios": "^1.4.0",
"http-status": "^1.7.0",
"jsonwebtoken": "^9.0.0",
"zod": "^3.22.1"
Expand Down
Loading

0 comments on commit 056427f

Please sign in to comment.