Announcement

Collapse
No announcement yet.

Help converting rtf document to plain text

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help converting rtf document to plain text

    Does anyone have any suggestions as to how I might be able to convert a RTF document that I am extracting from an Oracle database using .getClob() to plain text for the receiving system which cannot handle rtf format?

  • #2
    Originally posted by seaston View Post
    Does anyone have any suggestions as to how I might be able to convert a RTF document that I am extracting from an Oracle database using .getClob() to plain text for the receiving system which cannot handle rtf format?
    Mirth Connect includes iText, so that may be your best bet. Though, you may also be able to just strip all RTF commands with a regular expression.
    Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

    Nicholas Rupley
    Work: 949-237-6069
    Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


    - How do I foo?
    - You just bar.

    Comment


    • #3
      This is what I have done so far (part of a transformer step), using regular expressions:

      Code:
      var results = new XML("<results/>");
      var result = dbConn.executeCachedQuery(query);
      
      result.beforeFirst();
      
      while (result.next()) {
      
      	var attendance = new XML("<attendance/>");
      	attendance["hospital_number"] = result.getString("hospital_number");
      	attendance["attendance_number"] = result.getString("attendance_number");
      	attendance["bookdate"] = result.getString("bookdate");
      	attendance["exams"] = result.getString("exams");
      	channelMap.put("report",result.getClob("reports"));
      	var cl=result.getClob("reports");
      	var strOut = new java.lang.StringBuffer();
      	var aux = new java.lang.String();
      	var br = new java.io.BufferedReader(cl.getCharacterStream());
      	while ((aux = br.readLine())!= null)
      		strOut.append(aux + "¬");
      	channelMap.put('gDocTextString', strOut);
      
      	// Using java.lang.String because javascript replace does not support negative lookbehind.
      	// These regular expressions seem to be quite effective at stripping out all the RTF control sequences
      	
      	resultString = java.lang.String(strOut).replaceAll("(?s)\\\\(par|line)(?=(\W|\\w+\\s|\\s|[{}]))", "¬");
      	resultString = java.lang.String(resultString).replaceAll("\\{\\*?\\\\[^{}]+\\}|\\\\(?=\\\\)|\\\\(?=[{}])|(?<!\\\\)[{}]|(?<!\\\\)\\\\[A-Za-z]+\n?(?:-?\\d+)?[ ]?", "");
      	resultString = java.lang.String(resultString).replaceAll("¬", "\n");
      	resultString = resultString.trim();
      	channelMap.put("resultString",resultString);
      	attendance["reports"] = resultString ;
      	results[""] += attendance;
          }
      
      
      dbConn.close();
      
      channelMap.put("results",results);
      tmp = results;

      I could not work out how to use iText to convert the rtf format to plain text. If anyone can help me out with an alternative to the code above using iText it would be appreciated.

      Comment


      • #4
        Which version of iText does Mirth use? Versions 5.0.0 and up don't include RTF support (that's been pushed to a separate project).

        Comment


        • #5
          Originally posted by sandersmr View Post
          Which version of iText does Mirth use? Versions 5.0.0 and up don't include RTF support (that's been pushed to a separate project).
          We're currently using version 2.0.8.
          Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

          Nicholas Rupley
          Work: 949-237-6069
          Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


          - How do I foo?
          - You just bar.

          Comment

          Working...
          X