Created
September 17, 2021 18:09
-
-
Save serhii-ilin/530d623894ce9cf95c9ede3d480921a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function movePatients(sourceGroupName, destinationGroupName, measureSetId) { | |
// Find source group | |
const oldGroup = db.getCollection("groups").findOne({ name: sourceGroupName }); | |
if (!oldGroup || !oldGroup._id) { | |
throw new Error(`Source Group ${sourceGroupName} cannot be found`); | |
} | |
print(`Source group located: ${oldGroup._id}`); | |
// Find destination group | |
const newGroup = db.getCollection("groups").findOne({ name: destinationGroupName }); | |
if (!newGroup || !newGroup._id) { | |
throw new Error(`Destination Group ${destinationGroupName} cannot be found`); | |
} | |
print(`Destination group located: ${newGroup._id}`); | |
// Update patients' group_id | |
const patientResult = db.getCollection("cqm_patients").updateMany({ | |
group_id: oldGroup._id, | |
measure_ids: measureSetId | |
}, { | |
$set: { group_id: newGroup._id } | |
}); | |
print(`${patientResult.modifiedCount} Patient(s) moved to group ${destinationGroupName}`); | |
} | |
movePatients("SOURCEEMAIL@orgname.org", "hmdmtjc", "755216B2-5FA4-474D-BB29-AE8EAA209460"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment