use of org.openmrs.ui.framework.fragment.action.FragmentActionResult in project openmrs-module-coreapps by openmrs.
the class QuickVisitFragmentControllerTest method shouldCreateNewVisitWithVisitTypeAndSingleVisitAttribute.
@Test
public void shouldCreateNewVisitWithVisitTypeAndSingleVisitAttribute() throws Exception {
Patient patient = new Patient();
Location visitLocation = new Location();
String formattedPatient = "Patient name";
when(uiUtils.format(patient)).thenReturn(formattedPatient);
when(uiUtils.message("coreapps.visit.createQuickVisit.successMessage", formattedPatient)).thenReturn(successMessage);
HttpSession session = mock(HttpSession.class);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getSession()).thenReturn(session);
Visit visit = createVisit();
VisitType visitType = new VisitType();
visitType.setId(1);
visitType.setName("Outpatient");
when(visitService.saveVisitType(visitType)).thenReturn(visitType);
// create a visit attribute type
VisitAttributeType visitAttributeType = new VisitAttributeType();
visitAttributeType.setVisitAttributeTypeId(1);
visitAttributeType.setName("First Visit");
visitAttributeType.setDatatypeClassname("org.openmrs.customdatatype.datatype.BooleanDatatype");
visitAttributeType.setMinOccurs(0);
when(visitService.saveVisitAttributeType(visitAttributeType)).thenReturn(visitAttributeType);
request.getParameterMap().put("attribute.1.new[0]", "false");
when(adtService.ensureVisit(eq(patient), any(Date.class), eq(visitLocation))).thenReturn(visit);
FragmentActionResult result = controller.create(adtService, visitService, patient, visitLocation, uiUtils, visitType, emrContext, request);
verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, successMessage);
verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
assertThat(result, is(CoreMatchers.any(FragmentActionResult.class)));
}
use of org.openmrs.ui.framework.fragment.action.FragmentActionResult in project openmrs-module-coreapps by openmrs.
the class QuickVisitFragmentControllerTest method shouldUpdateVisitWithExistingVisitAttributes.
@Test
public void shouldUpdateVisitWithExistingVisitAttributes() throws Exception {
Patient patient = new Patient();
patient.setId(1);
Location visitLocation = new Location();
String formattedPatient = "Patient name";
when(uiUtils.format(patient)).thenReturn(formattedPatient);
when(uiUtils.message("coreapps.visit.createQuickVisit.successMessage", formattedPatient)).thenReturn(successMessage);
String updateSuccessMessage = "Update message";
when(uiUtils.message("coreapps.visit.updateVisit.successMessage", formattedPatient)).thenReturn(updateSuccessMessage);
HttpSession session = mock(HttpSession.class);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getSession()).thenReturn(session);
Visit visit = createVisit();
visit.setPatient(patient);
VisitType visitType = new VisitType();
visitType.setId(1);
visitType.setName("Outpatient");
when(visitService.saveVisitType(visitType)).thenReturn(visitType);
// create visit attribute types
VisitAttributeType visitAttributeType = new VisitAttributeType();
visitAttributeType.setVisitAttributeTypeId(1);
visitAttributeType.setName("First Visit");
visitAttributeType.setDatatypeClassname("org.openmrs.customdatatype.datatype.BooleanDatatype");
visitAttributeType.setMinOccurs(0);
when(visitService.saveVisitAttributeType(visitAttributeType)).thenReturn(visitAttributeType);
VisitAttributeType visitAttributeType2 = new VisitAttributeType();
visitAttributeType2.setVisitAttributeTypeId(2);
visitAttributeType2.setName("Admission Date");
visitAttributeType2.setDatatypeClassname("org.openmrs.customdatatype.datatype.DateDatatype");
visitAttributeType2.setMinOccurs(0);
when(visitService.saveVisitAttributeType(visitAttributeType2)).thenReturn(visitAttributeType2);
VisitAttributeType visitAttributeType3 = new VisitAttributeType();
visitAttributeType3.setVisitAttributeTypeId(3);
visitAttributeType3.setName("Bed");
visitAttributeType3.setDatatypeClassname("org.openmrs.customdatatype.datatype.LongFreeTextDatatype");
visitAttributeType3.setMinOccurs(0);
when(visitService.saveVisitAttributeType(visitAttributeType3)).thenReturn(visitAttributeType3);
VisitAttributeType visitAttributeType4 = new VisitAttributeType();
visitAttributeType4.setVisitAttributeTypeId(4);
visitAttributeType4.setName("Ward");
visitAttributeType4.setDatatypeClassname("org.openmrs.customdatatype.datatype.LongFreeTextDatatype");
visitAttributeType4.setMinOccurs(0);
when(visitService.saveVisitAttributeType(visitAttributeType4)).thenReturn(visitAttributeType4);
request.getParameterMap().put("attribute.1.new[0]", "false");
request.getParameterMap().put("attribute.2.new[0]", "2016-12-08");
when(adtService.ensureVisit(eq(patient), any(Date.class), eq(visitLocation))).thenReturn(visit);
FragmentActionResult result = controller.create(adtService, visitService, patient, visitLocation, uiUtils, visitType, emrContext, request);
verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, successMessage);
verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
assertThat(result, is(CoreMatchers.any(FragmentActionResult.class)));
request.getParameterMap().put("attribute.3.new[0]", "Bed No.2");
request.getParameterMap().put("attribute.4.new[0]", "Male");
FragmentActionResult update = controller.update(visitService, patient, visit, null, uiUtils, request);
verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, updateSuccessMessage);
assertThat(update, is(CoreMatchers.any(FragmentActionResult.class)));
}
use of org.openmrs.ui.framework.fragment.action.FragmentActionResult in project openmrs-module-coreapps by openmrs.
the class QuickVisitFragmentControllerTest method shouldCreateNewVisitWithVisitType.
@Test
public void shouldCreateNewVisitWithVisitType() throws Exception {
Patient patient = new Patient();
Location visitLocation = new Location();
String formattedPatient = "Patient name";
when(uiUtils.format(patient)).thenReturn(formattedPatient);
when(uiUtils.message("coreapps.visit.createQuickVisit.successMessage", formattedPatient)).thenReturn(successMessage);
HttpSession session = mock(HttpSession.class);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getSession()).thenReturn(session);
Visit visit = createVisit();
VisitType visitType = new VisitType();
visitType.setId(1);
visitType.setName("Outpatient");
when(visitService.saveVisitType(visitType)).thenReturn(visitType);
when(adtService.ensureVisit(eq(patient), any(Date.class), eq(visitLocation))).thenReturn(visit);
FragmentActionResult result = controller.create(adtService, visitService, patient, visitLocation, uiUtils, visitType, emrContext, request);
verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, successMessage);
verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
assertThat(result, is(CoreMatchers.any(FragmentActionResult.class)));
}
use of org.openmrs.ui.framework.fragment.action.FragmentActionResult in project openmrs-module-coreapps by openmrs.
the class QuickVisitFragmentControllerTest method shouldFailIfActiveVisitAlreadyExists.
@Test
public void shouldFailIfActiveVisitAlreadyExists() throws Exception {
Patient patient = new Patient();
Location visitLocation = new Location();
when(adtService.getActiveVisit(patient, visitLocation)).thenReturn(new VisitDomainWrapper(null, null));
HttpSession session = mock(HttpSession.class);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getSession()).thenReturn(session);
FragmentActionResult result = controller.create(adtService, visitService, patient, visitLocation, uiUtils, null, emrContext, request);
assertThat(result, is(instanceOf(FailureResult.class)));
verify(adtService, never()).ensureVisit(eq(patient), any(Date.class), eq(visitLocation));
}
use of org.openmrs.ui.framework.fragment.action.FragmentActionResult in project openmrs-module-coreapps by openmrs.
the class QuickVisitFragmentControllerTest method shouldUpdateVisitWithDifferentVisitType.
@Test
public void shouldUpdateVisitWithDifferentVisitType() throws Exception {
Patient patient = new Patient();
patient.setId(1);
Location visitLocation = new Location();
String formattedPatient = "Patient name";
when(uiUtils.format(patient)).thenReturn(formattedPatient);
when(uiUtils.message("coreapps.visit.createQuickVisit.successMessage", formattedPatient)).thenReturn(successMessage);
String updateSuccessMessage = "Update message";
when(uiUtils.message("coreapps.visit.updateVisit.successMessage", formattedPatient)).thenReturn(updateSuccessMessage);
HttpSession session = mock(HttpSession.class);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getSession()).thenReturn(session);
Visit visit = createVisit();
visit.setPatient(patient);
VisitType visitType = new VisitType();
visitType.setId(1);
visitType.setName("Inpatient");
when(visitService.saveVisitType(visitType)).thenReturn(visitType);
VisitType visitType2 = new VisitType();
visitType2.setId(2);
visitType2.setName("Outpatient");
when(visitService.saveVisitType(visitType2)).thenReturn(visitType2);
when(adtService.ensureVisit(eq(patient), any(Date.class), eq(visitLocation))).thenReturn(visit);
FragmentActionResult result = controller.create(adtService, visitService, patient, visitLocation, uiUtils, visitType, emrContext, request);
verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, successMessage);
verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
assertThat(result, is(CoreMatchers.any(FragmentActionResult.class)));
FragmentActionResult update = controller.update(visitService, patient, visit, visitType2, uiUtils, request);
verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, updateSuccessMessage);
assertThat(update, is(CoreMatchers.any(FragmentActionResult.class)));
}
Aggregations