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()));
}
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()));
}
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;
}
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"));
}
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"));
}
Aggregations