ResourceProcessException {
int count = 0;
try {
JCas jcas = cas.getJCas();
JFSIndexRepository indexes;
Iterator<?> annotItr;
Iterator<?> checkExamItr;
boolean haveUSSoloExamType = false;
boolean haveUSExamType = false;
boolean haveLowerExtExamType = false;
boolean haveCombinedExamType = false;
boolean haveLowerSoloExamType = false;
boolean haveVRADExamType = false;
boolean locTermsOnly = false;
boolean noStenosis = true;
boolean noVein = true;
boolean noStent = true;
boolean CTTypeExam = false;
indexes = jcas.getJFSIndexRepository();
boolean negatedCase = true;
int locOnlyCount = 0;
int termOnlyCount = 0;
int probableCount = 0;
int veinCount = 0;
// Not needed for production use - add documentId that was collected
// in the CAS initializer
// if (isWindows()) {
FSIterator<TOP> documentIDIterator = indexes.getAllIndexedFS(DocumentID.type);
if (documentIDIterator.hasNext()) {
DocumentID did = (DocumentID) documentIDIterator.next();
casConsumerOffSetData.append(did.getDocumentID());
}
// }
// add clinic number, etc for local run
// if (isWindows())
addPatientMetaData(jcas);
annotItr = indexes.getAnnotationIndex(PADHit.type).iterator();
casConsumerOffSetData.append(COLLECTION_SEPARATOR
+ COUNT_PLACE_HOLDER + COLLECTION_SEPARATOR);
// Need subsection for special case where Ultrasound exams are being
// implemented:
// Case : UNK: if no relevant documents OR negation of positive
// evidence in US or V+IRA
checkExamItr = indexes.getAnnotationIndex(SubSection.type)
.iterator();
while (checkExamItr.hasNext()) {
SubSection ssId = (SubSection) checkExamItr.next();
// US_LOWER_SOLO (ultrasound_lower_extremity_one_side_only),
// CT_EXAM_SOLO (CAT_Scan_one_side_only)
if (ssId.getParentSectionId().compareTo(
ultrasound_lower_extremity_one_side_only) == 0
|| ssId.getParentSectionId().compareTo(
"CAT_Scan_one_side_only") == 0)
haveLowerSoloExamType = true;
if (ssId.getParentSectionId().indexOf("V_IRAD") >= 0
|| ssId.getParentSectionId().compareTo("V&IRAD") == 0)
haveVRADExamType = true;
// US_EXAM (ultrasound),
if (ssId.getParentSectionId().compareTo(ultrasound) == 0)
haveUSExamType = true;
// LOWER_EXT (lower_extremity),
if (ssId.getParentSectionId().compareTo(lower_extremity) == 0)
haveLowerExtExamType = true;
// US_LOWER_EXT (ultrasound_lower_extremity),
if (ssId.getParentSectionId().compareTo(
ultrasound_lower_extremity) == 0)
haveCombinedExamType = true;
// US_LOWER_SOLO (ultrasound_lower_extremity_one_side_only),
if (ssId.getParentSectionId().compareTo(
ultrasound_lower_extremity_one_side_only) == 0)
haveUSSoloExamType = true;
// CT_EXAM (CAT_Scan),
if (ssId.getParentSectionId().indexOf(CAT_Scan) > 0
|| ssId.getParentSectionId().compareTo(CAT_Scan) == 0)
CTTypeExam = true;
}
boolean negCount = false;
boolean probableCase = false;
boolean globalProbable = false;
int balanceCount = 0;
while (annotItr.hasNext()) {
count++;
negatedCase = false;
// probableCase = false;
if (count >= 1) {
casConsumerOffSetData.append("(");
casConsumerOutData.append(COLLECTION_SEPARATOR);
}
// add segment from term or location
PADHit uaHit = (PADHit) annotItr.next();
if (uaHit.getUaTerm() != null)
casConsumerOutData.append(((PADTerm) uaHit.getUaTerm())
.getSegmentID());
else if (uaHit.getUaLocation() != null)
casConsumerOutData.append(((PADLocation) uaHit
.getUaLocation()).getSegmentID());
// add location and term data
PADLocation ual = uaHit.getUaLocation();
PADTerm uat = uaHit.getUaTerm();
if (ual != null) {
casConsumerOutData.append(COLLECTION_SEPARATOR
+ ual.getCoveredText());
casConsumerOffSetData.append(ual.getBegin() + "-"
+ ual.getEnd() + ":");
if (ual.getPolarity() == -1
&& uat == null
|| (ual.getPolarity() == -1 && uat != null
&& uat.getTypeID() != disorderStenosis && ual
.getPolarity() == -1)) {
negatedCase = true;
} else if (ual.getIsStandAlone() != 1
&& ual.getPolarity() != -1
&& ual.getUncertainty() == disorderPatent) {
probableCase = true;
probableCount++;
} else
probableCase = false;
} else {
casConsumerOutData.append(COLLECTION_SEPARATOR + " ");
casConsumerOffSetData.append("-1:");
if (uat.getTypeID() == disorderStenosis
&& uat.getPolarity() != -1)
noStenosis = false;
if (uat != null && uat.getPolarity() == -1
&& uat.getTypeID() != disorderStenosis
&& uat.getTypeID() != anatomicalSiteExclusion)
negatedCase = true;
else if (uat != null
&& ((uat.getIsStandAlone() != 1 || uat.getTypeID() == disorderPatent) && uat
.getPolarity() != -1)) {
probableCase = true;
probableCount++;
} else
probableCase = false;
}
if (uat != null) {
casConsumerOutData.append(COLLECTION_SEPARATOR
+ uat.getCoveredText());
casConsumerOffSetData.append(uat.getBegin() + "-"
+ uat.getEnd() + ")");
if (uat.getTypeID() == disorderStenosis
&& uat.getPolarity() != -1)
noStenosis = false;
if (uat.getPolarity() == -1
&& uat.getTypeID() != disorderStenosis
&& uat.getUncertainty() != disorderPatent
&& uat.getTypeID() != anatomicalSiteExclusion
&& uat.getIsStandAlone() != 1)
negatedCase = true;
else if (uat.getUncertainty() == disorderPatent
&& uat.getIsStandAlone() != 1) {
probableCase = true;
probableCount++;
} else if (!negatedCase)
probableCase = false;
} else {
casConsumerOutData.append(COLLECTION_SEPARATOR + " ");
casConsumerOffSetData.append("-1)");
if (ual != null && ual.getPolarity() == -1
&& ual.getUncertainty() != disorderPatent)
negatedCase = true;
else if (ual.getIsStandAlone() != 1
&& ual.getPolarity() != -1
&& ual.getUncertainty() == disorderPatent) {
probableCase = true;
probableCount++;
}
else
probableCase = false;
}
if (probableCase)
globalProbable = true;
if ((negatedCase || probableCase)) {
count--;
negCount = true;
if (uat != null && !probableCase
&& uat.getTypeID() != disorderStenosis
&& uat.getTypeID() != disorderPatent) {
if (ual == null || (ual != null)
&& ual.getTypeID() != disorderPatent
&& ual.getPolarity() == -1)
balanceCount--;
}
} else
balanceCount++;
}
annotItr = indexes.getAnnotationIndex(PADLocation.type).iterator();
while (annotItr.hasNext()) {
PADLocation location = (PADLocation) annotItr.next();
Iterator<?> annotHitItr = indexes.getAnnotationIndex(
PADHit.type).iterator();
boolean skip = false;
if (location.getCoveredText().indexOf("vein") != -1) {
noVein = false;
veinCount++;
}
while (annotHitItr.hasNext() && !skip) {
PADHit uaHit = ((PADHit) annotHitItr.next());
if (uaHit.getUaLocation() != null
&& location.getBegin() == uaHit.getUaLocation()
.getBegin())
skip = true;
}
if (!skip) {
if (location.getPolarity() == -1) {
locTermsOnly = true;
}
if (location.getPolarity() != -1) {
locOnlyCount++;
casConsumerOffSetData.append("(");
casConsumerOffSetData.append("-1:");
casConsumerOffSetData.append(location.getBegin() + "-"
+ location.getEnd() + ")");
casConsumerOutData.append(COLLECTION_SEPARATOR);
casConsumerOutData.append(location.getSegmentID());
casConsumerOutData.append(COLLECTION_SEPARATOR
+ "**NO TERM**");
casConsumerOutData.append(COLLECTION_SEPARATOR
+ location.getCoveredText());
} else if (location.getPolarity() != -1
&& location.getTypeID() != disorderStenosis
&& location.getTypeID() != anatomicalSiteExclusion
&& location.getUncertainty() == disorderPatent)
locOnlyCount--;
}
}
annotItr = indexes.getAnnotationIndex(PADTerm.type).iterator();
while (annotItr.hasNext()) {
PADTerm term = (PADTerm) annotItr.next();
Iterator<?> annotHitItr = indexes.getAnnotationIndex(
PADHit.type).iterator();
boolean skip = false;
while (annotHitItr.hasNext() && !skip) {
PADHit uaHit = ((PADHit) annotHitItr.next());
if (uaHit.getUaTerm() != null