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

Add orchestrations #41

Merged
merged 11 commits into from
May 21, 2024
Merged

Add orchestrations #41

merged 11 commits into from
May 21, 2024

Conversation

bradsawadye
Copy link
Collaborator

@bradsawadye bradsawadye commented Apr 23, 2024

This adds functionality for recording all the data orchestrations in the mpi mediator. Gives us visibility on the requests to hapi fhir, Jempi and kafka from the mediator

Summary by CodeRabbit

  • New Features

    • Improved orchestration tracking for API responses, enhancing visibility and traceability of data processing.
  • Bug Fixes

    • Corrected status messages from 'Success' to 'Successful' to reflect accurate transaction states.
  • Version Updates

    • Updated project version to v2.3.0 for consistency across configuration files.
  • Tests

    • Added assertions for orchestration handling in various test cases to ensure robust validation of new features.

Orchestrations give visibility on how the data is manipulated. THey show us the responses from the different services that the data is sent to on the openhim console.
Copy link
Contributor

@drizzentic drizzentic left a comment

Choose a reason for hiding this comment

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

Looks good to me. Just a minor typo fix

src/routes/handlers/fetchPatientResources.ts Outdated Show resolved Hide resolved
Co-authored-by: Drizzentic <[email protected]>
@MatthewErispe MatthewErispe requested a review from drizzentic May 6, 2024 13:22
@drizzentic
Copy link
Contributor

@bradsawadye Please resolve the merge conflict

Copy link
Contributor

coderabbitai bot commented May 20, 2024

Walkthrough

This update enhances the mpi-mediator project by introducing orchestration handling, updating response statuses, and incorporating orchestrations into the response objects. The version has been incremented to v2.3.0 in both package.json and mediatorConfig.json.

Changes

File(s) Change Summary
package.json Updated version from v2.1.1 to v2.3.0.
src/middlewares/mpi-mdm-everything.ts, src/middlewares/mpi-mdm-summary.ts Modified functions to handle Orchestration objects and updated response status to 'Successful'.
src/middlewares/openhim-proxy-interceptor.ts, src/middlewares/validation.ts Changed transactionStatus from 'Success' to 'Successful'.
src/openhim/mediatorConfig.json Updated version from v2.0.0 to v2.3.0.
src/routes/handlers/fetchPatient.ts, src/routes/handlers/fetchPatientResources.ts, src/routes/handlers/fetchPatientSummaries.ts Added orchestration handling, updated response construction, and status messages.
src/types/response.ts Added Orchestration type and updated interfaces.
src/utils/kafkaFhir.ts, src/utils/utils.ts Added orchestration handling and updated transaction statuses.
tests/unit/fetchPatient.ts, tests/unit/fetchPatientResources.ts, tests/unit/fetchPatientSummaries.ts, tests/unit/kafkaAsyncPatientHandler.ts, tests/unit/kafkaFhir.ts Added assertions for orchestrations and updated status messages to 'Successful'.

🐇✨

In the code, a rabbit hops,
With orchestrations, it never stops,
From 'Success' to 'Successful' it goes,
Tracking each response, it shows.
Version bumped, features bright,
The mediator's future is in sight.

🛠️💻🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between b932896 and e8590b8.
Files selected for processing (22)
  • package.json (1 hunks)
  • src/middlewares/mpi-mdm-everything.ts (3 hunks)
  • src/middlewares/mpi-mdm-summary.ts (1 hunks)
  • src/middlewares/openhim-proxy-interceptor.ts (1 hunks)
  • src/middlewares/validation.ts (1 hunks)
  • src/openhim/mediatorConfig.json (1 hunks)
  • src/routes/handlers/fetchPatient.ts (5 hunks)
  • src/routes/handlers/fetchPatientResources.ts (4 hunks)
  • src/routes/handlers/fetchPatientSummaries.ts (5 hunks)
  • src/routes/handlers/matchPatientAsync.ts (2 hunks)
  • src/types/response.ts (1 hunks)
  • src/utils/kafkaFhir.ts (11 hunks)
  • src/utils/utils.ts (6 hunks)
  • tests/unit/fetchPatient.ts (3 hunks)
  • tests/unit/fetchPatientResources.ts (2 hunks)
  • tests/unit/fetchPatientSummaries.ts (2 hunks)
  • tests/unit/kafkaAsyncPatientHandler.ts (3 hunks)
  • tests/unit/kafkaFhir.ts (4 hunks)
  • tests/unit/matchPatientAsync.ts (1 hunks)
  • tests/unit/matchPatientSync.ts (12 hunks)
  • tests/unit/middlewares.ts (3 hunks)
  • tests/unit/utils.ts (1 hunks)
Files skipped from review due to trivial changes (5)
  • package.json
  • src/middlewares/openhim-proxy-interceptor.ts
  • src/openhim/mediatorConfig.json
  • tests/unit/kafkaAsyncPatientHandler.ts
  • tests/unit/matchPatientAsync.ts
Additional Context Used
Learnings (1)
src/routes/handlers/fetchPatient.ts (1)
User: bradsawadye
PR: jembi/mpi-mediator#45
File: src/routes/index.ts:75-79
Timestamp: 2024-05-14T09:04:31.151Z
Learning: The `fetchPatientById` function in `src/routes/handlers/fetchPatient.ts` includes internal error handling and returns a formatted response object, making additional try-catch blocks in the route handler unnecessary.
Additional comments not posted (31)
src/types/response.ts (4)

7-7: Optional headers in Response interface enhance flexibility.


10-17: Enhancements to Request interface improve its adaptability and usability.


20-24: Introduction of Orchestration interface supports new functionality for orchestration tracking.


29-29: Addition of orchestrations to OpenHimResponseObject aligns with enhanced orchestration handling.

src/middlewares/mpi-mdm-summary.ts (2)

6-6: Import of Orchestration is essential for handling new orchestration features.


9-30: Proper handling of orchestrations in fetchAllLinkedPatientSummary enhances visibility and tracking, aligning with PR objectives.

src/middlewares/validation.ts (1)

40-40: Update of transactionStatus to 'Successful' improves consistency in status messaging across the application.

src/routes/handlers/matchPatientAsync.ts (1)

17-62: Handling of orchestrations in matchAsyncHandler enhances transparency and tracking of asynchronous operations.

src/middlewares/mpi-mdm-everything.ts (2)

4-4: Import of Orchestration is essential for handling new orchestration features in the MDM expansion.


Line range hint 14-35: Proper handling of orchestrations in fetchAllLinkedPatientResources enhances visibility and tracking, aligning with PR objectives.

src/routes/handlers/fetchPatientResources.ts (1)

27-45: Handling of orchestrations in fetchAllPatientResourcesByRefs enhances visibility and tracking, aligning with PR objectives.

src/routes/handlers/fetchPatientSummaries.ts (1)

Line range hint 23-55: Handling of orchestrations in fetchAllPatientSummariesByRefs enhances visibility and tracking, aligning with PR objectives.

tests/unit/fetchPatientResources.ts (1)

122-125: Tests for fetchAllPatientResourcesByRefs effectively verify the handling and population of orchestrations.

tests/unit/fetchPatientSummaries.ts (1)

207-210: LGTM! Consider adding assertions to verify the content of the orchestrations array.

Verification successful

The search results indicate that there are indeed assertions checking the content of the orchestrations array in various test files. Specifically, there are assertions verifying the name and response.status of the orchestrations.

  • tests/unit/matchPatientSync.ts
  • tests/unit/kafkaFhir.ts

These files contain assertions that check the content of the orchestrations array, ensuring that the orchestrations are being recorded and validated correctly.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the content of orchestrations in the tests.

# Test: Search for assertions related to orchestrations content. Expect: Assertions checking the content.
rg --type typescript $'expect(.+orchestrations\[\d+\].response).to'

Length of output: 103



Script:

#!/bin/bash
# Description: Verify the content of orchestrations in the tests.

# Test: Search for assertions related to orchestrations content. Expect: Assertions checking the content.
rg 'expect(.+orchestrations\[\d+\].response).to' --glob '*.ts'

Length of output: 64



Script:

#!/bin/bash
# Description: Search for references to the orchestrations array in the test files.

