|
#1
|
|||
|
|||
|
Good day to all!
Hoping to get a little insight on a small problem I am having. I have a blank template as follows: MSH|^~\&|PD|PD|ENG|LAB||||||P|2.3|| PID|1||||^^||||||^^^^||||||||| PV1|1|O|PD^||||^^||||||||||||||||||||||||||||||||| |||||| ORC|||||||||^^^^^R|^^|||| OBR||||||||||||||||||||||||||| OBX|1|TX|||MICRO REPORT FOLLOWS:|||||| NTE|||| All is good with me populating the fields I need to. However, there are times when a segment is sent by the client which is not on the template (i.e DG1, IN1 etc...). They are not always sent so I did not put them into the template. But I want to include those extra segments unchanged. For some reason, with my current setup, they are deleted. My question is, how can I include the segments which are not a part of the template. Thank you in advance for any and all assistance. |
|
#2
|
|||
|
|||
|
Another problem with this is, there could be multiple segments.
Thanks again. |
|
#3
|
|||
|
|||
|
If you want to add segments to your outbound message, just do: "tmp.appendChild(segment);" So if you want to copy over all DG1 segments, you could do something like:
Code:
for each (dg1 in msg.DG1)
tmp.appendChild(dg1.copy());
|
|
#4
|
|||
|
|||
|
Thank you very much for you quick response Sir Sage.
May I ask just one more question to this point. Using your script, will that put the DG1 segments at the end of the rest of the defined segments or will they be placed in the same position as they come in? |
|
#5
|
|||
|
|||
|
Hmm.. This coding adds to the end of the segments. Is there another function that will add the undefined segments to their incoming position?
<thinking out loud> Unless I use createSegmentAfter and scroll thru each DG1?... |
|
#6
|
|||
|
|||
|
That will add them to the end of the message, not in the order that they appear. The problem with adding them in the order that they appear is that you have already defined an outbound message that has a MSH, PID, PV1, ORC, OBR, OBX and NTE segment.
Instead, what I would do is just create a bare-bones outbound template like "MSH|^~\&", iterate through each segment in msg in order, and add them (in order) to tmp as necessary. |
|
#7
|
|||
|
|||
|
Quote:
An extensive outbound template with multiple segments really should only be used when you're absolutely sure of what the expected format is going to be. If there are dynamic elements to the outbound message that depend on what the format of the incoming message is, then it's better to either 1) not use an outbound template at all and instead just modify msg, or 2) only use a bare-bones outbound template and add to it dynamically. |
|
#8
|
|||
|
|||
|
After trying a couple of things, and listening to your advice, I will go with option 1 and Not use the template. Too many variables with this client so it is best to have the most flexibility. Alas, no more drag and drop.
Again my thanks for your input and patience. |
|
#9
|
|||
|
|||
|
You can still use an outbound template and take advantage of the drag-and-drop functionality, and then just remove it when you're done. Then at the top of your code you'll have to manually initialize tmp, and at the end of your code you'll just have to overwrite msg with "msg = tmp.copy();".
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|