Repository navigation
stop:647 Nikshay Workflow: Map residential area to the Nikshay area v… #162
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
Merged
chetansaroya
merged 1 commit into
PSMRI:release-3.13.0
from
chetansaroya:bugfix/invalid-area
Nov 12, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
src/main/java/com/iemr/admin/service/nikshayidgenerate/NikshayAreaMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * AMRIT – Accessible Medical Records via Integrated Technologies | ||
| * Integrated EHR (Electronic Health Records) Solution | ||
| * | ||
| * Copyright (C) "Piramal Swasthya Management and Research Institute" | ||
| * | ||
| * This file is part of AMRIT. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see https://www.gnu.org/licenses/. | ||
| */ | ||
| package com.iemr.admin.service.nikshayidgenerate; | ||
|
|
||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * AMRIT household area (i_householddetails.residentialArea) to a value Ni-kshay's enrolment | ||
| * form accepts. A blank value, the text "null" (how the app saves a missing area), or any | ||
| * text that is not one of those choices and has no mapping, is sent as Unknown so | ||
| * enrolment is not rejected with "Invalid Area". | ||
| */ | ||
| public final class NikshayAreaMapper { | ||
|
|
||
| static final String UNKNOWN = "Unknown"; | ||
|
|
||
| // Exact strings from beta.nikshay.in enrolment (the area options of the add case form). | ||
| private static final String[] NIKSHAY = { | ||
| "Tribal-Non Particularly Vulnerable Tribal Groups", | ||
| "Tribal-Particularly Vulnerable Tribal Groups", | ||
| "Rural", | ||
| "Urban", | ||
| "Urban Slum", | ||
| UNKNOWN }; | ||
|
|
||
| private static final Map<String, String> NIKSHAY_BY_KEY = new LinkedHashMap<>(); | ||
| private static final Map<String, String> AMRIT_TO_NIKSHAY = new LinkedHashMap<>(); | ||
|
|
||
| static { | ||
| for (String value : NIKSHAY) { | ||
| NIKSHAY_BY_KEY.put(key(value), value); | ||
| } | ||
| // AMRIT's area choices; Rural, Urban, Urban Slum and Unknown are the same as Ni-kshay's. | ||
| put("Tribal NPVTG", "Tribal-Non Particularly Vulnerable Tribal Groups"); | ||
| put("Tribal-PVTG", "Tribal-Particularly Vulnerable Tribal Groups"); | ||
| put("null", UNKNOWN); | ||
| } | ||
|
|
||
| private NikshayAreaMapper() { | ||
| } | ||
|
|
||
| /** A Ni-kshay area. Never null, and never a value outside Ni-kshay's list. */ | ||
| public static String toNikshay(String amritArea) { | ||
| String normalized = key(amritArea); | ||
| if (normalized.isEmpty()) { | ||
| return UNKNOWN; | ||
| } | ||
| String alreadyNikshay = NIKSHAY_BY_KEY.get(normalized); | ||
| if (alreadyNikshay != null) { | ||
| return alreadyNikshay; | ||
| } | ||
| String mapped = AMRIT_TO_NIKSHAY.get(normalized); | ||
| return mapped == null ? UNKNOWN : mapped; | ||
| } | ||
|
|
||
| private static void put(String amrit, String nikshay) { | ||
| AMRIT_TO_NIKSHAY.put(key(amrit), nikshay); | ||
| } | ||
|
|
||
| private static String key(String value) { | ||
| if (value == null) { | ||
| return ""; | ||
| } | ||
| return value.trim().toLowerCase().replaceAll("[^a-z0-9]+", " ").replaceAll("\\s+", " ").trim(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Use
Locale.ROOTfor area normalization.With a Turkish default locale,
"TRIBAL NPVTG"lowercases with a dotlessı. The ASCII filter then produces"tr bal npvtg", which does not match the stored"tribal npvtg"key. The mapper sends"Unknown"instead of the tribal category. Java documents this locale-sensitive behavior. (docs.oracle.com)Import
java.util.Localeand usetoLowerCase(Locale.ROOT).Based on learnings, internal comparison keys must use locale-independent case normalization.
Source: Learnings
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.
Not required.
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.
@chetansaroya Understood. I’ll leave the resolution decision to you.
You are interacting with an AI system.