# Find all references to the orchestrations array in .ts files.
rg 'orchestrations' --glob '*.ts'

Length of output: 8688

src/routes/handlers/fetchPatient.ts (3)

Line range hint 105-168: LGTM! Ensure that the orchestration objects are correctly populated with request and response details.


Line range hint 171-206: LGTM! Ensure that the orchestration objects are correctly populated with request and response details.


Line range hint 38-90: LGTM! Ensure that the orchestration objects are correctly populated with request and response details.

Verification successful

The verification script successfully identified multiple instances where orchestration objects are being populated with response details. This confirms that the orchestration objects are correctly initialized and used within the fetchPatientByQuery function.

  • orchestrations[0].response.status = mpiResponse.status;
  • orchestrations[0].response.body = JSON.stringify(mpiResponse.body);
  • orchestrations[0].response.timestamp = format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
  • orchestrations[0].response.status = fhirResponse.status;
  • orchestrations[0].response.body = JSON.stringify(fhirResponse.body);
  • orchestrations[0].response.timestamp = format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
  • orchestrations[1].response.status = mpiResponse.status;
  • orchestrations[1].response.body = JSON.stringify(mpiResponse.body);
  • orchestrations[1].response.timestamp = format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX");

These lines indicate that the orchestration objects are being populated with the necessary response details, ensuring proper tracking of requests and responses.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the orchestration objects in the function `fetchPatientByQuery`.

# Test: Search for the usage of orchestration objects. Expect: Proper initialization and usage.
rg --type typescript $'orchestrations\[\d+\].response' src/routes/handlers/fetchPatient.ts

Length of output: 126



Script:

#!/bin/bash
# Description: Verify the orchestration objects in the function `fetchPatientByQuery`.

# Test: Search for the usage of orchestration objects. Expect: Proper initialization and usage.
rg --type ts $'orchestrations\\[\\d+\\].response' src/routes/handlers/fetchPatient.ts

Length of output: 748

tests/unit/kafkaFhir.ts (2)

118-121: LGTM! Ensure that the orchestration objects are correctly populated with request and response details in error scenarios.


62-67: LGTM! Consider adding more detailed assertions to verify the specific properties of the orchestration objects.

Verification successful

The search results indicate that there are multiple references to orchestrations in the test files, including assertions checking their properties. This confirms that the orchestration handling is being tested adequately.

  • tests/unit/kafkaFhir.ts contains assertions checking the orchestration names and response statuses.
  • Other test files also include assertions related to orchestrations, ensuring comprehensive coverage.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the content of orchestrations in the tests.

# Test: Search for assertions related to orchestrations content. Expect: Assertions checking the content.
rg --type typescript $'expect(.+orchestrations\[\d+\].response).to'

Length of output: 103



Script:

#!/bin/bash
# Description: Verify the content of orchestrations in the tests.

# Test: Search for assertions related to orchestrations content. Expect: Assertions checking the content.
rg 'expect(.+orchestrations\[\d+\].response).to' --glob '*.ts'

Length of output: 64



Script:

#!/bin/bash
# Description: Verify the presence of assertions related to orchestrations in the tests.

# Test: Search for any assertions related to orchestrations. Expect: Assertions checking the content.
rg 'expect(.+orchestrations\[\d+\]).to' --glob '*.ts'

Length of output: 55



Script:

#!/bin/bash
# Description: Verify the presence of orchestrations in the tests.

# Test: Search for any references to orchestrations in the test files. Expect: References to orchestrations.
rg 'orchestrations' --glob '*.ts'

Length of output: 8688

src/utils/utils.ts (2)

278-286: LGTM! Ensure that the createHandlerResponseObject function correctly includes orchestrations in the response object.


Line range hint 111-125: LGTM! Ensure that the buildOpenhimResponseObject function correctly handles different content types and includes orchestrations in the response object.

src/utils/kafkaFhir.ts (1)

Line range hint 57-186: LGTM! Ensure that the orchestration objects in the sendToFhirAndKafka function are correctly populated with request and response details.

Verification successful

