Coverage Report - ca.uhn.hl7v2.app.HL7FileMsgCorrector
 
Classes in this File Line Coverage Branch Coverage Complexity
HL7FileMsgCorrector
0%
0/25
0%
0/2
1.667
 
 1  
 /*
 2  
  * Created on Apr 14, 2005
 3  
  * HL7FileMsgCorrector.java
 4  
  * 
 5  
  */
 6  
 package ca.uhn.hl7v2.app;
 7  
 
 8  
 import java.io.BufferedReader;
 9  
 import java.io.BufferedWriter;
 10  
 import java.io.FileWriter;
 11  
 import java.io.IOException;
 12  
 import java.io.InputStream;
 13  
 import java.io.InputStreamReader;
 14  
 
 15  
 import org.slf4j.Logger;
 16  
 import org.slf4j.LoggerFactory;
 17  
 
 18  
 
 19  
 /**
 20  
  * This is an application that will perform specific translations on the
 21  
  * hl7 messages stored within a flat file.  It will output the new messages to 
 22  
  * "./correctedMessageFile.txt"  
 23  
  * 
 24  
  * @author <a href="mailto:neal.acharya@uhn.on.ca">Neal Acharya</a>
 25  
  * @version $Revision: 1.1 $ updated on $Date: 2007-02-19 02:24:37 $ by $Author: jamesagnew $
 26  
  * @deprecated
 27  
  */
 28  
 public class HL7FileMsgCorrector {
 29  
     
 30  0
     private static final Logger ourLog =  LoggerFactory.getLogger(HL7FileMsgCorrector.class);
 31  
 
 32  
     /**
 33  
      * 
 34  
      */
 35  
     public HL7FileMsgCorrector() {
 36  0
         super();
 37  
         // TODO Auto-generated constructor stub
 38  0
     }
 39  
 
 40  
 
 41  
     public static void main(String[] args) {
 42  
         
 43  
         //NOTE, depending on the size of the flat file you may need to increase the stack
 44  
         //and heap size of the JVM when running this class.
 45  
         //If so then use the following VM args -Xmx512m -Xms512m -Xss2m
 46  
         
 47  0
         String fileName = "./QueuedRoutStatOrders.dat";
 48  0
         InputStream inputStream = HL7FileMsgCorrector.class.getClassLoader().getResourceAsStream(fileName);
 49  
               
 50  
         try {
 51  0
             BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream  ) );  
 52  0
             BufferedWriter writer = new BufferedWriter(new FileWriter("./correctedMessageFile.txt"));
 53  
             
 54  0
             String lineRead = null;
 55  0
             StringBuffer buf = new StringBuffer();
 56  0
             while ((lineRead = reader.readLine()) != null) {                
 57  0
                 buf.append(lineRead);
 58  0
                 buf.append("\r");
 59  
             }
 60  0
             String fileString = buf.toString().trim();
 61  
             
 62  
             //Perform a translation
 63  0
             String newFileString = addPreMshCarriageReturns(fileString);
 64  
             
 65  
             //write the string to a file
 66  0
             writer.write(newFileString);            
 67  0
             writer.close();
 68  0
             ourLog.info("file conversion completed");
 69  
         }
 70  0
         catch (IOException e) {
 71  
             // TODO Auto-generated catch block
 72  0
             e.printStackTrace();
 73  0
         }       
 74  
         
 75  0
     }
 76  
 
 77  
 
 78  
     /**
 79  
      * @param theFileString ..
 80  
      * @return ...
 81  
      * Adds two carriage returns before each MSH segment
 82  
      * we expect the file to be used by the HL7ServerTestHelper         
 83  
      */
 84  
     private static String addPreMshCarriageReturns(String theFileString) {
 85  0
         theFileString = theFileString.replaceAll(".MSH\\|", "\rMSH|");
 86  0
         theFileString = theFileString.replaceAll("MSH\\|", "\rMSH|");
 87  0
         theFileString = theFileString.replaceAll("//", "");
 88  0
         return theFileString;
 89  
     }
 90  
 }