icefoganalytics / elcc-data-management

Data Management application for Education's Early Learning Child Centre
Apache License 2.0
0 stars 0 forks source link

Change Second School Age (PT) to (FT) #85

Closed klondikemarlen closed 1 month ago

klondikemarlen commented 1 month ago

Relates to:

Context

Currently there are 2 School Age (PT) and one should be School Age (FT). This is correct in the Administration panel but not being reflected on the actual data entry screens.

The Admin UI located at https://elcc.ynet.gov.yk.ca/administration/submission-lines, lets us change the data for new worksheets, but it doesn't update the labeling of existing worksheets.

image

Implementation

  1. Fix duplicates in funding submission line names in the seeds; Second "School Age (PT)" should have been called "School Age (FT)".
  2. Write some SQL queries to fix up the data.
script-1-clean-up-funding-submision-line-jsons-values-column.sql

```sql WITH second_occurrence_lines AS ( SELECT funding_submission_line_jsons.id, funding_submission_line_jsons.[values], funding_submission_line.[key] AS json_array_index, ROW_NUMBER() OVER ( PARTITION BY funding_submission_line_jsons.id, JSON_VALUE(funding_submission_line.[value], '$.sectionName'), JSON_VALUE(funding_submission_line.[value], '$.lineName') ORDER BY funding_submission_line.[key] ) AS occurrence_number FROM funding_submission_line_jsons CROSS APPLY OPENJSON(funding_submission_line_jsons.[values]) AS funding_submission_line WHERE JSON_VALUE(funding_submission_line.[value], '$.lineName') = 'School Age (PT)' ) UPDATE funding_submission_line_jsons SET [values] = JSON_MODIFY( funding_submission_line_jsons.[values], '$[' + CAST(second_occurrence_lines.json_array_index AS nvarchar(10)) + '].lineName', 'School Age (FT)' ) FROM funding_submission_line_jsons INNER JOIN second_occurrence_lines ON funding_submission_line_jsons.id = second_occurrence_lines.id WHERE second_occurrence_lines.occurrence_number = 2; ```

script-2-clean-up-funding-submission-lines.sql

```sql WITH duplicate_lines AS ( SELECT id, ROW_NUMBER() OVER ( PARTITION BY fiscal_year, section_name, line_name ORDER BY created_at ) AS row_num FROM funding_submission_lines WHERE line_name = 'School Age (PT)' ) UPDATE funding_submission_lines SET line_name = 'School Age (FT)' WHERE id IN ( SELECT id FROM duplicate_lines WHERE row_num = 2 ); ```

Concerns

Since having typoes in names is pretty common, we might need to provide a UI for fixing these kinds of things. The current UI only supports fixing the issue into the future, not fixing past typos.

Screenshots

image

Testing Instructions

  1. Drop the database via dev down -v
  2. Boot the app and run the seeds via dev up
  3. Check that the app complies, and that you can log in at http://localhost:8080.
  4. Go to http://localhost:8080/child-care-centres/1/2022-23/worksheets/april, and create the worksheets if they don't exist.
  5. Check that in the section "Administration (10% of Spaces)" there is a "School Age (PT)" and a "School Age (FT)" column.

Production Fixup instructions.

  1. Fix the data located in the admin page https://elcc.ynet.gov.yk.ca/administration/submission-lines.
  2. Run the first sql script against the production database.
  3. Run the second sql script against the production database (may be obviated by step 1)