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(utils): added and updated the bulk-update-patients script #1805

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

RamilGaripov
Copy link
Contributor

refs. metriport/metriport-internal#1350

Description

  • Added a script to update patients who do not have any successful XCPD links

Testing

  • Local
    • Ran locally pointing to prod db

Release Plan

  • Merge this

Copy link
Member

@leite08 leite08 left a comment

Choose a reason for hiding this comment

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

It would be good to have a notification with the amount of data to be processed/patients updated and main parameters, and a sleep of ~10s so the dev decides whether to move forward with the execution or not.

packages/utils/src/bulk-update-patients.ts Outdated Show resolved Hide resolved
packages/utils/src/bulk-update-patients.ts Outdated Show resolved Hide resolved

main();

async function getPatientCqLinks(sequelize: Sequelize, cxId: string): Promise<CqPatientDataResult> {
Copy link
Member

Choose a reason for hiding this comment

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

nit: put both helper functions at top of file

Copy link
Member

Choose a reason for hiding this comment

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

There's no definition for this, I personally prefer the main function at the top, that's how we read code, from the main logic to the detail anyways.

https://www.notion.so/metriport/Development-Best-Practices-bb3574d3c83d46dc9914a9e5c5542ca7?pvs=4#de6ccc0884ec4c8c976858ec476b34be

@RamilGaripov RamilGaripov marked this pull request as draft May 3, 2024 15:49
@RamilGaripov RamilGaripov marked this pull request as ready for review May 3, 2024 17:51
Copy link
Member

@leite08 leite08 left a comment

Choose a reason for hiding this comment

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

The main issue is how we update the patient. We need to redesign this script.

totalFacilities++;
const patientsList = await metriportAPI.listPatients(facility.id);

await displayWarningAndConfirmation(facilities.length);
Copy link
Member

Choose a reason for hiding this comment

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

We should be sending the amount of patients here, no?

If we're sending alarm/note for each facility, we prob should state the facility id an index.

And we should prob do this after we filter the ones created after the date filter, right?

}

patientsWithNoLinks.push(patient);
patientsNoLinks++;
Copy link
Member

Choose a reason for hiding this comment

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

No need for this, we can just call patientsWithNoLinks.length at any time


for (let i = 0; i < facilities.length; i++) {
const facility = facilities[i];
totalFacilities++;
Copy link
Member

Choose a reason for hiding this comment

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

ditto: can just call facilities.length

}

const patientChunks = chunk(patientsWithNoLinks, PATIENT_CHUNK_SIZE);
console.log(`Facility ${facility.id} has ${patientsWithNoLinks.length} patients`);
Copy link
Member

Choose a reason for hiding this comment

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

...patients with no links - they'll be updated.

Comment on lines +114 to +118
const addressObject = Array.isArray(patient.address)
? patient.address[0]
: patient.address;
const address = addressObject as Address;
await updatePatient(patient, address, facility.id);
Copy link
Member

Choose a reason for hiding this comment

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

@thomasyopes is adding multiple addresses, we should take that into account.

Also, this would remove any address that we augmented from links.

We should probably write an internal endpoint to which we could send a list of patient IDs and it would trigger a PD instead of updating the patient using the SDK.

@RamilGaripov RamilGaripov marked this pull request as draft May 8, 2024 14:53
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.

None yet

3 participants