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

Improvements to DQ and DR PRs #1528

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft

Improvements to DQ and DR PRs #1528

wants to merge 4 commits into from

Conversation

jonahkaye
Copy link
Member

@jonahkaye jonahkaye commented Jan 26, 2024

Refs: #1379

Description

TODO

Testing

  • Local

    • tested with local mock-ihe-gateway
  • staging

  • branch to staging

Release Plan

  • Merge this

@jonahkaye jonahkaye self-assigned this Jan 26, 2024
this._s3.upload(
{
try {
const data = await this._s3
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified to use await/async

exists: true,
size: head.ContentLength,
contentType: head.ContentType,
eTag: head.ETag,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed unnessecary conditionals

return `${cxId}/${patientId}/${cxId}_${patientId}_${fileName}`;
};

export const parseS3FileName = (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved these files to metriport business logic files instead of s3.ts

const stringSize = size ? size.toString() : "";
const hash = eTag ? eTag : "";
const stringSize = size.toString();
const hash = eTag;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed unnessecary conditionals

const patients: Patient[] = response.data.map((patient: PatientDTO) =>
getDomainFromDTO(patient)
);
patients.forEach(validatePatient);
return patients;
} catch (error) {
console.log("Failing on request to internal endpoint", error);
console.log(`Failing on request to internal endpoint ${JSON.stringify(error)}`);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no multiline errors

@@ -58,14 +58,17 @@ export class PatientLoaderMetriportAPI implements PatientLoader {
lastNameInitial: data?.lastNameInitial,
},
});
// call convertToDomainObject(response) here
if (!response.data) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response.data is of type any so checking if undefined to prevent runtime errors

@@ -166,6 +174,8 @@ async function createAndUploadMetadataFile({
title,
});

console.log(`Uploading metadata to S3 with key: ${s3MetadataFileName}`);
console.log(
`Uploading metadata to S3 with key: ${s3MetadataFileName}, cxId: ${cxId}, patientId: ${patientId}`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more descriptive logging

HEALTHCARE_FACILITY_TYPE_CODE_CLASSIFICATION_SCHEME,
TYPE_CODE_CLASSIFICATION_SCHEME,
PATIENT_ID_CLASSIFICATION_SCHEME,
DOCUMENT_ENTRY_CLASSIFICATION_SCHEME,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing all hardcoding

error instanceof XDSMissingHomeCommunityId ||
error instanceof XDSRegistryError
) {
if (error instanceof IHEGatewayError) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplification since XDSUnknownPatientId etc are all instances of IHEGatewayError

patientId: string,
bucketName: string
): Promise<string[] | undefined> {
const Prefix = `${cxId}/${patientId}/uploads/`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing metriport business logic from retrieveDocumentsContentFromS3

import { IHEGatewayError, constructDRErrorResponse, XDSRegistryError } from "../error";

export async function processIncomingRequest(
payload: DocumentRetrievalReqFromExternalGW
): Promise<DocumentRetrievalRespToExternalGW> {
try {
// validate incoming request + look for patient and get all their documents from s3
const documents = await validateDR(payload);
const documents = await validateDRAndRetrievePresignedUrls(payload);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more descriptive function name

documentReferences.push(documentReference);
}

const promises = documentIds.map(id =>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

batch for efficiency

@@ -20,7 +19,7 @@ export const genderMapping: { [k in GenderAtBirth]: "female" | "male" } = {
export const toFHIR = (patient: Pick<Patient, "id" | "data">): FHIRPatient => {
return {
resourceType: "Patient",
id: uuidv7(),
id: patient.id,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the culprit 😭

@@ -17,6 +17,7 @@ export const handler = Sentry.AWSLambda.wrapHandler(async (event: APIGatewayProx
id: payload.id,
timestamp: payload.timestamp,
samlAttributes: payload.samlAttributes,
patientResource: payload.patientResource,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schema validation for all required fields

@@ -30,7 +30,7 @@ export const SamlAttributesSchema = z.object({

export const baseRequestSchema = z.object({
id: z.string(),
cxId: z.string().optional(),
cxId: z.string(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverting this back to mandatory and modifying the incoming request types to omit cxId

@@ -30,6 +30,8 @@ export const documentQueryReqToExternalGWSchema = documentQueryDefaultReqSchema.
export type DocumentQueryReqToExternalGW = z.infer<typeof documentQueryReqToExternalGWSchema>;

// FROM EXTERNAL GATEWAY
export const documentQueryReqFromExternalGWSchema = documentQueryDefaultReqSchema;
export const documentQueryReqFromExternalGWSchema = documentQueryDefaultReqSchema.omit({
cxId: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omit cxId in this schema since incoming requests don't have cxId

@@ -6,6 +6,12 @@ import { processIncomingRequest as processIncomingPdRequest } from "@metriport/c
import { MPIMetriportAPI } from "@metriport/core/mpi/patient-mpi-metriport-api";
import { getEnvVarOrFail } from "@metriport/core/util/env-var";

/*
This is a mock IHE gateway for Carequality interfaces to handle patient discovery (PD),
document query (DQ), and document retrieval (DR) requests. Use it for testing logic in
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

script explainer

@@ -9,6 +9,10 @@ const destinationBucket = getEnvVarOrFail("DESTINATION_BUCKET");
const region = getEnvVarOrFail("AWS_REGION");
const apiUrl = getEnvVarOrFail("API_URL");

/**
This script takes a document from a source bucket and uploads it to a destination bucket, and generates a metadata xml file for the document
*/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

script explainer string

@jonahkaye jonahkaye marked this pull request as ready for review January 28, 2024 02:17
@jonahkaye jonahkaye changed the title feat(cq): fixing nits on dq pr Improvements to DQ and DR PRs Jan 30, 2024
@jonahkaye jonahkaye marked this pull request as draft January 31, 2024 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant