opencrvs / opencrvs-core

A global solution to civil registration
https://www.opencrvs.org
Other
85 stars 68 forks source link

Enable amending initially configured locations #6679

Open rikukissa opened 5 months ago

rikukissa commented 5 months ago

Description

So in other words, make it possible to correct existing details. In this task we build the foundation for temporality of Locations.

A location is created in the wrong hierarchy during initial configuration or with the wrong spelling. Moving the location hierarchy for the location or updating the spelling should update all records associated with it be they “declared, validated (e.g. active workqueue)” or “issued” and therfore no longer in a workqueue.

Acceptance criteria

Notice that in this first phase, for location information queries to Hearth, we can still heavily rely on the Location / Location_history functionality and none of the MongoDB queries for fetching location details should change. If a location name or partOf is changed, the previous version gets pushed to Location_history and we don't have to worry about it too much.

Known limitations

Technical tasks

This model changes location details directly and does not provide "temporality". If you change location name today, even records from 10 years ago show the new location name. Same with if you move the location to a new parent location.

rikukissa commented 5 months ago

CSV changes in country config works like this

1. Version in CSV (or country config API)

JWMRGwDBXK,Ibombo District Office,Location/oEBf29y8JP8,CRVS_OFFICE

So seeding created this

name: Ibombo District Office
valid_from: 1970
valid_to: 27/3/2024
is_valid: true 

is_valid flag is only for demonstrative purposes.

2. Version in CSV (or country config API) when a new deployment was made 27/3/2024

JWMRGwDBXK,Ibombo's District Office,Location/oEBf29y8JP8,CRVS_OFFICE

The existing record was changed to

name: Ibombo District Office
valid_from: 1970
valid_to: 27/3/2024
is_valid: false 

New record was written

name: Ibombo's District Office
valid_from: 27/3/2024
valid_to: 1/1/3000
is_valid: true

3. Version in CSV (or country config API). Validity period now defined

JWMRGwDBXK,Ibombo's Great District Office,Location/oEBf29y8JP8,CRVS_OFFICE,1/5/2024,1/1/3000

The existing record was changed to

name: Ibombo's District Office
valid_from: 27/3/2024
valid_to: 1/1/3000
is_valid: false 

New record was written

name: Ibombo's Great District Office
valid_from: 1/5/2024
valid_to: 1/1/3000
is_valid: true
naftis commented 3 months ago
  • [ ] Add an example script to country config service for updating locations: 2 days
    • Fetches a list of locations
    • If any item of location list has changed, (so one of the following fields change name, partOf):
    • Update the location with details given by country config
    • If items have been removed: invalidate the existing location by changing its status to inactive

@Zangetsu101 @rikukissa This could make sense to be within core in data-seeder. A yarn seed:locations script similar to the current location seeding. data-seeder already has the means to fetch the locations from country-config and while it does stuff via the temporary super user, this seeding could require setting a token

Zangetsu101 commented 3 months ago

The issue with the super user is that we deactivate it as soon as seeding's finished

naftis commented 1 month ago

The groundwork for allowing to change location structures is done. Now we only save the leaf level locations and the full path of a location is then fetched from ground up.

For the location configuration to be a documented and configurable feature, we depend on a real need from a country/installation. There are options for how to allow configuring the locations (UI, or only a Postman example request, or a GitHub Action which re-seeds the locations...), but we are missing a real-world use case to finish the design of the feature

naftis commented 1 month ago

Remove eventJurisdictionIds from search; they are not referenced in very many places

  1. the event is in health location, we use eventLocationId
  2. if the event isn't in a health location, the full path is still saved.
  3. if the event is international, whatever is inputted to the fields is being saved. We do not allow searching international events with other than country though, so that can safely be removed.

ElasticSearch rows image

Case 2 needs to be refactored when the actual UI/location editing feature is created. I'd say it's a small issue though, as the searching itself already uses leaf level locations, and we simply can then reindex the ElasticSearch to only save the leaf level.