Search in sources :

Example 51 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class VisitDetailsFragmentControllerTest method shouldReturnEncounterWithinBoundaries.

@Test
public void shouldReturnEncounterWithinBoundaries() {
    ParseEncounterToJson parseEncounterToJson = mock(ParseEncounterToJson.class);
    when(parseEncounterToJson.createEncounterJSON(any(User.class), any(Encounter.class))).thenReturn(new SimpleObject());
    VisitDomainWrapper visitWrapper = mock(VisitDomainWrapper.class);
    when(visitWrapper.getSortedEncounters()).thenReturn(getTestEncounterList(100));
    VisitDetailsFragmentController controller = new VisitDetailsFragmentController();
    List<SimpleObject> encounters;
    encounters = controller.getEncounterListAsJson(parseEncounterToJson, visitWrapper, new User(), 0, 50);
    assertThat(encounters.size(), is(50));
    encounters = controller.getEncounterListAsJson(parseEncounterToJson, visitWrapper, new User(), 50, 50);
    assertThat(encounters.size(), is(50));
    encounters = controller.getEncounterListAsJson(parseEncounterToJson, visitWrapper, new User(), 0, 200);
    assertThat(encounters.size(), is(100));
    encounters = controller.getEncounterListAsJson(parseEncounterToJson, visitWrapper, new User(), 99, 25);
    assertThat(encounters.size(), is(1));
    encounters = controller.getEncounterListAsJson(parseEncounterToJson, visitWrapper, new User(), 100, 25);
    assertThat(encounters.isEmpty(), is(true));
}
Also used : ParseEncounterToJson(org.openmrs.module.coreapps.parser.ParseEncounterToJson) User(org.openmrs.User) SimpleObject(org.openmrs.ui.framework.SimpleObject) Encounter(org.openmrs.Encounter) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Test(org.junit.Test)

Example 52 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class VisitDetailsFragmentControllerTest method isSimpleObjectWith.

private Matcher<SimpleObject> isSimpleObjectWith(final Object... propertiesAndValues) {
    return new ArgumentMatcher<SimpleObject>() {

        @Override
        public boolean matches(Object o) {
            SimpleObject so = (SimpleObject) o;
            for (int i = 0; i < propertiesAndValues.length; i += 2) {
                String property = (String) propertiesAndValues[i];
                Object expectedValue = propertiesAndValues[i + 1];
                if (!OpenmrsUtil.nullSafeEquals(so.get(property), expectedValue)) {
                    return false;
                }
            }
            return true;
        }
    };
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) ArgumentMatcher(org.mockito.ArgumentMatcher) SimpleObject(org.openmrs.ui.framework.SimpleObject)

Example 53 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class ParserEncounterIntoSimpleObjects method parseObs.

private SimpleObject parseObs(Obs obs, Locale locale) {
    if ("org.openmrs.Location".equals(obs.getComment())) {
        return (parseObsWithLocationAnswer(obs, locationService.getLocation(Integer.valueOf(obs.getValueText()))));
    } else {
        SimpleObject simpleObject = SimpleObject.create("obsId", obs.getObsId());
        simpleObject.put("question", capitalizeString(uiUtils.format(obs.getConcept())));
        simpleObject.put("answer", uiUtils.format(obs));
        return simpleObject;
    }
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject)

Example 54 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class ParserEncounterIntoSimpleObjects method parseDiagnosis.

private SimpleObject parseDiagnosis(DiagnosisMetadata diagnosisMetadata, Obs obs) {
    Diagnosis diagnosis = diagnosisMetadata.toDiagnosis(obs);
    String answer = "(" + uiUtils.message("coreapps.Diagnosis.Certainty." + diagnosis.getCertainty()) + ") ";
    answer += diagnosis.getDiagnosis().formatWithCode(uiUtils.getLocale(), emrApiProperties.getConceptSourcesForDiagnosisSearch());
    SimpleObject simpleObject = SimpleObject.fromObject(obs, uiUtils, "obsId");
    simpleObject.put("question", formatDiagnosisQuestion(diagnosis.getOrder()));
    simpleObject.put("answer", answer);
    simpleObject.put("order", diagnosis.getOrder().ordinal());
    return simpleObject;
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis)

