feat(centralServer): no-issue: add patient program registration importer#9613
feat(centralServer): no-issue: add patient program registration importer#9613julianam-w wants to merge 8 commits intomainfrom
Conversation
Add bulk importer for enrolling patients into program registries via xlsx upload. Uses a single 'ppr' sheet with comma-separated condition IDs. Supports upsert semantics, FK validation, Excel date conversion, and dry run mode. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ondition errors Move the registration findOne query above the condition loop to avoid redundant DB hits. Catch condition creation errors individually so a failed condition does not incorrectly mark the registration as errored. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update actions/checkout, actions/setup-node from non-existent v6 to v4, and actions/cache/restore and actions/cache/save from v3 to v4. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This reverts commit 2f6002a.
Postgres doesn't reliably return whether an upserted row was created or updated, so check for an existing record before the upsert to determine the correct stat. Also reuse the upsert's returned instance for condition creation to avoid a redundant findOne. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| patientId: patient.id, | ||
| programRegistryId, | ||
| date: dateString, | ||
| ...(registrationStatus && { registrationStatus }), |
There was a problem hiding this comment.
[Bugs & Correctness] critical
Re-importing the same spreadsheet will create duplicate PatientProgramRegistrationCondition rows. The registration itself is upserted (composite PK on patientId+programRegistryId), but conditions are always create()d with no duplicate check. On re-import, each condition row is inserted again with a new UUID. Either check for an existing condition before creating, or delete all conditions for the registration before re-creating them (within the same row handler).
| const record = await models[modelName].findByPk(id); | ||
| if (!record) { | ||
| throw new Error(`${fieldLabel} "${id}" does not exist`); | ||
| } |
There was a problem hiding this comment.
[Security] suggestion
validateForeignKey uses findByPk(id) where id comes from untrimmed spreadsheet cell values. While Sequelize parameterises the query (no SQL injection), the id value is only trimmed at the row level by trimRow (which trims keys, not values). A cell value like ' some-id ' with leading/trailing whitespace would fail lookup silently. Consider trimming id inside validateForeignKey or in parseCommaSeparated for condition IDs, to avoid confusing 'does not exist' errors caused by invisible whitespace.
|
🦸 Review Hero Summary Below consensus threshold (7 unique issues not confirmed by majority)
Local fix prompt (copy to your coding agent)Fix these issues identified on the pull request. One commit per issue fixed.
|
…nd trim cell values Trim string values in trimRow (was only trimming keys) so leading/trailing whitespace in spreadsheet cells does not cause silent FK lookup failures. Delete existing PatientProgramRegistrationCondition rows before re-creating them when condition IDs are provided, so re-importing the same spreadsheet does not accumulate duplicate condition rows. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…eting on re-import Rather than deleting and re-creating PatientProgramRegistrationCondition rows on re-import, check for an existing record and skip creation if one already exists, tracking it as 'skipped' in the import stats. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Changes
Adds a bulk importer for enrolling patients into program registries via xlsx upload. The importer uses a single
pprsheet with the following columns:date,registration_status,patient_display_id,program_registry_id,clinician_idclinical_status_id,registering_facility_id,deactivated_clinician_id,deactivated_dateprogram_registry_condition_ids(comma-separated),program_registry_condition_category_idFeatures:
Route:
POST /api/admin/import/patientProgramRegistrationsAuto-Deploy
Options
Tests
Review Hero
Remember to...