Search in sources :

Example 6 with FragmentActionResult

use of org.openmrs.ui.framework.fragment.action.FragmentActionResult in project openmrs-module-coreapps by openmrs.

the class QuickVisitFragmentControllerTest method shouldCreateNewVisitWithVisitTypeAndMultipleVisitAttributes.

@Test
public void shouldCreateNewVisitWithVisitTypeAndMultipleVisitAttributes() 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 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);
    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)));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) FragmentActionResult(org.openmrs.ui.framework.fragment.action.FragmentActionResult) Date(java.util.Date) Test(org.junit.Test)

Example 7 with FragmentActionResult

use of org.openmrs.ui.framework.fragment.action.FragmentActionResult in project openmrs-module-coreapps by openmrs.

the class QuickVisitFragmentControllerTest method shouldUpdateVisitWithNewVisitAttributes.

@Test
public void shouldUpdateVisitWithNewVisitAttributes() 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);
    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.1.existing[1]", "true");
    request.getParameterMap().put("attribute.2.existing[2]", "2016-12-07");
    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)));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) FragmentActionResult(org.openmrs.ui.framework.fragment.action.FragmentActionResult) Date(java.util.Date) Test(org.junit.Test)

Example 8 with FragmentActionResult

use of org.openmrs.ui.framework.fragment.action.FragmentActionResult in project openmrs-module-coreapps by openmrs.

the class QuickVisitFragmentControllerTest method shouldCreateNewVisit.

@Test
public void shouldCreateNewVisit() 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();
    when(adtService.ensureVisit(eq(patient), any(Date.class), eq(visitLocation))).thenReturn(visit);
    FragmentActionResult result = controller.create(adtService, visitService, patient, visitLocation, uiUtils, null, 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)));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) FragmentActionResult(org.openmrs.ui.framework.fragment.action.FragmentActionResult) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Date (java.util.Date)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 HttpSession (javax.servlet.http.HttpSession)8 Test (org.junit.Test)8 FragmentActionResult (org.openmrs.ui.framework.fragment.action.FragmentActionResult)8 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)1