-
Notifications
You must be signed in to change notification settings - Fork 7
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
tweak(adminPanel): RN-1274: Remove outdated survey responses and associated answers from DHIS via sync queue #5827
tweak(adminPanel): RN-1274: Remove outdated survey responses and associated answers from DHIS via sync queue #5827
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few changes requested, and maybe some testing around 2 areas come to mind:
- Editing already outdated survey responses / answers
- Un-outdating a survey response should push it to dhis2
I think the second might just work but worth double checking.
Also, could we get some unit tests for this 🙏
queryValidSurveyResponseIds = async ( | ||
surveyResponseIds, | ||
excludeEventBased = false, | ||
includeOutdated = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
includeOutdated = false, | |
outdated = false, |
I felt the wording here was a little misleading, as includeOutdated
suggests that we get both outdated
and not outdated
responses to me
excludeEventBased = false, | ||
includeOutdated = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
excludeEventBased = false, | |
includeOutdated = false, | |
{ excludeEventBased = false, oudated = false } = {}, |
How about wrapping these parameters into a single options argument? That way callers can do:
this.queryValidSurveyResponseIds(surveyResponseIds, { excludeEventBased: true, outdated: true });
// instead of
this.queryValidSurveyResponseIds(surveyResponseIds, true, true);
Which reads a lot more clearly to me.
excludeEventBased = false, | ||
includeOutdated = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would suggest same change here
excludeEventBased = false, | |
includeOutdated = false, | |
{ excludeEventBased = false, outdated = false } = {}, |
); | ||
validSurveyResponseIds.push(...batchOfSurveyResponses.map(r => r.id)); | ||
} | ||
return validSurveyResponseIds; | ||
}; | ||
|
||
getOutdatedAnswers = async surveyResponseIds => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getOutdatedAnswers = async surveyResponseIds => { | |
getDeletesForAssociatedAnswers = async surveyResponseIds => { |
})); | ||
|
||
// get the answers that are associated with the survey responses that are being updated to 'outdated' | ||
const deleteAnswers = await this.getOutdatedAnswers(surveyResponseUpdateIds); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const deleteAnswers = await this.getOutdatedAnswers(surveyResponseUpdateIds); | |
const outdatedAnswerDeletes = await this.getOutdatedAnswers(surveyResponseUpdateIds); |
I know this one is super nitpicky but it feels in line with oudatedSurveyResponseDeletes
// filter out answers for questions that do not sync to dhis | ||
const dhisLinkedAnswers = await this.filterDhisLinkedAnswers(associatedAnswers); | ||
|
||
// create delete changes for the answers | ||
const deleteAnswers = await Promise.all( | ||
dhisLinkedAnswers.map(async a => ({ | ||
record_type: 'answer', | ||
record_id: a.id, | ||
type: 'delete', | ||
new_record: null, | ||
old_record: await a.getData(), | ||
})), | ||
); | ||
|
||
return deleteAnswers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to test to check that this code doesn't lead to us attempting to delete the same answer twice if it the survey response changes. Admittedly we're moving away from changing survey responses in favour of outdating but it does still happen.
Looking at this code, it does seem like we'd attempt to delete it twice, and if so that might be a problem. A fix would be to not push a delete to the dhis sync queue if there's already one there?
Hey @rohan-bes, any chance you can re-review this one? Georgia wants to get it into this next release ideally |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes @alexd-bes 🙏
const batchOfSurveyResponses = await this.models.database.executeSql( | ||
` | ||
SELECT DISTINCT survey_response.id as id | ||
FROM survey_response | ||
JOIN survey ON survey_response.survey_id = survey.id | ||
JOIN data_group ON data_group.id = survey.data_group_id | ||
JOIN entity ON survey_response.entity_id = entity.id | ||
AND data_group.service_type = 'dhis' | ||
where data_group.service_type = 'dhis' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this was all part of the join previously?? Huh... I think this change is safe and definitely easier to reason about...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep it was, my assumption is it should be filtering by dhis service types so I think it makes sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it will still filter actually when you add AND
clauses in the join, but I'm not certain if the filtering would resolve in the same way.
For instance:
SELECT * FROM ancestor_descendant_relation adr
JOIN entity e ON adr.entity_id = e.id AND e.type = 'country';
# will resolve to the same set as:
SELECT * FROM ancestor_descendant_relation adr
JOIN entity e ON adr.entity_id = e.id
WHERE e.type = 'country';
Could I ask you to just double check this one actually 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just reverted it to the old way, just to make sure there are no regressions
…when resubmitting (#5758) * RN-1274: change route to `surveyResponses/:id/resubmit` * RN-1274: Reworked ResubmitSurveyResponse route to create a new response and outdate the previous one * RN-1274: Added resubmitSurveyResponse to the CentralApi * RN-1274: Added ResubmitSurveyResponseRoute to datatrak-web-server * RN-1274: Reworked survey response resubmission in datatrak to use the new backend routes * Fix tests * Edit survey response metadata * Fix tests * Edit survey response metadata * Resubmit survey response with original data time and user ID * PR fixes * take 1 * feat(adminPanel): RN-1228: Link surveys to Datatrak Web (#5671) * Make links * Use projectId * Update user preferences if project id is in url * Add comment * Allow country codes to be fetched for surveys * Link directly to survey * Default to DL and alphabetise the country codes * Change tooltip text * Update copy * Hide button for surveys with no countries --------- Co-authored-by: Andrew <vanbeekandrew@gmail.com> * Fix dataTime timezone change * Allow file questions to be viewed and changed * feat(tupaiaWeb): RN-1367: Multiphotograph viz captions + restyle (#5769) * Add `label` property to view data * Preview display * Display max 3 * WIP carousel * WIP * Working thumbnails * Working carousel * WiP * Styling * Add comments * Update schemas.ts * Adjust height and alignment * Make images contained * Fix responsive issue --------- Co-authored-by: Andrew <vanbeekandrew@gmail.com> * Fix issue * Fix date of data * Add outdated column to survey responses in admin panel * Reset entity question values when filter questions change * fix(datatrakWeb): Fix country code selector in reports export * fix(adminPanel): RN-1375: update 'Add' project editor for consistency (#5816) update editor column for consistency * Handle existing file answers * Use existing entity id if present * Add pill styling for response status field * Handle file names * Change pill colours around * Handle survey response file names * Don't save file url in answer * Fix tests * Don't default dates on resubmit * Handle when photo answer is a url * Allow `null` default date for resubmission * Save previous metadata on tracked entity * Fix undefined models error * Update project.pbxproj * Hide survey resubmit button for outdated responses * tweak(tupaiaWeb): RN-1394: Update tool tip for visualisation export (#5824) Tool tip update * tweak(adminPanel): RN-1399: Update icon and color as per Figma layouts (#5825) Download Icon update * tweak(adminPanel): RN-1274: Remove outdated survey responses and associated answers from DHIS via sync queue (#5827) * Remove outdated survey responses and associated answers from dhis via sync queue * Add tests * Add answers back into queue when survey response is changed back to current * Handle answers for outdated->current tests * Fix tests * Revert change to filter * Ignore outdated surveys from exports * Code question should be code generator type * Fix tests * Fix timezone issues * Update processSurveyResponse.test.ts * Get all answers for survey response * Handle when photo includes a url * Fix tests * Fix crashing error * Concert jpeg to jpg * Keep existing survey response timezone * fix(tupaiaWeb): RN-1414: Fix dashboard item permission error (#5836) Update ReportPermissionsChecker.js * Timezones * fix(adminPanel): RN-1289: update the entity associated with a survey resubmission (#5817) * Initial update * test updates * Update importSurveyResponses.js * Update importSurveyResponses.js * Update importSurveyResponses.js * Update SurveyResponseUpdatePersistor.js * Delete ~$nonPeriodicUpdates.xlsx * test updates * review comments * review updates * addition of tests --------- Co-authored-by: Andrew <vanbeekandrew@gmail.com> * Convert data_time to timezone date on server * Fix tests * Make dates/times zoneless so that they appear the same to everyone * Fix tests * Fix timezone offsets * Handle timezones with DST * Fixes --------- Co-authored-by: alexd-bes <129009580+alexd-bes@users.noreply.github.com> Co-authored-by: Salman <114740396+hrazasalman@users.noreply.github.com> Co-authored-by: Andrew <vanbeekandrew@gmail.com> Co-authored-by: Tom Caiger <caigertom@gmail.com>
* WIP * Rearrange routes * Ability to resubmit * Ability to upload images in resubmission * Success screen * Loading state * Disable create new autocomplete abilities in resubmit (temp) * tidy ups * Remove unused import * Fix imports * Update SurveyResponsePage.tsx * Fix tests * Update packages/datatrak-web-server/src/routes/SingleSurveyResponseRoute.ts Co-authored-by: Rohan Port <59544282+rohan-bes@users.noreply.github.com> * feat(adminPanel): RN-1243: Resubmit survey response modal should link to Datatrak Web (#5640) * WIP * WIP * WIP * Styling * WIP * Error dismiss * WIP * Use updated entity country code if applicable * Don't update user project/country if in resubmit mode * Fix build * Add REACT_APP_DATATRAK_WEB_URL to .env.example * Build fixes * Apply primary entity answer to resubmit * Fix breaking data_time questions * Fix build * Fix survey responses with file uploads * Display file name for saved file questions and fix remove file value * Use dataTime for date questions * fix permissions * Send timezone through with resubmission * Open up permissions * feat(dataTrak): RN-1274: Keep 'outdated' historical survey responses when resubmitting (#5758) * RN-1274: change route to `surveyResponses/:id/resubmit` * RN-1274: Reworked ResubmitSurveyResponse route to create a new response and outdate the previous one * RN-1274: Added resubmitSurveyResponse to the CentralApi * RN-1274: Added ResubmitSurveyResponseRoute to datatrak-web-server * RN-1274: Reworked survey response resubmission in datatrak to use the new backend routes * Fix tests * Edit survey response metadata * Fix tests * Edit survey response metadata * Resubmit survey response with original data time and user ID * PR fixes * take 1 * feat(adminPanel): RN-1228: Link surveys to Datatrak Web (#5671) * Make links * Use projectId * Update user preferences if project id is in url * Add comment * Allow country codes to be fetched for surveys * Link directly to survey * Default to DL and alphabetise the country codes * Change tooltip text * Update copy * Hide button for surveys with no countries --------- Co-authored-by: Andrew <vanbeekandrew@gmail.com> * Fix dataTime timezone change * Allow file questions to be viewed and changed * feat(tupaiaWeb): RN-1367: Multiphotograph viz captions + restyle (#5769) * Add `label` property to view data * Preview display * Display max 3 * WIP carousel * WIP * Working thumbnails * Working carousel * WiP * Styling * Add comments * Update schemas.ts * Adjust height and alignment * Make images contained * Fix responsive issue --------- Co-authored-by: Andrew <vanbeekandrew@gmail.com> * Fix issue * Fix date of data * Add outdated column to survey responses in admin panel * Reset entity question values when filter questions change * fix(datatrakWeb): Fix country code selector in reports export * fix(adminPanel): RN-1375: update 'Add' project editor for consistency (#5816) update editor column for consistency * Handle existing file answers * Use existing entity id if present * Add pill styling for response status field * Handle file names * Change pill colours around * Handle survey response file names * Don't save file url in answer * Fix tests * Don't default dates on resubmit * Handle when photo answer is a url * Allow `null` default date for resubmission * Save previous metadata on tracked entity * Fix undefined models error * Update project.pbxproj * Hide survey resubmit button for outdated responses * tweak(tupaiaWeb): RN-1394: Update tool tip for visualisation export (#5824) Tool tip update * tweak(adminPanel): RN-1399: Update icon and color as per Figma layouts (#5825) Download Icon update * tweak(adminPanel): RN-1274: Remove outdated survey responses and associated answers from DHIS via sync queue (#5827) * Remove outdated survey responses and associated answers from dhis via sync queue * Add tests * Add answers back into queue when survey response is changed back to current * Handle answers for outdated->current tests * Fix tests * Revert change to filter * Ignore outdated surveys from exports * Code question should be code generator type * Fix tests * Fix timezone issues * Update processSurveyResponse.test.ts * Get all answers for survey response * Handle when photo includes a url * Fix tests * Fix crashing error * Concert jpeg to jpg * Keep existing survey response timezone * fix(tupaiaWeb): RN-1414: Fix dashboard item permission error (#5836) Update ReportPermissionsChecker.js * Timezones * fix(adminPanel): RN-1289: update the entity associated with a survey resubmission (#5817) * Initial update * test updates * Update importSurveyResponses.js * Update importSurveyResponses.js * Update importSurveyResponses.js * Update SurveyResponseUpdatePersistor.js * Delete ~$nonPeriodicUpdates.xlsx * test updates * review comments * review updates * addition of tests --------- Co-authored-by: Andrew <vanbeekandrew@gmail.com> * Convert data_time to timezone date on server * Fix tests * Make dates/times zoneless so that they appear the same to everyone * Fix tests * Fix timezone offsets * Handle timezones with DST * Fixes --------- Co-authored-by: alexd-bes <129009580+alexd-bes@users.noreply.github.com> Co-authored-by: Salman <114740396+hrazasalman@users.noreply.github.com> Co-authored-by: Andrew <vanbeekandrew@gmail.com> Co-authored-by: Tom Caiger <caigertom@gmail.com> --------- Co-authored-by: Rohan Port <59544282+rohan-bes@users.noreply.github.com> Co-authored-by: Andrew <vanbeekandrew@gmail.com> Co-authored-by: Salman <114740396+hrazasalman@users.noreply.github.com> Co-authored-by: Tom Caiger <caigertom@gmail.com>
* fix(tupaiaWeb): RN-1414: Fix dashboard item permission error (#5836) Update ReportPermissionsChecker.js * fix(adminPanel): RN-1289: update the entity associated with a survey resubmission (#5817) * Initial update * test updates * Update importSurveyResponses.js * Update importSurveyResponses.js * Update importSurveyResponses.js * Update SurveyResponseUpdatePersistor.js * Delete ~$nonPeriodicUpdates.xlsx * test updates * review comments * review updates * addition of tests --------- Co-authored-by: Andrew <vanbeekandrew@gmail.com> * feat(datatrakWeb): RN-1243: resubmit surveys via Datatrak Web (#5638) * WIP * Rearrange routes * Ability to resubmit * Ability to upload images in resubmission * Success screen * Loading state * Disable create new autocomplete abilities in resubmit (temp) * tidy ups * Remove unused import * Fix imports * Update SurveyResponsePage.tsx * Fix tests * Update packages/datatrak-web-server/src/routes/SingleSurveyResponseRoute.ts Co-authored-by: Rohan Port <59544282+rohan-bes@users.noreply.github.com> * feat(adminPanel): RN-1243: Resubmit survey response modal should link to Datatrak Web (#5640) * WIP * WIP * WIP * Styling * WIP * Error dismiss * WIP * Use updated entity country code if applicable * Don't update user project/country if in resubmit mode * Fix build * Add REACT_APP_DATATRAK_WEB_URL to .env.example * Build fixes * Apply primary entity answer to resubmit * Fix breaking data_time questions * Fix build * Fix survey responses with file uploads * Display file name for saved file questions and fix remove file value * Use dataTime for date questions * fix permissions * Send timezone through with resubmission * Open up permissions * feat(dataTrak): RN-1274: Keep 'outdated' historical survey responses when resubmitting (#5758) * RN-1274: change route to `surveyResponses/:id/resubmit` * RN-1274: Reworked ResubmitSurveyResponse route to create a new response and outdate the previous one * RN-1274: Added resubmitSurveyResponse to the CentralApi * RN-1274: Added ResubmitSurveyResponseRoute to datatrak-web-server * RN-1274: Reworked survey response resubmission in datatrak to use the new backend routes * Fix tests * Edit survey response metadata * Fix tests * Edit survey response metadata * Resubmit survey response with original data time and user ID * PR fixes * take 1 * feat(adminPanel): RN-1228: Link surveys to Datatrak Web (#5671) * Make links * Use projectId * Update user preferences if project id is in url * Add comment * Allow country codes to be fetched for surveys * Link directly to survey * Default to DL and alphabetise the country codes * Change tooltip text * Update copy * Hide button for surveys with no countries --------- Co-authored-by: Andrew <vanbeekandrew@gmail.com> * Fix dataTime timezone change * Allow file questions to be viewed and changed * feat(tupaiaWeb): RN-1367: Multiphotograph viz captions + restyle (#5769) * Add `label` property to view data * Preview display * Display max 3 * WIP carousel * WIP * Working thumbnails * Working carousel * WiP * Styling * Add comments * Update schemas.ts * Adjust height and alignment * Make images contained * Fix responsive issue --------- Co-authored-by: Andrew <vanbeekandrew@gmail.com> * Fix issue * Fix date of data * Add outdated column to survey responses in admin panel * Reset entity question values when filter questions change * fix(datatrakWeb): Fix country code selector in reports export * fix(adminPanel): RN-1375: update 'Add' project editor for consistency (#5816) update editor column for consistency * Handle existing file answers * Use existing entity id if present * Add pill styling for response status field * Handle file names * Change pill colours around * Handle survey response file names * Don't save file url in answer * Fix tests * Don't default dates on resubmit * Handle when photo answer is a url * Allow `null` default date for resubmission * Save previous metadata on tracked entity * Fix undefined models error * Update project.pbxproj * Hide survey resubmit button for outdated responses * tweak(tupaiaWeb): RN-1394: Update tool tip for visualisation export (#5824) Tool tip update * tweak(adminPanel): RN-1399: Update icon and color as per Figma layouts (#5825) Download Icon update * tweak(adminPanel): RN-1274: Remove outdated survey responses and associated answers from DHIS via sync queue (#5827) * Remove outdated survey responses and associated answers from dhis via sync queue * Add tests * Add answers back into queue when survey response is changed back to current * Handle answers for outdated->current tests * Fix tests * Revert change to filter * Ignore outdated surveys from exports * Code question should be code generator type * Fix tests * Fix timezone issues * Update processSurveyResponse.test.ts * Get all answers for survey response * Handle when photo includes a url * Fix tests * Fix crashing error * Concert jpeg to jpg * Keep existing survey response timezone * fix(tupaiaWeb): RN-1414: Fix dashboard item permission error (#5836) Update ReportPermissionsChecker.js * Timezones * fix(adminPanel): RN-1289: update the entity associated with a survey resubmission (#5817) * Initial update * test updates * Update importSurveyResponses.js * Update importSurveyResponses.js * Update importSurveyResponses.js * Update SurveyResponseUpdatePersistor.js * Delete ~$nonPeriodicUpdates.xlsx * test updates * review comments * review updates * addition of tests --------- Co-authored-by: Andrew <vanbeekandrew@gmail.com> * Convert data_time to timezone date on server * Fix tests * Make dates/times zoneless so that they appear the same to everyone * Fix tests * Fix timezone offsets * Handle timezones with DST * Fixes --------- Co-authored-by: alexd-bes <129009580+alexd-bes@users.noreply.github.com> Co-authored-by: Salman <114740396+hrazasalman@users.noreply.github.com> Co-authored-by: Andrew <vanbeekandrew@gmail.com> Co-authored-by: Tom Caiger <caigertom@gmail.com> --------- Co-authored-by: Rohan Port <59544282+rohan-bes@users.noreply.github.com> Co-authored-by: Andrew <vanbeekandrew@gmail.com> Co-authored-by: Salman <114740396+hrazasalman@users.noreply.github.com> Co-authored-by: Tom Caiger <caigertom@gmail.com> * fix(datatrakWeb): RN-1274: Remove check on autocomplete question for resubmit * fix(adminPanel): RN-1424: Fix max payload error when saving map overlay records (#5846) Create 20240818212910-removeMapOverlayConfigFromPgNotify-modifies-schema.js * deps(security): RN-1096: Update version of `decode-uri-component` (#5850) Update decide-uri-component * deps(security): RN-1096: Update version of `jsonwebtoken` (#5851) * Update json-web-token * Update jsonwebtoken in auth package * deps(security): RN-1096: Update XLSX version (#5849) * Update xlsx * xlsx fixes * Handle xlsx blank rows and parsing * tweak(types): RN-1418: Update EntityType type (#5871) * Update config for entity type * Types update * Fix uses of EntityType * tweak(adminPanel): RN-1393: Minor Admin panel updates (#5867) * Scroll on profile pages * Entity hierarchy export wording * Handle single button action widths * Bold active tabs * Move survey questions to the top of add survey modal * Fix input colours * Fix sync logs tooltip * PR fix * deps(root): RN-1417: Update storybook version (#5878) * Basic setup * Add warmup script * Update main.ts * deps(uiChartComponents): RN-1417: Update storybook version PART 2 (#5879) charts storybook * deps(uiMapComponents): RN-1417: Update storybook version PART 3 (#5880) * map components * Fix tests * deps(uiComponents): RN-1417: Update storybook version PART 4 (#5881) * ui components storybook * Fix tests * deps(tupaiaWeb): RN-1417: Update storybook version PART 5 (#5882) * tupaia web storybook * Fix tests * Fix build * tweak(centralServer): RN-1351: Handle bad DHIS2 sync requests (#5887) Throw an error and register bad requests on dhis sync queue * tweak(datatrakWeb): RN-1438: Upgrade React Query to V4 (#5868) * Bumping react-query * Update render.tsx * fixing Reports.test.tsx * navigation bug fix * removed logging * tweak(adminPanel): RN-1439: Upgrade React Query to V4 (#5875) * bumping to v4 * Update yarn.lock * tweak(psss): RN-1442: Upgrade React Query to V4 (#5874) * upgrade * Update yarn.lock * tweak(lesmis): RN-1441: Upgrade React Query to V4 (#5873) * upgrade * Update yarn.lock * tweak(tupaiaWeb): RN-1440: Upgrade React Query to V4 (#5870) * Bumping react-query * Bumping react-query to v4 * Update render.tsx * GitAction fix * fixing Reports.test.tsx * navigation bug fix * review update * removed logging * Update yarn.lock * Update yarn.lock * Update VerifyEmailPage.tsx * Update useReportPreview.js * fix(adminPanel): Miscellaneous Bug fixes (Tiny) (#5891) * bugfix * update * updates * tweak(tupaiaWeb): RN-1437: Download files visual restyle (#5889) * Common download files component * PR fix --------- Co-authored-by: Tom Caiger <caigertom@gmail.com> Co-authored-by: Salman <114740396+hrazasalman@users.noreply.github.com> Co-authored-by: Andrew <vanbeekandrew@gmail.com> Co-authored-by: Rohan Port <59544282+rohan-bes@users.noreply.github.com>
Issue RN-1274: Remove outdated survey responses and associated answers from DHIS via sync queue
Changes:
DHISChangeValidator
to createdelete
entries indhis_sync_queue
for outdated survey responses and their associated answers