-
Notifications
You must be signed in to change notification settings - Fork 38
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
base: develop
Are you sure you want to change the base?
Conversation
this._s3.upload( | ||
{ | ||
try { | ||
const data = await this._s3 |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 = ( |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)}`); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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}` |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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/`; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 => |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | |||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
script explainer string
Refs: #1379
Description
TODO
Testing
Local
staging
branch to staging
Release Plan