Announcement

Collapse
No announcement yet.

Problem with CSV file output

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

  • Problem with CSV file output

    Hello Everyone:

    I have been working on this problem for a couple days now and can't find a solution.

    I am converting a HL7 message into a flat csv file. This entails grabbing information from OBX segments but when ever a segment has more than one piece of data I get the following

    ,<OBX.5.1>Inhaler</OBX.5.1><OBX.5.1>Gum</OBX.5.1><OBX.5.1>Varenicline</OBX.5.1><OBX.5.1>Bupropion</OBX.5.1>,

    I also need to have the above data separated by a | to look like:

    ,inhaler|Gum|Varenicline|Bupropion,


    SAMPLE DATA

    MSH|^~\&|ANZER|PRH|COMM|PRH|20210712162355||ORU^R0 1|991B27B8A6E64E2C9BDE|P|2.5||||AL|||||
    EVN|R01|20210712162355|||ccd
    PID|1|0|125689||Test_125689^Fname^||20090818|M|||# 202-1599 Huron^^Mississauga^99^^||(999)999-9999||E|S||A*21-00003||||||||||||N
    PV1|1|I|2I^A011^1|L||^^|MUR^MURRAY^J SCOTT|^^|^^|ICU||||||N|PLAD^PLANTE^DANIEL|A|A*21-00003|S|||||||||||||||||||1804|||||20210702090723| 20210712161700
    OBR|1|||SMK^SMOKING CESSATION FORM|||20210712161600|20210712161600
    OBX|1|ST|Account Number||A*21-00003
    OBX|2|ST|MRN||125689
    OBX|3|ST|First Name||Fname
    OBX|4|ST|Last Name||Test_125689
    OBX|5|ST|Gender||M
    OBX|6|ST|Pregnant?||N
    OBX|7|ST|Breastfeeding?||N
    OBX|8|ST|Language||English
    OBX|9|ST|Main Phone #||999-999-9999
    OBX|10|ST|Alternative Phone #||
    OBX|11|ST|Birthdate||08/18/2009
    OBX|12|ST|Discharge Date||07/12/2021
    OBX|13|ST|Site||REGIONAL HOSPITAL
    OBX|14|ST|Unit/Clinic||2I A011-1
    OBX|15|ST|Unit Type||Inpt
    OBX|16|ST|Diagnosis/Visit Reason||ASTHMA
    OBX|17|ST|Used Tobacco Last 6m||Y
    OBX|18|ST|Cess. Aids used At Admission||Inhaler~Gum~Varenicline~Bupropion
    OBX|19|ST|Used Tobacco Last 7d||Y
    OBX|20|ST|Form of tobacco||Pipes~Smokeless~Cigarettes~Cigars
    OBX|21|ST|Num. of Cigs/Day||2
    OBX|22|ST|If not daily, Cigs/Montn||3
    OBX|23|ST|Num. of Years smoked||15
    OBX|24|ST|Min. After Waking||40
    OBX|25|ST|1-5 Import. to Quit||2
    OBX|26|ST|1-5 Conf. to Quit||4
    OBX|27|ST|Advised to Quit||Y
    OBX|28|ST|Feeling About Quitting||planning to quit in the next month
    OBX|29|ST|Past Quit Date||07/30/2021
    OBX|30|ST|Follow Up||Y
    OBX|31|ST|If Not, Why||
    OBX|32|ST|Follow Up Type||Phone
    OBX|33|ST|Email||
    OBX|34|ST|Pref. Follow Up Period||1-5 pm


    MY CODE IS AS FOLLOWS:

    var flatFileStr = "";
    for each (seg in msg.children())
    {
    if (seg.name().toString() == "OBX")
    {
    flatFileStr += seg['OBX.5']['OBX.5.1'].toString() + "," ;
    }
    }
    channelMap.put("flatFile", flatFileStr);


    CURRENT OUTPUT:

    A*21-00003,125689,Fname,Test_125689,M,N,N,English,999-999-9999,,08/18/2009,07/12/2021,REGIONAL HOSPITAL,2I A011-1,Inpt,ASTHMA,Y,<OBX.5.1>Inhaler</OBX.5.1><OBX.5.1>Gum</OBX.5.1><OBX.5.1>Varenicline</OBX.5.1><OBX.5.1>Bupropion</OBX.5.1>,Y,<OBX.5.1>Pipes</OBX.5.1><OBX.5.1>Smokeless</OBX.5.1><OBX.5.1>Cigarettes</OBX.5.1><OBX.5.1>Cigars</OBX.5.1>,2,3,15,40,2,4,Y,planning to quit in the next month,07/30/2021,Y,,Phone,,1-5 pm,


    any help would be appreciated

    Thanks

    Garry

  • #2
    You will have to iterate over OBX 5.1 to get each value. So another loop inside your current loop. There should be many links here on the forum that walk through that.
    Diridium Technologies, Inc.
    https://diridium.com

    Comment


    • #3
      Hi ghartlin, I am sure pacmano's solution will work but see if you can string replace <OBX.5.1> with empty string after creating the csv file. This is just a suggestion to your existing script but the best way is to use a loop inside an other loop.

      Comment

      Working...
      X