+ "PV2|||0112^TESTING|55555^PATIENT IS NORMAL|NONE|||19990225|19990226|1|1|TESTING|555888^NOTREAL^BOB^K^DR^MD||||||||||PROD^003^099|02|ER||NONE|19990225|19990223|19990316|NONE\r"
+ "AL1||SEV|001^POLLEN\r"
+ "AL1||SEV|003^DUST\r"
+ "GT1||0222PL|NOTREAL^BOB^B||STREET^OTHER STREET^CITY^ST^77787|(444)999-3333|(222)777-5555||||MO|111-33-5555||||NOTREAL GILL N|STREET^OTHER STREET^CITY^ST^99999|(111)222-3333\r"
+ "IN1||022254P|4558PD|BLUE CROSS|STREET^OTHER STREET^CITY^ST^00990||(333)333-6666||221K|LENIX|||19980515|19990515|||PATIENT01 TEST D||||||||||||||||||02LL|022LP554";
Parser p = new GenericParser();
Message hapiMsg = p.parse(msg);
/*
* Another way of reading messages is to use a Terser. The terser
* accepts a particular syntax to retrieve segments. See the API
* documentation for the Terser for more information.
*/
Terser terser = new Terser(hapiMsg);
/*
* Sending Application is in MSH-3-1 (the first component of the third
* field of the MSH segment)
*/
String sendingApplication = terser.get("/.MSH-3-1");
System.out.println(sendingApplication);
// HIS
/*
* We can use brackets to get particular repetitions
*/
String secondAllergyType = terser.get("/AL1(1)-3-2");
System.out.println(secondAllergyType);
// DUST
// We can also use the terser to set values
terser.set("/.MSH-3-1", "new_sending_app");
// Let's try something more complicated, adding values to an OBX in an ORU^R01
ORU_R01 oru = new ORU_R01();
oru.getMSH().getEncodingCharacters().setValue("^~\\&");
oru.getMSH().getFieldSeparator().setValue("|");
oru.getMSH().getMessageType().getMessageCode().setValue("ORU");
oru.getMSH().getMessageType().getTriggerEvent().setValue("R01");
oru.getMSH().getVersionID().getVersionID().setValue("2.5");
terser = new Terser(oru);
for (int i = 0; i < 5; i++) {
terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-1", "" + (i + 1));
terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-3", "ST");
terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-5", "This is the value for rep " + i);
}
System.out.println(p.encode(oru));
/*
* MSH|^~\&|||||||ORU^R01|||2.5
* OBX|1||ST||This is the value for rep 0
* OBX|2||ST||This is the value for rep 1