Skip to content

Commit

Permalink
BAH-2268 - [ Rohit ] - Resolves issue to display Form2 forms on patie…
Browse files Browse the repository at this point in the history
…nt dashboard (#157)
  • Loading branch information
rohit-yawalkar authored Sep 23, 2022
1 parent 82ba764 commit c186754
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected BahmniObservation map(EncounterTransaction.Observation observation, Ad

BahmniObservation bahmniObservation= createBahmniObservation(observation,additionalBahmniObservationFields,rootConcepts);

if (CONCEPT_DETAILS_CONCEPT_CLASS.equals(observation.getConcept().getConceptClass()) && flatten) {
if (validateFormNameSpace(observation) && flatten) {
handleFlattenedConceptDetails(observation,bahmniObservation);
} else if (observation.getGroupMembers().size() > 0) {
for (EncounterTransaction.Observation groupMember : observation.getGroupMembers()) {
Expand Down Expand Up @@ -84,6 +84,10 @@ protected BahmniObservation map(EncounterTransaction.Observation observation, Ad
return bahmniObservation;
}

private boolean validateFormNameSpace(EncounterTransaction.Observation observation) {
return observation.getFormNamespace() == null && CONCEPT_DETAILS_CONCEPT_CLASS.equals(observation.getConcept().getConceptClass());
}

private Serializable getComplexObsValue(BahmniObservation bahmniObservation) {
if (complexDataMappers.isEmpty()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ private EncounterTransaction.Concept createETConcept(String dataType, String etC
return etConcept;
}

private EncounterTransaction.Observation createETObservation(String UUID, EncounterTransaction.User user, Object value, EncounterTransaction.Concept concept) {
private EncounterTransaction.Observation createETObservation(String UUID, EncounterTransaction.User user, Object value, EncounterTransaction.Concept concept, String formNameSpace) {
EncounterTransaction.Observation observation = new EncounterTransaction.Observation();
observation.setUuid(UUID);
observation.setCreator(user);
observation.setFormNamespace(formNameSpace);
if (concept.getConceptClass().equals("Unknown")) {
observation.setValue(Boolean.parseBoolean((String)value));
} else if (value != null) {
Expand Down Expand Up @@ -130,8 +131,8 @@ public void testCreate() throws Exception {
Mockito.when(conceptService.getConceptByUuid("uuid1")).thenReturn(concept1);
Mockito.when(conceptService.getConceptByUuid("uuid2")).thenReturn(concept2);

EncounterTransaction.Observation observation1 = createETObservation("obs1-uuid", user1, "notes", etValueConcept);
EncounterTransaction.Observation observation2 = createETObservation("obs2-uuid", user2, null, etParentConcept);
EncounterTransaction.Observation observation1 = createETObservation("obs1-uuid", user1, "notes", etValueConcept, null);
EncounterTransaction.Observation observation2 = createETObservation("obs2-uuid", user2, null, etParentConcept, null);

AdditionalBahmniObservationFields additionalBahmniObservationFields = new AdditionalBahmniObservationFields(encounterUuid, new Date(), new Date(), obsGroupUuid);
List<BahmniObservation> actualObs = etObsToBahmniObsMapper.create(asList(observation1, observation2), additionalBahmniObservationFields);
Expand All @@ -157,8 +158,8 @@ public void testMap() throws Exception {
Concept parentConcept = createConcept("parentConcept", "N/A", null, null, null);
parentConcept.addSetMember(valueConcept);

EncounterTransaction.Observation observation1 = createETObservation("obs1-uuid", user1, "notes", etValueConcept);
EncounterTransaction.Observation observation2 = createETObservation("obs2-uuid", user2, null, etParentConcept);
EncounterTransaction.Observation observation1 = createETObservation("obs1-uuid", user1, "notes", etValueConcept, null);
EncounterTransaction.Observation observation2 = createETObservation("obs2-uuid", user2, null, etParentConcept, null);
observation2.setGroupMembers(asList(observation1));

AdditionalBahmniObservationFields additionalBahmniObservationFields = new AdditionalBahmniObservationFields(encounterUuid, new Date(), new Date(), obsGroupUuid);
Expand Down Expand Up @@ -192,9 +193,9 @@ public void testMapObservationValueWithUnknownConceptShortName() throws Exceptio
parentConcept.addSetMember(unknownConcept);


EncounterTransaction.Observation observation1 = createETObservation("obs1-uuid", user1, "notes", etValueConcept);
EncounterTransaction.Observation observation2 = createETObservation("obs2-uuid", user2, null, etParentConcept);
EncounterTransaction.Observation observation3 = createETObservation("obs3-uuid", user1, "true", etUnknownConcept);
EncounterTransaction.Observation observation1 = createETObservation("obs1-uuid", user1, "notes", etValueConcept, null);
EncounterTransaction.Observation observation2 = createETObservation("obs2-uuid", user2, null, etParentConcept, null);
EncounterTransaction.Observation observation3 = createETObservation("obs3-uuid", user1, "true", etUnknownConcept, null);
observation2.setGroupMembers(asList(observation1, observation3));

AdditionalBahmniObservationFields additionalBahmniObservationFields = new AdditionalBahmniObservationFields(encounterUuid, new Date(), new Date(), obsGroupUuid);
Expand All @@ -221,9 +222,9 @@ public void testMapObservationValueToUnknownConceptFullNameWhenShortNameIsNull()
Concept unknownConcept = createConcept("unknownConcept", "Boolean", "cuuid3", "Unknown", null);
parentConcept.addSetMember(unknownConcept);

EncounterTransaction.Observation observation1 = createETObservation("obs1-uuid", user1, "notes", etValueConcept);
EncounterTransaction.Observation observation2 = createETObservation("obs2-uuid", user2, null, etParentConcept);
EncounterTransaction.Observation observation3 = createETObservation("obs3-uuid", user1, "true", etUnknownConcept);
EncounterTransaction.Observation observation1 = createETObservation("obs1-uuid", user1, "notes", etValueConcept, null);
EncounterTransaction.Observation observation2 = createETObservation("obs2-uuid", user2, null, etParentConcept, null);
EncounterTransaction.Observation observation3 = createETObservation("obs3-uuid", user1, "true", etUnknownConcept, null);
observation2.setGroupMembers(asList(observation1, observation3));

AdditionalBahmniObservationFields additionalBahmniObservationFields = new AdditionalBahmniObservationFields(encounterUuid, new Date(), new Date(), obsGroupUuid);
Expand All @@ -233,6 +234,35 @@ public void testMapObservationValueToUnknownConceptFullNameWhenShortNameIsNull()
assertEquals(true, actualObs.isUnknown());
}

@Test
public void testObsMapToBahmniObsWithNotNullNameSpace() {

EncounterTransaction.User user1 = createETUser(person1name);

Mockito.when(authenticatedUser.getUserProperty(OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCALE)).thenReturn("fr");

EncounterTransaction.Concept etParentConcept = createETConcept(etDataType, "Concept Details", "valueName", "valueShortName", null);
EncounterTransaction.Concept etChildConcept1 = createETConcept("text", etValueConceptClass, "parentName", "parentShortName", null);
EncounterTransaction.Concept etChildConcept2 = createETConcept("Boolean", "Unknown", "Unknown", "unknownConcept", null);

Concept parentConcept = createConcept("parentConcept", "N/A", null, null, null);
Concept unknownConcept = createConcept("unknownConcept", "Boolean", "cuuid3", "Unknown", null);
parentConcept.addSetMember(unknownConcept);

// due to not null namespace it will map Obs to BahmniObs as it is
EncounterTransaction.Observation observation1 = createETObservation("obs1-uuid", user1, "notes", etChildConcept1, "test");
EncounterTransaction.Observation observation2 = createETObservation("obs3-uuid", user1, "true", etChildConcept1, "test");
EncounterTransaction.Observation observation3 = createETObservation("obs2-uuid", user1, null, etParentConcept, "test");
observation3.setGroupMembers(asList(observation1, observation2));

AdditionalBahmniObservationFields additionalBahmniObservationFields = new AdditionalBahmniObservationFields(encounterUuid, new Date(), new Date(), obsGroupUuid);

BahmniObservation actualObs = etObsToBahmniObsMapper.map(observation3, additionalBahmniObservationFields, asList(parentConcept), true);

assertEquals(2, actualObs.getGroupMembers().size());
assertEquals(etParentConcept.getName(), actualObs.getConcept().getName());
}

@Test
public void testMapObservationWithValueObservationFirstAndFollowedByUnknownObservation() throws Exception {

Expand All @@ -251,9 +281,9 @@ public void testMapObservationWithValueObservationFirstAndFollowedByUnknownObser
Concept unknownConcept = createConcept("unknownConcept", "Boolean", "cuuid3", "Unknown", "Unknown");
parentConcept.addSetMember(unknownConcept);

EncounterTransaction.Observation observation1 = createETObservation("obs1-uuid", user1, "notes", etValueConcept);
EncounterTransaction.Observation observation2 = createETObservation("obs2-uuid", user2, null, etParentConcept);
EncounterTransaction.Observation observation3 = createETObservation("obs3-uuid", user1, "false", etUnknownConcept);
EncounterTransaction.Observation observation1 = createETObservation("obs1-uuid", user1, "notes", etValueConcept, null);
EncounterTransaction.Observation observation2 = createETObservation("obs2-uuid", user2, null, etParentConcept, null);
EncounterTransaction.Observation observation3 = createETObservation("obs3-uuid", user1, "false", etUnknownConcept, null);
observation2.setGroupMembers(asList(observation1, observation3));

AdditionalBahmniObservationFields additionalBahmniObservationFields = new AdditionalBahmniObservationFields(encounterUuid, new Date(), new Date(), obsGroupUuid);
Expand All @@ -262,7 +292,7 @@ public void testMapObservationWithValueObservationFirstAndFollowedByUnknownObser
assertEquals("notes", actualObs.getValueAsString());
assertEquals(false, actualObs.isUnknown());

EncounterTransaction.Observation observation4 = createETObservation("obs3-uuid", user1, "true", etUnknownConcept);
EncounterTransaction.Observation observation4 = createETObservation("obs3-uuid", user1, "true", etUnknownConcept, null);
observation2.setGroupMembers(asList(observation1, observation4));
actualObs = etObsToBahmniObsMapper.map(observation2, additionalBahmniObservationFields, asList(parentConcept), true);

Expand All @@ -280,8 +310,8 @@ public void testSetHiNormalAndLowNormalWithBahmniObservationIfNumericConcept() {
EncounterTransaction.Concept etParentConcept = createETConcept(etDataType, "Concept Details", "parentName", "parentShortName", "PulseDataUuid");
EncounterTransaction.Concept etUnknownConcept = createETConcept("Boolean", "Unknown", "Unknown", "Unknown", null);

EncounterTransaction.Observation parentObservation = createETObservation("obs2-uuid", user1, null, etParentConcept);
EncounterTransaction.Observation unknownObservation = createETObservation("obs3-uuid", user1, "true", etUnknownConcept);
EncounterTransaction.Observation parentObservation = createETObservation("obs2-uuid", user1, null, etParentConcept, null);
EncounterTransaction.Observation unknownObservation = createETObservation("obs3-uuid", user1, "true", etUnknownConcept, null);
parentObservation.setGroupMembers(asList(unknownObservation));

ConceptNumeric valueConcept = (ConceptNumeric) createConceptNumeric(1, "Pulse", "Misc", 100.0, 50.0);
Expand Down

0 comments on commit c186754

Please sign in to comment.