// <span class="code-SummaryComment"><summary></span>
        /// Converts an HL7 message into a JSON Object from it's XML representation of the same message.
        /// <span class="code-SummaryComment"></summary></span>
        /// <span class="code-SummaryComment"><param name="sHL7">The HL7 to convert</param></span>
        /// <span class="code-SummaryComment"><returns></returns></span>
        public static string ConvertToJSON(string sHL7, JObject hl7metadata = null)
        {
            JObject o = HL7ToXmlConverter.ConvertToJObject(sHL7, hl7metadata);

            if (o == null)
            {
                return(null);
            }
            return(JsonConvert.SerializeObject(o["hl7message"]));
        }
Пример #2
0
 static void Main(string[] args)
 {
     //First argument is path to a file that contains a valid HL7 message.  (Must follow HL7 rules!!)
     if (args.Length > 0 && File.Exists(args[0]))
     {
         string        hl7     = File.ReadAllText(args[0]);
         JObject       obj     = HL7ToXmlConverter.ConvertToJObject(hl7);
         string        msgtype = obj["hl7message"]["MSH"]["MSH.9"].GetFirstField();
         StringBuilder builder = new StringBuilder();
         if (msgtype.Equals("ORU") || msgtype.Equals("MDM"))
         {
             if (obj["hl7message"]["OBX"] is JArray)
             {
                 foreach (var obx in obj["hl7message"]["OBX"])
                 {
                     if (Utilities.getFirstField(obx["OBX.2"]).Equals("TX") || Utilities.getFirstField(obx["OBX.2"]).Equals("FT"))
                     {
                         builder.Append(Utilities.getFirstField(obx["OBX.5"]).UnEscapeHL7());
                         builder.Append("\r\n");
                     }
                 }
             }
             else
             {
                 if (Utilities.getFirstField(obj["hl7message"]["OBX"]["OBX.2"]).Equals("TX") || Utilities.getFirstField(obj["hl7message"]["OBX"]["OBX.2"]).Equals("FT"))
                 {
                     builder.Append(Utilities.getFirstField(obj["hl7message"]["OBX"]["OBX.5"]).UnEscapeHL7());
                     builder.Append("\r\n");
                 }
             }
             Console.WriteLine(builder.ToString());
             Console.ReadLine();
         }
     }
     else
     {
         Console.WriteLine("Please pass in a valid path and file");
     }
 }