Announcement

Collapse
No announcement yet.

Need to force Windows style line endings for File Writer in Mirth 2.2.1

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

  • Need to force Windows style line endings for File Writer in Mirth 2.2.1

    I'm using a File Writer to write out an NVP (name-value pair) plain-text file, but I need to be able to write it out with Windows style line endings (CRLF) not the standard Unix style (LF). The receiving system is highly dependent on the style of the line endings, and I have no control over that.

    I can open up the template in a text editor (Notepad++) and see that it has the Windows line endings, but when the file is written out it only has the Unix endings.

    Here's a small sample of the NVP template:

    MRN:${patientMRN}
    Last Name:${patientLastName}
    First Name:${patientFirstName}
    Middle Name:
    DOB:${patientDOB}
    Gender:${patientSex}
    Attached Files

  • #2
    This might work...in a Javascript transfomer, do the following:

    var strCRLF = "\r\n";

    channelMap.put('strCRLF', strCRLF);

    Now in your destination, write your data, and at the end of the line you are writing add the STRCLF field, e.g.: blah blah data data $('strCRLF')

    Comment


    • #3
      Line Feed

      HI,

      I analysed your problem. Kindly refer the attachments to get a clear idea about it.. To create a platform independent LF, you can use line separator property or simply "\n"..
      Code:
      var outputStream = new java.io.FileOutputStream("/home/amarnath/samp/output/"+$('patientInternalId')+"(inbuilt).NVP");
      var writer= new java.io.OutputStreamWriter(outputStream);
      writer.write("MRN:"+$('patientInternalId'));
      writer.write("\nLast Name:"+$('patientLastName'));    
      // THE ABOVE CODE IS PLATFORM DEPENDENT AND VARIES IN DIFFERENT OS
      
      
      var outputStream = new java.io.FileOutputStream("/home/amarnath/samp/output/"+$('patientInternalId')+"(direct).NVP");
      var writer= new java.io.OutputStreamWriter(outputStream);
      writer.write("MRN:"+$('patientInternalId')+"\n");
      writer.write("Last Name:"+$('patientLastName')+"\n");
      //THE ABOVE CODE IS PLATFORM INDEPENDENT AND LOOKS THE SAME IN ALL OS
      Attached Files
      Amarnath. K

      Comment


      • #4
        In your File Writer template, right click and then check "Show Line Endings". Now you can see what you're putting in the template. You can use Enter or Shift+Enter to add different line endings.
        Jacob Brauer
        Director, Software Development
        NextGen Healthcare

        sigpic

        Comment


        • #5
          @ami199102 Thanks. I ended up having to use the Javascript Writer to write out the file.

          Code:
          var str = new java.lang.StringBuilder();
          str.append("MRN:").append($('patientInternalId')).append("\r\n");
          ...
          
          org.apache.commons.io.FileUtils.writeStringToFile(f, str.toString());

          Comment

          Working...
          X