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

ihe stack 4/4 - DR Response #1405

Merged
merged 21 commits into from
Jan 26, 2024
Merged

ihe stack 4/4 - DR Response #1405

merged 21 commits into from
Jan 26, 2024

Conversation

jonahkaye
Copy link
Member

@jonahkaye jonahkaye commented Jan 4, 2024

Ticket: #1379, #1358

Dependencies

Description

  • Implementing dr responses
  • refactoring pd, dq, dr responding code to have less code duplication
  • removing all DEPRECATED code from IHE GW testing partners implementation

Testing

  • Local
    • tested using mock endpoint
  • Staging
    • branched to staging

TODO

Release Plan

@jonahkaye jonahkaye changed the base branch from develop to 1379-incoming-dq-dr January 4, 2024 22:54
@jonahkaye jonahkaye changed the title 1379 dr incoming ihe stack 4/4 - DR Response Jan 4, 2024
@jonahkaye jonahkaye mentioned this pull request Jan 4, 2024
9 tasks
packages/utils/src/carequality/mock-ihe-gateway.ts Dismissed Show dismissed Hide dismissed
packages/utils/src/carequality/mock-ihe-gateway.ts Dismissed Show dismissed Hide dismissed
@jonahkaye jonahkaye mentioned this pull request Jan 4, 2024
4 tasks
@jonahkaye jonahkaye self-assigned this Jan 5, 2024
Copy link
Member Author

@jonahkaye jonahkaye left a comment

Choose a reason for hiding this comment

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

Ready for Review!

@jonahkaye jonahkaye marked this pull request as ready for review January 5, 2024 17:58
if (isBaseErrorResponse(response)) {
status = "failure";
} else if (isDocumentQueryResponse(response) || isDocumentRetrievalResponse(response)) {
if (isDocumentQueryResponse(response) || isDocumentRetrievalResponse(response)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I changed the order here. Why? Because of type narrowing! After some research:

In TypeScript, the process of refining the type of a variable within a certain scope based on conditions or type guards is known as "type narrowing". This feature helps prevent errors by ensuring that we only use properties and methods that are guaranteed to exist on the narrowed type.

In the original code, we first checked if response is a BaseErrorResponse using the isBaseErrorResponse type guard. If this condition was false, TypeScript narrowed the type of response to exclude BaseErrorResponse in the subsequent else if block. However, because BaseErrorResponse is not explicitly part of the IHEResult union, TypeScript inferred that response is of type never in the else if block. The never type in TypeScript represents a value that never occurs, which resulted in me getting an error when trying to access response.documentReference.

To resolve this, I rearranged the conditions to first check if response is a DocumentQueryResponse or DocumentRetrievalResponse. These types are part of the IHEResult union, so TypeScript can correctly infer the type of response in each block. This change ensures that we are correctly narrowing the type of response and prevents the TypeScript error.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, always from the more specific to the more generic when checking for types.

Base automatically changed from 1379-incoming-dq-dr to develop January 26, 2024 13:32
@@ -30,7 +30,7 @@ export const SamlAttributesSchema = z.object({

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

Choose a reason for hiding this comment

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

making optional because requests from the outside world will not have a cxID

Copy link
Member

Choose a reason for hiding this comment

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

Let's then use a diff base schema for those? It will be noisy/cumbersome to have optional cxId for our internal code when we know it always must be present.

@jonahkaye jonahkaye merged commit 71b4fd4 into develop Jan 26, 2024
19 checks passed
@jonahkaye jonahkaye deleted the 1379-dr-incoming branch January 26, 2024 16:18
@jonahkaye jonahkaye mentioned this pull request Jan 26, 2024
6 tasks
Copy link

🎉 This PR is included in version 5.49.0-develop.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

},
});
// call convertToDomainObject(response) here
const patients: Patient[] = response.data.map((patient: PatientDTO) =>
Copy link
Member

Choose a reason for hiding this comment

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

.data is any, so it might be undefined = potential runtime error

Since here, check other similar code in this file please, there are more of those

Comment on lines 80 to 81
const message = "Failed with the call to update the doc-ref of an uploaded file";
console.log(`${message}: ${docRef}`);
Copy link
Member

Choose a reason for hiding this comment

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

Do we really want to fail silently here?

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

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

Choose a reason for hiding this comment

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

Let's then use a diff base schema for those? It will be noisy/cumbersome to have optional cxId for our internal code when we know it always must be present.

@jonahkaye jonahkaye mentioned this pull request Jan 26, 2024
3 tasks
Copy link

🎉 This PR is included in version 5.49.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants