Could someone please help me on capturing the HL7 data into the SQL server using MIRTHCONNECT. I was searching for some examples and i was not able to find any tutorials which demonstrates looping through multiple segments. I was able to insert records into the database by going through the tutorials but still i`m stuck in doing the looping process.
Could someone please share me some links or give me some ideas so that i can go through those .
This is my initial thought to loop through each segment since i assume that Mirth connect reads a file line by line.
Thanks for the help
LOGIC -(I`m not sure whether this will be the right approach)
for each (seg in RAWFILE) {
if (seg.name().toString() == "MSH") {
insert into table values ();
}
if (seg.name().toString() == "PID") {
INSERT INTO TABLE2 VALUES ();
}
}
sample RAW DATA
MSH|^~&|LAB|CCF|||20040920080937||ORM^O01|42640000 009|P|2.3|
PID|||56797971||RESULTSREVIEW^TESTPATIENT^||196505 25|M||||||||||56797971|
PV1||O|UNKO^|||||
ORC|RE||A0203809||IP|||||||
OBR|1|A0203809|A0203809|400090^Complete Blood Count|||200609240000|||||||200609240847||deleted^^ ^^MD^^^^^^||||||200609241055|||P
OBX|1|ST|40010^White Blood Count (WBC) (x1000)||PENDING||||||P
OBX|2|ST|40020^Red Blood Count (RBC)||PENDING||||||P
ORC|RE||A0203809||CM|||||||
OBR|2|A0203809|A0203809|650300^Depakene (Valproic Acid) Level|||200609240000|||||||200609240847||^deleted^ ^^^MD^^^^^^||||||200609241055|||F
OBX|3|NM|65030^Depakene (Valproic Acid) Level||76.8|ug/ml|50-100||||F|||200609241054||
Sounds like you've got the db insertion working and you're having questions on how to handle repeating segments. Here is some code that I use in mirth for handling repeating segments. Of course your milage may vary but this should accomplish what you are wanting.
var segCount = 0;
// Loop through message and count number of OBX segments
for each (segment in msg.children()) {
if(segment.name() === 'OBX') {
segCount++;
}
}
// Make changes if there are OBX segments
if (segCount > 0) {
for (var i = 0; i < segCount; i++) {
tmp=msg;
// Add this segment to the database
insert into table values ();
// Here I am changing each OBX-5.1 to contain normal if OBX-3.1 is 'Some Text'
if (msg['OBX'][i]['OBX.3']['OBX.3.1'].toString() === 'Some text') {
tmp['OBX']['OBX.5']['OBX.5.1'] = 'Normal';
}
}
}