Examples of MedicationMention


Examples of org.apache.ctakes.typesystem.type.textsem.MedicationMention

  {
    int id = firstId;
    FSIterator itr = jcas.getJFSIndexRepository().getAnnotationIndex(type).iterator();
    while (itr.hasNext())
    {
      MedicationMention idAnnot = (MedicationMention) itr.next();
      idAnnot.setId(id);
      id++;
    }
    return id;
  }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.MedicationMention

   */

  private void generateDrugMentions(JCas jcas, Segment seg, boolean narrativeType) throws Exception
  {
    int begin = seg.getBegin(), end = seg.getEnd() + 1;
    MedicationMention nextNER = null;
    int nextNERPosition = 0;
    List uniqueNEs;
    List allNEs;

    int[] validNeTypes = { CONST.NE_TYPE_ID_DRUG, CONST.NE_TYPE_ID_UNKNOWN };
   
    try {
      uniqueNEs = findUniqueMentions( FSUtil.getAnnotationsInSpan(jcas, MedicationMention.type, begin, end, validNeTypes).toArray());
      // FIX ID: 3476114, ID: 3476113, and ID: 3476110
      int globalArraySize = uniqueNEs.size()*3;
      int [][] windowSpans =  new int [globalArraySize][2];
      int globalWindowSize = 0;
      if (narrativeType) {
        for (int neCount = 0; neCount < uniqueNEs.size() ; neCount ++ ) {
          boolean processedSpan = false;
          MedicationMention neNarrative = (MedicationMention) uniqueNEs.get(neCount);
          for (int spanCheck = 0 ; spanCheck < windowSpans.length && !processedSpan && windowSpans[spanCheck][0] != 0; spanCheck ++ ) {
            if (windowSpans[spanCheck][0] ==  neNarrative.getBegin())
              processedSpan = true;
          }
          if (!processedSpan) {
            int [][] narrativeSpans =  getWindowSpan(jcas, "narrative", MedicationMention.type, neNarrative.getBegin(), neNarrative.getEnd(),  false, globalArraySize);
            for (int elementCount = 0; elementCount < narrativeSpans.length; elementCount ++ ) {
              windowSpans[globalWindowSize] = narrativeSpans[elementCount];
              globalWindowSize++;
            }
          }
        }
      } else if (uniqueNEs.size() > 0){ // don't bother finding spans if no ne in list
        windowSpans = getWindowSpan(jcas, "list", MedicationMention.type, begin, end,  false, globalArraySize);
        if (windowSpans.length > 0 && windowSpans[0][0] == -1) {
          windowSpans[0][0] = begin;
          windowSpans[0][1] = end;
        }
      }
      for (int count= 0; count < windowSpans.length; count++) {
        List neTokenUpdatedList = getAnnotationsInSpan(jcas,
            MedicationMention.type, windowSpans[count][0], windowSpans[count][1]);

        if (!neTokenUpdatedList.isEmpty())
        {
          List globalDrugNERList = new ArrayList();
          try
          {
            generateDrugMentionsAndAnnotations(jcas, neTokenUpdatedList,
                windowSpans[count][0], windowSpans[count][1], null, null, 0, globalDrugNERList);
          } catch (NumberFormatException nfe)
          {
            iv_logger.info(nfe.getMessage());
          } catch (Exception e)
          {
            iv_logger.info(e.getMessage());
          }

          globalDrugNERList.clear();
        }
      }
    } catch (ArrayIndexOutOfBoundsException aioobe) {
      allNEs =
        FSUtil.getAnnotationsInSpan(jcas, MedicationMention.type, begin, end, validNeTypes);

      uniqueNEs = findUniqueMentions(allNEs.toArray());

      int lastNL = seg.getEnd();
      boolean lastOne = false;
      Iterator newLineItr =
        FSUtil.getAnnotationsIteratorInSpan(jcas, NewlineToken.type, begin, end);

      for (int i = 0; i < uniqueNEs.size(); i++)
      {
        MedicationMention thisNER = (MedicationMention) uniqueNEs.get(i);
        boolean hasNext = false;
        if (uniqueNEs.size() > i + 1)
        {
          nextNER = (MedicationMention) uniqueNEs.get(i + 1);
          nextNERPosition = nextNER.getBegin();
          if (nextNER != null)
            hasNext = true;
        } else if (!uniqueNEs.isEmpty())
        {
          nextNER = (MedicationMention) uniqueNEs.get(i);
          nextNERPosition = nextNER.getBegin();
          lastOne = true;
        }
        boolean foundLeftParen = false;
        boolean foundRightParen = false;

        foundRightParen = findCoveredTextInSpan(jcas, PunctuationToken.type, thisNER.getEnd(), thisNER.getEnd()+3, (new String[]{")","/"}));


        if (hasNext && !lastOne)
          end = nextNERPosition;
        else
          end = seg.getEnd();

        boolean hasNLEnd = true;
        boolean wrapItUp = false;

        while (hasNLEnd && !wrapItUp && end <= seg.getEnd()
            && ((begin < end) || (!hasNext && begin <= end) || foundLeftParen))
        {

          if (begin == end) {
            foundLeftParen = false;
            end = end+1;
          }
          NewlineToken nl = null;
          if (hasNLEnd && newLineItr.hasNext())
          {
            nl = (NewlineToken) newLineItr.next();
            hasNLEnd = true;
          }
          if ((!hasNext && begin <= end) || (nextNERPosition < end))
            wrapItUp = true;
          boolean findNextNL = false;

          if (lastNL <= thisNER.getBegin())
          {
            begin = thisNER.getBegin();
          }

          if ((nl != null) && (thisNER.getBegin() >= nl.getEnd()))
          {
            findNextNL = true;

          } else if (nl != null)
          {
            lastNL = nl.getEnd();
          }

          if (!hasNext)
          {
            findNextNL = false;
            end = seg.getEnd();
          }
          if (!findNextNL)
          {
            if ((nextNER != null)
                && (((nextNER.getCoveredText().compareToIgnoreCase(
                    thisNER.getCoveredText()) == 0) || ((foundRightParen) || nextNER.getBegin() == thisNER.getEnd() + 2))))
            {
              if (nl == null)
              {
                if (!hasNext)
                  end = seg.getEnd();
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.MedicationMention

      String [] relatedStatus, int countNER, List<DrugMentionAnnotation> globalDrugNER) throws Exception
      {

    Iterator<MedicationMention> uniqueNER = nerTokenList.iterator();
    DrugMentionAnnotation drugTokenAnt = null;
    MedicationMention tokenAnt = null;

    List<DrugMentionAnnotation> holdDrugNERArr = new ArrayList<DrugMentionAnnotation>();

    while (uniqueNER.hasNext())
    {

      tokenAnt = (MedicationMention) uniqueNER.next();
      boolean isDrugNER = false;
      FSArray ocArr = tokenAnt.getOntologyConceptArr();
      if (ocArr != null)
      {
        for (int i = 0; i < ocArr.size() && !isDrugNER; i++)
        {
          OntologyConcept oc = (OntologyConcept) ocArr.get(i);

          String scheme = oc.getCodingScheme();
          //if (scheme.compareTo("RXNORM") == 0)
          //{
            isDrugNER = true;
          //}

        }
      }
      if (tokenAnt != null && (isDrugNER || relatedStatus != null))
      {
        boolean keepNoChangeStatus = false;

        boolean maxExists = false;
        int maxOffsetEnd = 0;
        int holdRightEnd = end + 1;
        int holdLeftStart = begin;
        drugTokenAnt = new DrugMentionAnnotation(jcas, tokenAnt.getBegin(),
            tokenAnt.getEnd());
        tokenAnt.setTypeID(NERTypeIdentifier);
        holdDrugNERArr.add(drugTokenAnt);

        Iterator statusChangeItr = FSUtil.getAnnotationsIteratorInSpan(jcas, DrugChangeStatusAnnotation.type, holdLeftStart, holdRightEnd);
        List holdStatusChanges = new ArrayList();
        // Separate the subsection from the change status elements
        int[] localSpan = getNarrativeSpansContainingGivenSpanType(jcas, drugTokenAnt.getBegin(), iBoundaryAnnType);
        while (statusChangeItr.hasNext())
        {
          Iterator findSubSection = FSUtil.getAnnotationsIteratorInSpan(jcas, SubSectionAnnotation.type, holdLeftStart, holdRightEnd);
          // if there aren't subsection in the span add to the hold
          // status changes list (unless Maximum special case)
          boolean isolate = false;
          if (!findSubSection.hasNext())
          {

            DrugChangeStatusAnnotation dsa = (DrugChangeStatusAnnotation) statusChangeItr.next();

            // Maximum case means the drug mention elements should
            // be overridden by this value
            if (((dsa.getChangeStatus().compareTo(
                DrugChangeStatusElement.MAXIMUM_STATUS) != 0)
                && dsa.getEnd() < holdRightEnd)
                && (localSpan[0]<dsa.getBegin() && localSpan[1]> dsa.getEnd()))
            {
              holdStatusChanges.add(dsa);
            } else if (dsa.getChangeStatus().compareTo(
                DrugChangeStatusElement.MAXIMUM_STATUS) == 0
                && dsa.getEnd() < holdRightEnd)
            {
              maxExists = true;
              maxOffsetEnd = dsa.getEnd();
            }

          } else
          {
            statusChangeItr.next();// Added this line to make sure the the next DrugChangeStatusAnnotation in the event that there is no subsection to look at
            boolean noWeirdError = true;
            boolean pullOut = false;
            while (!pullOut && !isolate && findSubSection.hasNext()
                && noWeirdError)
            {
              try
              {
                // each status change is checked against all
                // available sub-spans in that range
                SubSectionAnnotation sub = (SubSectionAnnotation) findSubSection.next();
                Iterator findStartLF = FSUtil.getAnnotationsIteratorInSpan(
                    jcas, NewlineToken.type, holdLeftStart, sub.getBegin() + 1);
                Iterator findEndLF = FSUtil.getAnnotationsIteratorInSpan(jcas,
                    NewlineToken.type, sub.getEnd(), holdRightEnd);

                if (findStartLF.hasNext() && findEndLF.hasNext())
                {

                  while (findStartLF.hasNext())
                  {
                    // int countSymbols = 0;
                    NewlineToken nta = (NewlineToken) findStartLF.next();

                    // Iterator findSymbols =
                    // FSUtil.getAnnotationsInSpanIterator(jcas,
                    // SymbolToken.type,
                    // nta.getEnd(), sub.getBegin());
                    //         
                    // while (findSymbols.hasNext())
                    // {
                    // findSymbols.next();
                    // countSymbols++;
                    // }

                    int countSymbols = FSUtil.countAnnotationsInSpan(jcas,
                        SymbolToken.type, nta.getEnd(), sub.getBegin());

                    if ((nta.getEnd() + countSymbols + 1) >= sub.getBegin())
                    {
                      isolate = true;
                      holdRightEnd = sub.getBegin();
                      end = sub.getBegin();
                    }
                  }

                  if (!isolate)
                  {
                    DrugChangeStatusAnnotation dsa = (DrugChangeStatusAnnotation) statusChangeItr.next();
                    holdStatusChanges.add(dsa);
                    pullOut = true;
                    sub.removeFromIndexes();
                  }
                } else if (findEndLF.hasNext())
                {
                  // subsection is on a prior separate line than the rest
                  // of the content
                  holdLeftStart = sub.getEnd();
                  // sub.removeFromIndexes();

                } else if (sub.getBegin() > tokenAnt.getEnd())
                {
                  end = sub.getBegin();
                  holdRightEnd = sub.getBegin();
                  sub.removeFromIndexes();
                } else
                {
                  holdLeftStart = sub.getEnd();
                  holdRightEnd = tokenAnt.getBegin();
                }
              } catch (NoSuchElementException nsee)
              {
                noWeirdError = false;
                iv_logger.info(nsee.getLocalizedMessage());
              }
            }
          }
        }

        // handles cases like "then discontinue" so the two change status mentions are merged and the last
        // value is used for the change status i.e. 'discontinue'

        List modifiedOrderDrugStatusChanges = new ArrayList();
        Iterator sortStatusChanges = sortAnnotations(holdStatusChanges.toArray()).iterator();
        Iterator sortNextStatusChanges = sortAnnotations(holdStatusChanges.toArray()).iterator();
        // increment sortNextStatusChanges
        if (sortNextStatusChanges.hasNext()) sortNextStatusChanges.next();
        boolean skipNext = false;
        int checkSkippedOffsetBegin = 0, checkSkippedOffsetEnd = 0;
        while (sortStatusChanges.hasNext()) {
          DrugChangeStatusAnnotation hos1 = (DrugChangeStatusAnnotation) sortStatusChanges.next();
          if (sortNextStatusChanges.hasNext()) {

            DrugChangeStatusAnnotation hos2 = (DrugChangeStatusAnnotation) sortNextStatusChanges.next();
            if (hos1.getBegin() == hos2.getBegin()) {
              if (hos1.getEnd() >= hos2.getEnd()) {
                skipNext = true;
                checkSkippedOffsetBegin = hos2.getBegin();
                checkSkippedOffsetEnd = hos2.getEnd();
                hos2.removeFromIndexes();
                modifiedOrderDrugStatusChanges.add(hos1);

              } else {
                iv_logger.info("found reverse case . . need to handle");
              }

            } else if (!skipNext) {
              modifiedOrderDrugStatusChanges.add(hos1);
            } else
              skipNext = false;
          }
          else if (checkSkippedOffsetBegin == 0 || (checkSkippedOffsetBegin != hos1.getBegin() && checkSkippedOffsetEnd != hos1.getEnd())){
            modifiedOrderDrugStatusChanges.add(hos1);
          }
        }       

        Iterator orderedStatusChanges = sortAnnotations(holdStatusChanges.toArray()).iterator();
        Iterator orderedDrugStatusChanges = sortAnnotations(holdStatusChanges.toArray()).iterator();

        if (modifiedOrderDrugStatusChanges.size() > 0 ) {
          int [] newSpan = {begin, end};
          newSpan = statusChangePhraseGenerator ( jcas,  begin,  end,  maxExists,  uniqueNER,
              orderedStatusChanges,  modifiedOrderDrugStatusChanges,  relatedStatus,  drugTokenAnt, 
              globalDrugNER,  countNER );
          begin = newSpan[0];
          end = newSpan[1];
          if ((drugTokenAnt.getDrugChangeStatus() != null && drugTokenAnt.getDrugChangeStatus().equals(DrugChangeStatusToken.NOCHANGE)) ||
              (drugTokenAnt.getDrugChangeStatus() != null && drugTokenAnt.getDrugChangeStatus().equals(DrugChangeStatusToken.OTHER)))  {
            keepNoChangeStatus = true;
            if (drugTokenAnt.getDrugChangeStatus().equals(DrugChangeStatusToken.OTHER))
              drugTokenAnt.setDrugChangeStatus(DrugChangeStatusToken.NOCHANGE);
          }           
          // No change is default state since the change state has been handled
        }
        DrugMention dm = new DrugMention(jcas, begin, end)
        boolean overrideStatus = false;
        boolean statusFound = false;
        if (!keepNoChangeStatus) {
          // All entries may not be appropriate, so some
          // filtering
          // may need to be implemented here
          JFSIndexRepository indexes = jcas.getJFSIndexRepository();
          Iterator subSectionItr = indexes.getAnnotationIndex(
              SubSectionAnnotation.type).iterator();

          String statusKey = null;
          while (subSectionItr.hasNext() && !statusFound)
          {

            SubSectionAnnotation ssid = (SubSectionAnnotation) subSectionItr.next();

            if (ssid.getSubSectionBodyBegin() <= tokenAnt.getBegin()
                && ssid.getSubSectionBodyEnd() >= tokenAnt.getEnd())
            {

              // Look for special case where date comes before the
              // drug mention
              // A better means to locate the beginning of the chunk
              // is lacking here mainly due
              // to the fact that the sentence annotator cannot be
              // trusted to find the beginning
              // accurately.
              boolean overrideDate = false;
              Iterator statusSpecialDateItr = FSUtil.getAnnotationsIteratorInSpan(jcas, DateAnnotation.type, ssid.getEnd(), drugTokenAnt.getBegin());
              while (statusSpecialDateItr.hasNext() && !overrideDate)
              {
                DateAnnotation specialDate = (DateAnnotation) statusSpecialDateItr.next();
                Iterator findLF = FSUtil.getAnnotationsIteratorInSpan(jcas,
                    NewlineToken.type, ssid.getEnd(), specialDate.getBegin());
                if (!findLF.hasNext())
                {
                  // if (specialDate.getEnd() <=
                  // drugTokenAnt.getBegin() ){
                  drugTokenAnt.setStartDate(specialDate.getCoveredText());
                  overrideDate = true;
                }
              }

              DrugChangeStatusAnnotation dsa = null;
              if (orderedDrugStatusChanges.hasNext())
              {
                dsa = (DrugChangeStatusAnnotation) orderedDrugStatusChanges.next();
              }
              if (dsa != null
                  && (dsa.getChangeStatus().compareTo(DrugChangeStatusElement.START_STATUS) == 0 ||
                      dsa.getChangeStatus().compareTo(DrugChangeStatusElement.STOP_STATUS) == 0))
              {
                // Should we override here? Let's get only the first
                // one as an override

                drugTokenAnt.setDrugChangeStatus(dsa.getChangeStatus());
              } else
              {
                statusKey = dm.convertToChangeStatus(ssid.getCoveredText());
                if (ssid.getStatus() == 1)
                {

                  // drugTokenAnt.setCertainty(-1);
                  statusKey = DrugChangeStatusToken.STOP;
                }
                if (statusKey.compareTo(DrugChangeStatusToken.NOCHANGE) == 0)
                {
                  Iterator oneDrugChangeStatus = FSUtil.getAnnotationsIteratorInSpan(jcas,
                      DrugChangeStatusAnnotation.type, ssid.getBegin(), ssid.getEnd() + 1);
                  if (oneDrugChangeStatus.hasNext())
                  {
                    dsa = (DrugChangeStatusAnnotation) oneDrugChangeStatus.next();
                    drugTokenAnt.setDrugChangeStatus(dsa.getChangeStatus());
                    statusKey = dsa.getChangeStatus();
                  }
                }
                drugTokenAnt.setStatus(ssid.getStatus());
                dm.setDrugChangeStatusElement(statusKey, begin, end);

                statusFound = true;
              }
            }
          }

          // Look for special case where status comes before the drug
          // mention
          // A better means to locate the beginning of the chunk is
          // lacking here mainly due
          // to the fact that the sentence annotator cannot be trusted to
          // find the beginning
          // accurately.

          Iterator statusSpecialChangeItr = FSUtil.getAnnotationsIteratorInSpan(jcas, DrugChangeStatusAnnotation.type, begin - 20, drugTokenAnt.getBegin() + 1);
          while (statusSpecialChangeItr.hasNext())
          {
            DrugChangeStatusAnnotation specialDsa = (DrugChangeStatusAnnotation) statusSpecialChangeItr.next();
            if (specialDsa.getEnd() + 1 == drugTokenAnt.getBegin()
                && relatedStatus == null)
            {
              drugTokenAnt.setDrugChangeStatus(specialDsa.getChangeStatus());
              drugTokenAnt.setChangeStatusBegin(specialDsa.getBegin());
              drugTokenAnt.setChangeStatusEnd(specialDsa.getEnd());
              overrideStatus = true;
            }
          }
        }
        // If a strength token is discovered before the next
        // distinguished
        // drug mentions then the remaining sentence is scanned for
        // DrugChangeStatus.
        // Iterator strengthAllItr = FSUtil.getAnnotationsIteratorInSpan(
        // jcas, StrengthAnnotation.type, begin, end + 1);
        //
        // List holdStrength = new ArrayList();
        // while (strengthAllItr.hasNext()) {
        // StrengthAnnotation sa = (StrengthAnnotation) strengthAllItr
        // .next();
        // holdStrength.add(sa);
        // }
        String strengthText = null;
        boolean onlyNeedOneStrength = false;
        if (!keepNoChangeStatus || (drugTokenAnt.getStrength() == null)) {
          List holdStrength = getAnnotationsInSpan(jcas, StrengthAnnotation.type,
              begin, end + 1);

          Iterator strengthItr = findUniqueMentions(holdStrength.toArray()).iterator();

          double strengthValue = 0;


          int holdStrengthBeginOffset = 0, holdStrengthEndOffset = 0;


          while (strengthItr.hasNext() && !onlyNeedOneStrength)
          {
            StrengthAnnotation sa = (StrengthAnnotation) strengthItr.next();

            if (holdStrengthBeginOffset != sa.getBegin()
                && holdStrengthEndOffset != sa.getEnd()
                && (relatedStatus != null))
            {

              double curStrengthValue = 0;

              int hyphenLocation = sa.getCoveredText().indexOf("-");
              String holdStrengthValue = sa.getCoveredText();

              if (hyphenLocation > 0)
              {
                holdStrengthValue = holdStrengthValue.substring(0, hyphenLocation);
              }

              int spaceLocation = holdStrengthValue.indexOf(" ");

              if (spaceLocation > 0)
              {
                holdStrengthValue = holdStrengthValue.substring(0, spaceLocation);
              }

              if (holdStrengthValue != null
                  && holdStrengthValue.compareTo("") != 0)
                curStrengthValue = new Double(dm.parseDoubleValue(holdStrengthValue)).doubleValue();
              boolean findLowValue = true;

              if (relatedStatus[0].compareTo(DrugChangeStatusToken.INCREASE) == 0)
              {
                if (curStrengthValue > strengthValue)
                {
                  strengthValue = curStrengthValue;
                  strengthText = dm.getStrengthElement();
                }
              } else if (relatedStatus[0].compareTo(DrugChangeStatusToken.DECREASE) == 0)
              {
                if (findLowValue)
                  strengthValue = curStrengthValue;
                if (curStrengthValue <= strengthValue)
                {
                  strengthValue = curStrengthValue;
                  strengthText = dm.getStrengthElement();
                }
                findLowValue = false;

              } else if (relatedStatus[0].compareTo(DrugChangeStatusToken.SUM) == 0)
              {

                strengthValue = curStrengthValue;
                strengthText = dm.getStrengthElement();
                // get first value found
              }
            } else
            {
              strengthText = dm.getStrengthElement();
              if (!maxExists)
                onlyNeedOneStrength = true;
              else if (maxOffsetEnd + 1 == sa.getBegin())
              {
                onlyNeedOneStrength = true;
                strengthText = sa.getCoveredText();
              }
            }

            holdStrengthBeginOffset = sa.getBegin();
            holdStrengthEndOffset = sa.getEnd();

          }
        }
        String doseText = null;
        if (!keepNoChangeStatus || (drugTokenAnt.getDosage() == null)) {
          Iterator dosageItr = FSUtil.getAnnotationsIteratorInSpan(jcas,
              DosagesAnnotation.type, begin, end + 1);
          List holdDosages = new ArrayList();
          double doseValue = 0;

          int holdDoseBeginOffset = 0, holdDoseEndOffset = 0;
          boolean onlyNeedOneDose = false;

          while (dosageItr.hasNext() && !onlyNeedOneDose)
          {
            DosagesAnnotation da = (DosagesAnnotation) dosageItr.next();
            if (holdDoseBeginOffset != da.getBegin()
                && holdDoseEndOffset != da.getEnd() && relatedStatus != null)
            {
              int removeComma = da.getCoveredText().indexOf(',');
              String doseTextCheck = da.getCoveredText();
              if (removeComma > 0)
              {
                doseTextCheck = doseTextCheck.substring(0, removeComma);
              }
              double curDoseValue = new Double(dm.convertFromTextToNum(doseTextCheck)).doubleValue();
              boolean findLowValue = true;
              if (relatedStatus[0].compareTo(DrugChangeStatusToken.INCREASE) == 0)
              {
                if (curDoseValue > doseValue)
                {
                  doseValue = curDoseValue;
                  doseText = dm.getDosageElement();
                } else if (relatedStatus[0].compareTo(DrugChangeStatusToken.SUM) == 0)
                {

                  doseValue = curDoseValue;
                  doseText = dm.getDosageElement();

                }
              } else if (relatedStatus[0].compareTo(DrugChangeStatusToken.DECREASE) == 0)
              {
                if (findLowValue)
                  doseValue = curDoseValue;
                if (curDoseValue <= doseValue)
                {
                  doseValue = curDoseValue;
                  doseText = dm.getDosageElement();
                }
                findLowValue = false;
              }
              holdDosages.add(da);
              holdDoseBeginOffset = da.getBegin();
              holdDoseEndOffset = da.getEnd();
            } else
            {
              doseText = dm.getDosageElement();

              if (!maxExists)
                onlyNeedOneDose = true;
            }
          }
        }
        String frequencyText = null;
        if (!keepNoChangeStatus || (drugTokenAnt.getFrequency() == null)) {
          Iterator freqItr = FSUtil.getAnnotationsIteratorInSpan(jcas,
              FrequencyAnnotation.type, begin, end + 1);

          List holdFreqItr = new ArrayList();
          while (freqItr.hasNext())
          {
            holdFreqItr.add(freqItr.next());
          }
          Iterator frequencyItr = sortAnnotations(holdFreqItr.toArray()).iterator();

          List holdFrequency = new ArrayList();
          double frequencyValue = 0;

          int holdFrequencyBeginOffset = 0, holdFrequencyEndOffset = 0;
          boolean onlyNeedOneFrequency = false;

          while (frequencyItr.hasNext() && !onlyNeedOneFrequency)
          {
            FrequencyAnnotation fa = (FrequencyAnnotation) frequencyItr.next();

            if (dm.frequency != null
                && dm.frequency.getFrequencyMention() == null)
            {
              double curFrequencyValue = new Double(dm.convertFromTextToNum(fa.getCoveredText())).doubleValue();
              String curFreqValueText = new Double(curFrequencyValue).toString();
              dm.setFrequencyElement(curFreqValueText, fa.getBegin(), fa.getEnd());
              frequencyText = curFreqValueText;
            }
            onlyNeedOneFrequency = true;

            holdFrequency.add(fa);
            holdFrequencyBeginOffset = fa.getBegin();
            holdFrequencyEndOffset = fa.getEnd();
          }
        }
        boolean foundPRN = false;
        String frequencyUnitText = null;
        if (!keepNoChangeStatus || (drugTokenAnt.getFrequencyUnit() == null)) {
          Iterator frequencyUnitItr = FSUtil.getAnnotationsIteratorInSpan(jcas,
              FrequencyUnitAnnotation.type, begin, end + 1);
          List holdFrequencyUnit = new ArrayList();
          double frequencyUnitValue = 0;

          int holdFrequencyUnitBeginOffset = 0, holdFrequencyUnitEndOffset = 0;
          boolean onlyNeedOneFrequencyUnit = false;


          while (frequencyUnitItr.hasNext() && !onlyNeedOneFrequencyUnit)
          {
            FrequencyUnitAnnotation fua = (FrequencyUnitAnnotation) frequencyUnitItr.next();
            if (holdFrequencyUnitBeginOffset != fua.getBegin()
                && holdFrequencyUnitEndOffset != fua.getEnd()
                && relatedStatus != null)
            {
              double curFrequencyUnitValue = new Float(fua.getPeriod()).doubleValue();

              boolean findLowValue = true;
              if (relatedStatus[0].compareTo(DrugChangeStatusToken.INCREASE) == 0)
              {
                if (curFrequencyUnitValue > frequencyUnitValue)
                {
                  frequencyUnitValue = curFrequencyUnitValue;
                  frequencyUnitText = dm.getFrequencyUnitElement();
                }
              } else if (relatedStatus[0] == null
                  || relatedStatus[0].compareTo(DrugChangeStatusToken.DECREASE) == 0)
              {
                if (findLowValue)
                  frequencyUnitValue = curFrequencyUnitValue;
                if (curFrequencyUnitValue <= frequencyUnitValue)
                {
                  frequencyUnitValue = curFrequencyUnitValue;
                  frequencyUnitText = dm.getFrequencyUnitElement();
                }
                findLowValue = false;
              }
            } else
            {
              if (fua.getPeriod() == FrequencyUnitToken.QUANTITY_PRN)
                foundPRN = true;
              else
              {
                frequencyUnitText = dm.getFrequencyUnitElement();

                if (!maxExists)
                {
                  onlyNeedOneStrength = true;
                }

              }
            }

            holdFrequencyUnit.add(fua);
            holdFrequencyUnitBeginOffset = fua.getBegin();
            holdFrequencyUnitEndOffset = fua.getEnd();
          }

        }
        if (recurseNER != null && recurseNER.getDrugChangeStatus() != null
            && relatedStatus[0] != null  && dm.changeStatus == null)
          drugTokenAnt.setDrugChangeStatus(relatedStatus[0]);
        else if (keepNoChangeStatus || (dm.changeStatus != null &&
            (dm.changeStatus.getDrugChangeStatus().equals(DrugChangeStatusToken.INCREASEFROM)
                || dm.changeStatus.getDrugChangeStatus().equals(DrugChangeStatusToken.DECREASEFROM)))) {
          drugTokenAnt.setDrugChangeStatus(DrugChangeStatusToken.NOCHANGE);
        }
        else if (dm.getDrugChangeStatusElement() != null
            && dm.getDrugChangeStatusElement().compareTo("") != 0
            && dm.getDrugChangeStatusElement().compareTo(
                DrugChangeStatusToken.NOCHANGE) != 0
                /*
                 * && drugTokenAnt.getDrugChangeStatus() != null && drugTokenAnt
                 * .getDrugChangeStatus().compareTo(DrugChangeStatusToken .NOCHANGE)
                 * == 0
                 */
                && !overrideStatus)
        {
          // Don't want subsections here

          Iterator negateStatusChanges = FSUtil.getAnnotationsIteratorInSpan(
              jcas, SubSectionAnnotation.type,
              dm.changeStatus.getBeginOffset(),
              dm.changeStatus.getEndOffset() + 2);
          if ((!negateStatusChanges.hasNext() || statusFound) && !keepNoChangeStatus) {
            drugTokenAnt.setDrugChangeStatus(dm.getDrugChangeStatusElement());
            drugTokenAnt.setChangeStatusBegin(dm.getChangeStatusBegin());
            drugTokenAnt.setChangeStatusEnd(dm.getChangeStatusEnd());
          }
          else
            drugTokenAnt.setDrugChangeStatus(DrugChangeStatusToken.NOCHANGE);
        } else if (relatedStatus != null && relatedStatus[0] != null) {
          drugTokenAnt.setDrugChangeStatus(relatedStatus[0]);
          drugTokenAnt.setChangeStatusBegin(new Integer (relatedStatus[1]).intValue());
          drugTokenAnt.setChangeStatusEnd(new Integer (relatedStatus[2]).intValue());
        } else if (drugTokenAnt.getDrugChangeStatus() == null
            || drugTokenAnt.getDrugChangeStatus().compareTo("") == 0)
          drugTokenAnt.setDrugChangeStatus(DrugChangeStatusToken.NOCHANGE);
        if (!keepNoChangeStatus) {
          String relatedStatusString = null;
          if (relatedStatus != null && relatedStatus[0] != null)
            relatedStatusString = relatedStatus[0];
          float confidenceScore = alignDrugMentionAttributes( strengthText,  dm ,  drugTokenAnt,  recurseNER,  relatedStatusString,  statusFound,  overrideStatus,
              maxExists,  doseText,  frequencyText,  frequencyUnitText);
          drugTokenAnt.setConfidence(confidenceScore);
        }

        if (foundPRN)
          drugTokenAnt.setDrugChangeStatus(drugTokenAnt.getDrugChangeStatus());

        ChunkAnnotation ca = new ChunkAnnotation(jcas, begin, end);
        ca.addToIndexes();
        ca.setSentenceID(tokenAnt.getSentenceID());

        drugTokenAnt.addToIndexes();
        globalDrugNER.add(drugTokenAnt);

      }

      if (isDrugNER)
      {
        countNER = globalDrugNER.size();
        boolean gotChangeStatus = false;
        for (int i = 0; i < countNER; i++)
        {
          if (!globalDrugNER.get(i).getDrugChangeStatus().equals("noChange") && !globalDrugNER.get(i).getDrugChangeStatus().equals("stop") && !globalDrugNER.get(i).getDrugChangeStatus().equals("start"))
            gotChangeStatus = true;
          if (i == 0) {
            addMedicationSpecificAttributes(jcas, globalDrugNER.get(i), tokenAnt);
          }
          else if (gotChangeStatus){
            MedicationMention mem = new MedicationMention(jcas, globalDrugNER.get(i).getBegin(), globalDrugNER.get(i).getEnd());
            addMedicationSpecificAttributes(jcas, globalDrugNER.get(i), mem);
            mem.addToIndexes(jcas);
          }
        }
      }
     
    }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.MedicationMention

      {
    boolean noPriorMention = false;
    boolean noPostMention = false;
    int originalEndSpan = endSpan;
    int originalBeginSpan = beginSpan;
    MedicationMention neAnnot = new MedicationMention(jcas, tokenDrugNER.getBegin(),
        tokenDrugNER.getEnd());
    int beginChunk = drugChangeStatus.getEnd();
    DrugMention compareDM = new DrugMention(jcas, beginChunk, endSpan);
    DrugMention priorDM = new DrugMention(jcas, beginSpan, drugChangeStatus.getBegin());
    if ((priorDM.dosage == null) && (priorDM.strength == null) && (priorDM.frequency == null ) )
      noPriorMention = true;
    if ((compareDM.dosage == null) && (compareDM.strength == null) && (compareDM.frequency == null ) )
      noPostMention = true;
    count++;
    if ( !noPriorMention)  {
      if (priorDM.dosage != null) {
        tokenDrugNER.setDosage(priorDM.getDosageElement());
        tokenDrugNER.setDosageBegin(priorDM.getDosageBegin());
        tokenDrugNER.setDosageEnd(priorDM.getDosageEnd());
      }
      if (priorDM.strength != null) {
        tokenDrugNER.setStrength(priorDM.getStrengthElement());
        tokenDrugNER.setStrengthBegin(priorDM.getStrengthBegin());
        tokenDrugNER.setStrengthEnd(priorDM.getStrengthEnd());
        tokenDrugNER.setStrengthUnit(priorDM.getStrengthUnitElement());
        tokenDrugNER.setSuBegin(priorDM.getStrengthUnitBegin());
        tokenDrugNER.setSuEnd(priorDM.getStrengthUnitEnd());
      }
      if (priorDM.frequency != null) {
        tokenDrugNER.setFrequency(priorDM.getFrequencyElement());
        tokenDrugNER.setFrequencyBegin(priorDM.getFrequencyBegin());
        tokenDrugNER.setFrequencyEnd(priorDM.getFrequencyEnd());
      }
    }
    neAnnot.setTypeID(NERTypeIdentifier);
    int [] updatedSpan = {beginSpan, endSpan};

    List<MedicationMention> buildNewNER = new ArrayList<MedicationMention>();

    buildNewNER.add(neAnnot);

    if (drugChangeStatus.getChangeStatus().compareTo(
        DrugChangeStatusToken.DECREASE) == 0)
    {
      int endChunk = 0;
      int startChunk = 0;
      int midChunk = 0;
      if (noPriorMention) {//Look for highest value on right side
        startChunk =  getAdjustedWindowSpan(jcas,  beginChunk, endSpan, false)[0];
        midChunk =  getAdjustedWindowSpan(jcas,  beginChunk, endSpan, true)[0];
        endChunk = getAdjustedWindowSpan(jcas,  beginChunk, endSpan, true)[1];
      }
      updatedSpan[0] = beginChunk;
      String [] changeStatusArray = new String [] {DrugChangeStatusToken.DECREASE, new Integer (drugChangeStatus.getBegin()).toString(), new Integer(drugChangeStatus.getEnd()).toString()};
      generateDrugMentionsAndAnnotations(jcas, buildNewNER, beginChunk,
          midChunk, tokenDrugNER, changeStatusArray, count,
          globalNER);
      if (noPriorMention) {
        compareDM = new DrugMention(jcas, startChunk, endChunk);
        if (compareDM.dosage != null) {
          tokenDrugNER.setDosage(compareDM.getDosageElement());
          tokenDrugNER.setDosageBegin(compareDM.getDosageBegin());
          tokenDrugNER.setDosageEnd(compareDM.getDosageEnd());
        }
        if (compareDM.strength != null) {
          tokenDrugNER.setStrength(compareDM.getStrengthElement());
          tokenDrugNER.setStrengthBegin(compareDM.getStrengthBegin());
          tokenDrugNER.setStrengthEnd(compareDM.getStrengthEnd());
          tokenDrugNER.setStrengthUnit(compareDM.getStrengthUnitElement());
          tokenDrugNER.setSuBegin(compareDM.getStrengthUnitBegin());
          tokenDrugNER.setSuEnd(compareDM.getStrengthUnitEnd());
        }
        if (compareDM.frequency != null) {
          tokenDrugNER.setFrequency(compareDM.getFrequencyElement());
          tokenDrugNER.setFrequencyBegin(compareDM.getFrequencyBegin());
          tokenDrugNER.setFrequencyEnd(compareDM.getFrequencyEnd());
        }
      }
      tokenDrugNER.setDrugChangeStatus(DrugChangeStatusToken.NOCHANGE);
    } else if (drugChangeStatus.getChangeStatus().compareTo(
        DrugChangeStatusToken.DECREASEFROM) == 0)
    {
      if (noPriorMention) {//Look for lowest value on right side
        beginChunk = getAdjustedWindowSpan(jcas,  beginChunk, endSpan, true)[0];
        if (beginChunk == -1) {
          beginChunk = drugChangeStatus.getEnd();
        }
      }
      String [] changeStatusArray = new String [] {DrugChangeStatusToken.DECREASE, new Integer (drugChangeStatus.getBegin()).toString(), new Integer(drugChangeStatus.getEnd()).toString()};
      generateDrugMentionsAndAnnotations(jcas,
          buildNewNER, beginChunk, endSpan,
          tokenDrugNER, changeStatusArray, count, globalNER);
      if (noPriorMention) {
        priorDM = new DrugMention(jcas, originalBeginSpan, beginChunk);
        if (priorDM.dosage != null) {
          tokenDrugNER.setDosage(priorDM.getDosageElement());
          tokenDrugNER.setDosageBegin(priorDM.getDosageBegin());
          tokenDrugNER.setDosageEnd(priorDM.getDosageEnd());
        }
        if (priorDM.strength != null) {
          tokenDrugNER.setStrength(priorDM.getStrengthElement());
          tokenDrugNER.setStrengthBegin(priorDM.getStrengthBegin());
          tokenDrugNER.setStrengthEnd(priorDM.getStrengthEnd());
          tokenDrugNER.setStrengthUnit(compareDM.getStrengthUnitElement());
          tokenDrugNER.setSuBegin(compareDM.getStrengthUnitBegin());
          tokenDrugNER.setSuEnd(compareDM.getStrengthUnitEnd());
        }
        if (priorDM.frequency != null) {
          tokenDrugNER.setFrequency(priorDM.getFrequencyElement());
          tokenDrugNER.setFrequencyBegin(priorDM.getFrequencyBegin());
          tokenDrugNER.setFrequencyEnd(priorDM.getFrequencyEnd());
        }
      }
      tokenDrugNER.setDrugChangeStatus(DrugChangeStatusToken.NOCHANGE);

    } else if (drugChangeStatus.getChangeStatus().compareTo(
        DrugChangeStatusToken.INCREASE) == 0)
    {
      if (noPriorMention) {//Look for highest value on right side
        endSpan =  getAdjustedWindowSpan(jcas,  beginChunk, endSpan, true)[0];
      }
      updatedSpan[0] = beginChunk;
      String [] changeStatusArray = new String [] {DrugChangeStatusToken.INCREASE, new Integer (drugChangeStatus.getBegin()).toString(), new Integer(drugChangeStatus.getEnd()).toString()};
      generateDrugMentionsAndAnnotations(jcas, buildNewNER, beginChunk,
          endSpan, tokenDrugNER, changeStatusArray, count,
          globalNER);
      if (noPriorMention) {
        compareDM = new DrugMention(jcas, endSpan, originalEndSpan);
        if (compareDM.dosage != null) {
          tokenDrugNER.setDosage(compareDM.getDosageElement());
          tokenDrugNER.setDosageBegin(compareDM.getDosageBegin());
          tokenDrugNER.setDosageEnd(compareDM.getDosageEnd());
        }
        if (compareDM.strength != null) {
          tokenDrugNER.setStrength(compareDM.getStrengthElement());
          tokenDrugNER.setStrengthBegin(compareDM.getStrengthBegin());
          tokenDrugNER.setStrengthEnd(compareDM.getStrengthEnd());
          tokenDrugNER.setStrengthUnit(compareDM.getStrengthUnitElement());
          tokenDrugNER.setSuBegin(compareDM.getStrengthUnitBegin());
          tokenDrugNER.setSuEnd(compareDM.getStrengthUnitEnd());
        }
        if (compareDM.frequency != null) {
          tokenDrugNER.setFrequency(compareDM.getFrequencyElement());
          tokenDrugNER.setFrequencyBegin(compareDM.getFrequencyBegin());
          tokenDrugNER.setFrequencyEnd(compareDM.getFrequencyEnd());
        }
      }
      tokenDrugNER.setDrugChangeStatus(DrugChangeStatusToken.OTHER);
    } else if (drugChangeStatus.getChangeStatus().compareTo(
        DrugChangeStatusToken.INCREASEFROM) == 0)
    {
      int startChunk = 0;
      int endChunk = 0;
      int midChunk = 0;
      if (noPriorMention) {//Look for lowest value on right side
        startChunk = getAdjustedWindowSpan(jcas,  beginChunk, endSpan, false)[0];
        midChunk =  getAdjustedWindowSpan(jcas,  beginChunk, endSpan, false)[1];
        endChunk = getAdjustedWindowSpan(jcas,  beginChunk, endSpan, true)[1];
      }
      String [] changeStatusArray = new String [] {DrugChangeStatusToken.INCREASE, new Integer (drugChangeStatus.getBegin()).toString(), new Integer(drugChangeStatus.getEnd()).toString()};
      generateDrugMentionsAndAnnotations(jcas, buildNewNER, startChunk,
          endChunk, tokenDrugNER,
          changeStatusArray, count, globalNER);
      if (noPriorMention) {
        priorDM = new DrugMention(jcas, originalBeginSpan, midChunk);
        if (priorDM.dosage != null) {
          tokenDrugNER.setDosage(priorDM.getDosageElement());
          tokenDrugNER.setDosageBegin(priorDM.getDosageBegin());
          tokenDrugNER.setDosageEnd(priorDM.getDosageEnd());
        }
        if (priorDM.strength != null) {
          tokenDrugNER.setStrength(priorDM.getStrengthElement());
          tokenDrugNER.setStrengthBegin(priorDM.getStrengthBegin());
          tokenDrugNER.setStrengthEnd(priorDM.getStrengthEnd());
          tokenDrugNER.setStrengthUnit(priorDM.getStrengthUnitElement());
          tokenDrugNER.setSuBegin(priorDM.getStrengthUnitBegin());
          tokenDrugNER.setSuEnd(priorDM.getStrengthUnitEnd());
        }
        if (priorDM.frequency != null) {
          tokenDrugNER.setFrequency(priorDM.getFrequencyElement());
          tokenDrugNER.setFrequencyBegin(priorDM.getFrequencyBegin());
          tokenDrugNER.setFrequencyEnd(priorDM.getFrequencyEnd());
        }
      }
      tokenDrugNER.setDrugChangeStatus(DrugChangeStatusToken.NOCHANGE);
    } else if (drugChangeStatus.getChangeStatus().compareTo(
        DrugChangeStatusToken.STOP) == 0)
    {
      tokenDrugNER.setDrugChangeStatus(tokenDrugNER.getDrugChangeStatus());
    } else if ((drugChangeStatus.getChangeStatus().compareTo(
        DrugChangeStatusToken.OTHER) == 0)
        || drugChangeStatus.getChangeStatus().compareTo(
            DrugChangeStatusToken.SUM) == 0)
    {


      double strengthChange = 1;
      double dosageChange = 1;
      double frequencyChange = 1;
      if (noPriorMention) {
        int [] updateSpan =   getAdjustedWindowSpan(jcas,  beginChunk, endSpan, false);
        compareDM = new DrugMention(jcas, endSpan, originalEndSpan);
        if (compareDM.dosage != null) {
          tokenDrugNER.setDosage(compareDM.getDosageElement());
          tokenDrugNER.setDosageBegin(compareDM.getDosageBegin());
          tokenDrugNER.setDosageEnd(compareDM.getDosageEnd());
        }
        if (compareDM.strength != null) {
          tokenDrugNER.setStrength(compareDM.getStrengthElement());
          tokenDrugNER.setStrengthBegin(compareDM.getStrengthBegin());
          tokenDrugNER.setStrengthEnd(compareDM.getStrengthEnd());
          tokenDrugNER.setStrengthUnit(compareDM.getStrengthUnitElement());
          tokenDrugNER.setSuBegin(compareDM.getStrengthUnitBegin());
          tokenDrugNER.setSuEnd(compareDM.getStrengthUnitEnd());
        }
        if (compareDM.frequency != null) {
          tokenDrugNER.setFrequency(compareDM.getFrequencyElement());
          tokenDrugNER.setFrequencyBegin(compareDM.getFrequencyBegin());
          tokenDrugNER.setFrequencyEnd(compareDM.getFrequencyEnd());
        }
      }
      tokenDrugNER.setDrugChangeStatus(DrugChangeStatusToken.OTHER);
      if (compareDM.getStrengthElement() != null
          && compareDM.getStrengthElement().compareTo("") != 0
          && compareDM != null)
      {
        strengthChange = new Double(compareDM.parseDoubleValue(compareDM.getStrengthElement())).doubleValue();

      } else if (priorDM.getStrengthElement() != null
          && priorDM.getStrengthElement().compareTo("") != 0
          && priorDM.getStrengthElement().length() > 0)
      {
        int spacePosition = priorDM.getStrengthElement().indexOf(" ");
        if (spacePosition > 0)
        {
          strengthChange = new Double(priorDM.parseDoubleValue(priorDM.getStrengthElement().substring(0, spacePosition))).doubleValue();

        } else
        {
          strengthChange = new Double(priorDM.parseDoubleValue(priorDM.getStrengthElement())).doubleValue();

        }
      }
      if (compareDM.getDosageElement() != null
          && compareDM.getDosageElement().compareTo("") != 0)
      {
        dosageChange = new Double(compareDM.parseDoubleValue(compareDM.getDosageElement())).doubleValue();
      } else if (priorDM.getDosageElement() != null
          && priorDM.getDosageElement().compareTo("") != 0)
      {
        dosageChange = new Double(priorDM.parseDoubleValue(priorDM.getDosageElement())).doubleValue();
      }
      if (compareDM.getFrequencyElement() != null
          && compareDM.getFrequencyElement().compareTo("") != 0)
      {
        frequencyChange = new Double(compareDM.parseDoubleValue(compareDM.getFrequencyElement())).doubleValue();
      } else if (priorDM.getFrequencyElement() != null
          && priorDM.getFrequencyElement().compareTo("") != 0)
      {
        frequencyChange = new Double(priorDM.parseDoubleValue(priorDM.getFrequencyElement())).doubleValue();
      }

      double strengthBefore = 1;
      double dosageBefore = 1;
      double frequencyBefore = 1;

      if (priorDM.getStrengthElement() != null
          && priorDM.getStrengthElement().compareTo("") != 0
          && priorDM.getStrengthElement().length() > 0)
      {
        strengthBefore = new Double(priorDM.parseDoubleValue(priorDM.getStrengthElement())).doubleValue();
        tokenDrugNER.setStrength(priorDM.getStrengthElement());
        tokenDrugNER.setStrengthBegin(priorDM.getStrengthBegin());
        tokenDrugNER.setStrengthEnd(priorDM.getStrengthEnd());
        tokenDrugNER.setStrengthUnit(priorDM.getStrengthUnitElement());
        tokenDrugNER.setSuBegin(priorDM.getStrengthUnitBegin());
        tokenDrugNER.setSuEnd(priorDM.getStrengthUnitEnd());
      } else if (tokenDrugNER.getStrength() != null
          && tokenDrugNER.getStrength().compareTo("") != 0
          && tokenDrugNER.getStrength().length() > 0)
      {
        boolean handledSeparator = false;
        int hyphPosition = tokenDrugNER.getStrength().indexOf('-');
        String hyphString = tokenDrugNER.getStrength();
        if (hyphPosition > 0)
        {
          hyphString = tokenDrugNER.getStrength().substring(0, hyphPosition);

          strengthBefore = new Double(compareDM.parseDoubleValue(compareDM.convertFromTextToNum(hyphString))).doubleValue();
          handledSeparator = true;
        }
        int spacePosition = hyphString.indexOf(" ");
        if (spacePosition > 0)
        {
          hyphString = hyphString.substring(0, spacePosition);
          strengthBefore = new Double(priorDM.parseDoubleValue(priorDM.convertFromTextToNum(hyphString))).doubleValue();
          handledSeparator = true;
        }
        if (!handledSeparator)
          strengthBefore = new Double(compareDM.parseDoubleValue(tokenDrugNER.getStrength())).doubleValue();
      }
      if (priorDM.getDosageElement() != null
          && priorDM.getDosageElement().compareTo("") != 0
          && priorDM.dosage != null)
      {
        dosageBefore = new Double(priorDM.getDosageElement()).doubleValue();
        tokenDrugNER.setDosage(priorDM.getDosageElement());
        tokenDrugNER.setDosageBegin(priorDM.getDosageBegin());
        tokenDrugNER.setDosageEnd(priorDM.getDosageEnd());
      } else if (tokenDrugNER.getDosage() != null
          && tokenDrugNER.getDosage().compareTo("") != 0)
      {
        dosageBefore = new Double(compareDM.parseDoubleValue(tokenDrugNER.getDosage())).doubleValue();
      }
      if (priorDM.getFrequencyElement() != null
          && priorDM.getFrequencyElement().compareTo("") != 0)
      {
        frequencyBefore = new Double(priorDM.parseDoubleValue(priorDM.getFrequencyElement())).doubleValue();
        tokenDrugNER.setFrequency(priorDM.getFrequencyElement());

      } else if (tokenDrugNER.getFrequency() != null
          && tokenDrugNER.getFrequency().compareTo("") != 0)
      {
        frequencyBefore = new Double(compareDM.parseDoubleValue(tokenDrugNER.getFrequency())).doubleValue();
      }
      if ((drugChangeStatus.getChangeStatus().compareTo(
          DrugChangeStatusToken.SUM) == 0)
          && (strengthChange > 1 && strengthBefore > 1 || strengthChange == strengthBefore))
      {
        Iterator findLF = FSUtil.getAnnotationsIteratorInSpan(jcas,
            NewlineToken.type, neAnnot.getBegin(), beginChunk);
        if (!findLF.hasNext())
        {
          if (frequencyChange <= 1 && frequencyBefore > 1)
            tokenDrugNER.setFrequency("1.0");
          String [] changeStatusArray = new String [] {DrugChangeStatusToken.SUM, new Integer (0).toString(), new Integer(0).toString()};
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.MedicationMention

  }

  return span;
}
  private void findFSMInRange(JCas jcas, int begin, int end) throws Exception {
    MedicationMention ne = null;
    WordToken we = null;
    // grab iterator over tokens within this chunk
    Iterator btaItr = FSUtil.getAnnotationsInSpanIterator(jcas,
        BaseToken.type, begin,
        end+1);
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.MedicationMention

        }
      }

    } else if (elementType == MedicationMention.type) {
      while (neItr.hasNext()) {
        MedicationMention nea = (MedicationMention) neItr.next();
        if(nea.getTypeID()==1 || nea.getTypeID()==0) {
          lastLocation[0]= nea.getBegin();
          lastLocation[1] = nea.getEnd();
          if ((counter == 0 || lastLocation[0] != location[counter-1][0]) && (nea.getBegin()>=begin && nea.getEnd() <= end)) {
            location[counter][0]= lastLocation[0];
            location[counter][1]= lastLocation[1];
            counter++;
          }

        }
      }
    } else if (elementType == PunctuationToken.type) {
      while (neItr.hasNext()) {
        boolean foundPair = false;
        PunctuationToken nea = (PunctuationToken) neItr.next();
        if (nea.getCoveredText().compareTo("(")==0)
          lastLocation[0] = nea.getBegin();
        else if (nea.getCoveredText().compareTo(")")==0) {
          lastLocation[1] = nea.getEnd();
          foundPair = true;
        }
        if (nea.getBegin()>=begin && nea.getEnd() <= end && foundPair && (counter == || (counter> 0 && lastLocation[0] !=  location[counter - 1][0]))) {
          location[counter][0]= lastLocation[0];
          location[counter][1]= lastLocation[1];
          counter++;
        }
      }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.MedicationMention

    Iterator neItr = FSUtil.getAnnotationsIteratorInSpan(jcas, MedicationMention.type, begin, end);

    int numDrugs=0;
    int beginOffset=0;
    while (neItr.hasNext()) {
      MedicationMention nea = (MedicationMention) neItr.next();
     
      if((nea.getTypeID()==|| nea.getTypeID()==0) && beginOffset != nea.getBegin())    
        numDrugs++;
      beginOffset = nea.getBegin();
    }
    if(numDrugs>1) return true;
    else return false;        
  }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.MedicationMention

    if (drugSpanLength > 1)
      for (int j = 0; j < drugSpanLength; j++) {
        Iterator drugListItr = FSUtil.getAnnotationsIteratorInSpan(jcas, MedicationMention.type, drugSpan[j][0], drugSpan[j][1]+1);
        Iterator drugListItrNext = FSUtil.getAnnotationsIteratorInSpan(jcas, MedicationMention.type, drugSpan[j+1][0], drugSpan[j+1][1]+1);
        if (drugListItr.hasNext()) {
          MedicationMention nea = (MedicationMention) drugListItr.next();
          drugSpanArray[j][0] = nea.getBegin();
          boolean patternFound = false;
          boolean hasNext = true;
          boolean isPairedDrug = false;
          boolean usingLeftParenthesisExclusive = false;
          boolean usingLeftParenthesisInclusive = false;
          boolean usingRightParenthesisInclusive = false;
          int endRange = 0;
          int countMultiplePre = 0;
          char highestInRange = ' ';
          char lowestPositiveInRange = ' ';
          char lowestInRange = ' ';
          int highestValueInRange = 0;
          int lowestValueInRange = 0;
          int lowestPositiveValueInRange = endPhrase;
          if (drugListItrNext.hasNext()) {
            MedicationMention neaNext = (MedicationMention) drugListItrNext.next();
            endPhrase = neaNext.getBegin();
          } else {
            hasNext = false;
            endPhrase = senSpan[1];
          }
          int [] testForMultipleElementsInRange = {0,0};
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.MedicationMention

      }

    } else if (elementType == MedicationMention.type) {
      int holdEndElement = 0;
      while (neItr.hasNext()) {
        MedicationMention nea = (MedicationMention) neItr.next();
        if(nea.getTypeID()==1 || nea.getTypeID()==0) {
          lastLocation[0]= nea.getBegin();
          lastLocation[1] = nea.getEnd();
          if ((counter == 0 || lastLocation[0] != location[counter-1][0]) && (nea.getBegin()>=begin && nea.getEnd() <= end)) {
            location[counter][0]= lastLocation[0];
            holdEndElement = location[counter][1] = lastLocation[1];
            counter++;
          } else if (counter > 0 && holdEndElement > lastLocation[1]) {
            holdEndElement = location[counter-1][1] = lastLocation[1];
          }

        }
      }
    } else if (elementType == PunctuationToken.type) {
      while (neItr.hasNext()) {
        int holdBeginElement = 0;
        boolean foundPair = false;
        PunctuationToken nea = (PunctuationToken) neItr.next();
        if (nea.getCoveredText().compareTo("(")==0 || nea.getCoveredText().compareTo("[")==0)
          lastLocation[0] = nea.getBegin();
        else if (nea.getCoveredText().compareTo(")")==0 || nea.getCoveredText().compareTo("]")==0) {
          lastLocation[1] = nea.getEnd();
          foundPair = true;
        }
        if (holdBeginElement < nea.getBegin() && nea.getBegin()>=begin && nea.getEnd() <= end && foundPair) {
          location[counter][0]= lastLocation[0];
          location[counter][1]= lastLocation[1];
          counter++;
        }
      }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.MedicationMention

               conceptArr.set( arrIdx, umlsConcept );
               arrIdx++;
            }
            IdentifiedAnnotation annotation;
            if ( typeId == CONST.NE_TYPE_ID_DRUG ) {
               annotation = new MedicationMention( jcas );
            } else if ( typeId == CONST.NE_TYPE_ID_ANATOMICAL_SITE ) {
               annotation = new AnatomicalSiteMention( jcas );
            } else if ( typeId == CONST.NE_TYPE_ID_DISORDER ) {
               annotation = new DiseaseDisorderMention( jcas );
            } else if ( typeId == CONST.NE_TYPE_ID_FINDING ) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.