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

feat(elation): new action to create a referral order #535

Conversation

ebomcke-awell
Copy link
Contributor

@ebomcke-awell ebomcke-awell commented Dec 12, 2024

User description

  • add create referral order action
  • add create referral order and search contacts to elation
    api client
  • add missing specialties property in elation contact type

PR Type

Enhancement, Tests


Description

  • Implemented a new action createReferralOrder to create referral orders in Elation.
  • Added API client methods for creating referral orders and searching contacts by name.
  • Defined fields, data points, and validation schema for the referral order action.
  • Added unit tests to validate the functionality and error handling of the createReferralOrder action.
  • Extended Elation types to include referral order and specialty definitions.
  • Introduced mock data and updated test utilities for referral order testing.

Changes walkthrough 📝

Relevant files
Tests
3 files
client.ts
Add mock for createReferralOrder in client tests                 

extensions/elation/mocks/client.ts

  • Added a mock implementation for createReferralOrder.
  • Updated the mock client return object to include createReferralOrder.
  • +5/-1     
    constants.ts
    Add mock data for referral order and contacts                       

    extensions/elation/mocks/constants.ts

  • Added referralOrderExample mock data.
  • Added searchContactsResponseExample mock data.
  • Included specialties property in findContactResponseExample.
  • +18/-0   
    createReferralOrder.test.ts
    Add unit tests for createReferralOrder action                       

    extensions/elation/actions/createReferralOrder/createReferralOrder.test.ts

  • Added unit tests for createReferralOrder action.
  • Tested scenarios for successful creation, contact selection, and error
    handling.
  • +124/-0 
    Enhancement
    11 files
    dataPoints.ts
    Add dataPoints configuration for referral order                   

    extensions/elation/actions/createReferralOrder/config/dataPoints.ts

    • Defined dataPoints configuration for referral order action.
    +8/-0     
    fields.ts
    Define fields and validation schema for referral order     

    extensions/elation/actions/createReferralOrder/config/fields.ts

  • Defined fields for referral order action including validation schema.
  • Added dropdown options for authorization_for field.
  • +72/-0   
    index.ts
    Export referral order configuration modules                           

    extensions/elation/actions/createReferralOrder/config/index.ts

    • Exported dataPoints and fields configurations.
    +2/-0     
    createReferralOrder.ts
    Implement createReferralOrder action with API integration

    extensions/elation/actions/createReferralOrder/createReferralOrder.ts

  • Implemented createReferralOrder action.
  • Added error handling for validation and API errors.
  • Integrated with Elation API for referral order creation and letter
    posting.
  • +115/-0 
    index.ts
    Export createReferralOrder action                                               

    extensions/elation/actions/createReferralOrder/index.ts

    • Exported createReferralOrder action.
    +1/-0     
    client.ts
    Extend Elation client with referral order and contact search

    extensions/elation/client.ts

  • Added methods for creating referral orders and searching contacts by
    name.
  • Updated existing methods to align with new functionality.
  • +41/-2   
    contact.ts
    Extend ElationContact type with specialties                           

    extensions/elation/types/contact.ts

    • Added specialties property to ElationContact interface.
    +3/-0     
    referralOrder.ts
    Define types for referral order API                                           

    extensions/elation/types/referralOrder.ts

    • Added types for referral order input and response.
    +12/-0   
    specialty.ts
    Define ElationSpecialty type                                                         

    extensions/elation/types/specialty.ts

    • Added type definition for ElationSpecialty.
    +4/-0     
    referralOrder.zod.ts
    Add validation schema for referral order                                 

    extensions/elation/validation/referralOrder.zod.ts

  • Added Zod schema for referral order validation.
  • Included enums for authorization and resolution states.
  • +49/-0   
    specialty.zod.ts
    Add validation schema for specialty                                           

    extensions/elation/validation/specialty.zod.ts

    • Added Zod schema for specialty validation.
    +8/-0     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    - add create referral order action
    - add create referral order and search contacts to elation
    api client
    - add missing specialties property in elation contact type
    @ebomcke-awell ebomcke-awell force-pushed the et-592-new-action-in-elation-extension-create-referral-order branch from 54c1a62 to 08f9be2 Compare December 12, 2024 13:20
    @ebomcke-awell ebomcke-awell marked this pull request as draft December 12, 2024 14:31
    @ebomcke-awell ebomcke-awell marked this pull request as ready for review December 12, 2024 14:31
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

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

    Possible Bug
    The specialty field is being set to { name: specialty } when creating a referral order, but there is no validation or check to ensure that the specialty value corresponds to a valid specialty in Elation. This could lead to unexpected errors or invalid data being sent to the API.

    Error Handling
    The error handling for searchContactsByName assumes that the first contact in the results is always valid. There is no fallback or additional validation in case the contact data is incomplete or incorrect.

    Code Smell
    The onActivityCreated function is quite large and handles multiple responsibilities, such as validation, API calls, and error handling. Consider refactoring it into smaller, more focused functions for better readability and maintainability.

    Validation Inconsistency
    The referralOrderSchema includes optional fields like icd10_codes and specialty, but there is no validation to ensure these fields are properly populated when required by the API. This could lead to runtime errors.

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add a check to ensure the contactsResponse.results array contains valid data before accessing its elements

    Handle cases where the contactsResponse.results array is empty or undefined to avoid
    runtime errors when accessing the first element.

    extensions/elation/actions/createReferralOrder/createReferralOrder.ts [38]

    -const contact = contactsResponse.results[0]
    +const contact = contactsResponse.results?.[0];
    +if (!contact) {
    +  throw new Error(`No valid contact found with the name ${contact_name}.`);
    +}
    Suggestion importance[1-10]: 9

    Why: This suggestion prevents runtime errors by ensuring the contactsResponse.results array is not empty or undefined before accessing its elements. It improves the reliability of the code and handles edge cases effectively.

    9
    Add validation or fallback for the specialty field to prevent potential API errors

    Ensure that the specialty field is properly validated before being passed to the
    API, as it is currently being used directly without checking if it matches the
    expected format or values.

    extensions/elation/actions/createReferralOrder/createReferralOrder.ts [46]

    -specialty: { name: specialty },
    +specialty: specialty ? { name: specialty } : null,
    Suggestion importance[1-10]: 8

    Why: The suggestion addresses a potential issue where the specialty field might not be properly validated or could be null, leading to API errors. Adding a fallback ensures robustness and prevents unexpected failures during API calls.

    8
    Validate the referralOrderResponse.id to ensure it exists before using it in API calls

    Ensure that the referralOrderResponse.id is validated or checked for existence
    before using it in subsequent API calls to avoid potential null or undefined errors.

    extensions/elation/actions/createReferralOrder/createReferralOrder.ts [57]

    +if (!referralOrderResponse.id) {
    +  throw new Error('Referral order creation failed: Missing ID.');
    +}
     referral_order: referralOrderResponse.id,
    Suggestion importance[1-10]: 8

    Why: The suggestion ensures that the referralOrderResponse.id is checked for existence before being used, which prevents potential null or undefined errors in subsequent API calls. This improves error handling and code robustness.

    8
    General
    Add a default value or validation for the specialty field to prevent issues with null or undefined values

    Add a fallback mechanism or validation for payload.fields.specialty to handle cases
    where it might be null or undefined, as the API expects a valid specialty object.

    extensions/elation/actions/createReferralOrder/createReferralOrder.ts [29]

    -const { patient, practice, contact_name, body, authorization_for, consultant_name, specialty } = FieldsValidationSchema.parse(payload.fields)
    +const { patient, practice, contact_name, body, authorization_for, consultant_name, specialty = '' } = FieldsValidationSchema.parse(payload.fields)
    Suggestion importance[1-10]: 7

    Why: Adding a default value for the specialty field ensures that the code does not break when the field is null or undefined. While useful, the impact is slightly less critical as the field is already being validated by the schema.

    7

    Copy link
    Contributor

    @bejoinka bejoinka left a comment

    Choose a reason for hiding this comment

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

    just a general comment on the try / catch mechanism -> reducing boilerplate for extensions developers

    @ebomcke-awell ebomcke-awell merged commit 31412a1 into main Dec 12, 2024
    1 check passed
    @ebomcke-awell ebomcke-awell deleted the et-592-new-action-in-elation-extension-create-referral-order branch December 12, 2024 15:56
    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.

    2 participants