/**
   * Resolve the Iterator
   *
   * @param iterator
   * @param maxToReturn
   * @param code
   * @return
   */
  public Vector<Entity> resolveIterator(
      ResolvedConceptReferencesIterator iterator, int maxToReturn, String code) {

    Vector<Entity> v = new Vector<Entity>();

    if (iterator == null) {
      _logger.warn("No match.");
      return v;
    }
    try {
      int iteration = 0;
      while (iterator.hasNext()) {
        iteration++;
        iterator = iterator.scroll(maxToReturn);
        ResolvedConceptReferenceList rcrl = iterator.getNext();
        ResolvedConceptReference[] rcra = rcrl.getResolvedConceptReference();
        for (int i = 0; i < rcra.length; i++) {
          ResolvedConceptReference rcr = rcra[i];
          Entity ce = rcr.getReferencedEntry();
          if (code == null) {
            v.add(ce);
          } else {
            if (ce.getEntityCode().compareTo(code) != 0) v.add(ce);
          }
        }
      }
    } catch (Exception e) {
      _logger.warn(e.getMessage());
    }
    return v;
  }
    @Override
    public DirectoryResult<T> execute(String state, int start, int maxResults) {
      ResolvedConceptReferencesIterator iterator;
      try {
        iterator =
            searchExtension.search(
                state, toCodingSchemeReference(this.codeSystemVersions), MatchAlgorithm.LUCENE);
      } catch (LBParameterException e) {
        throw new RuntimeException(e);
      }

      ResolvedConceptReferenceList list;
      boolean atEnd;
      try {
        list = iterator.get(start, start + maxResults);
        atEnd = iterator.numberRemaining() <= start + maxResults;
      } catch (Exception e) {
        throw new RuntimeException(e);
      }

      List<T> returnList = new ArrayList<T>();
      for (ResolvedConceptReference ref : list.getResolvedConceptReference()) {
        returnList.add(this.doTransform(ref));
      }

      return new DirectoryResult<T>(returnList, atEnd);
    }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.LexGrid.LexBIG.Utility.Iterators.EntityListIterator#numberRemaining()
  */
 public int numberRemaining() throws LBResourceUnavailableException {
   int number = 0;
   for (ResolvedConceptReferencesIterator itr : _iterators) {
     number += itr.numberRemaining();
   }
   return number;
 }
