Skip to content

Commit

Permalink
BAH 3455| Locale issue while sending request with diagnoses (#247)
Browse files Browse the repository at this point in the history
* Add locale of concept in BahmniDiagnosisMetadata

* Fix tests of BahmniDiagnosisMetadataTest

* Refactor import statement

* Add Locale import statement

* BAH-3455 | Refactored imports

---------

Co-authored-by: SanoferSameera <[email protected]>
  • Loading branch information
poojadeshpande01 and SanoferSameera authored Jan 12, 2024
1 parent 21f340a commit 09a996c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;

import static java.util.stream.Collectors.toList;
Expand All @@ -37,16 +38,21 @@ public class BahmniDiagnosisMetadata {

private EncounterTransactionMapper encounterTransactionMapper;

private Concept getConceptsByNameAndLocale(String name, Locale locale) {
List<Concept> conceptList = conceptService.getConceptsByName(name, locale, false);
return conceptList.isEmpty() ? null : conceptList.get(0);
}

public Concept getBahmniInitialDiagnosisConcept() {
return conceptService.getConceptByName(BAHMNI_INITIAL_DIAGNOSIS);
return getConceptsByNameAndLocale(BAHMNI_INITIAL_DIAGNOSIS, Locale.ENGLISH);
}

public Concept getBahmniDiagnosisRevisedConcept() {
return conceptService.getConceptByName(BAHMNI_DIAGNOSIS_REVISED);
return getConceptsByNameAndLocale(BAHMNI_DIAGNOSIS_REVISED, Locale.ENGLISH);
}

public Concept getBahmniDiagnosisStatusConcept() {
return conceptService.getConceptByName(BAHMNI_DIAGNOSIS_STATUS);
return getConceptsByNameAndLocale(BAHMNI_DIAGNOSIS_STATUS, Locale.ENGLISH);
}

@Autowired
Expand Down Expand Up @@ -179,8 +185,8 @@ public Obs findMatchingDiagnosis(Collection<Obs> observations, BahmniDiagnosis b
private boolean isDiagnosisNotRevised(Obs obs) {
return !obs.getGroupMembers(false).stream()
.anyMatch(groupMember -> {
return groupMember.getConcept().equals(getBahmniDiagnosisRevisedConcept())
&& groupMember.getValueAsBoolean();});
return groupMember.getConcept().equals(getBahmniDiagnosisRevisedConcept())
&& groupMember.getValueAsBoolean();});
}

private boolean isDiagnosisMatching(Obs obs, EncounterTransaction.Diagnosis diagnosis) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import static org.hamcrest.CoreMatchers.is;
Expand Down Expand Up @@ -82,7 +83,7 @@ public void shouldMatchCodedDiagnosis() {
Obs diagnosisObs =
new ObsBuilder().withConcept(diagnosisSetConcept)
.withGroupMembers(
new ObsBuilder().withConcept(codedDiagnosisConcept)
new ObsBuilder().withConcept(codedDiagnosisConcept)
.withValue(feverConcept).build(),
new ObsBuilder().withConcept(conceptForName("Diagnosis Order"))
.withValue(conceptForName("Primary")).build(),
Expand Down Expand Up @@ -213,7 +214,7 @@ public void shouldNotConsiderRevisedObsWhileFindingMatchingObs() throws Exceptio
when(properties.getDiagnosisMetadata().getCodedDiagnosisConcept()).thenReturn(codedDiagnosisConcept);
when(properties.getDiagnosisMetadata().getNonCodedDiagnosisConcept()).thenReturn(nonCodedDiagnosisConcept);
when(conceptService.getTrueConcept()).thenReturn(conceptTrue);
when(conceptService.getConceptByName(BAHMNI_DIAGNOSIS_REVISED)).thenReturn(revised);
when(conceptService.getConceptsByName(BAHMNI_DIAGNOSIS_REVISED,Locale.ENGLISH,false)).thenReturn(Arrays.asList(revised));
Concept feverConcept = conceptForName("Fever");
Obs aCodedDiagnosisObs =
new ObsBuilder().withConcept(diagnosisSetConcept)
Expand Down

0 comments on commit 09a996c

Please sign in to comment.