@Test
  public void testViewDicomHeaderByIdPublicForPublicImage() throws Exception {
    PublicData publicDataMock = createMock(PublicData.class);

    URL testDicomUrl = this.getClass().getClassLoader().getResource("test.dcm");
    FileUtils.copyURLToFile(testDicomUrl, new File("/tmp/test.dcm"));

    expect(SpringApplicationContext.getBean("imageDAO")).andReturn(imageDAOMock);
    expect(imageDAOMock.findImagePath(591166)).andReturn("/tmp/test.dcm");
    expectNew(PublicData.class).andReturn(publicDataMock);
    expect(publicDataMock.checkPublicImage(591166)).andReturn(Boolean.TRUE);
    publicDataMock.setAuthorizationManager(authorizationManagerMock);

    replayMock();
    replay(PublicData.class, publicDataMock);

    LocalDicomTagViewer localDicomTagViewer = new LocalDicomTagViewer();
    localDicomTagViewer.setPublicData(true);
    localDicomTagViewer.setAuthorizationManager(authorizationManagerMock);

    List<DicomTagDTO> tags = localDicomTagViewer.viewDicomHeader(591166);
    Assert.assertTrue(tags.size() == 110);

    new File("/tmp/test.dcm").delete();

    verify(PublicData.class, publicDataMock);
  }