Example 55 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class RetrospectiveVisitFragmentController method create.

public Object create(@SpringBean("adtService") AdtService adtService, @RequestParam("patientId") Patient patient, @RequestParam("locationId") Location location, @RequestParam("startDate") Date startDate, @RequestParam(value = "stopDate", required = false) Date stopDate, HttpServletRequest request, UiUtils ui) {
    // if no stop date, set it to start date
    if (stopDate == null) {
        stopDate = startDate;
    }
    // set the startDate time component to the start of day
    startDate = new DateTime(startDate).withTime(0, 0, 0, 0).toDate();
    // if stopDate is today, set stopDate to current datetime, otherwise set time component to end of date
    if (new DateTime().withTime(0, 0, 0, 0).equals(new DateTime(stopDate).withTime(0, 0, 0, 0))) {
        stopDate = new Date();
    } else {
        stopDate = new DateTime(stopDate).withTime(23, 59, 59, 999).toDate();
    }
    try {
        VisitDomainWrapper createdVisit = adtService.createRetrospectiveVisit(patient, location, startDate, stopDate);
        request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, ui.message("coreapps.retrospectiveVisit.addedVisitMessage"));
        request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
        return SimpleObject.create("success", true, "id", createdVisit.getVisit().getId().toString(), "uuid", createdVisit.getVisit().getUuid());
    } catch (ExistingVisitDuringTimePeriodException e) {
        // if there are existing visit(s), return these existing visits
        List<SimpleObject> simpleVisits = new ArrayList<SimpleObject>();
        List<VisitDomainWrapper> visits = adtService.getVisits(patient, location, startDate, stopDate);
        if (visits != null) {
            for (VisitDomainWrapper visit : visits) {
                simpleVisits.add(SimpleObject.create("startDate", ui.format(new DateTime(visit.getVisit().getStartDatetime()).toDateMidnight().toDate()), "stopDate", ui.format(new DateTime(visit.getVisit().getStopDatetime()).toDateMidnight().toDate()), "id", visit.getVisit().getId(), "uuid", visit.getVisit().getUuid()));
            }
        }
        return simpleVisits;
    } catch (Exception e) {
        log.error("Unable to add retrospective visit", e);
        return new FailureResult(ui.message(e.getMessage()));
    }
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) FailureResult(org.openmrs.ui.framework.fragment.action.FailureResult) ExistingVisitDuringTimePeriodException(org.openmrs.module.emrapi.adt.exception.ExistingVisitDuringTimePeriodException) ArrayList(java.util.ArrayList) List(java.util.List) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) DateTime(org.joda.time.DateTime) Date(java.util.Date) ExistingVisitDuringTimePeriodException(org.openmrs.module.emrapi.adt.exception.ExistingVisitDuringTimePeriodException)

Aggregations

SimpleObject (org.openmrs.ui.framework.SimpleObject)67 Test (org.junit.Test)37 Location (org.openmrs.Location)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)26 ArrayList (java.util.ArrayList)18 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)17 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)13 Config (org.openmrs.module.pihcore.config.Config)12 DateTime (org.joda.time.DateTime)11 Date (java.util.Date)9 Encounter (org.openmrs.Encounter)9 Concept (org.openmrs.Concept)6 Patient (org.openmrs.Patient)6 Obs (org.openmrs.Obs)5 Visit (org.openmrs.Visit)5 LinkedHashMap (java.util.LinkedHashMap)4 List (java.util.List)3 ConceptSearchResult (org.openmrs.ConceptSearchResult)3 Form (org.openmrs.Form)3