Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RELEASE 1801 1827 #2301

Merged
merged 22 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
034f2f2
fix(api): point API's getDocumentsFromFHIR to core's getDocuments
leite08 Jun 15, 2024
979f369
fix(api): point API's searchDocuments to core's searchDocuments
leite08 Jun 15, 2024
b5af7f7
refactor(core): return docRef w/ ID on search +
leite08 Jun 15, 2024
69d04c4
refactor(core): api to use Core's searchDocuments
leite08 Jun 15, 2024
c383685
build: update WH docs
leite08 Jun 15, 2024
def4f9c
fix(docs): typo on WH
leite08 Jun 17, 2024
4baa6ea
build: add wh types to start doc download, consolidated data and bulk…
leite08 Jun 18, 2024
4f7c54f
Merge pull request #2284 from metriport/1040-update-wh-docs
leite08 Jun 19, 2024
ce53590
Merge pull request #2282 from metriport/1827-doc-id
leite08 Jun 19, 2024
cfe5b26
refactor: use executeWithRetries and the net one throughout
leite08 Jun 15, 2024
ebcf17c
refactor: apply executeWithRetries to lower level funcitons +
leite08 Jun 18, 2024
556025f
refactor: apply executeWithRetries to missing lower level function
leite08 Jun 18, 2024
899a914
chore(release): publish
leite08 Jun 18, 2024
056427f
Merge pull request #2285 from metriport/1827-update-lambdas-to-retry
leite08 Jun 19, 2024
c72ffdf
fix(infra): 1/3 create ALB version of the API
leite08 Jun 19, 2024
5bd5ce6
fix(infra): 1/3 permissions to the ALB based fargate service
leite08 Jun 19, 2024
cfe3969
fix(infra): 1/3 add DB access to new ALB fargate service
leite08 Jun 19, 2024
3f316aa
fix(infra): 1/3 NLB pointing to ALB
leite08 Jun 19, 2024
e032d95
fix(infra): 1/3 use existing log on new ALB fargate
leite08 Jun 20, 2024
055dff2
Merge pull request #2303 from metriport/1040-alb-behind-api-nlb_1
leite08 Jun 20, 2024
dfddbbe
chore(release): publish
leite08 Jun 20, 2024
3aca99d
Merge pull request #2308 from metriport/1827-publish-npm-packages
leite08 Jun 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: apply executeWithRetries to lower level funcitons +
- apply executeWithRetries to lower level funcitons
- remove the deprecated S3Utils from lambdas package

Ref. metriport/metriport-internal#1827

Signed-off-by: Rafael Leite <[email protected]>
  • Loading branch information
