}
Iterator nerItr = indexes.getAnnotationIndex(MedicationEventMention.type).iterator();
while (nerItr.hasNext())
{
MedicationEventMention neAnnot = (MedicationEventMention) nerItr.next();
//System.err.println("DrugNE :"+neAnnot.getCoveredText());
gotDup = false;
// assign segment ID
Iterator segItr = segmentSet.iterator();
while (segItr.hasNext())
{
Segment seg = (Segment) segItr.next();
if ((keepTrackOfDupBegin == neAnnot.getBegin()) && (keepTrackOfDupEnd == neAnnot.getEnd()))
{
gotDup = true;
}
if ((neAnnot.getBegin() >= seg.getBegin())
&& (neAnnot.getEnd() <= seg.getEnd()) && !gotDup) {
// found segment for this NE
String segmentID = seg.getId();
if (iv_medicalSections.contains(segmentID)
|| !iv_useCurrentMedsSectionOnly.booleanValue()) {
if (!gotDup) {
keepTrackOfDupBegin = neAnnot.getBegin();
keepTrackOfDupEnd = neAnnot.getEnd();
Date localDate = neAnnot.getStartDate();//.getStartDate();
String chunk = null;
boolean foundChunk = false;
Iterator findChunk = indexes
.getAnnotationIndex(
ChunkAnnotation.type)
.iterator();
try {
while (findChunk.hasNext() && !foundChunk)
{
ChunkAnnotation ca = (ChunkAnnotation) findChunk.next();
if (neAnnot.getBegin() >= ca.getBegin()
&& neAnnot.getEnd() <= ca
.getEnd()) {
chunk = ca.getCoveredText()
.replace('\n', ' ')
.replace(',', ';');
foundChunk = true;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String containedInSubSection = segmentID;
Iterator subSectionItr = indexes.getAnnotationIndex(
SubSectionAnnotation.type).iterator();
while (subSectionItr.hasNext())
{
SubSectionAnnotation ssAnnot = (SubSectionAnnotation) subSectionItr.next();
if (ssAnnot.getSubSectionBodyBegin() <= neAnnot.getBegin() && ssAnnot.getSubSectionBodyEnd() >= neAnnot.getEnd())
{
Iterator textSpanInSs = FSUtil.getAnnotationsIteratorInSpan(jcas, WordToken.type, ssAnnot.getSubSectionHeaderBegin(), ssAnnot.getSubSectionHeaderEnd());
String subSectionHeaderName = "";
while (textSpanInSs.hasNext())
{
WordToken wta = (WordToken) textSpanInSs.next();
subSectionHeaderName = subSectionHeaderName + " " + wta.getCoveredText();
}
containedInSubSection = containedInSubSection+"|"+subSectionHeaderName+"|"+ssAnnot.getStatus();
}
}
gotMeds = true;
trackMedOccur++;
Calendar calendar = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("MM'/'dd'/'yyyy");
if(vRevDate != null && vRevDate.length() > 0)
calendar.setTimeInMillis(new Long(vRevDate).longValue());
else if(vNoteDate != null && vNoteDate.length() > 0)
calendar.setTimeInMillis(new Long(vNoteDate).longValue());
String globalDate = format.format(calendar.getTime());
// if (localDate == null
// || localDate.length() < 1) {
// localDate = globalDate;
// }
// Iterator neItr = FSUtil.getAnnotationsIteratorInSpan(jcas, IdentifiedAnnotation.type, neAnnot.getBegin(), neAnnot.getEnd()+1);
String neCui = "n/a";
String status = "n/a";
String rxNormCui = "n/a";
FSArray ocArr = neAnnot.getOntologyConceptArr();
if (ocArr != null)
{
for (int i = 0; i < ocArr.size(); i++)
{
OntologyConcept oc = (OntologyConcept) ocArr.get(i);
neCui = oc.getCode();
rxNormCui = oc.getOui();
}
}
MedicationStrength strengthTerm = neAnnot.getMedicationStrength();//getStrength();
String strengthTermString = "null";
if (strengthTerm != null)
strengthTermString = strengthTerm.getNumber()+ " " +strengthTerm.getUnit();
String medicationDosageString = "null";
if (neAnnot.getMedicationDosage() != null && neAnnot.getMedicationDosage().getValue() != null)
medicationDosageString = neAnnot.getMedicationDosage().getValue();
String medicationFrequencyNumber = "null";
if (neAnnot.getMedicationFrequency() != null && neAnnot.getMedicationFrequency().getNumber() != null)
medicationFrequencyNumber = neAnnot.getMedicationFrequency().getNumber()+" "+neAnnot.getMedicationFrequency().getUnit();
String duration = "null";
if (neAnnot.getMedicationDuration() != null && neAnnot.getMedicationDuration().getValue() != null)
duration = neAnnot.getMedicationDuration().getValue();
String route = "null";
if (neAnnot.getMedicationRoute() != null && neAnnot.getMedicationRoute().getValue() != null)
route = neAnnot.getMedicationRoute().getValue();
String form = "null";
if (neAnnot.getMedicationForm() != null && neAnnot.getMedicationForm().getValue() != null)
form = neAnnot.getMedicationForm().getValue();
String changeStatus = "null";
if (neAnnot.getMedicationStatusChange() != null && neAnnot.getMedicationStatusChange().getValue() != null )
changeStatus = neAnnot.getMedicationStatusChange().getValue();
medInfo = clinicNumber + "," +neAnnot.getCoveredText() + "," + rxNormCui
+ ",\"" + neAnnot.getStartDate() + "\","
+ globalDate + "," + medicationDosageString + "," +strengthTermString + ","
+ medicationFrequencyNumber + "," + duration + "," + route + ","
+ form + "," + status + ","
+ changeStatus + "," +neAnnot.getConfidence() + "," +containedInSubSection
+ "," +docLinkId+"_"+docRevision+","+chunk;
store(fileForIO, medInfo);
}
}
}