feat(integrations): PHX-297: Send transactions to open mSupply API#9195
Conversation
Summary of ChangesHello @NavarroEmilioLuis, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request establishes a new, automated integration with the Open mSupply API, designed to streamline the transfer of dispensed medication data from the system. It introduces a robust scheduled process that handles authentication, batches data for efficient transmission, and provides detailed logging for monitoring and troubleshooting. The integration is highly configurable through facility-specific settings, ensuring flexibility and control over how medication data is synchronized with external mSupply instances. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new integration to send medication dispense transactions to an open mSupply API. The changes follow a good pattern, including a database migration for logging, a new Sequelize model, a scheduled task for processing, comprehensive tests, and the necessary configuration and settings schemas. My review focuses on improving the robustness of the data processing. I've identified a potential correctness issue with the batch pagination logic that could lead to data inconsistency under concurrent operations, and a minor issue with logging that might discard useful debugging information. Overall, this is a solid implementation of the new feature.
rohan-bes
left a comment
There was a problem hiding this comment.
Have a few comments and optional requests for rename/refactor, but nothing blocking. Looks solid, and with all things integrations there's usually a bit of tweaking once you start actually integrating so best to get to that point sooner rather than later :)
| } | ||
|
|
||
| // Designed to post dispensed medications from pharmacy to an Open mSupply instance | ||
| export class mSupplyMedIntegrationProcessor extends ScheduledTask { |
There was a problem hiding this comment.
I know you're following a bit of a convention here with the DHIS2IntegrationProcessor but tbh I don't love that naming convention as its not very clear about what the task actually does. Thoughts on something like MSupplyMedicationStockUpdater?
There was a problem hiding this comment.
I'm fine either way, though I'm unsure what we will have to do with the new endpoint update. I'd rather leave it generic + comment
| const batchCount = Math.ceil(toProcess / batchSize); | ||
|
|
||
| for (let i = 0; i < batchCount; i++) { | ||
| const medications = await this.models.MedicationDispense.findAll({ |
There was a problem hiding this comment.
I could have seen us wanting to group the dispenses by medication code, so that we just send the sum of all dispenses per medication. Was that considered? I guess we get a bit more granularity this way for reporting and can better handle when mSupply stock runs out.
There was a problem hiding this comment.
Considered for a second maybe, but I think it's getting ahead. Also, would not work with the current cursor approach as we would have to save a log per group code or something in the likes.
PS: I'd also leave this for later if anything, considering granularity + simplicity + deadline!
Co-authored-by: Rohan Port <59544282+rohan-bes@users.noreply.github.com>
|
Android builds 📱
|
🍹
|
| "mSupplyMedIntegrationProcessor": { | ||
| "enabled": false, | ||
| "schedule": "0 2 * * *", | ||
| "batchSize": 100, | ||
| "batchSleepAsyncDurationInMilliseconds": 50 | ||
| }, | ||
| }, | ||
| "integrations": { | ||
| "mSupplyMed": { | ||
| "enabled": false, | ||
| "username": "", | ||
| "password": "" | ||
| } |
There was a problem hiding this comment.
Deployment team, this is the change, new integration and schedule for the facility server
Changes
Follows a similar pattern to the DHIS integration. More information on Linear cause there are lots of details here. Note that one third of the LOC is the test file, the other third is probably boilerplate (migration, model, config, dbt) and the rest is the actual task file to send the transactions.
Deploys