Skip to content
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

Suman, Pramida|#432|Supporting obsIgnoreList parameter while fetching… #20

Merged
merged 1 commit into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,34 @@ private List<BahmniObservation> convertToBahmniObservation(List<Obs> observation


private List<Obs> filterIgnoredObs(List<String> obsIgnoreList, List<Obs> observations) {
if (null != obsIgnoreList && obsIgnoreList.size() > 0) {
ArrayList<Obs> filteredObs = new ArrayList<>();
for (Obs observation : observations) {
Obs filteredGroupMembers = filterGroupMembers(observation, obsIgnoreList);
if(filteredGroupMembers.getGroupMembers().size()>0)
filteredObs.add(filteredGroupMembers);
return null != obsIgnoreList && obsIgnoreList.size() > 0 ? filterObs(obsIgnoreList, observations) : observations;
}

private List<Obs> filterObs(List<String> obsIgnoreList, List<Obs> observations) {
ArrayList<Obs> filteredObs = new ArrayList<>();
for (Obs observation : observations) {
if(!isContains(obsIgnoreList, observation)) {
if(hasGroupMembers(observation)) {
Obs filteredGroupMembers = filterGroupMembers(observation, obsIgnoreList);
if (hasGroupMembers(filteredGroupMembers))
filteredObs.add(filteredGroupMembers);
} else {
filteredObs.add(observation);
}
}
return filteredObs;
}
return observations;
return filteredObs;
}

private boolean hasGroupMembers(Obs observation) {
return observation.getGroupMembers().size() > 0;
}

private Obs filterGroupMembers(Obs observation, List<String> obsIgnoreList) {
HashSet<Obs> filteredGroup = new HashSet<>();
for (Obs groupMember : observation.getGroupMembers()) {
if (!obsIgnoreList.contains(groupMember.getConcept().getName().toString())) {
if (groupMember.getGroupMembers().size() > 0)
if (!isContains(obsIgnoreList, groupMember)) {
if (hasGroupMembers(groupMember))
groupMember = filterGroupMembers(groupMember, obsIgnoreList);
filteredGroup.add(groupMember);
}
Expand All @@ -124,6 +135,10 @@ private Obs filterGroupMembers(Obs observation, List<String> obsIgnoreList) {
return observation;
}

private boolean isContains(List<String> obsIgnoreList, Obs obs) {
return obsIgnoreList.contains(obs.getConcept().getName().toString());
}

@Override
public Collection<BahmniObservation> getLatest(String patientUuid, Collection<Concept> concepts, Integer numberOfVisits, List<String> obsIgnoreList,
Boolean filterOutOrderObs, Order order) {
Expand Down Expand Up @@ -205,43 +220,43 @@ public Collection<BahmniObservation> getObservationsForEncounter(String encounte
}

@Override
public Collection<BahmniObservation> getObservationsForPatientProgram(String patientProgramUuid, List<String> conceptNames) {
public Collection<BahmniObservation> getObservationsForPatientProgram(String patientProgramUuid, List<String> conceptNames, List<String> obsIgnoreList) {
List<Obs> observations = new ArrayList<>();
if (conceptNames == null)
return new ArrayList<>();
for (String conceptName : conceptNames) {
observations.addAll(obsDao.getObsByPatientProgramUuidAndConceptNames(patientProgramUuid, Arrays.asList(conceptName), null, ObsDaoImpl.OrderBy.DESC, null, null));
}

return omrsObsToBahmniObsMapper.map(observations, getConceptsByName(conceptNames));
return omrsObsToBahmniObsMapper.map(filterIgnoredObs(obsIgnoreList,observations), getConceptsByName(conceptNames));
}

@Override
public Collection<BahmniObservation> getLatestObservationsForPatientProgram(String patientProgramUuid, List<String> conceptNames) {
public Collection<BahmniObservation> getLatestObservationsForPatientProgram(String patientProgramUuid, List<String> conceptNames, List<String> obsIgnoreList) {
List<Obs> observations = new ArrayList<>();
if (conceptNames == null)
return new ArrayList<>();
for (String conceptName : conceptNames) {
List<Obs> obsByPatientProgramUuidAndConceptName = obsDao.getObsByPatientProgramUuidAndConceptNames(patientProgramUuid, Arrays.asList(conceptName), null, OrderBy.DESC, null, null);
List<Obs> obsByPatientProgramUuidAndConceptName = obsDao.getObsByPatientProgramUuidAndConceptNames(patientProgramUuid, Arrays.asList(conceptName), null, OrderBy.DESC, null, null);
List<Obs> obsList = getAllLatestObsForAConcept(obsByPatientProgramUuidAndConceptName);
if (CollectionUtils.isNotEmpty(obsList)) {
observations.addAll(obsList);
}
}

return omrsObsToBahmniObsMapper.map(observations, getConceptsByName(conceptNames));
return omrsObsToBahmniObsMapper.map(filterIgnoredObs(obsIgnoreList,observations), getConceptsByName(conceptNames));
}

@Override
public Collection<BahmniObservation> getInitialObservationsForPatientProgram(String patientProgramUuid, List<String> conceptNames) {
public Collection<BahmniObservation> getInitialObservationsForPatientProgram(String patientProgramUuid, List<String> conceptNames, List<String> obsIgnoreList) {
List<Obs> observations = new ArrayList<>();
if (conceptNames == null)
return new ArrayList<>();
for (String conceptName : conceptNames) {
observations.addAll(obsDao.getObsByPatientProgramUuidAndConceptNames(patientProgramUuid, Arrays.asList(conceptName), 1, ObsDaoImpl.OrderBy.ASC, null, null));
}

return omrsObsToBahmniObsMapper.map(observations, getConceptsByName(conceptNames));
return omrsObsToBahmniObsMapper.map(filterIgnoredObs(obsIgnoreList,observations), getConceptsByName(conceptNames));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void shouldRetrieveObsForPatientProgram() throws Exception {
ArrayList<String> conceptNames = new ArrayList<>();
conceptNames.add("conceptABC");

Collection<BahmniObservation> observations = bahmniObsService.getObservationsForPatientProgram("dfdfoifo-dkcd-475d-b939-6d82327f36a3", conceptNames);
Collection<BahmniObservation> observations = bahmniObsService.getObservationsForPatientProgram("dfdfoifo-dkcd-475d-b939-6d82327f36a3", conceptNames, null);

assertEquals(1, observations.size());
assertEquals("6d8f507a-fb899-11e3-bb80-996addb6f9we", observations.iterator().next().getUuid());
Expand All @@ -202,7 +202,7 @@ public void shouldRetrieveEmptyObsListWhenPatientProgramUuidDoesNotExist() throw
ArrayList<String> conceptNames = new ArrayList<>();
conceptNames.add("conceptABC");

Collection<BahmniObservation> observations = bahmniObsService.getObservationsForPatientProgram("patientProgramUuid", conceptNames);
Collection<BahmniObservation> observations = bahmniObsService.getObservationsForPatientProgram("patientProgramUuid", conceptNames, null);

assertEquals(0, observations.size());
}
Expand All @@ -212,7 +212,7 @@ public void shouldRetrieveEmptyObsIfPatientProgramDoesNotHaveAnyEncounters() thr
ArrayList<String> conceptNames = new ArrayList<>();
conceptNames.add("conceptABC");

Collection<BahmniObservation> observations = bahmniObsService.getObservationsForPatientProgram("df0foifo-dkcd-475d-b939-6d82327f36a3", conceptNames);
Collection<BahmniObservation> observations = bahmniObsService.getObservationsForPatientProgram("df0foifo-dkcd-475d-b939-6d82327f36a3", conceptNames, null);

assertEquals(0, observations.size());
}
Expand All @@ -227,21 +227,99 @@ public void shouldRetrieveBahmniObservationByObservationUuid() throws Exception

@Test
public void shouldRetrieveAllLatestObservationsForMultiSelectConcept() {
List<BahmniObservation> observations = (List<BahmniObservation>) bahmniObsService.getLatestObservationsForPatientProgram("df0foif1-dkcd-475d-b939-6d82327f36a3", Arrays.asList("Systolic"));
List<BahmniObservation> observations = (List<BahmniObservation>) bahmniObsService.getLatestObservationsForPatientProgram("df0foif1-dkcd-475d-b939-6d82327f36a3", Arrays.asList("Systolic"), null);
assertEquals(3, observations.size());
}

@Test
public void shouldRetrieveAllLatestObservationSingleValueConcept() {
List<BahmniObservation> observations = (List<BahmniObservation>) bahmniObsService.getLatestObservationsForPatientProgram("df0foif1-dkcd-475d-b939-6d82327f36a3", Arrays.asList("Diastolic"));
List<BahmniObservation> observations = (List<BahmniObservation>) bahmniObsService.getLatestObservationsForPatientProgram("df0foif1-dkcd-475d-b939-6d82327f36a3", Arrays.asList("Diastolic"), null);
assertEquals(1, observations.size());
assertEquals(100.0, observations.get(0).getValue());
}

@Test
public void shouldRetrieveRevisionBahmniObservationByObservationUuid() throws Exception {
BahmniObservation bahmniObservation = bahmniObsService.getRevisedBahmniObservationByUuid("uuid99998");

assertNotNull("BahmniObservation should not be null", bahmniObservation);
assertEquals("uuid999982", bahmniObservation.getUuid());
}

@Test
public void shouldNotRetrieveIgnoreObsAndItsChildrenForPatientProgram() throws Exception {
ArrayList<String> conceptNames = new ArrayList<>();
conceptNames.add("Health Education");
List<String> obsIgnoreList = new ArrayList<>();
obsIgnoreList.add("HE, Marital status");

Collection<BahmniObservation> observations = bahmniObsService.getObservationsForPatientProgram("dfdfoifo-dkcd-475d-b939-6d82327f36a3", conceptNames, obsIgnoreList);

assertEquals(1, observations.size());
assertEquals(1, observations.iterator().next().getGroupMembers().size());
assertEquals("HE, Date of consultation", observations.iterator().next().getGroupMembers().iterator().next().getConceptNameToDisplay());
}

@Test
public void shouldRetrieveAllObsIncludingChildrenForPatientProgram() throws Exception {
ArrayList<String> conceptNames = new ArrayList<>();
conceptNames.add("Health Education");
List<String> obsIgnoreList = new ArrayList<>();
obsIgnoreList.add("HE, Date of consultation");

Collection<BahmniObservation> observations = bahmniObsService.getObservationsForPatientProgram("dfdfoifo-dkcd-475d-b939-6d82327f36a3", conceptNames, obsIgnoreList);

Collection<BahmniObservation> groupMembers = observations.iterator().next().getGroupMembers();
Iterator<BahmniObservation> iterator = groupMembers.iterator();
BahmniObservation observationOne = iterator.next();
Collection<BahmniObservation> childMembers = observationOne.getGroupMembers();

assertEquals(1, observations.size());
assertEquals(1, groupMembers.size());
assertEquals("HE, Marital status",observationOne.getConceptNameToDisplay());
assertEquals(1, childMembers.size());
assertEquals("HE, Date Of Marriage", childMembers.iterator().next().getConceptNameToDisplay());
}

@Test
public void shouldReturnEmptyArrayIfConceptNameIsSameAsIgnoreListForPatientProgram() throws Exception {
ArrayList<String> conceptNames = new ArrayList<>();
conceptNames.add("Health Education");
List<String> obsIgnoreList = new ArrayList<>();
obsIgnoreList.add("Health Education");

Collection<BahmniObservation> observations = bahmniObsService.getObservationsForPatientProgram("dfdfoifo-dkcd-475d-b939-6d82327f36a3", conceptNames, obsIgnoreList);

assertEquals(0, observations.size());
}

@Test
public void shouldReturnAllObsInConceptNamesIfThereAreNoMatchesInObsIgnoreListForPatientProgram() throws Exception {
ArrayList<String> conceptNames = new ArrayList<>();
conceptNames.add("HE, Date Of Marriage");
List<String> obsIgnoreList = new ArrayList<>();
obsIgnoreList.add("HE, Da Of Marriage");

Collection<BahmniObservation> observations = bahmniObsService.getObservationsForPatientProgram("dfdfoifo-dkcd-475d-b939-6d82327f36a3", conceptNames, obsIgnoreList);

assertEquals(1, observations.size());
}

@Test
public void shouldRetrieveLatestObservationsNotInIgnoreListForMultiSelectConcept() {
List<BahmniObservation> observations = (List<BahmniObservation>) bahmniObsService.getLatestObservationsForPatientProgram("df0foif1-dkcd-475d-b939-6d82327f36a3", Arrays.asList("Systolic"), Arrays.asList("Systolic"));
assertEquals(0, observations.size());
}

@Test
public void shouldRetrieveInitalObservationsNotInIgnoreListForPatientProgram() throws Exception {
List<BahmniObservation> observations = (List<BahmniObservation>) bahmniObsService.getInitialObservationsForPatientProgram("df0foif1-dkcd-475d-b939-6d82327f36a3", Arrays.asList("Systolic"), Arrays.asList("Systolic"));
assertEquals(0, observations.size());
}

@Test
public void shouldRetrieveAllInitalObservationsForPatientProgram() throws Exception {
List<BahmniObservation> observations = (List<BahmniObservation>) bahmniObsService.getInitialObservationsForPatientProgram("df0foif1-dkcd-475d-b939-6d82327f36a3", Arrays.asList("Systolic"), null);
assertEquals(1, observations.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,33 +168,42 @@ public void shouldCallObsServiceWithEmptyListOfEncountersWhenProgramUuidIsNull()
public void shouldGetObsbyPatientProgramUuid() throws Exception {
String patientProgramUuid = "patientProgramUuid";
ArrayList<String> conceptNames = new ArrayList<>();
List<Obs> obs = new ArrayList<>();
conceptNames.add("Paracetamol");
Collection<Concept> names = new ArrayList<Concept>() {{add(null);}};

bahmniObsService.getObservationsForPatientProgram(patientProgramUuid, conceptNames);
bahmniObsService.getObservationsForPatientProgram(patientProgramUuid, conceptNames, null);

verify(obsDao).getObsByPatientProgramUuidAndConceptNames(patientProgramUuid, Arrays.asList("Paracetamol"), null, ObsDaoImpl.OrderBy.DESC, null, null);
verify(obsDao).getObsByPatientProgramUuidAndConceptNames(patientProgramUuid, Arrays.asList("Paracetamol"), null, ObsDaoImpl.OrderBy.DESC, null, null);
verify(omrsObsToBahmniObsMapper, times(1)).map(obs, names);
}

@Test
public void shouldGetLatestObsbyPatientProgramUuid() throws Exception {
String patientProgramUuid = "patientProgramUuid";
List<String> conceptNames = new ArrayList<>();
conceptNames.add("Paracetamol");
List<Obs> obs = new ArrayList<>();
Collection<Concept> names = new ArrayList<Concept>() {{add(null);}};

bahmniObsService.getLatestObservationsForPatientProgram(patientProgramUuid, conceptNames);
bahmniObsService.getLatestObservationsForPatientProgram(patientProgramUuid, conceptNames, null);

verify(obsDao).getObsByPatientProgramUuidAndConceptNames(patientProgramUuid, Arrays.asList("Paracetamol"), null, ObsDaoImpl.OrderBy.DESC, null, null);
verify(obsDao).getObsByPatientProgramUuidAndConceptNames(patientProgramUuid, Arrays.asList("Paracetamol"), null, ObsDaoImpl.OrderBy.DESC, null, null);
verify(omrsObsToBahmniObsMapper, times(1)).map(obs, names);
}

@Test
public void shouldGetInitialObsbyPatientProgramUuid() throws Exception {
String patientProgramUuid = "patientProgramUuid";
List<String> conceptNames = new ArrayList<>();
conceptNames.add("Paracetamol");
List<Obs> obs = new ArrayList<>();
Collection<Concept> names = new ArrayList<Concept>() {{add(null);}};

bahmniObsService.getInitialObservationsForPatientProgram(patientProgramUuid, conceptNames);
bahmniObsService.getInitialObservationsForPatientProgram(patientProgramUuid, conceptNames, null);

verify(obsDao).getObsByPatientProgramUuidAndConceptNames(patientProgramUuid, Arrays.asList("Paracetamol"), 1, ObsDaoImpl.OrderBy.ASC, null, null);
verify(omrsObsToBahmniObsMapper, times(1)).map(obs, names);
}

@Test
Expand Down
Loading