private static final Pattern lookForPercent = Pattern.compile("[%]");
public DrugMention(JCas jcas, int beginPos, int endPos) {
Iterator drugStatusTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas, DrugChangeStatusAnnotation.type, beginPos, endPos);
while (drugStatusTokenItr.hasNext()){
DrugChangeStatusAnnotation focusToken = (DrugChangeStatusAnnotation) drugStatusTokenItr.next();
String localStatus = null;
if ((localStatus = findDrugChangeStatusElement(jcas, focusToken
.getBegin(), focusToken.getEnd())) == null) {
changeStatus = new DrugChangeStatusElement(focusToken
.getCoveredText(), focusToken.getBegin(),
focusToken.getEnd());
} else {
setDrugChangeStatusElement(localStatus, focusToken
.getBegin(), focusToken.getEnd());
}
}
if (changeStatus != null
&& (changeStatus.getDrugChangeStatus().equals(DrugChangeStatusToken.INCREASEFROM)
|| changeStatus.getDrugChangeStatus().equals(DrugChangeStatusToken.DECREASE))) {
findMaxValue = false;
}
Iterator dateTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas,
DateAnnotation.type, beginPos, endPos);
while (dateTokenItr.hasNext()){
DateAnnotation focusToken = (DateAnnotation) dateTokenItr.next();
String localDate = null;
if ((localDate = findStartDateElement(jcas, focusToken.getBegin(),
focusToken.getEnd())) == null) {
startDate = new StartDateElement(focusToken.getCoveredText(),
focusToken.getBegin(), focusToken.getEnd());
} else {
setStartDateElement(localDate, focusToken.getBegin(),
focusToken.getEnd());
}
}
Iterator doseTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas,
DosagesAnnotation.type, beginPos, endPos);
while (doseTokenItr.hasNext()){
DosagesAnnotation focusToken = (DosagesAnnotation) doseTokenItr.next();
String localDose = null;
if ((localDose = findDosageElement(jcas, focusToken.getBegin(),
focusToken.getEnd())) == null) {
dosage = new DosageElement(focusToken.getCoveredText(),
focusToken.getBegin(), focusToken.getEnd());
} else {
setDosageElement(localDose, focusToken.getBegin(),
focusToken.getEnd());
}
}
Iterator frequencyTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas,
FrequencyAnnotation.type, beginPos, endPos);
while (frequencyTokenItr.hasNext()){
FrequencyAnnotation focusToken = (FrequencyAnnotation) frequencyTokenItr.next();
String localFreq = null;
if ((localFreq = findFrequencyElement(jcas, focusToken
.getBegin(), focusToken.getEnd())) == null) {
frequency = new FrequencyElement(focusToken
.getCoveredText(), focusToken.getBegin(),
focusToken.getEnd());
} else if ((frequency != null && localFreq != null)
&& (frequency.getFrequencyMention().compareTo("") != 0)
&& (localFreq.compareTo("") != 0)
&& (parseIntValue(localFreq) > parseIntValue(frequency
.getFrequencyMention()) && findMaxValue == true)) {
// Need a way to find the largest frequency and/or convert
// it to factor daily dosage
setFrequencyElement(localFreq, focusToken.getBegin(),
focusToken.getEnd());
} else {
setFrequencyElement(localFreq, focusToken.getBegin(),
focusToken.getEnd());
}
}
Iterator frequencyUnitTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas,
FrequencyUnitAnnotation.type, beginPos, endPos);
while (frequencyUnitTokenItr.hasNext()){
FrequencyUnitAnnotation focusToken = (FrequencyUnitAnnotation) frequencyUnitTokenItr.next();
String localFreq = null;
if ((localFreq = findFrequencyUnitElement(jcas,
focusToken.getBegin(), focusToken.getEnd())) == null) {
frequencyUnit = new FrequencyUnitElement(focusToken
.getCoveredText(), focusToken.getBegin(),
focusToken.getEnd());
} else if (frequencyUnit == null
&& findMaxValue == true) {
// Need a way to find the largest frequency and/or convert
// it to factor daily dosage
setFrequencyUnitElement(localFreq, focusToken.getBegin(),
focusToken.getEnd());
}
}
Iterator strengthUnitTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas, StrengthUnitAnnotation.type, beginPos, endPos);
while (strengthUnitTokenItr.hasNext()){
StrengthUnitAnnotation focusToken = (StrengthUnitAnnotation) strengthUnitTokenItr.next();
setStrengthUnitElement(focusToken.getCoveredText(),
focusToken.getBegin(), focusToken.getEnd());
}
Iterator strengthTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas, StrengthAnnotation.type, beginPos, endPos);
while (strengthTokenItr.hasNext()){
StrengthAnnotation focusToken = (StrengthAnnotation) strengthTokenItr.next();
String localStrength = null;
if ((localStrength = findStrengthElement(jcas, focusToken
.getBegin(), focusToken.getEnd())) == null) {
strength = new StrengthElement(focusToken.getCoveredText(),
focusToken.getBegin(), focusToken.getEnd());
} else {
if (strength != null) {
// check for range and compare
int spacePosition = strength.getStrengthMention()
.indexOf(" ");
int spacePos = localStrength
.indexOf(" ");
if (spacePosition > 0 && spacePos > 0
&& parseDoubleValue(strength
.getStrengthMention().substring(0,
spacePosition)) < parseDoubleValue(localStrength
.substring(0, localStrength
.indexOf(" ")))&& findMaxValue == true) {
setStrengthElement(localStrength, focusToken
.getBegin(), focusToken.getEnd());
} else {
String stringRange = strength.getStrengthMention();
int hyphPosition = 0;
if ((stringRange.length() > 0)
&& (stringRange.indexOf('-') > 0)) {
hyphPosition = stringRange.indexOf('-');
Double firstValue = new Double(
parseDoubleValue(stringRange
.subSequence(0, hyphPosition)));
Double secondValue = new Double(
parseDoubleValue(stringRange
.substring(hyphPosition + 2)));
if (firstValue.doubleValue() >= secondValue
.doubleValue() && findMaxValue == true) {
setStrengthElement(firstValue.toString(),
focusToken.getBegin(), focusToken
.getEnd());
} else {
setStrengthElement(firstValue.toString(),
focusToken.getBegin(), focusToken
.getEnd());
}
}
}
} else if ((localStrength.length() > 0)
&& (localStrength.indexOf('-') > 0)) {
int hyphPosition = 0;
hyphPosition = localStrength.indexOf('-');
Double firstValue = new Double(
parseDoubleValue(localStrength.subSequence(0,
hyphPosition)));
Double secondValue = new Double(
parseDoubleValue(localStrength
.substring(hyphPosition + 2)));
if (firstValue.doubleValue() >= secondValue
.doubleValue() && findMaxValue == true) {
setStrengthElement(firstValue.toString(),
focusToken.getBegin(), focusToken.getEnd());
} else {
setStrengthElement(firstValue.toString(),
focusToken.getBegin(), focusToken.getEnd());
}
setStrengthElement(localStrength,
focusToken.getBegin(), focusToken.getEnd());
} else {
setStrengthElement(localStrength,
focusToken.getBegin(), focusToken.getEnd());
}
}
}
Iterator formTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas, FormAnnotation.type, beginPos, endPos);
while (formTokenItr.hasNext()){
FormAnnotation focusToken = (FormAnnotation) formTokenItr.next();
String localForm = null;
if ((localForm = findFormElement(jcas, focusToken.getBegin(),
focusToken.getEnd())) == null) {
form = new FormElement(focusToken.getCoveredText(),
focusToken.getBegin(), focusToken.getEnd());
} else {
setFormElement(localForm, focusToken.getBegin(), focusToken
.getEnd());
}
}
Iterator routeTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas, RouteAnnotation.type, beginPos, endPos);
while (routeTokenItr.hasNext()){
RouteAnnotation focusToken = (RouteAnnotation) routeTokenItr.next();
String localRoute = null;
if ((localRoute = findRouteElement(jcas, focusToken.getBegin(),
focusToken.getEnd())) == null) {
route = new RouteElement(focusToken.getCoveredText(),
focusToken.getBegin(), focusToken.getEnd());
} else {
setRouteElement(localRoute, focusToken.getBegin(),
focusToken.getEnd());
}
}
Iterator durationTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas, DurationAnnotation.type, beginPos, endPos);
while (durationTokenItr.hasNext()){
DurationAnnotation focusToken = (DurationAnnotation) durationTokenItr.next();
String localDuration = null;
if ((localDuration = findDurationElement(jcas, focusToken
.getBegin(), focusToken.getEnd())) == null) {
duration = new DurationElement(focusToken.getCoveredText(),
focusToken.getBegin(), focusToken.getEnd());
} else {
setDurationElement(localDuration, focusToken.getBegin(),
focusToken.getEnd());
}
}