Announcement

Collapse
No announcement yet.

Creating a message mapping in Javascript

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

  • Creating a message mapping in Javascript

    Our current project is using Mirth as a front-end to a Ruby on Rails application. Right now I'm working out how to get any HL7 message in and process it into an HTTP POST call.

    What I'm working towards is getting in a message like this
    Code:
    MSH|^~&|LinkLogic-2009|2009001^ALL|MedicalProblemsDB|ALL|20070501124502||PPR^PC2|1493642702350870|P|2.3|||NE|NE
    PID|1|34|256546||Smith^Bob^Q||19470508|F||U|1234 Lake Ave^^Fort Wayne^IN^46815||(212)555-8059|||U|||000-00-0000
    PV1|1|O|^^^ALL
    PRB|UP|20070501124353|924.11^CONTUSION^I9|1493642573000890||||||||||||20070501||1|Diagnosis of
    PRB|UP|20070501124353|719.46^PAIN-KNEE^I9|1493642573150890||||||||||||20070501||1|Diagnosis of
    PRB|UP|20070501124353|844.9^SPRAIN/STRAIN^I9|1493642573300890||||||||||||20070501||1|Diagnosis of
    and making an HTTP POST call like this

    Is there a built-in JavaScript function that will help me to step through the message like this?

    I'm thinking it has to be done in JavaScript because I want every message, no matter what type, to be processed and passed on. So converting from in JavaScript msg['PID']['PID.5']['PID.5.1'] to the PID_5_1 HTTP variable happens without creating a map by hand.

    I think a recursive function in JavaScript using the message segment keys method to step through and channelMap.put will work, but I wanted to ask if there was a faster way to do this before creating that method.

    Post edited by: jbartels, at: 08/13/2007 12:47

    Post edited by: jbartels, at: 08/13/2007 12:47
    Jon Bartels

    Zen is hiring!!!!
    http://consultzen.com/careers/
    Talented healthcare IT professionals wanted. Engineers to sales to management.
    Good benefits, great working environment, genuinely interesting work.

  • #2
    Re:Creating a message mapping in Javascript

    My JavaScript is rusty but this is what I was thinking:

    Code:
    //define our recursive function
    function recurseThruMessage(segment)
    {
    	//if we are at a segment containing data and not more segments
    	if (segment.keys.length == 0)
    	{
    		//replaces dots in key name with underscores as the new key name then inserts the value
    		channelMap.put(key.replace(/\./g,"_"),segment[key])
    	}
    	//otherwise we have more segments to process
    	else
    	{
    		//step through each segment
    		for(var key in segment)
    		{
    			recurseThruMessage(segment[key])
    		}
    	}
    }	
    
    //send the entire message as the starting set
    recurseThruMessage(msg)
    Post edited by: jbartels, at: 08/13/2007 13:08
    Jon Bartels

    Zen is hiring!!!!
    http://consultzen.com/careers/
    Talented healthcare IT professionals wanted. Engineers to sales to management.
    Good benefits, great working environment, genuinely interesting work.

    Comment


    • #3
      Re:Creating a message mapping in Javascript

      Code:
      //define our recursive function
      function recurseThruMessage(segment)
      {
      	for (var key in segment)
      	{
      		//if we are at a segment containing data and not more segments
      		if (typeof segment[key] != Array)
      		{
      			//replaces dots in key name with underscores as the new key name then inserts the value
      			channelMap.put(key.replace(/\./g,"_"«»), segment[key])
      		}
      		//otherwise we have more segments to process
      		else
      		{
      			//step through each segment
      			recurseThruMessage(segment[key])
      		}
      	}
      }	
      
      //send the entire message as the starting set
      recurseThruMessage(msg)
      The mapping keeps showing up with the variable field set to "0" and the value equaling the XML representation of the message. I suspect it lies in the typeof condition. That should only hit when it gets to a piece of data that is a string or a number then do the mapping.

      The message board keeps eating my regular expression too. The regex for the replace method is /\./g.
      Jon Bartels

      Zen is hiring!!!!
      http://consultzen.com/careers/
      Talented healthcare IT professionals wanted. Engineers to sales to management.
      Good benefits, great working environment, genuinely interesting work.

      Comment


      • #4
        Re:Creating a message mapping in Javascript

        Channel is attached.

        I'm stumped as to how to get this work. Any help is appreciated! HL7_to_REST.xml (5714 bytes)
        Jon Bartels

        Zen is hiring!!!!
        http://consultzen.com/careers/
        Talented healthcare IT professionals wanted. Engineers to sales to management.
        Good benefits, great working environment, genuinely interesting work.

        Comment


        • #5
          Re:Creating a message mapping in Javascript

          Ok. I got it mostly working (thanks to gerald for pointing me to the e4x reference!).

          The mappings are coming through like I want them to, now I'm lost as to how I actually tell the sender to send everything in the map.

          Do I need to do this in JavaScript in the transformer? If so how, if not where? HL7_to_REST-c48578e259d7d126eb244c65886a8040.xml (6432 bytes)
          Jon Bartels

          Zen is hiring!!!!
          http://consultzen.com/careers/
          Talented healthcare IT professionals wanted. Engineers to sales to management.
          Good benefits, great working environment, genuinely interesting work.

          Comment


          • #6
            Re:Creating a message mapping in Javascript

            Last post. I got it working. HL7_to_REST-e1e03e305d8af79d35309ccd90f34899.xml (6827 bytes)
            Jon Bartels

            Zen is hiring!!!!
            http://consultzen.com/careers/
            Talented healthcare IT professionals wanted. Engineers to sales to management.
            Good benefits, great working environment, genuinely interesting work.

            Comment

            Working...
            X