public void endElement()

in ctakes-preprocessor/src/main/java/org/apache/ctakes/preprocessor/ClinicalNotePreProcessor.java [704:835]


    public void endElement(String uri, String localName, String qName)
            throws SAXException
    { // must be first statement of method to properly capture contiguous text nodes
        if (iv_contiguousTextBuffer.length() > 0)
        {
            newTextNode();
        }

        if (iv_insideHeader)
        {
            if (localName.equals("clinical_document_header"))
            {
                iv_insideHeader = false;
            }
            else if (iv_insideAdminData && localName.equals("cn1_admin_data"))
            {
                iv_insideAdminData = false;
            }
            else if (iv_insideTranscriptionist
                    && localName.equals("transcriptionist"))
            {
                iv_insideTranscriptionist = false;
            }
            else if (iv_insidePatientEncounter
                    && localName.equals("patient_encounter"))
            {
                iv_insidePatientEncounter = false;
            }
            else if (iv_insideLegalAuth
                    && localName.equals("legal_authenticator"))
            {
                iv_insideLegalAuth = false;
            }
            else if (localName.equals("provider"))
            {
                iv_insideProvider = false;
            }
            else if (localName.equals("service_location"))
            {
                iv_insideServiceLoc = false;
            }
        }
        else if (localName.equals("paragraph"))
        {
            iv_sectionText.append('\n');
        }
        else if (iv_insideSection && localName.equals("section"))
        {
            iv_sectionNestingLevel--;

            if (iv_sectionNestingLevel == 0)               
            {
                if (iv_sectionText.toString().trim().length() > 0)
                {
                    String sectionStartMarker = getSectionStartMarker(iv_sectionIdentifier);
                    iv_text.append(sectionStartMarker);
                    iv_text.append('\n');
                    iv_text.append('\n');
                    if (!iv_includeSectionMarkers)
                    {
                        // skip past the section marker text
                        iv_sectionStartOffset = iv_text.length();
                    }

                    iv_text.append(compress(iv_sectionText));
                    SegmentMetaData smd = new SegmentMetaData();
                    IntegerRange span = new IntegerRange();
                    span.start = iv_sectionStartOffset;
                    span.end = iv_text.length();
                    smd.span = span;
                    smd.id = iv_sectionIdentifier;
                    iv_docMetaData.addSegment(smd);
                    String sectionEndMarker = getSectionEndMarker(iv_sectionIdentifier);
                    iv_text.append('\n');
                    iv_text.append(sectionEndMarker);
                    iv_text.append('\n');
                    iv_text.append('\n');                    
                }

                iv_insideSection = false;
                iv_sectionIdentifier = null;
                iv_sectionText = null;
            }
        }
        else if (iv_insideCaption && localName.equals("caption"))
        {
            iv_insideCaption = false;
        }
        else if (iv_insideTable && localName.equals("table"))
        {

            // iv_tableType = UNKNOWN_TABLE_TYPE;
            iv_tdCounter = 0;
            iv_headerList.clear();
            iv_insideTable = false;
        }
        else if (iv_insideTableRow && localName.equals("tr"))
        {
            iv_examComponentText = null;
            iv_insideExamComponent = false;
            iv_examComponentTableDataCnt = 0;
            iv_insideTableRow = false;
            iv_tableHeaderKeyID = null;
            iv_sectionText.append('\n');
        }
        else if (iv_insideTableRow && localName.equals("th"))
        {
            iv_insideTableHeader = false;
        }
        else if (iv_insideTableRow && localName.equals("td"))
        {
            if (iv_tdCounter < iv_headerList.size())
            {
                String thText = iv_headerList.get(iv_tdCounter);
                Annotation a = new Annotation();
                a.iv_type = thText;
                a.startOffset = iv_tdStartOffset;
                compress(iv_sectionText);
                a.endOffset = iv_text.length() + iv_sectionText.length();
                iv_docMetaData.addAnnotation(a);
            }
            iv_insideTableData = false;
            iv_sectionText.append(' ');
            iv_tdCounter++;
        }
        else if (iv_insideTableRow && localName.equals("br"))
        {
            // there are line breaks in the clinical note
            // inject a newline character for each <br/>
            iv_sectionText.append('\n');
        }
    }