Ejemplo n.º 1
0
  /**
   * Search for Data Elements using the Long Name
   *
   * @param args
   */
  public static void main(String[] args) {
    try {

      System.out.println("...TestCaDsrApi Started...");
      ApplicationService appService =
          ApplicationServiceProvider.getApplicationServiceFromUrl(
              "https://cadsrapi.nci.nih.gov/cadsrapi4");
      System.out.println("Searching for DataElements");

      // Search for the Data Element with the Long Name "Patient Race Category*". The asterisk (*)
      // is a wild card.
      DataElement dataElement = new DataElement();
      dataElement.setLongName("Patient Race Category*");
      // dataElement.setPublicID(2238438L);
      // dataElement.setLatestVersionIndicator("Yes");
      List<Object> results = appService.search(DataElement.class, dataElement);
      System.out.println(" received results : " + results.size());

      for (int i = 0; i < results.size(); i++) {
        // Show the DE
        Object curr = results.get(i);
        DataElement de = (DataElement) curr;
        System.out.println("===Data Element " + de.getLongName());
        System.out.println("Data Element " + de.getVersion());
        System.out.println("Data Element " + de.getPreferredDefinition());
      }
    } catch (Exception exception) {
      System.out.println("--------Error in the TestCaDsrApi");
      exception.printStackTrace();
    }
  }
 public List<PointOfContactBean> findPointOfContactsBySampleId(String sampleId)
     throws PointOfContactException {
   try {
     CaNanoLabApplicationService appService =
         (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
     DetachedCriteria crit =
         DetachedCriteria.forClass(Sample.class)
             .add(Property.forName("id").eq(new Long(sampleId)));
     crit.setFetchMode("primaryPointOfContact", FetchMode.JOIN);
     crit.setFetchMode("primaryPointOfContact.organization", FetchMode.JOIN);
     crit.setFetchMode("otherPointOfContactCollection", FetchMode.JOIN);
     crit.setFetchMode("otherPointOfContactCollection.organization", FetchMode.JOIN);
     crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
     List results = appService.query(crit);
     List<PointOfContactBean> pointOfContactCollection = new ArrayList<PointOfContactBean>();
     for (int i = 0; i < results.size(); i++) {
       Sample particle = (Sample) results.get(i);
       PointOfContact primaryPOC = particle.getPrimaryPointOfContact();
       Collection<PointOfContact> otherPOCs = particle.getOtherPointOfContactCollection();
       pointOfContactCollection.add(new PointOfContactBean(primaryPOC));
       for (PointOfContact poc : otherPOCs) {
         pointOfContactCollection.add(new PointOfContactBean(poc));
       }
     }
     return pointOfContactCollection;
   } catch (Exception e) {
     String err = "Problem finding all PointOfContact collections with the given sample ID.";
     logger.error(err, e);
     throw new PointOfContactException(err, e);
   }
 }
  private void deleteSampleWhenError(String sampleName) throws Exception {
    Sample sample = this.findFullyLoadedSampleByName(sampleName);
    CaNanoLabApplicationService appService =
        (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
    // delete characterizations
    if (sample.getCharacterizationCollection() != null) {
      for (Characterization achar : sample.getCharacterizationCollection()) {
        charService.deleteCharacterization(achar);
      }
    }

    // delete composition
    if (sample.getSampleComposition() != null) {
      compService.deleteComposition(sample.getSampleComposition());
    }
    sample.setSampleComposition(null);

    // remove publication associations
    if (sample.getPublicationCollection() != null) {
      sample.setPublicationCollection(null);
    }
    // remove keyword associations
    if (sample.getKeywordCollection() != null) {
      sample.setKeywordCollection(null);
    }
    appService.saveOrUpdate(sample);
    appService.delete(sample);
    // remove all csm entries associated with sample
    this.accessUtils.removeCSMEntries(sample.getId().toString());
  }
  private List<Characterization> loadCharacterizations(String sampleId) throws Exception {
    List<Characterization> chars = new ArrayList<Characterization>();

    CaNanoLabApplicationService appService =
        (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(Characterization.class);
    crit.createAlias("sample", "sample");
    crit.add(Property.forName("sample.id").eq(new Long(sampleId)));
    // fully load characterization
    crit.setFetchMode("pointOfContact", FetchMode.JOIN);
    crit.setFetchMode("pointOfContact.organization", FetchMode.JOIN);
    crit.setFetchMode("protocol", FetchMode.JOIN);
    crit.setFetchMode("protocol.file", FetchMode.JOIN);
    crit.setFetchMode("protocol.file.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("experimentConfigCollection", FetchMode.JOIN);
    crit.setFetchMode("experimentConfigCollection.technique", FetchMode.JOIN);
    crit.setFetchMode("experimentConfigCollection.instrumentCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection.datumCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection.datumCollection.conditionCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection.fileCollection", FetchMode.JOIN);
    crit.setFetchMode("findingCollection.fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List results = appService.query(crit);

    for (int i = 0; i < results.size(); i++) {
      Characterization achar = (Characterization) results.get(i);
      chars.add(achar);
    }
    return chars;
  }
 /**
  * Persist a new sample or update an existing canano sample
  *
  * @param sample
  * @throws SampleException , DuplicateEntriesException
  */
 public void saveSample(SampleBean sampleBean)
     throws SampleException, DuplicateEntriesException, NoAccessException {
   if (user == null) {
     throw new NoAccessException();
   }
   Boolean newSample = true;
   if (sampleBean.getDomain().getId() != null) {
     newSample = false;
   }
   Sample sample = sampleBean.getDomain();
   try {
     if (!newSample
         && !securityService.checkCreatePermission(sampleBean.getDomain().getId().toString())) {
       throw new NoAccessException();
     }
     CaNanoLabApplicationService appService =
         (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
     Sample dbSample = (Sample) appService.getObject(Sample.class, "name", sample.getName());
     if (dbSample != null && !dbSample.getId().equals(sample.getId())) {
       throw new DuplicateEntriesException();
     }
     if (sample.getKeywordCollection() != null) {
       Collection<Keyword> keywords = new HashSet<Keyword>(sample.getKeywordCollection());
       sample.getKeywordCollection().clear();
       for (Keyword keyword : keywords) {
         Keyword dbKeyword =
             (Keyword) appService.getObject(Keyword.class, "name", keyword.getName());
         if (dbKeyword != null) {
           keyword.setId(dbKeyword.getId());
         } else {
           keyword.setId(null);
         }
         // turned off cascade save-update in order to share the same
         // keyword instance with File keywords.
         appService.saveOrUpdate(keyword);
         sample.getKeywordCollection().add(keyword);
       }
     }
     appService.saveOrUpdate(sample);
     // save default access
     if (newSample) {
       super.saveDefaultAccessibilities(sample.getId().toString());
     }
   } catch (NoAccessException e) {
     throw e;
   } catch (DuplicateEntriesException e) {
     throw e;
   } catch (Exception e) {
     String err = "Error in saving the sample";
     logger.error(err, e);
     throw new SampleException(err, e);
   }
 }
  private SampleComposition loadComposition(String sampleId) throws Exception {
    SampleComposition composition = null;

    CaNanoLabApplicationService appService =
        (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(SampleComposition.class);
    crit.createAlias("sample", "sample");
    crit.add(Property.forName("sample.id").eq(new Long(sampleId)));
    crit.setFetchMode("nanomaterialEntityCollection", FetchMode.JOIN);
    crit.setFetchMode("nanomaterialEntityCollection.fileCollection", FetchMode.JOIN);
    crit.setFetchMode(
        "nanomaterialEntityCollection.fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("nanomaterialEntityCollection.composingElementCollection", FetchMode.JOIN);
    crit.setFetchMode(
        "nanomaterialEntityCollection.composingElementCollection.inherentFunctionCollection",
        FetchMode.JOIN);
    crit.setFetchMode(
        "nanomaterialEntityCollection.composingElementCollection.inherentFunctionCollection.targetCollection",
        FetchMode.JOIN);
    crit.setFetchMode("functionalizingEntityCollection", FetchMode.JOIN);
    crit.setFetchMode("functionalizingEntityCollection.fileCollection", FetchMode.JOIN);
    crit.setFetchMode(
        "functionalizingEntityCollection.fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("functionalizingEntityCollection.functionCollection", FetchMode.JOIN);
    crit.setFetchMode(
        "functionalizingEntityCollection.functionCollection.targetCollection", FetchMode.JOIN);
    crit.setFetchMode("functionalizingEntityCollection.activationMethod", FetchMode.JOIN);
    crit.setFetchMode("chemicalAssociationCollection", FetchMode.JOIN);
    crit.setFetchMode("chemicalAssociationCollection.fileCollection", FetchMode.JOIN);
    crit.setFetchMode(
        "chemicalAssociationCollection.fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("chemicalAssociationCollection.associatedElementA", FetchMode.JOIN);
    crit.setFetchMode("chemicalAssociationCollection.associatedElementB", FetchMode.JOIN);
    crit.setFetchMode("fileCollection", FetchMode.JOIN);
    crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List result = appService.query(crit);

    if (!result.isEmpty()) {
      composition = (SampleComposition) result.get(0);
    }
    return composition;
  }
  private Sample findFullyLoadedSampleByName(String sampleName) throws Exception {
    CaNanoLabApplicationService appService =
        (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
    // load composition and characterization separate because of Hibernate
    // join limitation
    DetachedCriteria crit =
        DetachedCriteria.forClass(Sample.class)
            .add(Property.forName("name").eq(sampleName).ignoreCase());
    Sample sample = null;

    // load composition and characterization separate because of
    // Hibernate join limitation
    crit.setFetchMode("primaryPointOfContact", FetchMode.JOIN);
    crit.setFetchMode("primaryPointOfContact.organization", FetchMode.JOIN);
    crit.setFetchMode("otherPointOfContactCollection", FetchMode.JOIN);
    crit.setFetchMode("otherPointOfContactCollection.organization", FetchMode.JOIN);
    crit.setFetchMode("keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("publicationCollection", FetchMode.JOIN);
    crit.setFetchMode("publicationCollection.authorCollection", FetchMode.JOIN);
    crit.setFetchMode("publicationCollection.keywordCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    List result = appService.query(crit);
    if (!result.isEmpty()) {
      sample = (Sample) result.get(0);
    }
    if (sample == null) {
      throw new NotExistException("Sample doesn't exist in the database");
    }

    // fully load composition
    SampleComposition comp = this.loadComposition(sample.getId().toString());
    sample.setSampleComposition(comp);

    // fully load characterizations
    List<Characterization> chars = this.loadCharacterizations(sample.getId().toString());
    if (chars != null && !chars.isEmpty()) {
      sample.setCharacterizationCollection(new HashSet<Characterization>(chars));
    } else {
      sample.setCharacterizationCollection(null);
    }
    return sample;
  }
  public void deleteSample(String sampleName)
      throws SampleException, NoAccessException, NotExistException {
    if (user == null) {
      throw new NoAccessException();
    }
    Sample sample = null;
    try {
      // / / fully load original sample
      sample = findFullyLoadedSampleByName(sampleName);
      CaNanoLabApplicationService appService =
          (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
      // / / delete characterizations
      if (sample.getCharacterizationCollection() != null) {
        for (Characterization achar : sample.getCharacterizationCollection()) {
          charService.deleteCharacterization(achar);
        }
      }

      // / / delete composition
      if (sample.getSampleComposition() != null) {
        compService.deleteComposition(sample.getSampleComposition());
      }
      sample.setSampleComposition(null);

      // / / remove publication associations
      if (sample.getPublicationCollection() != null) {
        sample.setPublicationCollection(null);
      }
      // / / remove keyword associations
      if (sample.getKeywordCollection() != null) {
        sample.setKeywordCollection(null);
      }
      appService.saveOrUpdate(sample);
      appService.delete(sample);
    } catch (NotExistException e) {
      throw e;
    } catch (Exception e) {
      String err = "Error in deleting the sample " + sampleName;
      logger.error(err, e);
      throw new SampleException(err, e);
    }
  }
  public SortedSet<String> getAllOrganizationNames() throws PointOfContactException {
    try {
      SortedSet<String> names = new TreeSet<String>(new Comparators.SortableNameComparator());
      CaNanoLabApplicationService appService =
          (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
      HQLCriteria crit =
          new HQLCriteria(
              "select org.name from gov.nih.nci.cananolab.domain.common.Organization org");
      List results = appService.query(crit);

      logger.debug(
          "Completed select org.name from gov.nih.nci.cananolab.domain.common.Organization org");
      for (int i = 0; i < results.size(); i++) {
        String name = ((String) results.get(i)).trim();
        names.add(name);
      }
      return names;
    } catch (Exception e) {
      String err = "Error finding organization for " + helper.getUser().getLoginName();
      logger.error(err, e);
      throw new PointOfContactException(err, e);
    }
  }
 public void updatePOCAssociatedWithCharacterizations(
     String sampleName, Long oldPOCId, Long newPOCId) throws SampleException {
   try {
     CaNanoLabApplicationService appService =
         (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
     DetachedCriteria crit = DetachedCriteria.forClass(Characterization.class);
     crit.createAlias("sample", "sample");
     crit.createAlias("pointOfContact", "poc");
     crit.add(Property.forName("poc.id").eq(oldPOCId));
     crit.add(Property.forName("sample.name").eq(sampleName));
     crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
     List results = appService.query(crit);
     for (int i = 0; i < results.size(); i++) {
       Characterization achar = (Characterization) results.get(i);
       // update POC to the new ID
       achar.getPointOfContact().setId(newPOCId);
       appService.saveOrUpdate(achar);
     }
   } catch (Exception e) {
     String err = "Error in updating POC associated sample characterizations " + sampleName;
     logger.error(err, e);
     throw new SampleException(err, e);
   }
 }
Ejemplo n.º 11
0
 public GeneBySymbolQueryAction() throws Exception {
   this.as = (CaBioApplicationService) ApplicationServiceProvider.getApplicationService();
   this.rs = new ReportService(as);
 }
  public SampleBean cloneSample(String originalSampleName, String newSampleName)
      throws SampleException, NoAccessException, DuplicateEntriesException, NotExistException {
    if (user == null) {
      throw new NoAccessException();
    }
    SampleBean newSampleBean = null;
    Sample origSample = null;
    SampleBean origSampleBean = null;
    Sample newSample0 = new Sample();
    try {
      CaNanoLabApplicationService appService =
          (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
      Sample dbNewSample = (Sample) appService.getObject(Sample.class, "name", newSampleName);
      if (dbNewSample != null) {
        throw new DuplicateEntriesException();
      }
      // fully load original sample
      origSample = findFullyLoadedSampleByName(originalSampleName);
      origSampleBean = new SampleBean(origSample);
      newSample0.setName(newSampleName);
      newSample0.setCreatedBy(user.getLoginName() + ":" + Constants.AUTO_COPY_ANNOTATION_PREFIX);
      newSample0.setCreatedDate(new Date());
      // save the sample so later up just update the cloned the
      // associations.
      SampleBean newSampleBean0 = new SampleBean(newSample0);
      // save the sample to get an ID before saving associations
      saveSample(newSampleBean0);
    } catch (NotExistException e) {
      throw e;
    } catch (DuplicateEntriesException e) {
      throw e;
    } catch (Exception e) {
      String err = "Error in loading the original sample " + originalSampleName;
      logger.error(err, e);
      throw new SampleException(err, e);
    }
    try {
      // clone the sample
      Sample newSample = origSampleBean.getDomainCopy(user.getLoginName());
      newSample.setName(newSampleName);
      // keep the id
      newSample.setId(newSample0.getId());
      newSampleBean = new SampleBean(newSample);

      // retrieve accessibilities of the original sample
      List<AccessibilityBean> groupAccesses =
          super.findGroupAccessibilities(origSample.getId().toString());
      List<AccessibilityBean> userAccesses =
          super.findUserAccessibilities(origSample.getId().toString());
      origSampleBean.setGroupAccesses(groupAccesses);
      origSampleBean.setUserAccesses(userAccesses);

      // need to save associations one by one (except keywords)
      // Hibernate mapping settings for most use cases
      saveClonedPOCs(newSampleBean);
      saveClonedCharacterizations(origSample.getName(), newSampleBean);
      saveClonedComposition(origSampleBean, newSampleBean);
      saveClonedPublications(origSampleBean, newSampleBean);
      saveSample(newSampleBean);
      newSampleBean.setUser(user);
      // assign accessibility for the new sample
      for (AccessibilityBean access : origSampleBean.getAllAccesses()) {
        this.assignAccessibility(access, newSampleBean.getDomain());
      }
    } catch (Exception e) {
      // delete the already persisted new sample in case of error
      try {
        this.deleteSampleWhenError(newSample0.getName());
      } catch (Exception ex) {
        String err = "Error in deleting the errored cloned-sample " + newSample0.getName();
        logger.error(err, e);
        throw new SampleException(err, ex);
      }
      String err = "Error in cloning the sample " + originalSampleName;
      logger.error(err, e);
      throw new SampleException(err, e);
    }
    return newSampleBean;
  }
  public void savePointOfContact(PointOfContactBean pocBean)
      throws PointOfContactException, NoAccessException {
    if (user == null) {
      throw new NoAccessException();
    }
    try {
      PointOfContact dbPointOfContact = null;
      Long oldPOCId = null;
      String oldOrgName = null;
      Boolean newPOC = true;
      Boolean newOrg = true;
      CaNanoLabApplicationService appService =
          (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
      PointOfContact domainPOC = pocBean.getDomain();
      Organization domainOrg = domainPOC.getOrganization();
      // get existing organization from database and reuse ID,
      // created by and created date
      // address information will be updated
      Organization dbOrganization = helper.findOrganizationByName(domainOrg.getName());
      if (dbOrganization != null) {
        domainOrg.setId(dbOrganization.getId());
        domainOrg.setCreatedBy(dbOrganization.getCreatedBy());
        domainOrg.setCreatedDate(dbOrganization.getCreatedDate());
        newOrg = false;
      }
      // create a new org if not an existing one
      else {
        domainOrg.setId(null);
      }
      // if point of contact has no ID
      if (domainPOC.getId() == null) {
        // check if org name, first name and last name matches existing
        // one
        dbPointOfContact =
            helper.findPointOfContactByNameAndOrg(
                domainPOC.getFirstName(),
                domainPOC.getLastName(),
                domainPOC.getOrganization().getName());
        // if found, reuse ID, created_date and created_by
        if (dbPointOfContact != null) {
          domainPOC.setId(dbPointOfContact.getId());
          domainPOC.setCreatedDate(dbPointOfContact.getCreatedDate());
          domainPOC.setCreatedBy(dbPointOfContact.getCreatedBy());
          newPOC = false;
        }
      } else {
        // check if organization is changed
        dbPointOfContact = helper.findPointOfContactById(domainPOC.getId().toString());
        Organization dbOrg = dbPointOfContact.getOrganization();
        // if organization information is changed, create a new POC
        if (!dbOrg.getName().equals(domainOrg.getName())) {
          oldPOCId = domainPOC.getId();
          oldOrgName = dbOrg.getName();
          domainPOC.setId(null);
          newPOC = true;
        }
        // if name information is changed, create a new POC
        else if (domainPOC.getFirstName() != null
                && !domainPOC.getFirstName().equalsIgnoreCase(dbPointOfContact.getFirstName())
            || domainPOC.getLastName() != null
                && !domainPOC.getLastName().equalsIgnoreCase(dbPointOfContact.getLastName())) {
          newPOC = true;
        } else {
          domainPOC.setId(dbPointOfContact.getId());
          domainPOC.setCreatedBy(dbPointOfContact.getCreatedBy());
          domainPOC.setCreatedDate(dbPointOfContact.getCreatedDate());
          newPOC = false;
        }
      }
      appService.saveOrUpdate(domainPOC);

      if (newPOC) {
        this.saveAccessibility(AccessibilityBean.CSM_PUBLIC_ACCESS, domainPOC.getId().toString());
      }
      if (newOrg) {
        this.saveAccessibility(
            AccessibilityBean.CSM_PUBLIC_ACCESS, domainPOC.getOrganization().getId().toString());
      }
    } catch (Exception e) {
      String err = "Error in saving the PointOfContact.";
      logger.error(err, e);
      throw new PointOfContactException(err, e);
    }
  }
Ejemplo n.º 14
0
  public static String getEVSCode(String prefName, String dtsVocab) {
    LexEVSApplicationService evsService = null;

    try {
      evsService =
          (LexEVSApplicationService)
              ApplicationServiceProvider.getApplicationService("EvsServiceInfo");

    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    if (dtsVocab == null) dtsVocab = "";
    String CCode = "";
    if (dtsVocab.equals("Thesaurus/Metathesaurus")
        || dtsVocab.equals("")
        || dtsVocab.equals("NCI Thesaurus")
        || dtsVocab.equals("NCI_Thesaurus")) dtsVocab = "NCI_Thesaurus";
    ResolvedConceptReferenceList codes2 = null;
    int codesSize = 0;

    try {
      CodedNodeSet metaNodes = evsService.getNodeSet("NCI MetaThesaurus", null, null);

      metaNodes =
          metaNodes.restrictToMatchingDesignations(
              prefName, // the text to match
              CodedNodeSet.SearchDesignationOption
                  .PREFERRED_ONLY, // whether to search all designation, only Preferred or only
                                   // Non-Preferred
              "exactMatch", // the match algorithm to use
              null); // the language to match (null matches all)

      metaNodes = metaNodes.restrictToStatus(ActiveOption.ACTIVE_ONLY, null);

      codes2 =
          metaNodes.resolveToList(
              null, // Sorts used to sort results (null means sort by match score)
              null, // PropertyNames to resolve (null resolves all)
              new CodedNodeSet.PropertyType[] {
                PropertyType.DEFINITION, PropertyType.PRESENTATION
              }, // PropertyTypess to resolve (null resolves all)  //PropertyTypess to resolve (null
                 // resolves all)
              10 // cap the number of results returned (-1 resolves all)
              );
      codesSize = codes2.getResolvedConceptReferenceCount();

    } catch (Exception ex) {
      System.err.println("Error do_getEVSCode:resolveToList: " + ex.toString());
      ex.printStackTrace();
    }

    if (codes2 != null) {
      ResolvedConceptReference conceptReference = new ResolvedConceptReference();
      // logger.debug("Got "+codesSize+" results for the do_getEVSCode search using prefName and
      // exactMatch");
      for (int i = 0; i < codesSize; i++) {
        conceptReference = (ResolvedConceptReference) codes2.getResolvedConceptReference(i);
        CCode = (String) conceptReference.getConceptCode();
      }
    }

    evsService = null;
    return CCode;
  }
Ejemplo n.º 15
0
  public static List searchEVS(
      String term,
      String dtsVocab,
      String retired,
      String sSearchInEVS,
      String sUISearchType,
      String sMetaSource,
      int sMetaLimit)
      throws Exception {

    String algorithm;
    String altNameType;
    String CCode;
    String prefName = "";
    Boolean isRetired = new Boolean(false);
    Boolean bTrue = new Boolean(true);
    Boolean bFalse = new Boolean(false);
    boolean isMetaCodeSearch = false;
    Boolean codeFoundInThesaurus = new Boolean(false);
    String source = "";
    String definition = "";
    List vCon = new ArrayList();
    String sDefDefault = "No value exists.";
    String sDef = "";
    String sDefSrc = "";
    // List vCon = null;
    List vMetaDefs = new ArrayList();
    // List vMetaDefs = null;

    if (dtsVocab.equals("Thesaurus/Metathesaurus")
        || dtsVocab.equals("")
        || dtsVocab.equals("NCI Thesaurus")
        || dtsVocab.equals("NCI_Thesaurus")) {
      dtsVocab = "NCI Thesaurus";
      altNameType = "NCI_CONCEPT_CODE";
    }
    // for search Meta by (LOINC) code
    else if (dtsVocab.equals("Metathesaurus") || sSearchInEVS.equals("Code")) {
      dtsVocab = "NCI_Thesaurus";
      altNameType = "NCI_CONCEPT_CODE";
      isMetaCodeSearch = true;
      sUISearchType = "term";
    }
    // for Meta searches only (no Thes search), like in getSuperConcepts Meta
    else if (dtsVocab.equals("NCI Metathesaurus")) {
      altNameType = "UMLS_CUI";
      isMetaCodeSearch = false;
      sUISearchType = "term";
    } else altNameType = "";

    LexEVSApplicationService evsService =
        (LexEVSApplicationService)
            ApplicationServiceProvider.getApplicationService("EvsServiceInfo");

    /*  if (!sSearchInEVS.equals("Concept Code") || term.equals("")) {*/
    Pattern pattern = Pattern.compile("^C\\d{2,8}");
    Matcher matcher = pattern.matcher(term);

    algorithm = getAlgorithm(term);
    term = cleanTerm(term);
    int totalReturnCount = 0;

    try {
      if (retired.equals(
          "Include")) // do this if all concepts, including retired, should be included
      isRetired = new Boolean(false);
      else {

        try {

          ResolvedConceptReferenceList rcrl =
              searchPrefTerm(evsService, dtsVocab, term, sMetaLimit, algorithm);
          if (rcrl != null && rcrl.getResolvedConceptReferenceCount() > 0)
            isRetired = (Boolean) (!rcrl.getResolvedConceptReference(0).getEntity().isIsActive());

        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }

      if (isRetired.equals(bFalse)) {
        ResolvedConceptReferenceList concepts = null;
        // CCode = term;
        int codesSize = 0;
        try {
          if (sSearchInEVS.equals("Concept Code") || matcher.matches())
            concepts = searchConceptCode(evsService, dtsVocab, term, sMetaLimit);
          else concepts = searchPrefTerm(evsService, dtsVocab, term, sMetaLimit, algorithm);

          codesSize = concepts.getResolvedConceptReferenceCount();

        } catch (Exception ex) {
          System.out.println("Error do_EVSSearch get concept: " + ex.toString());
        }

        if (concepts != null && codesSize > 0) {

          codeFoundInThesaurus = new Boolean(true);

          prefName = concepts.getResolvedConceptReference(0).getEntityDescription().getContent();

          concepts = new ResolvedConceptReferenceList();
          try {
            concepts = searchPrefTerm(evsService, dtsVocab, prefName, sMetaLimit, algorithm);
            codesSize = concepts.getResolvedConceptReferenceCount();
          } catch (Exception ex) {
            // ex.printStackTrace();
            System.out.println("Error do_EVSSearch DescLogic: " + ex.toString());
          }
          if (concepts != null) {
            ResolvedConceptReference rcr = new ResolvedConceptReference();
            for (int i = 0; i < codesSize; i++) {
              rcr = concepts.getResolvedConceptReference(i);
              prefName = rcr.getEntityDescription().getContent();
              CCode = rcr.getConceptCode();

              Definition[] defs = rcr.getEntity().getDefinition();
              if (defs == null) defs = new Definition[0];
              sDef = sDefDefault; // "No Value Exists.";
              sDefSrc = "";

              for (int k = 0; k < defs.length; k++) {

                Definition def = defs[k];

                if (def != null) {
                  if (def.getIsPreferred() != null) {
                    sDef = def.getValue().getContent();
                    if (def.getSourceCount() > 0)
                      sDefSrc = def.getSource(0).getContent(); // get def source
                  }
                }
              }

              EVSBean conBean = new EVSBean();
              conBean.setCode(CCode);
              conBean.setDefinition(sDef);
              conBean.setDictionary(dtsVocab);
              conBean.setName(prefName);
              conBean.setSource(sDefSrc);
              conBean.setType(altNameType);
              vCon.add(conBean);
              totalReturnCount++;

              if (totalReturnCount >= sMetaLimit) return vCon;
            }
          }
        }
      }

    } catch (Exception ex) {
      System.out.println("Error do_EVSSearch Concept code: " + ex.toString());
    }

    // Search Meta
    int length = 0;
    length = term.length();
    ResolvedConceptReferenceList concepts = null;
    if (sSearchInEVS.equals("Concept Code"))
      concepts = searchConceptCode(evsService, "NCI Metathesaurus", term, sMetaLimit);
    else if (!sSearchInEVS.equals("Concept Code"))
      concepts = searchPrefTerm(evsService, "NCI Metathesaurus", term, sMetaLimit, algorithm);

    if (concepts != null) {
      ResolvedConceptReference rcr = new ResolvedConceptReference();
      for (int i = 0; i < concepts.getResolvedConceptReferenceCount(); i++) {
        if (totalReturnCount >= sMetaLimit) break;
        rcr = concepts.getResolvedConceptReference(i);
        prefName = rcr.getEntityDescription().getContent();
        CCode = rcr.getConceptCode();

        Definition[] defs = rcr.getEntity().getDefinition();
        if (defs == null) defs = new Definition[0];
        sDef = sDefDefault; // "No Value Exists.";
        sDefSrc = "";

        for (int k = 0; k < defs.length; k++) {

          Definition def = defs[k];

          if (def != null) {
            sDef = def.getValue().getContent();
            if (def.getSourceCount() > 0) sDefSrc = def.getSource(0).getContent(); // get def source
          }

          EVSBean conBean = new EVSBean();
          conBean.setCode(CCode);
          conBean.setDefinition(sDef);
          conBean.setDictionary("NCI Metathesaurus");
          conBean.setName(prefName);
          conBean.setSource(sDefSrc);
          conBean.setType("UMLS_CUI");
          vCon.add(conBean);
          totalReturnCount++;
          if (totalReturnCount >= sMetaLimit) break;
        }
      }
    }

    evsService = null;
    System.out.println(vCon.size());
    return vCon;
  }