Skip to content

OBPIH-7443 fix import demo products error when tag is null and when category nam…#5436

Merged
kchelstowski merged 1 commit intorelease/0.9.5from
bug/OBPIH-7443-demo-data-cats-tags
Aug 7, 2025
Merged

OBPIH-7443 fix import demo products error when tag is null and when category nam…#5436
kchelstowski merged 1 commit intorelease/0.9.5from
bug/OBPIH-7443-demo-data-cats-tags

Conversation

@ewaterman
Copy link
Member

…e doesn't match the case

✨ Description of Change

Link to GitHub issue or Jira ticket: https://pihemr.atlassian.net/browse/OBPIH-7443

Description: Two fixes:

  • tagNamesForAllProducts + products.tags.flatten() as List<String> throws an error when tagNamesForAllProducts is null
  • Some product categories in the demo data aren't a case-sensitive match to a default category. In the base install changelog it was creating a category with name "ARVS" but in the products.csv demo data it was trying to assign "ARVs" to the products. This caused the import service to not be able to resolve the category and thus threw an error. I changed the csv file to use "ARVS" so that it matches the real category, but I also refactored the import logic to be case-insensitive so that even without the csv change it'll see them as the same category. The current behaviour on prod is that it's case-insensitive so the change in this PR preserves existing behaviour. (I refactored product import recently which changed the behaviour to be case-sensitive.)

The behaviour is slightly different depending on if the categories already exist:

Say we want to import product 1 with category "HI" and product 2 with category "hi"

Scenario 1) Categories "HI" and "hi" both already exist. When we import, p1 gets category "HI" and p2 gets category "hi"
Scenario 2) Category "HI" already exists, "hi" does not. When we import, both p1 and p2 get category "HI"
Scenario 3) Category "hi" already exists, "HI" does not. When we import, both p1 and p2 get category "hi"
Scenario 4) Neither category "hi" nor "HI" already exist. Whichever category appears first in the csv will get created and used for both products. If "hi" is first, both p1 and p2 get the categcategory "hi".

Kinda weird behaviour but it does make sense since if we already have two categories with the same name but a different case, we presumably want to match those directly, and if we only have one or neither, we assume user input error and do a case-insensitive match. And again, this is the existing behaviour.


📷 Screenshots & Recordings (optional)

@ewaterman ewaterman self-assigned this Aug 7, 2025
@github-actions github-actions bot added type: bug Addresses unintended behaviours of the app domain: backend Changes or discussions relating to the backend server flag: config change Hilights a pull request that contains a change to the app config labels Aug 7, 2025
,CR388,Default,Lamivudine 150mg + nevirapine 200mg + zidovudine 300mg tablet,,ARVS,,,Each,Primary Care,0.29,TRUE,,,,,,,,,,,,,,,
,TZ835,Default,Lamivudine 150mg + zidovudine 300mg tablet,,ARVS,,,Each,Primary Care,0.29,TRUE,,,,,,,,,,,,,,,
,CM871,Default,Lamivudine 150mg tablet,,ARVS,,,Each,Primary Care,0.29,TRUE,,,,,,,,,,,,,,,
,MC017,Default,Lamivudine 30mg + nevirapine 50mg + zidovudine 60mg tablet,,ARVS,,,Each,Primary Care,0.29,TRUE,,,,,,,,,,,,,,,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at default_OB_categories.csv (and changelog-insert-data-core.groovy but I don't think that's used). The categories are created with ARVS but this file tried to set ARVs.

The code change in ProductService makes this csv change unnecessary (because it doesn't case-insensitive matching), but I figured it'd be best to keep the data in sync.

* when importing data since user input errors are common. In other scenarios this equivalency might not be useful
* (we might want to treat "name" and "NAME" as different), so make sure to be intentional when using this class.
*/
private class CategoriesByDesensitizedName {
Copy link
Member Author

@ewaterman ewaterman Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to make this a class because it allowed for clearer usage of the map. Users of the class don't need to remember to desensitize the data, it happens automatically. All they need to do is provide the category for puts, and category name for gets

@kchelstowski kchelstowski merged commit dddf0f6 into release/0.9.5 Aug 7, 2025
5 checks passed
@kchelstowski kchelstowski deleted the bug/OBPIH-7443-demo-data-cats-tags branch August 7, 2025 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: backend Changes or discussions relating to the backend server flag: config change Hilights a pull request that contains a change to the app config type: bug Addresses unintended behaviours of the app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants