Skip to content

Commit 61af500

Browse files
authored
fix(data): add deleted rows back to patient to prevent misalignment of patient IDs (#584)
In #582, rows were removed from the QuestionnaireDB `patient` table, to let the `SyncPublishQuestionnaire` event populate this table. However, this caused a misalignment of patient IDs, because deleted patients were no longer being added to the table. This led to rows in `answerQuestionnaire` and `answer` being misattributed to the wrong users (e.g., a row in `answerQuestionnaire` previously attributing a questionnaire to Laurie, patient 9, was now linking it to Kathy, new patient 9). This PR adds all row inserts back to `patient` (including the deleted rows), to fix the offset in IDs (e.g. restoring Laurie as patient 9), and to prevent issues with unpredictable syncing in general. This will also allow us to more easily clean up questionnaire data for deleted users.
1 parent 4b7fef0 commit 61af500

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

db_management/questionnairedb/data/test/answers.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
--
33
-- SPDX-License-Identifier: AGPL-3.0-or-later
44

5+
-- TODO clean up data for deleted patientIds (see db_management/questionnairedb/data/test/omi/patients.sql)
56
INSERT INTO `answer` (`ID`, `questionnaireId`, `sectionId`, `questionId`, `typeId`, `answerSectionId`, `languageId`, `patientId`, `answered`, `skipped`, `deleted`, `deletedBy`, `creationDate`, `createdBy`, `lastUpdated`, `updatedBy`) VALUES
67
(281, 11, 11, 823, 2, 55, -1, 1, 1, 0, 0, '', '2016-11-25 18:18:38', 'QUESTIONNAIRE_MIGRATION_2019', '2023-06-02 14:25:14', 'QUESTIONNAIRE_MIGRATION_2019'),
78
(282, 11, 11, 824, 2, 55, -1, 1, 1, 0, 0, '', '2016-11-25 18:18:38', 'QUESTIONNAIRE_MIGRATION_2019', '2023-06-02 14:25:14', 'QUESTIONNAIRE_MIGRATION_2019'),
@@ -2797,6 +2798,7 @@ SET creationDate = DATE_ADD(now(), INTERVAL -13 DAY),
27972798
WHERE questionnaireId=204
27982799
and sectionId=154;
27992800

2801+
-- TODO clean up data for deleted patientIds (see db_management/questionnairedb/data/test/omi/patients.sql)
28002802
INSERT INTO `answerQuestionnaire` (`ID`, `questionnaireId`, `patientId`, `status`, `deleted`, `deletedBy`, `creationDate`, `createdBy`, `lastUpdated`, `updatedBy`, `respondentUsername`, `respondentDisplayName`) VALUES
28012803
-- esas-r answer instances for bart homer and marge and lisa and rory
28022804
(184, 136, 1, 0, 0, '', '2000-01-01 00:00:00', 'QUESTIONNAIRE_V2_AUTO_SYNC', '2000-01-01 00:00:00', '3_APP_100.100.100', '', ''),

db_management/questionnairedb/data/test/ohigph/patients.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
--
33
-- SPDX-License-Identifier: AGPL-3.0-or-later
44

5-
-- patients get synced automatically via the DB event that runs periodically
5+
-- TODO Rows in `answerQuestionnaire` and `answer` from `db_management/questionnairedb/data/test/answers.sql` may not line up
6+
-- TODO with the right PatientIds based on data synced here. Consider separating questionnaire answers per hospital.
7+
8+
-- patients get synced automatically via the DB event SyncPublishQuestionnaire that runs periodically

db_management/questionnairedb/data/test/omi/patients.sql

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,30 @@
22
--
33
-- SPDX-License-Identifier: AGPL-3.0-or-later
44

5-
-- patients get synced automatically via the DB event that runs periodically
5+
-- Legacy (deleted) test patients are kept until all their remaining data in QuestionnaireDB is cleaned up
6+
-- Otherwise, data linked to certain patientIds will be orphaned
7+
REPLACE INTO `patient` (`ID`, `hospitalId`, `externalId`, `deleted`, `deletedBy`, `creationDate`, `createdBy`, `lastUpdated`, `updatedBy`) VALUES
8+
(1, -1, 51, 1, '', '2025-01-01 00:00:00', 'TEST_DATA_MARGE_DELETED', '2025-01-01 00:00:00', 'TEST_DATA'),
9+
(2, -1, 52, 1, '', '2025-01-01 00:00:00', 'TEST_DATA_HOMER_DELETED', '2025-01-01 00:00:00', 'TEST_DATA'),
10+
(3, -1, 53, 1, '', '2025-01-01 00:00:00', 'TEST_DATA_BART_DELETED', '2025-01-01 00:00:00', 'TEST_DATA'),
11+
(5, -1, 55, 1, '', '2025-01-01 00:00:00', 'TEST_DATA_MONA_DELETED', '2025-01-01 00:00:00', 'TEST_DATA'),
12+
(6, -1, 56, 1, '', '2025-01-01 00:00:00', 'TEST_DATA_FRED_DELETED', '2025-01-01 00:00:00', 'TEST_DATA'),
13+
(7, -1, 57, 1, '', '2025-01-01 00:00:00', 'TEST_DATA_PEBBLES_DELETED', '2025-01-01 00:00:00', 'TEST_DATA'),
14+
(8, -1, 58, 1, '', '2025-01-01 00:00:00', 'TEST_DATA_WEDNESDAY_DELETED', '2025-01-01 00:00:00', 'TEST_DATA'),
15+
16+
(9, -1, 92, 0, '', '2025-01-01 00:00:00', 'TEST_DATA_LAURIE', '2025-01-01 00:00:00', 'TEST_DATA'),
17+
(10, -1, 59, 0, '', '2025-01-01 00:00:00', 'TEST_DATA_RORY', '2025-01-01 00:00:00', 'TEST_DATA'),
18+
(11, -1, 93, 0, '', '2025-01-01 00:00:00', 'TEST_DATA_JOHN', '2025-01-01 00:00:00', 'TEST_DATA'),
19+
(12, -1, 94, 0, '', '2025-01-01 00:00:00', 'TEST_DATA_RICHARD', '2025-01-01 00:00:00', 'TEST_DATA'),
20+
(13, -1, 96, 0, '', '2025-01-01 00:00:00', 'TEST_DATA_CARA', '2025-01-01 00:00:00', 'TEST_DATA'),
21+
(14, -1, 99, 0, '', '2025-01-01 00:00:00', 'TEST_DATA_VALERIE', '2025-01-01 00:00:00', 'TEST_DATA'),
22+
(15, -1, 100, 0, '', '2025-01-01 00:00:00', 'TEST_DATA_PETE', '2025-01-01 00:00:00', 'TEST_DATA'),
23+
(16, -1, 101, 0, '', '2025-01-01 00:00:00', 'TEST_DATA_MARTIN', '2025-01-01 00:00:00', 'TEST_DATA'),
24+
(17, -1, 102, 0, '', '2025-01-01 00:00:00', 'TEST_DATA_KATHY', '2025-01-01 00:00:00', 'TEST_DATA'),
25+
(18, -1, 103, 0, '', '2025-01-01 00:00:00', 'TEST_DATA_MIKE', '2025-01-01 00:00:00', 'TEST_DATA');
26+
27+
-- Update all timestamps to the current time
28+
UPDATE `patient`
29+
SET
30+
`creationDate` = now(),
31+
`lastUpdated` = now();

0 commit comments

Comments
 (0)