The verification script confirms that the orchestrations array is being used correctly in the sendToFhirAndKafka function. The array is initialized and orchestration objects are being pushed to it as expected.

  • The orchestrations array is initialized.
  • Orchestration objects are added to the orchestrations array using the push method.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the orchestration objects in the `sendToFhirAndKafka` function.

# Test: Search for the usage of orchestration objects. Expect: Proper initialization and usage.
rg --type typescript $'orchestrations\[\d+\].response' src/utils/kafkaFhir.ts

Length of output: 113



Script:

#!/bin/bash
# Description: Verify the orchestration objects in the `sendToFhirAndKafka` function.

# Test: Search for the usage of orchestration objects. Expect: Proper initialization and usage.
rg --type ts $'orchestrations\\[\\d+\\].response' src/utils/kafkaFhir.ts

Length of output: 70



Script:

#!/bin/bash
# Description: Verify the initialization and usage of the orchestration objects in the `sendToFhirAndKafka` function.

# Search for the initialization of the `orchestrations` array.
rg --type ts 'orchestrations\s*=\s*\[\]' src/utils/kafkaFhir.ts

# Search for the addition of orchestration objects to the `orchestrations` array.
rg --type ts 'orchestrations\.push' src/utils/kafkaFhir.ts

Length of output: 230

tests/unit/matchPatientSync.ts (5)

8-8: Ensure the new imports are utilized effectively in the tests.

Also applies to: 13-13


Line range hint 60-102: The test case checks the orchestration handling in matchSyncHandler. It's good to see the orchestration array being tested for its length, ensuring that no orchestrations were unintentionally added.

Also applies to: 111-111, 118-118, 127-128


Line range hint 133-193: This test case effectively checks the error handling and orchestration recording when the patient creation fails. It's crucial to verify that the orchestration details are correctly populated, including the status and the specific request details.


248-257: The test case for successful patient handling in the FHIR store and Kafka is well-implemented. It checks the orchestration details and ensures that the response status is 'Successful', which aligns with the new status updates across the system.

Also applies to: 266-273, 301-301


434-441: This test ensures that the orchestration array is empty when no new orchestrations are added, which is a good practice to confirm the expected behavior of the system under test.

Also applies to: 450-450

tests/unit/fetchPatient.ts (2)

140-140: The tests verify that the orchestrations array has exactly two entries, which is expected behavior given the operations performed. This is a good check to ensure that all expected orchestrations are being recorded.

Also applies to: 251-251


467-467: This test ensures that three orchestrations are recorded, which likely corresponds to the three network calls made in the test. It's important to verify that each external interaction is being orchestrated as expected.

tests/unit/middlewares.ts (1)

259-259: The tests check the 'Successful' status in various middleware functions, aligning with the system-wide update from 'Success' to 'Successful'. It's good to see that the orchestrations are being checked, ensuring that they are being recorded as expected.

Also applies to: 360-363, 426-429

tests/unit/utils.ts (1)

578-578: Update to 'Successful' aligns with the PR's objective to standardize status messages.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between e8590b8 and c6c9c85.
Files selected for processing (5)
  • tests/cucumber/step-definitions/fhirAccessProxy.ts (3 hunks)
  • tests/cucumber/step-definitions/mpiAccessProxy.ts (1 hunks)
  • tests/cucumber/step-definitions/patientSubmission.ts (2 hunks)
  • tests/cucumber/step-definitions/patientSyncMatching.ts (1 hunks)
  • tests/cucumber/step-definitions/validation.ts (1 hunks)
Files skipped from review due to trivial changes (4)
  • tests/cucumber/step-definitions/fhirAccessProxy.ts
  • tests/cucumber/step-definitions/patientSubmission.ts
  • tests/cucumber/step-definitions/patientSyncMatching.ts
  • tests/cucumber/step-definitions/validation.ts
Additional comments not posted (2)
tests/cucumber/step-definitions/mpiAccessProxy.ts (2)

73-73: LGTM! The status check for a successful response is correctly aligned with the updated status message conventions.


73-73: LGTM! The status check for an error response is correctly handled.

@bradsawadye bradsawadye merged commit 1e311b2 into main May 21, 2024
2 checks passed
@bradsawadye bradsawadye deleted the add-orchestrations branch May 21, 2024 09:34
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.

2 participants