/** @see RadiologyObsFormController#getDicomViewerUrl(Study, Patient) */
  @Test
  @Verifies(
      value = "should return null given non completed study and patient",
      method = "getDicomViewerUrl(Study, Patient)")
  public void getDicomViewerUrl_ShouldReturnNullGivenNonCompletedStudyAndPatient()
      throws Exception {

    mockStudy.setPerformedStatus(PerformedProcedureStepStatus.IN_PROGRESS);

    when(RadiologyProperties.getServersAddress()).thenReturn("localhost");
    when(RadiologyProperties.getServersPort()).thenReturn("8081");
    when(RadiologyProperties.getDicomViewerUrlBase()).thenReturn("/weasis/viewer?");

    Method getDicomViewerUrlMethod =
        radiologyObsFormController
            .getClass()
            .getDeclaredMethod(
                "getDicomViewerUrl",
                new Class[] {org.openmrs.module.radiology.Study.class, org.openmrs.Patient.class});
    getDicomViewerUrlMethod.setAccessible(true);

    String dicomViewerUrl =
        (String)
            getDicomViewerUrlMethod.invoke(
                radiologyObsFormController, new Object[] {mockStudy, mockPatient});

    assertThat(dicomViewerUrl, nullValue());
  }
  /** @see RadiologyObsFormController#updateReadingPhysician(Study) */
  @Test
  @Verifies(
      value = "should not update reading physician for given study with reading physician",
      method = "updateReadingPhysician(Study)")
  public void
      updateReadingPhysician_shouldNotUpdateReadingPhysicianForGivenStudyWithReadingPhysician()
          throws Exception {

    User otherMockReadingPhysician = RadiologyTestData.getMockRadiologyReadingPhysician();
    assertThat(mockReadingPhysician, is(not(otherMockReadingPhysician)));

    mockStudy.setReadingPhysician(mockReadingPhysician);
    when(Context.getAuthenticatedUser()).thenReturn(otherMockReadingPhysician);

    Method updateReadingPhysicianMethod =
        radiologyObsFormController
            .getClass()
            .getDeclaredMethod(
                "updateReadingPhysician", new Class[] {org.openmrs.module.radiology.Study.class});
    updateReadingPhysicianMethod.setAccessible(true);

    assertThat(mockStudy.getReadingPhysician(), is(mockReadingPhysician));

    updateReadingPhysicianMethod.invoke(radiologyObsFormController, new Object[] {mockStudy});

    assertThat(mockStudy.getReadingPhysician(), is(mockReadingPhysician));
  }
  /** @see RadiologyObsFormController#populateModelAndView(RadiologyOrder, Obs) */
  @Test
  @Verifies(
      value =
          "should populate the model and view for given radiology order  with completed study and obs",
      method = "populateModelAndView(RadiologyOrder, Obs)")
  public void
      populateModelAndView_ShouldPopulateModelAndViewWithObsForGivenRadiologyOrderWithCompletedStudyAndObs()
          throws Exception {

    mockStudy.setPerformedStatus(PerformedProcedureStepStatus.COMPLETED);

    Method populateModelAndViewMethod =
        radiologyObsFormController
            .getClass()
            .getDeclaredMethod(
                "populateModelAndView",
                new Class[] {
                  org.openmrs.module.radiology.RadiologyOrder.class, org.openmrs.Obs.class
                });
    populateModelAndViewMethod.setAccessible(true);

    ModelAndView modelAndView =
        (ModelAndView)
            populateModelAndViewMethod.invoke(
                radiologyObsFormController, new Object[] {mockRadiologyOrder, mockObs});

    assertThat(mockObs.getPerson(), is((Person) mockRadiologyOrder.getPatient()));

    assertThat(modelAndView.getModelMap(), hasKey("obs"));
    Obs obs = (Obs) modelAndView.getModelMap().get("obs");
    assertThat(obs, is(mockObs));

    assertThat(modelAndView.getModelMap(), hasKey("studyUID"));
    String studyUID = (String) modelAndView.getModelMap().get("studyUID");
    assertNotNull(studyUID);
    assertThat(studyUID, is(mockStudy.getStudyInstanceUid()));

    assertThat(modelAndView.getModelMap(), hasKey("previousObs"));
    List<Obs> previousObs = (List<Obs>) modelAndView.getModelMap().get("previousObs");
    assertNotNull(previousObs);
    assertThat(previousObs, is(radiologyService.getObsByOrderId(mockRadiologyOrder.getId())));

    assertThat(modelAndView.getModelMap(), hasKey("dicomViewerUrl"));
  }
  /** @see RadiologyObsFormController#getDicomViewerUrl(Study, Patient) */
  @Test
  @Verifies(
      value = "should return dicom viewer url given completed study and patient",
      method = "getDicomViewerUrl(Study, Patient)")
  public void getDicomViewerUrl_ShouldReturnDicomViewerUrlGivenCompletedStudyAndPatient()
      throws Exception {

    mockStudy.setPerformedStatus(PerformedProcedureStepStatus.COMPLETED);

    when(RadiologyProperties.getServersAddress()).thenReturn("localhost");
    when(RadiologyProperties.getServersPort()).thenReturn("8081");
    when(RadiologyProperties.getDicomViewerUrlBase()).thenReturn("/weasis/viewer?");

    Method getDicomViewerUrlMethod =
        radiologyObsFormController
            .getClass()
            .getDeclaredMethod(
                "getDicomViewerUrl",
                new Class[] {org.openmrs.module.radiology.Study.class, org.openmrs.Patient.class});
    getDicomViewerUrlMethod.setAccessible(true);

    String dicomViewerUrl =
        (String)
            getDicomViewerUrlMethod.invoke(
                radiologyObsFormController, new Object[] {mockStudy, mockPatient});

    assertNotNull(dicomViewerUrl);

    String patID = mockPatient.getPatientIdentifier().getIdentifier();
    assertThat(
        dicomViewerUrl,
        is(
            "http://localhost:8081/weasis/viewer?studyUID="
                + mockStudy.getStudyInstanceUid()
                + "&patientID="
                + patID));
  }
  /** @see RadiologyObsFormController#updateReadingPhysician(Study) */
  @Test
  @Verifies(
      value =
          "should not update reading physician if user is not authenticated as reading physician",
      method = "updateReadingPhysician(Study)")
  public void
      updateReadingPhysician_shouldNotUpdateReadingPhysicianIfUserIsNotAuthenticatedAsReadingPhysician()
          throws Exception {

    when(Context.getAuthenticatedUser()).thenReturn(mockRadiologyScheduler);

    Method updateReadingPhysicianMethod =
        radiologyObsFormController
            .getClass()
            .getDeclaredMethod(
                "updateReadingPhysician", new Class[] {org.openmrs.module.radiology.Study.class});
    updateReadingPhysicianMethod.setAccessible(true);

    assertThat(mockStudy.getReadingPhysician(), nullValue());

    updateReadingPhysicianMethod.invoke(radiologyObsFormController, new Object[] {mockStudy});

    assertThat(mockStudy.getReadingPhysician(), nullValue());
  }