Skip to content

7272 ensure patients are visible on oms central #7338

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

Merged

Conversation

lache-melvin
Copy link
Contributor

@lache-melvin lache-melvin commented Apr 15, 2025

Fixes #7272

πŸ‘©πŸ»β€πŸ’» What does this PR do?

Adds push of name/name_store_join to OMS Central, and additional "add patient visibility to central" call to the /name-store-join endpoint

Reasoning outlined in a README

πŸ’Œ Any notes for the reviewer?

I did test all of the cases below, and it took a hot minute. Given I've done a full manual test and so would QA, maybe is ok for this to be a code review only idk lol

All cases working except "Patient B" below - a patient that is visible in multiple OMS stores already, and that already has vaccination records. Upgrade to 2.7 makes the vax card accessible in all the stores where patient is visible. But remote site is already at latest changelog cursor before upgrading, so OMS central doesn't think there are any new vaccination records that it needs to send out.

Reinitialising the remote site (after upgrading and a sync) would resolve this, as initialisation is from changelog 0. Given low likelihood of vaccination records existing, maybe this is actually an ok solution? Add to release notes/support upgrade info to check for this case and reinitialise if needed?

πŸ§ͺ Testing

Dear QA: I am sorry but you'll need to reinitialise for this one 😒

  • Have OMS Central site, and two remote sites (Site A and Site B) all on v2.6.0 (please don't use 2.6.1+, unless Change vaccination date to not null migration failsΒ #7299 fix is definitely in the version you are testing lol)
  • Before upgrading, have the following patients (ensure they are NOT visible from any store on OMS Central):
    • Patient A: visible only on Site 1
      • Enrol Patient A in immunisation program, give some vaccinations
    • Patient B: visible on Site 1 and Site 2
      • At Site 1, enrol patient B in immunisation program, give some vaccinations
      • You're on 2.6, so this won't be visible in Site 2
  • Patient C: visible only on Site 2
    • Enrol Patient C in immunisation program, give some vaccinations
  • Patient D: created Legacy mSupply - not visible on any of your OMS sites
  • Upgrade your OMS Central server
  • Upgrade Site 1
    • Sync Site 1 - no sync errors after upgrade
    • Fetch Patient C (Go to Patient List > Add patient > input Patient C details > it should find a match - fetch)
    • Fetch is successful
    • Patient C's vaccination records shouldn't come through yet - Patient C comes from Site 2, which hasn't upgraded
  • Upgrade Site 2
  • Sync Site 2
  • BAD BUT EXPECTED: you can see the vax card for patient B, but the existing vaccinations from Site 1 won't be there
    • (solution TBC, we might just ignore this use case...)
  • Fetch Patient A
  • Fetch is successful
  • You can now see Patient A's vaccination records from Site 2
  • Also fetch Patient D
  • Fetch should be successful
  • Enrol Patient D in the vaccination program and give some doses
  • Sync
  • Back on Site 1
    • Sync - Patient C's vaccination records should now be visible, as Site 2 has upgraded
    • Fetch Patient D
    • You should receive the vaccination records
    • Make a change to one of the patient's vaccinations
    • Ensure this syncs back to Site 2
  • Reinitialise Site 2 - ensure you get back all vaccination records for all the patients
    • At this point you should also get those missing vaccination records for Patient B!

πŸ“ƒ Documentation

  • Part of an epic: documentation will be completed for the feature as a whole
  • No documentation required: no user facing changes or a bug fix which isn't a change in behaviour
  • These areas should be updated or checked:
    1.
    2.

πŸ“ƒ Reviewer Checklist

The PR Reviewer(s) should fill out this section before approving the PR

Breaking Changes

  • No Breaking Changes in the Graphql API
  • Technically some Breaking Changes but not expected to impact any integrations

Issue Review

  • All requirements in original issue have been covered
  • A follow up issue(s) have been created to cover additional requirements

Tests Pass

  • Postgres
  • SQLite
  • Frontend

@github-actions github-actions bot added this to the v2.7.0 milestone Apr 15, 2025
@github-actions github-actions bot added enhancement New feature or request sync Team Ruru πŸ¦‰ Roxy, Noel, Chris, Aimee, LachΓ© Severity: High Bugs breaking core functionality or with no/unacceptable workaround. High impact. Next patch release feature: vaccine card deployment gotchas labels Apr 15, 2025
INSERT INTO changelog (table_name, record_id, row_action, store_id, name_link_id)
SELECT 'vaccination', id, 'UPSERT', store_id, patient_link_id
FROM vaccination
WHERE patient_link_id <> '';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @andreievg - lol sorry we've gone through this a few times, and I know low likelihood of vaccination records existing. But not inserting name_link_id with changelog here meant that if had existing vaccinations were created on OMS Central, they'd never end up with a changelog with name_link_id populated (that was only happening after remote site push).

These would then not sync out if patient visibility added. Best to insert changelog correctly with name_link_id, only where name_link_id does exist. Am I missing an edge case where this could error?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm i am not sure tbh, i feel like in this case it's better to just WHERE patient_link_id IN (SELECT id from name_link_id), to be safe and reduce use case thinking

@lache-melvin lache-melvin marked this pull request as ready for review April 16, 2025 02:15
@github-actions github-actions bot added the Severity: Hotfix Extreme user impact. Can't finalise invoices. Needs patch release and installation immediately. label Apr 16, 2025
Note! patient_link_id is required field, so if <2.7 sites sync vaccination records to 2.7+ OMS Central, they will
fail to integrate. They will re-sync and integrate when remote site upgrades, but records would be lost if
remote site reinitialises before upgrading. Considering this low likelihood, as feature not officially rolled out
before 2.7.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should this be added to release notes or something

@lache-melvin lache-melvin removed the Severity: Hotfix Extreme user impact. Can't finalise invoices. Needs patch release and installation immediately. label Apr 16, 2025
ctx: &ServiceContext,
name_id: &str,
) -> Result<(), CentralApiError> {
let timeout = Duration::from_secs(30);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how long I should set for timeout?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We've added wait for processors logic, I think that might be better? https://github.com/msupply-foundation/open-msupply/pull/1706/files

Copy link
Collaborator

@andreievg andreievg Apr 16, 2025

Choose a reason for hiding this comment

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

It would be different for the synchroniser_driver though, the trigger would also get a channel to report on finish, does that sounds like too much work ? (if you think it is, i'll have a good look at what you have here)

Btw for the patient_id thing in trigger I think we could have kept existing trigger and add another one trigger_with_patient_id.

And if we implement the waiting I would do create another trigger_with_await (or something like that)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, created issue - #7435

@andreievg andreievg self-assigned this Apr 16, 2025
@@ -20,10 +21,13 @@ use crate::{

use super::PatientSearch;

#[derive(Debug)]
#[derive(Error, Debug)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

great

// More robust to check patient record has been received
if !sync_status.is_syncing {
// If sync finished but integration of patient failed, will break after timeout
if check_patient_exists(&ctx.connection, &name_id)?.is_some() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's cool

break;
}
}
debug!("Patient not yet found, awaiting sync completion...");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Every 500ms ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol ever the optimist

Ok(())
}

impl From<GetActiveStoresOnSiteError> for CentralApiError {
Copy link
Collaborator

Choose a reason for hiding this comment

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

At some point we agreed that ? make it hard to trace the conversion, so should only convert error for common things. Not requesting change now, but I would do a helper method in CentralApiError (that accept same thing as format_error)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, ended up replacing with map_error in the next PR, adding the processor πŸ™

Copy link
Collaborator

@andreievg andreievg left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @lache-melvin, we can do the await for sync refactor after we get 2.7RC (with this change) build out for testing : )

@lache-melvin lache-melvin merged commit 6c29d21 into v2.7.0-RC Apr 22, 2025
2 checks passed
@lache-melvin lache-melvin deleted the 7272-ensure-patients-are-visible-on-oms-central branch April 22, 2025 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployment gotchas enhancement New feature or request feature: vaccine card Severity: High Bugs breaking core functionality or with no/unacceptable workaround. High impact. Next patch release sync Team Ruru πŸ¦‰ Roxy, Noel, Chris, Aimee, LachΓ©
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants