Skip to content

Commit

Permalink
fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
kavitha-sundararajan committed Oct 10, 2024
1 parent 9254963 commit b8a6bf3
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bahmni.module.bahmnicore.dao.VisitDao;
import org.bahmni.module.bahmnicore.dao.impl.ObsDaoImpl;
import org.bahmni.module.bahmnicore.dao.impl.ObsDaoImpl.OrderBy;
import org.bahmni.module.bahmnicore.service.BahmniConceptService;
import org.bahmni.module.bahmnicore.service.BahmniObsService;
import org.bahmni.module.bahmnicore.service.BahmniProgramWorkflowService;
import org.bahmni.module.bahmnicore.util.MiscUtils;
Expand Down Expand Up @@ -37,16 +38,18 @@ public class BahmniObsServiceImpl implements BahmniObsService {
private ConceptService conceptService;
private BahmniProgramWorkflowService programWorkflowService;
private ObsService obsService;
private BahmniConceptService bahmniConceptService;

@Autowired
public BahmniObsServiceImpl(ObsDao obsDao, OMRSObsToBahmniObsMapper omrsObsToBahmniObsMapper, VisitService visitService, ConceptService conceptService, VisitDao visitDao, BahmniProgramWorkflowService programWorkflowService, ObsService obsService) {
public BahmniObsServiceImpl(ObsDao obsDao, OMRSObsToBahmniObsMapper omrsObsToBahmniObsMapper, VisitService visitService, ConceptService conceptService, VisitDao visitDao, BahmniProgramWorkflowService programWorkflowService, ObsService obsService, BahmniConceptService bahmniConceptService) {
this.obsDao = obsDao;
this.omrsObsToBahmniObsMapper = omrsObsToBahmniObsMapper;
this.visitService = visitService;
this.conceptService = conceptService;
this.visitDao = visitDao;
this.programWorkflowService = programWorkflowService;
this.obsService = obsService;
this.bahmniConceptService = bahmniConceptService;
}

@Override
Expand Down Expand Up @@ -220,7 +223,7 @@ public Collection<BahmniObservation> getObservationForVisit(String visitUuid, Li
List<Person> persons = new ArrayList<>();
persons.add(visit.getPatient());
List<Obs> observations = obsDao.getObsForVisits(persons, new ArrayList<>(visit.getEncounters()),
MiscUtils.getConceptsForNames(conceptNames, conceptService), obsIgnoreList, filterOutOrders, order);
MiscUtils.getConceptsForNames(conceptNames, bahmniConceptService, conceptService), obsIgnoreList, filterOutOrders, order);
observations = new ArrayList<>(getObsAtTopLevelAndApplyIgnoreList(observations, conceptNames, obsIgnoreList));
return omrsObsToBahmniObsMapper.map(observations, null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.bahmni.module.bahmnicore.util;

import org.apache.commons.collections.CollectionUtils;
import org.bahmni.module.bahmnicore.service.BahmniConceptService;
import org.openmrs.Concept;
import org.openmrs.ConceptName;
import org.openmrs.api.ConceptService;
Expand All @@ -15,12 +16,12 @@
import java.util.regex.Pattern;

public class MiscUtils {
public static List<Concept> getConceptsForNames(List<String> conceptNames, ConceptService conceptService) {
public static List<Concept> getConceptsForNames(List<String> conceptNames, BahmniConceptService bahmniConceptService, ConceptService conceptService) {
//Returning null for the sake of UTs
if (CollectionUtils.isNotEmpty(conceptNames)) {
List<Concept> rootConcepts = new ArrayList<>();
for (String rootConceptName : conceptNames) {
Concept concept = conceptService.getConceptByName(rootConceptName);
Concept concept = bahmniConceptService.getConceptByFullySpecifiedName(rootConceptName);
if (concept == null) {
concept = getConceptInDefaultLocale(conceptService, rootConceptName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.bahmni.module.bahmnicore.dao.ObsDao;
import org.bahmni.module.bahmnicore.dao.VisitDao;
import org.bahmni.module.bahmnicore.dao.impl.ObsDaoImpl;
import org.bahmni.module.bahmnicore.service.BahmniConceptService;
import org.bahmni.module.bahmnicore.service.BahmniObsService;
import org.bahmni.module.bahmnicore.service.BahmniProgramWorkflowService;
import org.bahmni.test.builder.ConceptBuilder;
Expand Down Expand Up @@ -73,6 +74,8 @@ public class BahmniObsServiceImplTest {
private ObsService obsService;
@Mock
private OMRSObsToBahmniObsMapper omrsObsToBahmniObsMapper;
@Mock
private BahmniConceptService bahmniConceptService;

@Before
public void setUp() {
Expand All @@ -81,7 +84,7 @@ public void setUp() {
mockStatic(LocaleUtility.class);
when(LocaleUtility.getDefaultLocale()).thenReturn(Locale.ENGLISH);
when(observationTypeMatcher.getObservationType(any(Obs.class))).thenReturn(ObservationTypeMatcher.ObservationType.OBSERVATION);
bahmniObsService = new BahmniObsServiceImpl(obsDao, omrsObsToBahmniObsMapper, visitService, conceptService, visitDao, bahmniProgramWorkflowService, obsService);
bahmniObsService = new BahmniObsServiceImpl(obsDao, omrsObsToBahmniObsMapper, visitService, conceptService, visitDao, bahmniProgramWorkflowService, obsService, bahmniConceptService);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bahmni.module.bahmnicore.util;

import org.bahmni.module.bahmnicore.service.BahmniConceptService;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.api.ConceptService;
Expand All @@ -24,12 +25,13 @@ public class MiscUtilsTest {
@Test
public void shouldReturnConceptsWhenTheyAreAvailable() {
ConceptService conceptService = mock(ConceptService.class);
BahmniConceptService bahmniconceptService = mock(BahmniConceptService.class);
String nonExistantConceptName = "doesNotExist";
String sampleConceptName = "sampleConcept";
when(conceptService.getConceptByName(nonExistantConceptName)).thenReturn(null);
Concept sampleConcept = new Concept();
when(conceptService.getConceptByName(sampleConceptName)).thenReturn(sampleConcept);
Collection<Concept> concepts = MiscUtils.getConceptsForNames(Arrays.asList(sampleConceptName, nonExistantConceptName), conceptService);
when(bahmniconceptService.getConceptByFullySpecifiedName(sampleConceptName)).thenReturn(sampleConcept);
Collection<Concept> concepts = MiscUtils.getConceptsForNames(Arrays.asList(sampleConceptName, nonExistantConceptName), bahmniconceptService, conceptService);
assertThat(concepts.size(), is(equalTo(1)));
assertThat(concepts.iterator().next(), is(sampleConcept));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bahmni.module.bahmnicore.web.v1_0.controller;

import org.bahmni.module.bahmnicore.service.BahmniConceptService;
import org.bahmni.module.bahmnicore.service.BahmniOrderService;
import org.bahmni.module.bahmnicore.util.MiscUtils;
import org.openmrs.Concept;
Expand All @@ -22,11 +23,13 @@
public class BahmniOrderController extends BaseRestController {
private ConceptService conceptService;
private BahmniOrderService bahmniOrderService;
private BahmniConceptService bahmniConceptService;

@Autowired
public BahmniOrderController(ConceptService conceptService, BahmniOrderService bahmniOrderService) {
public BahmniOrderController(ConceptService conceptService, BahmniOrderService bahmniOrderService, BahmniConceptService bahmniConceptService) {
this.conceptService = conceptService;
this.bahmniOrderService = bahmniOrderService;
this.bahmniConceptService = bahmniConceptService;
}


Expand All @@ -44,7 +47,7 @@ public List<BahmniOrder> get(@RequestParam(value = "patientUuid", required = tru


if (visitUuid != null) {
return bahmniOrderService.ordersForVisit(visitUuid, orderTypeUuid, rootConceptNames, MiscUtils.getConceptsForNames(obsIgnoreList, conceptService));
return bahmniOrderService.ordersForVisit(visitUuid, orderTypeUuid, rootConceptNames, MiscUtils.getConceptsForNames(obsIgnoreList, bahmniConceptService, conceptService));
}

List<Concept> rootConcepts = getConcepts(rootConceptNames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.commons.lang3.ObjectUtils;
import org.bahmni.module.bahmnicore.extensions.BahmniExtensions;
import org.bahmni.module.bahmnicore.obs.ObservationsAdder;
import org.bahmni.module.bahmnicore.service.BahmniConceptService;
import org.bahmni.module.bahmnicore.service.BahmniObsService;
import org.bahmni.module.bahmnicore.util.MiscUtils;
import org.bahmni.module.bahmnicore.web.v1_0.LocaleResolver;
Expand Down Expand Up @@ -48,13 +49,15 @@ public class BahmniObservationsController extends BaseRestController {
private ConceptService conceptService;
private VisitService visitService;
private BahmniExtensions bahmniExtensions;
private BahmniConceptService bahmniConceptService;

@Autowired
public BahmniObservationsController(BahmniObsService bahmniObsService, ConceptService conceptService, VisitService visitService, BahmniExtensions bahmniExtensions) {
public BahmniObservationsController(BahmniObsService bahmniObsService, ConceptService conceptService, VisitService visitService, BahmniExtensions bahmniExtensions, BahmniConceptService bahmniConceptService) {
this.bahmniObsService = bahmniObsService;
this.conceptService = conceptService;
this.visitService = visitService;
this.bahmniExtensions = bahmniExtensions;
this.bahmniConceptService = bahmniConceptService;
}

@RequestMapping(method = RequestMethod.GET)
Expand Down Expand Up @@ -105,12 +108,12 @@ public Collection<BahmniObservation> get(@RequestParam(value = "visitUuid", requ

Visit visit = visitService.getVisitByUuid(visitUuid);
if (ObjectUtils.equals(scope, INITIAL)) {
return bahmniObsService.getInitialObsByVisit(visit, MiscUtils.getConceptsForNames(conceptNames, conceptService), obsIgnoreList, filterObsWithOrders);
return bahmniObsService.getInitialObsByVisit(visit, MiscUtils.getConceptsForNames(conceptNames, bahmniConceptService, conceptService), obsIgnoreList, filterObsWithOrders);
} else if (ObjectUtils.equals(scope, LATEST)) {
return bahmniObsService.getLatestObsByVisit(visit, MiscUtils.getConceptsForNames(conceptNames, conceptService), obsIgnoreList, filterObsWithOrders);
return bahmniObsService.getLatestObsByVisit(visit, MiscUtils.getConceptsForNames(conceptNames, bahmniConceptService, conceptService), obsIgnoreList, filterObsWithOrders);
} else {
// Sending conceptName and obsIgnorelist, kinda contradicts, since we filter directly on concept names (not on root concept)
return bahmniObsService.getObservationForVisit(visitUuid, conceptNames, MiscUtils.getConceptsForNames(obsIgnoreList, conceptService), filterObsWithOrders, null);
return bahmniObsService.getObservationForVisit(visitUuid, conceptNames, MiscUtils.getConceptsForNames(obsIgnoreList, bahmniConceptService, conceptService), filterObsWithOrders, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.bahmni.module.bahmnicore.web.v1_0.controller;

import org.bahmni.module.bahmnicore.extensions.BahmniExtensions;
import org.bahmni.module.bahmnicore.service.BahmniConceptService;
import org.bahmni.module.bahmnicore.service.BahmniObsService;
import org.bahmni.module.bahmnicore.web.v1_0.controller.display.controls.BahmniObservationsController;
import org.bahmni.test.builder.VisitBuilder;
Expand Down Expand Up @@ -39,6 +40,8 @@ public class BahmniObservationsControllerTest {
private VisitService visitService;
@Mock
private BahmniExtensions bahmniExtensions;
@Mock
private BahmniConceptService bahmniConceptService;

private Visit visit;
private Concept concept;
Expand All @@ -49,9 +52,10 @@ public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
visit = new VisitBuilder().build();
concept = new Concept();
bahmniObservationsController = new BahmniObservationsController(bahmniObsService, conceptService, visitService, bahmniExtensions);
bahmniObservationsController = new BahmniObservationsController(bahmniObsService, conceptService, visitService, bahmniExtensions, bahmniConceptService);
when(visitService.getVisitByUuid("visitId")).thenReturn(visit);
when(conceptService.getConceptByName("Weight")).thenReturn(concept);
when(bahmniConceptService.getConceptByFullySpecifiedName("Weight")).thenReturn(concept);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bahmni.module.bahmnicore.web.v1_0.controller;

import org.bahmni.module.bahmnicore.service.BahmniConceptService;
import org.bahmni.module.bahmnicore.service.BahmniOrderService;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -31,6 +32,9 @@ public class BahmniOrderControllerTest {
@Mock
private ConceptService conceptService;

@Mock
private BahmniConceptService bahmniConceptService;

private Patient patient;
private Concept concept;

Expand All @@ -41,6 +45,7 @@ public void setUp() throws Exception {
patient = new Patient();
patient.setUuid("patientUuid");
when(conceptService.getConceptByName("Weight")).thenReturn(concept);
when(bahmniConceptService.getConceptByFullySpecifiedName("Weight")).thenReturn(concept);
}

@Test
Expand All @@ -54,7 +59,7 @@ public void shouldReturnBahmniOrdersForOrderType() throws Exception {

when(bahmniOrderService.ordersForOrderType("patientUuid", Arrays.asList(concept), null, null, "OrderTypeUuid", true, locationUuids)).thenReturn(Arrays.asList(bahmniOrder));

BahmniOrderController bahmniOrderController = new BahmniOrderController(conceptService, bahmniOrderService);
BahmniOrderController bahmniOrderController = new BahmniOrderController(conceptService, bahmniOrderService, bahmniConceptService);
List<BahmniOrder> bahmniOrders = bahmniOrderController.get("patientUuid", Arrays.asList("Weight"),"OrderTypeUuid", null, null, null, null, true, locationUuids);

verify(bahmniOrderService, never()).ordersForOrderUuid("patientUuid", Arrays.asList(concept), null, "someUuid");
Expand All @@ -71,7 +76,7 @@ public void shouldReturnBahmniOrdersForOrderUuid() throws Exception {
bahmniOrder.setBahmniObservations(Arrays.asList(obs));

when(bahmniOrderService.ordersForOrderUuid("patientUuid", Arrays.asList(this.concept), null, "OrderUuid")).thenReturn(Arrays.asList(bahmniOrder));
BahmniOrderController bahmniOrderController = new BahmniOrderController(conceptService, bahmniOrderService);
BahmniOrderController bahmniOrderController = new BahmniOrderController(conceptService, bahmniOrderService, bahmniConceptService);
List<BahmniOrder> bahmniOrders = bahmniOrderController.get("patientUuid", Arrays.asList("Weight"), null, null, "OrderUuid", 0, null, true, null);

verify(bahmniOrderService, never()).ordersForOrderType("patientUuid", Arrays.asList(concept), null, null, "someUuid", true, null);
Expand All @@ -87,7 +92,7 @@ public void shouldReturnBahmniOrdersForVisit() throws Exception {
bahmniOrder.setBahmniObservations(Arrays.asList(obs));

when(bahmniOrderService.ordersForVisit("visitUuid", "orderTypeUuid", Arrays.asList("Weight"), Arrays.asList(concept))).thenReturn(Arrays.asList(bahmniOrder));
BahmniOrderController bahmniOrderController = new BahmniOrderController(conceptService, bahmniOrderService);
BahmniOrderController bahmniOrderController = new BahmniOrderController(conceptService, bahmniOrderService, bahmniConceptService);
List<BahmniOrder> bahmniOrders = bahmniOrderController.get("patientUuid", Arrays.asList("Weight"), "orderTypeUuid", "visitUuid", null, null, Arrays.asList("Weight"), false, null);

verify(bahmniOrderService, never()).ordersForOrderType("patientUuid", Arrays.asList(concept), null, null, "someUuid", true, null);
Expand Down

0 comments on commit b8a6bf3

Please sign in to comment.