Search in sources :

Example 21 with SimpleObject

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

the class RetrospectiveVisitFragmentControllerTest method test_shouldCreateNewRetrospectiveVisit_whenNoStopDateSpecified.

@Test
public void test_shouldCreateNewRetrospectiveVisit_whenNoStopDateSpecified() throws Exception {
    when(ui.message("coreapps.retrospectiveVisit.addedVisitMessage")).thenReturn("success message");
    Patient patient = createPatient();
    Location location = new Location();
    Date startDate = new DateTime(2012, 1, 1, 12, 12, 12).toDate();
    // should round to the time components to the start and end of the days, respectively
    Date expectedStartDate = new DateTime(2012, 1, 1, 0, 0, 0, 0).toDate();
    Date expectedStopDate = new DateTime(2012, 1, 1, 23, 59, 59, 999).toDate();
    Visit visit = createVisit();
    when(adtService.createRetrospectiveVisit(patient, location, expectedStartDate, expectedStopDate)).thenReturn(new VisitDomainWrapper(visit));
    SimpleObject result = (SimpleObject) controller.create(adtService, patient, location, startDate, null, request, ui);
    verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, ui.message("coreapps.retrospectiveVisit.addedVisitMessage"));
    verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
    assertTrue((Boolean) result.get("success"));
    assertThat((String) result.get("id"), is(visit.getId().toString()));
    assertThat((String) result.get("uuid"), is(visit.getUuid()));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Date(java.util.Date) DateTime(org.joda.time.DateTime) Location(org.openmrs.Location) Test(org.junit.Test)

Example 22 with SimpleObject

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

the class RetrospectiveVisitFragmentControllerTest method test_shouldCreateNewRetrospectiveVisit.

@Test
public void test_shouldCreateNewRetrospectiveVisit() throws Exception {
    when(ui.message("coreapps.retrospectiveVisit.addedVisitMessage")).thenReturn("success message");
    Patient patient = createPatient();
    Location location = new Location();
    Date startDate = new DateTime(2012, 1, 1, 12, 12, 12).toDate();
    Date stopDate = new DateTime(2012, 1, 2, 13, 13, 13).toDate();
    // should round to the time components to the start and end of the days, respectively
    Date expectedStartDate = new DateTime(2012, 1, 1, 0, 0, 0, 0).toDate();
    Date expectedStopDate = new DateTime(2012, 1, 2, 23, 59, 59, 999).toDate();
    Visit visit = createVisit();
    when(adtService.createRetrospectiveVisit(patient, location, expectedStartDate, expectedStopDate)).thenReturn(new VisitDomainWrapper(visit));
    SimpleObject result = (SimpleObject) controller.create(adtService, patient, location, startDate, stopDate, request, ui);
    verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, ui.message("coreapps.retrospectiveVisit.addedVisitMessage"));
    verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
    assertTrue((Boolean) result.get("success"));
    assertThat((String) result.get("id"), is(visit.getId().toString()));
    assertThat((String) result.get("uuid"), is(visit.getUuid()));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Date(java.util.Date) DateTime(org.joda.time.DateTime) Location(org.openmrs.Location) Test(org.junit.Test)

Example 23 with SimpleObject

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

the class EncounterDiagnosesFragmentController method generateJsForDiagnoses.

private List<String> generateJsForDiagnoses(List<Diagnosis> diagnoses, UiUtils ui) throws Exception {
    // to ensure we have the exact same json format as search results, borrow the simplify method from here
    DiagnosesFragmentController diagnosesFragmentController = new DiagnosesFragmentController();
    List<String> jsForDiagnoses = new ArrayList<String>();
    Collections.sort(diagnoses, new Comparator<Diagnosis>() {

        @Override
        public int compare(Diagnosis left, Diagnosis right) {
            return left.getOrder().compareTo(right.getOrder());
        }
    });
    for (Diagnosis d : diagnoses) {
        CodedOrFreeTextAnswer diagnosis = d.getDiagnosis();
        String jsDiagnosis;
        if (diagnosis.getNonCodedAnswer() != null) {
            jsDiagnosis = "'" + ui.escapeJs(diagnosis.getNonCodedAnswer()) + "'";
        } else {
            ConceptSearchResult csr = new ConceptSearchResult(null, diagnosis.getCodedAnswer(), diagnosis.getSpecificCodedAnswer());
            SimpleObject simple = diagnosesFragmentController.simplify(csr, ui, Context.getLocale());
            jsDiagnosis = simple.toJson();
        }
        jsForDiagnoses.add("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer(" + jsDiagnosis + "), confirmed: " + (d.getCertainty().equals(Diagnosis.Certainty.CONFIRMED)) + ", primary: " + (d.getOrder().equals(Diagnosis.Order.PRIMARY)) + ", existingObs: " + d.getExistingObs().getId() + " }");
    }
    return jsForDiagnoses;
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) ArrayList(java.util.ArrayList) DiagnosesFragmentController(org.openmrs.module.coreapps.fragment.controller.DiagnosesFragmentController) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer) ConceptSearchResult(org.openmrs.ConceptSearchResult)

Example 24 with SimpleObject

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

the class ParseEncounterToJsonTest method userShouldEditEncounterWhenDoesNotHavePrivilegeButParticipateInTheEncounter.

@Test
public void userShouldEditEncounterWhenDoesNotHavePrivilegeButParticipateInTheEncounter() {
    mockStatic(Context.class);
    when(Context.getAuthenticatedUser()).thenReturn(new User());
    User user = new User();
    user.setPerson(new Person());
    Encounter encounter = createEncounter();
    encounter.addProvider(new EncounterRole(5), createProvider(user));
    encounter.setCreator(new User());
    SimpleObject encounterJSON = parseEncounterToJson.createEncounterJSON(user, encounter);
    assertTrue((Boolean) encounterJSON.get("canEdit"));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 25 with SimpleObject

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

the class ParseEncounterToJsonTest method userShouldEditEncounterWhenIsAdmin.

@Test
public void userShouldEditEncounterWhenIsAdmin() {
    User user = new User();
    user.addRole(createRoleAdminForUser());
    Encounter encounter = createEncounter();
    encounter.setCreator(new User());
    SimpleObject encounterJSON = parseEncounterToJson.createEncounterJSON(user, encounter);
    assertTrue((Boolean) encounterJSON.get("canEdit"));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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