leite08 committed Jun 19, 2024
commit ebcf17cfa701833e6343227ae3cbc0489cc54ba5
64 changes: 40 additions & 24 deletions packages/core/src/command/patient-loader-metriport-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PatientDTO, USState } from "@metriport/api-sdk";
import { executeWithNetworkRetries } from "@metriport/shared";
import axios from "axios";
import { Patient } from "../domain/patient";
import { errorToString } from "../util/error/shared";
Expand All @@ -12,34 +13,45 @@ export class PatientLoaderMetriportAPI implements PatientLoader {
constructor(private readonly apiUrl: string) {}

public async getStatesFromPatientIds(cxId: string, patientIds: string[]): Promise<string[]> {
const resp = await axios.get(`${this.apiUrl}/internal/patient/states`, {
params: {
cxId,
patientIds: patientIds.join(","),
},
});
const resp = await executeWithNetworkRetries(
() =>
axios.get(`${this.apiUrl}/internal/patient/states`, {
params: {
cxId,
patientIds: patientIds.join(","),
},
}),
{ retryOnTimeout: true }
);
return resp.data.states;
}

// TODO: Response is DTO not domain object
async getOneOrFail({ id, cxId }: GetOne): Promise<Patient> {
const response = await axios.get(`${this.apiUrl}/internal/patient/${id}?cxId=${cxId}`);
const response = await executeWithNetworkRetries(
() => axios.get(`${this.apiUrl}/internal/patient/${id}?cxId=${cxId}`),
{ retryOnTimeout: true }
);
const patient = getDomainFromDTO(response.data);
validatePatient(patient);
return patient;
}

// TODO: Response is DTO not domain object
async findBySimilarity({ cxId, data }: FindBySimilarity): Promise<Patient[]> {
const response = await axios.get(`${this.apiUrl}/internal/patient`, {
params: {
cxId: cxId,
dob: data?.dob,
genderAtBirth: data?.genderAtBirth,
firstNameInitial: data?.firstNameInitial,
lastNameInitial: data?.lastNameInitial,
},
});
const response = await executeWithNetworkRetries(
() =>
axios.get(`${this.apiUrl}/internal/patient`, {
params: {
cxId: cxId,
dob: data?.dob,
genderAtBirth: data?.genderAtBirth,
firstNameInitial: data?.firstNameInitial,
lastNameInitial: data?.lastNameInitial,
},
}),
{ retryOnTimeout: true }
);
const patients: Patient[] = response.data.map((patient: PatientDTO) =>
getDomainFromDTO(patient)
);
Expand All @@ -49,14 +61,18 @@ export class PatientLoaderMetriportAPI implements PatientLoader {

async findBySimilarityAcrossAllCxs({ data }: Omit<FindBySimilarity, "cxId">): Promise<Patient[]> {
try {
const response = await axios.get(`${this.apiUrl}/internal/mpi/patient`, {
params: {
dob: data?.dob,
genderAtBirth: data?.genderAtBirth,
firstNameInitial: data?.firstNameInitial,
lastNameInitial: data?.lastNameInitial,
},
});
const response = await executeWithNetworkRetries(
() =>
axios.get(`${this.apiUrl}/internal/mpi/patient`, {
params: {
dob: data?.dob,
genderAtBirth: data?.genderAtBirth,
firstNameInitial: data?.firstNameInitial,
lastNameInitial: data?.lastNameInitial,
},
}),
{ retryOnTimeout: true }
);
// call convertToDomainObject(response) here
const patients: Patient[] = response.data.map((patient: PatientDTO) =>
getDomainFromDTO(patient)
Expand Down
16 changes: 7 additions & 9 deletions packages/core/src/external/aws/document-signing/bulk-sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,13 @@ export async function searchDocumentsSignUrlsAndSendToApi(

const response = urls.flatMap(url => (url !== undefined ? url : []));

await executeWithNetworkRetries(() =>
ossApiClient.callInternalEndpoint({
cxId,
patientId,
requestId,
docs: response,
status: "completed",
})
);
await ossApiClient.callInternalEndpoint({
cxId,
patientId,
requestId,
docs: response,
status: "completed",
});
} catch (error) {
const msg = "Error getting signed URLs";
const extra = { ...getNetworkErrorDetails(error), cxId, patientId, requestId };
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/external/aws/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export class S3Utils {

return newKey;
}

async uploadFile({
bucket,
key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import {
InboundPatientDiscoveryResp,
PatientResource,
} from "@metriport/ihe-gateway-sdk";
import { executeWithNetworkRetries } from "@metriport/shared";
import { Address } from "../../../domain/address";
import { getStateEnum } from "../../../domain/geographic-locations";
import { Patient, PatientData } from "../../../domain/patient";
import { MPI } from "../../../mpi/mpi";
import { normalizeGender, normalizePatient } from "../../../mpi/normalize-patient";
import { patientMPIToPartialPatient } from "../../../mpi/shared";
import {
constructPDErrorResponse,
Expand All @@ -15,11 +16,8 @@ import {
XDSRegistryError,
} from "../error";
import { toIheGatewayPatientResource } from "../ihe-gateway-v2/patient";
import { validateFHIRAndExtractPatient } from "./validating-pd";

import { getStateEnum } from "../../../domain/geographic-locations";
import { normalizeGender, normalizePatient } from "../../../mpi/normalize-patient";
import { METRIPORT_HOME_COMMUNITY_ID } from "../shared";
import { validateFHIRAndExtractPatient } from "./validating-pd";

function constructMatchResponse(
payload: InboundPatientDiscoveryReq,
Expand All @@ -46,7 +44,7 @@ export async function processInboundPatientDiscovery(
): Promise<InboundPatientDiscoveryResp> {
try {
const patient = validateFHIRAndExtractPatient(payload);
const matchingPatient = await executeWithNetworkRetries(() => mpi.findMatchingPatient(patient));
const matchingPatient = await mpi.findMatchingPatient(patient);
if (!matchingPatient) {
return constructPDNoMatchResponse(payload);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export class DocumentDownloaderLocal extends DocumentDownloader {
const onEnd = () => {
console.log("Finished downloading document");
};
let downloadResult = await this.downloadFromCommonwellIntoS3(document, fileInfo, onData, onEnd);
let downloadResult = await executeWithNetworkRetries(
() => this.downloadFromCommonwellIntoS3(document, fileInfo, onData, onEnd),
{ retryOnTimeout: true, initialDelay: 500, maxAttempts: 5 }
);

// Check if the detected file type is in the accepted content types and update it if not
downloadResult = await this.checkAndUpdateMimeType({
Expand Down Expand Up @@ -83,7 +86,7 @@ export class DocumentDownloaderLocal extends DocumentDownloader {

/**
* Checks if the content type of a downloaded document is accepted. If not accepted, updates the content type
* and extension in S3 and returns the updated download result.
* and extension in S3 and returns the updated download result.
*/
async checkAndUpdateMimeType({
document,
Expand Down
21 changes: 7 additions & 14 deletions packages/lambdas/src/cw-doc-contribution.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { S3Utils } from "@metriport/core/external/aws/s3";
import { docContributionFileParam } from "@metriport/core/external/commonwell/document/document-contribution";
import { errorToString, executeWithRetries } from "@metriport/shared";
import { errorToString } from "@metriport/shared";
import * as Sentry from "@sentry/serverless";
import * as lambda from "aws-lambda";
import { capture } from "./shared/capture";
import { getEnvOrFail } from "./shared/env";
import { S3Utils } from "./shared/s3";

// Keep this as early on the file as possible
capture.init();
Expand Down Expand Up @@ -52,18 +52,11 @@ export const handler = Sentry.AWSLambda.wrapHandler(
}

console.log(`Key: ${key}`);
const url = await executeWithRetries(
() =>
s3Utils.s3.getSignedUrlPromise("getObject", {
Bucket: bucketName,
Key: key,
Expires: SIGNED_URL_DURATION_SECONDS,
}),
{
maxAttempts: 3,
initialDelay: 500,
}
);
const url = await s3Utils.getSignedUrl({
bucketName,
fileName: key,
durationSeconds: SIGNED_URL_DURATION_SECONDS,
});
return sendResponse({
statusCode: 301,
headers: {
Expand Down
6 changes: 1 addition & 5 deletions packages/lambdas/src/document-downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { DownloadResult } from "@metriport/core/external/commonwell/document/doc
import { DocumentDownloaderLambdaRequest } from "@metriport/core/external/commonwell/document/document-downloader-lambda";
import { DocumentDownloaderLocal } from "@metriport/core/external/commonwell/document/document-downloader-local";
import { getEnvType } from "@metriport/core/util/env-var";
import { executeWithNetworkRetries } from "@metriport/shared";
import * as Sentry from "@sentry/serverless";
import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
Expand Down Expand Up @@ -73,10 +72,7 @@ export const handler = Sentry.AWSLambda.wrapHandler(
},
capture,
});
const result = await executeWithNetworkRetries(
() => docDownloader.download({ document, fileInfo }),
{ retryOnTimeout: true, initialDelay: 500, maxAttempts: 5 }
);
const result = await docDownloader.download({ document, fileInfo });

console.log(`Done - ${JSON.stringify(result)}`);
return result;
Expand Down
31 changes: 0 additions & 31 deletions packages/lambdas/src/shared/s3.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/lambdas/src/sqs-to-converter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { S3Utils } from "@metriport/core/external/aws/s3";
import {
executeWithNetworkRetries,
executeWithRetries,
Expand All @@ -13,7 +14,6 @@ import { getEnvOrFail } from "./shared/env";
import { isAxiosBadGateway, isAxiosTimeout } from "./shared/http";
import { Log, prefixedLog } from "./shared/log";
import { apiClient } from "./shared/oss-api";
import { S3Utils } from "./shared/s3";
import { SQSUtils } from "./shared/sqs";
import { cleanUpPayload } from "./sqs-to-converter/cleanup";

Expand Down
2 changes: 1 addition & 1 deletion packages/lambdas/src/sqs-to-fhir.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MedplumClient } from "@medplum/core";
import { Bundle, Resource } from "@medplum/fhirtypes";
import { S3Utils } from "@metriport/core/external/aws/s3";
import { MetriportError } from "@metriport/core/util/error/metriport-error";
import {
executeWithNetworkRetries,
Expand All @@ -17,7 +18,6 @@ import { getEnvOrFail, isSandbox } from "./shared/env";
import { isAxiosBadGateway, isAxiosTimeout } from "./shared/http";
import { Log, prefixedLog } from "./shared/log";
import { apiClient } from "./shared/oss-api";
import { S3Utils } from "./shared/s3";
import { SQSUtils } from "./shared/sqs";

// Keep this as early on the file as possible
Expand Down