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

Create a new "lab order signed" timer in the elation extension #577

Conversation

ebomcke-awell
Copy link
Contributor

This experimental feature adds the ability to wait for resource updates in a care flow.
This specific timer has been tested with an alternative implementation, this PR only moves the logic into the extension itself.

Copy link

github-actions bot commented Feb 4, 2025

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Issue

The evaluate function assumes the input parameter will always conform to the ElationWebhookPayload structure. Consider adding validation or type-checking to handle unexpected input formats gracefully.

evaluate: (input: unknown) => {
  const payload = input as ElationWebhookPayload
  const { data: labOrder, action } = payload
  return (
    action === 'saved' &&
    payload.resource === 'lab_orders' &&
    !isNil(labOrder.signed_by) &&
    !isNil(labOrder.signed_date)
  )
Resource ID Extraction

The extractResourceId function directly casts input to ElationWebhookPayload. Ensure that this casting is safe and that invalid inputs are handled to prevent runtime errors.

extractResourceId: (input: unknown) => {
  const payload = input as ElationWebhookPayload
  return payload.data.id

Copy link

github-actions bot commented Feb 4, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Score
Possible issue
Validate input type in evaluate function

Add validation to ensure that the input parameter in the evaluate function is of the
expected type ElationWebhookPayload to prevent runtime errors caused by unexpected
input types.

extensions/elation/timers/labOrderSigned.ts [14-21]

-const payload = input as ElationWebhookPayload
-const { data: labOrder, action } = payload
+if (typeof input !== 'object' || input === null || !('data' in input) || !('action' in input) || !('resource' in input)) {
+  throw new Error('Invalid input type');
+}
+const payload = input as ElationWebhookPayload;
+const { data: labOrder, action } = payload;
 return (
   action === 'saved' &&
   payload.resource === 'lab_orders' &&
   !isNil(labOrder.signed_by) &&
   !isNil(labOrder.signed_date)
-)
+);
Suggestion importance[1-10]: 9

Why: Adding validation for the input parameter in the evaluate function is crucial to prevent runtime errors caused by unexpected input types. This suggestion directly enhances the robustness of the code by ensuring the input conforms to the expected structure before proceeding.

9
Add null check for data.id

Add a null or undefined check for payload.data.id in the extractResourceId function
to avoid potential runtime errors when accessing id.

extensions/elation/timers/labOrderSigned.ts [24-26]

-const payload = input as ElationWebhookPayload
-return payload.data.id
+const payload = input as ElationWebhookPayload;
+if (!payload.data || !payload.data.id) {
+  throw new Error('Invalid or missing resource ID');
+}
+return payload.data.id;
Suggestion importance[1-10]: 8

Why: Adding a null or undefined check for payload.data.id in the extractResourceId function is a valuable improvement to prevent potential runtime errors. This ensures the function handles invalid or missing data gracefully, improving code reliability.

8
General
Strengthen typing for data property

Extend the ElationWebhookPayload interface to include stricter typing for the data
property, ensuring that required fields like id and optional fields like patient are
properly validated.

extensions/elation/timers/types.ts [1-5]

 export interface ElationWebhookPayload {
-  action: string
-  data: { id: string; patient?: number } & Record<string, unknown>
-  resource: string
+  action: string;
+  data: { id: string; patient?: number; signed_by?: string; signed_date?: string } & Record<string, unknown>;
+  resource: string;
 }
Suggestion importance[1-10]: 7

Why: Extending the ElationWebhookPayload interface to include stricter typing for the data property improves type safety and ensures required fields are properly validated. While beneficial, this suggestion has a moderate impact as it primarily enhances developer experience and reduces potential type-related errors.

7

@ebomcke-awell ebomcke-awell merged commit f98b609 into main Feb 4, 2025
2 of 3 checks passed
@ebomcke-awell ebomcke-awell deleted the et-851-create-lab-order-signed-off-and-referral-order-signed-off branch February 4, 2025 10:39
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.

1 participant