Esempio n. 4
0
  @Test
  public void testGetTargetCodesToNodeList() throws Exception {
    LexBIGService lbs = ServiceHolder.instance().getLexBIGService();

    CodedNodeGraph mappingGraph = lbs.getNodeGraph(MAPPING_SCHEME_URI, null, null);

    CodedNodeSet cns =
        mappingGraph.restrictToTargetCodeSystem(PARTS_SCHEME).toNodeList(null, false, true, 0, -1);

    ResolvedConceptReferencesIterator itr = cns.resolve(null, null, null);

    int count = 0;

    Set<String> foundCodes = new HashSet<String>();

    while (itr.hasNext()) {
      count++;
      foundCodes.add(itr.next().getCode());
    }

    assertEquals(3, foundCodes.size());

    assertTrue(foundCodes.contains("R0001"));
    assertTrue(foundCodes.contains("E0001"));
    assertTrue(foundCodes.contains("P0001"));
  }
 /*
  * (non-Javadoc)
  *
  * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
  */
 public int compare(
     ResolvedConceptReferencesIterator itr1, ResolvedConceptReferencesIterator itr2) {
   try {
     return itr2.numberRemaining() - itr1.numberRemaining();
   } catch (LBResourceUnavailableException e) {
     throw new RuntimeException(e);
   }
 }
 /** Removes the empty iterators. */
 private void removeEmptyIterators() {
   List<ResolvedConceptReferencesIterator> newList =
       new ArrayList<ResolvedConceptReferencesIterator>();
   for (ResolvedConceptReferencesIterator itr : _iterators) {
     try {
       if (itr.hasNext()) {
         newList.add(itr);
       }
     } catch (LBResourceUnavailableException e) {
       throw new RuntimeException(e);
     }
   }
   _iterators = newList;
 }
  public void testNextInt() {
    try {
      LexBIGService lbs = ServiceHolder.instance().getLexBIGService();
      CodedNodeSet cns = lbs.getCodingSchemeConcepts("NCI Thesaurus", null);
      cns = cns.restrictToMatchingDesignations("heart", null, "startsWith", null);

      ResolvedConceptReferencesIterator rcrl = cns.resolve(null, null, null, null, false);

      ResolvedConceptReferenceList list1 = rcrl.next(10);
      ResolvedConceptReferenceList list2 = rcrl.next(10);

      assertFalse(compareResolvedConceptReferenceList(list1, list2));
    } catch (Exception e) {
      fail("Exception Thrown: " + e.getMessage());
      e.printStackTrace();
    }
  }
 /**
  * Gets the next from list.
  *
  * @return the next from list
  */
 private ResolvedConceptReference getNextFromList() {
   try {
     while (hasNext()) {
       int iterator = _currentIterator % _iterators.size();
       ResolvedConceptReferencesIterator itr = _iterators.get(iterator);
       if (itr.hasNext()) {
         _currentIterator++;
         return itr.next();
       } else {
         _currentIterator++;
       }
     }
     return null;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
  /**
   * Get concept Entity by code
   *
   * @param codingScheme
   * @param code
   * @return
   */
  public ResolvedConceptReference getConceptByCode(String codingScheme, String code) {
    CodedNodeSet cns = null;
    ResolvedConceptReferencesIterator iterator = null;

    try {
      LexBIGService lbSvc = RemoteServerUtil.createLexBIGService();
      cns = lbSvc.getCodingSchemeConcepts(codingScheme, null);
      ConceptReferenceList crefs = createConceptReferenceList(new String[] {code}, codingScheme);
      cns.restrictToCodes(crefs);
      iterator = cns.resolve(null, null, null);
      if (iterator.numberRemaining() > 0) {
        ResolvedConceptReference ref = (ResolvedConceptReference) iterator.next();
        return ref;
      }
    } catch (LBException e) {
      _logger.info("Error: " + e.getMessage());
    }

    return null;
  }
Esempio n. 10
0
  public void run() throws LBException {
    ValueSetDefinition vsd = Util.promptForValueSetDefinition(message);
    if (vsd != null) {
      AbsoluteCodingSchemeVersionReferenceList acsvList = null;
      Util.displayMessage("Now select Code System to use to resolve Value Set Definition");
      CodingSchemeSummary css = Util.promptForCodeSystem();
      if (css != null) {
        acsvList = new AbsoluteCodingSchemeVersionReferenceList();
        acsvList.addAbsoluteCodingSchemeVersionReference(
            Constructors.createAbsoluteCodingSchemeVersionReference(
                css.getCodingSchemeURI(), css.getRepresentsVersion()));
      }

      LexEVSValueSetDefinitionServices vsdServ =
          LexEVSValueSetDefinitionServicesImpl.defaultInstance();
      ResolvedValueSetDefinition rVSD = null;
      try {
        rVSD =
            vsdServ.resolveValueSetDefinition(
                new URI(vsd.getValueSetDefinitionURI()), null, acsvList, null, null);
      } catch (URISyntaxException e) {
        e.printStackTrace();
      }

      if (rVSD != null) {
        Util.displayMessage(
            "Member of Value Set Definition (" + vsd.getValueSetDefinitionURI() + ") are :");
        ResolvedConceptReferencesIterator conceptItr = rVSD.getResolvedConceptReferenceIterator();
        while (conceptItr.hasNext()) {
          ResolvedConceptReference concept = conceptItr.next();
          Util.displayMessage("Concept code : " + concept.getCode());
          Util.displayMessage("\tCoding Scheme Name...: " + concept.getCodingSchemeName());
          Util.displayMessage("\tCoding Scheme URI....: " + concept.getCodingSchemeURI());
          Util.displayMessage("\tCoding Scheme Version: " + concept.getCodingSchemeVersion());
        }
      } else {
        Util.displayMessage(
            "No members found for Value Set Definition : '" + vsd.getValueSetDefinitionURI() + "'");
      }
    }
  }
  public void testNext() {
    try {
      LexBIGService lbs = ServiceHolder.instance().getLexBIGService();
      CodedNodeSet cns = lbs.getCodingSchemeConcepts("NCI Thesaurus", null);
      cns = cns.restrictToMatchingDesignations("heart", null, "startsWith", null);

      ResolvedConceptReferencesIterator rcrl = cns.resolve(null, null, null, null, false);

      String conceptCode = null;

      while (rcrl.hasNext()) {
        ResolvedConceptReference ref = rcrl.next();
        String currentCode = ref.getConceptCode();
        assertFalse(currentCode.equals(conceptCode));
        conceptCode = currentCode;
      }
    } catch (Exception e) {
      fail("Exception Thrown: " + e.getMessage());
      e.printStackTrace();
    }
  }
 /*
  * (non-Javadoc)
  *
  * @see org.LexGrid.LexBIG.Utility.Iterators.EntityListIterator#release()
  */
 public void release() throws LBResourceUnavailableException {
   for (ResolvedConceptReferencesIterator itr : _iterators) {
     itr.release();
   }
 }