예제 #2
0
  public void recordDownload(Map<String, SeriesSearchResult> seriesItemMap, String loginName)
      throws Exception {
    DownloadDataDAO downloadDAO =
        (DownloadDataDAO) SpringApplicationContext.getBean("downloadDataDAO");

    for (String key : seriesItemMap.keySet()) {
      SeriesSearchResult ssr = seriesItemMap.get(key);
      long size = ssr.computeExactSize();
      downloadDAO.record(ssr.getSeriesInstanceUid(), loginName, "classic", size);
    }
  }
  @Test
  public void testViewDicomHeaderById() throws Exception {

    URL testDicomUrl = this.getClass().getClassLoader().getResource("test.dcm");
    FileUtils.copyURLToFile(testDicomUrl, new File("/tmp/test.dcm"));

    expect(SpringApplicationContext.getBean("imageDAO")).andReturn(imageDAOMock);
    expect(imageDAOMock.findImagePath(591166)).andReturn("/tmp/test.dcm");

    replayMock();

    LocalDicomTagViewer localDicomTagViewer = new LocalDicomTagViewer();
    List<DicomTagDTO> tags = localDicomTagViewer.viewDicomHeader(591166);
    Assert.assertTrue(tags.size() == 110);

    new File("/tmp/test.dcm").delete();
  }
  /**
   * Just test reduction of triples to patients... do the heavy lifting of all criteria permutations
   * in the DICOM Query Handler tests
   */
  @Test
  public void testSearchForPatients() throws Exception {
    DICOMQuery dicomQuery = new DICOMQuery();

    ImageModalityCriteria imageModalityCriteria = new ImageModalityCriteria();
    imageModalityCriteria.setImageModalityValue("CT");
    dicomQuery.setCriteria(imageModalityCriteria);

    StudyNumberDTO studyNumberDTO0 = new StudyNumberDTO(1, "1", "p1", 2, 5);
    StudyNumberDTO studyNumberDTO1 = new StudyNumberDTO(6, "6", "p2", 1, 1);

    /////////////////////////////////

    mockStatic(SpringApplicationContext.class);
    mockStatic(ApplicationFactory.class);
    ApplicationFactory applicationFactoryMock = createMock(ApplicationFactory.class);
    StudyNumberMap studyNumberMapMock = createMock(StudyNumberMap.class);
    DICOMQueryHandler dicomQueryHandlerMock = createMock(DICOMQueryHandler.class);

    expect(ApplicationFactory.getInstance()).andReturn(applicationFactoryMock).anyTimes();
    expect(applicationFactoryMock.getStudyNumberMap()).andReturn(studyNumberMapMock).anyTimes();
    expect(studyNumberMapMock.getStudiesForPatient(1)).andReturn(studyNumberDTO0);
    expect(studyNumberMapMock.getStudiesForPatient(6)).andReturn(studyNumberDTO1);
    expect(SpringApplicationContext.getBean("dicomQueryHandler")).andReturn(dicomQueryHandlerMock);
    expect(dicomQueryHandlerMock.findTriples(dicomQuery)).andReturn(constructTriples());

    replay(SpringApplicationContext.class);
    replay(ApplicationFactory.class, applicationFactoryMock);
    replay(DICOMQueryHandler.class, dicomQueryHandlerMock);
    replay(StudyNumberMap.class, studyNumberMapMock);

    //////////////////

    List<PatientSearchResult> results = patientSearcher.searchForPatients(dicomQuery);
    Assert.assertTrue(results.size() == 2);
    Assert.assertTrue(results.get(0).getSubjectId().equals("1"));
    Assert.assertTrue(results.get(1).getSubjectId().equals("6"));

    verify(SpringApplicationContext.class);
    verify(ApplicationFactory.class, applicationFactoryMock);
    verify(DICOMQueryHandler.class, dicomQueryHandlerMock);
    verify(StudyNumberMap.class, studyNumberMapMock);
  }
 public String findEmailByUserName(String uName) {
   NCIASecurityManager nciaSecurityManager =
       (NCIASecurityManager) SpringApplicationContext.getBean("nciaSecurityManager");
   String email = nciaSecurityManager.getUserEmail(uName);
   return email;
 }
  /** Saves the query with the desired name */
  public String saveQuery() {
    logger.debug("query name is: " + queryName);
    SearchWorkflowBean swb = BeanManager.getSearchWorkflowBean();
    String queryNameText = "MAINbody:searchMenuForm:saveQueryView:queryName";

    // Check to see if the query is being edited, if so, this will be
    // performed
    // when the user wants to update the query
    if (swb.isEditingSavedQuery()) {
      queryNameText = "MAINbody:searchMenuForm:saveQueryView:newDataQuery";
      swb.setToggleQuery(false);
      if (updateQuery) {
        QueryStorageManager qManager =
            (QueryStorageManager) SpringApplicationContext.getBean("queryStorageManager");
        long newQueryId;

        try {
          newQueryId = qManager.updateQuery(query);
          query.setSavedQueryId(newQueryId);
          MessageUtil.addInfoMessage(
              queryNameText, "queryUpdated", new Object[] {query.getQueryName()});

          swb.setEditingSavedQuery(false);
          queryName = "";
        } catch (Exception e) {
          logger.error("Problem updating the query", e);

          MessageUtil.addErrorMessage(queryNameText, "queryErrorUpdating");
        }

        return null;
      }
    }

    // This will be performed when the user is either saving a new query
    // or saving a current query with a different name.
    if (!swb.isEditingSavedQuery() || !updateQuery) {
      if ((queryName == null) || queryName.equals("")) {
        MessageUtil.addErrorMessage(queryNameText, "queryBlankName");
      } else {
        SecurityBean secure = BeanManager.getSecurityBean();
        SavedQueryBean queryBean = BeanManager.getSavedQueryBean();
        String uName = secure.getUsername();
        String oldQueryName = query.getQueryName();
        query.setQueryName(queryName);
        query.setUserID(uName);
        swb.setToggleQuery(false);
        QueryStorageManager qManager =
            (QueryStorageManager) SpringApplicationContext.getBean("queryStorageManager");
        long newQueryId;

        try {
          newQueryId = qManager.saveQuery(query);
          query.setSavedQueryId(newQueryId);
          queryBean.updateSavedQueryCount();
          MessageUtil.addInfoMessage(
              queryNameText, "querySaved", new Object[] {query.getQueryName()});
          swb.setEditingSavedQuery(false);
          updateQuery = true;
        } catch (DuplicateQueryException dq) {
          MessageUtil.addErrorMessage(queryNameText, "queryExists");
          query.setQueryName(oldQueryName);
        } catch (Exception e) {
          logger.error("Problem storing the query", e);
          MessageUtil.addErrorMessage(queryNameText, "queryExists");
          query.setQueryName(oldQueryName);
        }
      }

      queryName = "";
    }

    return null;
  }
예제 #7
0
 /**
  * Constructor - initializes this instance of AuthorizationManager with no user name provided.
  * This constructor should only be used authorizing against "public" data.
  *
  * @throws Exception
  */
 public AuthorizationManager() throws Exception {
   NCIASecurityManager mgr =
       (NCIASecurityManager) SpringApplicationContext.getBean("nciaSecurityManager");
   securityRights = mgr.getSecurityMapForPublicRole();
 }
예제 #8
0
 /**
  * Constructor - initializes this instance of AuthorizationManager for the user
  *
  * @param userId
  * @throws Exception
  */
 public AuthorizationManager(Long userId) throws Exception {
   NCIASecurityManager mgr =
       (NCIASecurityManager) SpringApplicationContext.getBean("nciaSecurityManager");
   securityRights = mgr.getSecurityMap(String.valueOf(userId));
 }
예제 #9
0
 /**
  * Constructor - initializes this instance of AuthorizationManager for the user
  *
  * @param userName
  * @throws Exception
  */
 public AuthorizationManager(String userName) throws Exception {
   NCIASecurityManager mgr =
       (NCIASecurityManager) SpringApplicationContext.getBean("nciaSecurityManager");
   String userId = mgr.getUserId(userName);
   securityRights = mgr.getSecurityMap(userId);
 }