use of ca.uhn.hl7v2.app.Application in project jmonkeyengine by jMonkeyEngine.
the class TestGhostObject method main.
public static void main(String[] args) {
Application app = new TestGhostObject();
app.start();
}
use of ca.uhn.hl7v2.app.Application in project openmrs-core by openmrs.
the class ADTA28Handler method processADT_A28.
private Message processADT_A28(ADT_A05 adt) throws HL7Exception {
// validate HL7 version
validate(adt);
// extract segments for convenient use below
MSH msh = getMSH(adt);
PID pid = getPID(adt);
// Obtain message control id (unique ID for message from sending
// application). Eventually avoid replaying the same message.
String messageControlId = msh.getMessageControlID().getValue();
log.debug("Found HL7 message in inbound queue with control id = " + messageControlId);
// Add creator of the patient to application
String sendingApp = msh.getSendingApplication().getComponent(0).toString();
log.debug("SendingApplication = " + sendingApp);
// Search for the patient
Integer patientId = findPatientId(pid);
// Create new patient if the patient id doesn't exist yet
if (patientId == null) {
log.info("Creating new patient in response to ADT_A28 " + messageControlId);
Patient patient = createPatient(pid, sendingApp);
if (patient == null) {
throw new HL7Exception("Couldn't create Patient object from PID");
}
Context.getPatientService().savePatient(patient);
} else {
log.info("Ignoring ADT_A28 message because patient (" + patientId + ") already exists.");
}
return adt;
}
use of ca.uhn.hl7v2.app.Application in project openmrs-core by openmrs.
the class HL7ServiceTest method processHL7Message_shouldParseMessageTypeSuppliedByModule.
/**
* @see HL7Service#processHL7Message(Message)
*/
@Test
@Ignore("TRUNK-3945")
public void processHL7Message_shouldParseMessageTypeSuppliedByModule() throws Exception {
Properties props = super.getRuntimeProperties();
props.setProperty(ModuleConstants.RUNTIMEPROPERTY_MODULE_LIST_TO_LOAD, "org/openmrs/hl7/include/examplehl7handlers-0.1.omod");
// the above module provides a handler for messages of type "ADR" with trigger "A19"
ModuleUtil.startup(props);
// the application context cannot restart here to load in the moduleApplicationContext that
// calls the setHL7Handlers method so we're doing it manually here
Class<Application> c = (Class<Application>) Context.loadClass("org.openmrs.module.examplehl7handlers.ADRHandler");
Application classInstance = c.newInstance();
HashMap<String, Application> map = new HashMap<>();
map.put("ADR_A19", classInstance);
HL7ServiceImpl.getInstance().setHL7Handlers(map);
HL7Service hl7service = Context.getHL7Service();
Message message = hl7service.parseHL7String("MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ADR^A19|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||3^^^^||John3^Doe^||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||450|||||||||20080206\r" + "OBX|2|DT|5096^RETURN VISIT DATE^99DCT||20080229|||||||||20080212");
Assert.assertNotNull(message);
try {
hl7service.processHL7Message(message);
Assert.fail("Should not be here. The ADR_A19 parser provided by the module throws an ApplicationException.");
} catch (HL7Exception e) {
if (e.getCause() != null)
Assert.assertEquals("In ADR A19 parser", e.getCause().getMessage());
else {
log.error("unable to parse message", e);
Assert.fail("something bad happened, check the log statement 1 line up");
}
}
ModuleUtil.shutdown();
}
use of ca.uhn.hl7v2.app.Application in project openmrs-core by openmrs.
the class ORUR01Handler method processORU_R01.
/**
* Bulk of the processing done here. Called by the main processMessage method
*
* @param oru the message to process
* @return the processed message
* @throws HL7Exception
* @should process multiple NK1 segments
*/
private Message processORU_R01(ORU_R01 oru) throws HL7Exception {
// TODO: ideally, we would branch or alter our behavior based on the
// sending application.
// validate message
validate(oru);
// extract segments for convenient use below
MSH msh = getMSH(oru);
PID pid = getPID(oru);
List<NK1> nk1List = getNK1List(oru);
PV1 pv1 = getPV1(oru);
// we're using the ORC assoc with first OBR to
ORC orc = getORC(oru);
// hold data enterer and date entered for now
// Obtain message control id (unique ID for message from sending
// application)
String messageControlId = msh.getMessageControlID().getValue();
if (log.isDebugEnabled()) {
log.debug("Found HL7 message in inbound queue with control id = " + messageControlId);
}
// create the encounter
Patient patient = getPatient(pid);
if (log.isDebugEnabled()) {
log.debug("Processing HL7 message for patient " + patient.getPatientId());
}
Encounter encounter = createEncounter(msh, patient, pv1, orc);
// do the discharge to location logic
try {
updateHealthCenter(patient, pv1);
} catch (Exception e) {
log.error("Error while processing Discharge To Location (" + messageControlId + ")", e);
}
// process NK1 (relationship) segments
for (NK1 nk1 : nk1List) {
processNK1(patient, nk1);
}
// list of concepts proposed in the obs of this encounter.
// these proposals need to be created after the encounter
// has been created
List<ConceptProposal> conceptProposals = new ArrayList<>();
// create observations
if (log.isDebugEnabled()) {
log.debug("Creating observations for message " + messageControlId + "...");
}
// we ignore all MEDICAL_RECORD_OBSERVATIONS that are OBRs. We do not
// create obs_groups for them
List<Integer> ignoredConceptIds = new ArrayList<>();
String obrConceptId = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_MEDICAL_RECORD_OBSERVATIONS, "1238");
if (StringUtils.hasLength(obrConceptId)) {
ignoredConceptIds.add(Integer.valueOf(obrConceptId));
}
// we also ignore all PROBLEM_LIST that are OBRs
String obrProblemListConceptId = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PROBLEM_LIST, "1284");
if (StringUtils.hasLength(obrProblemListConceptId)) {
ignoredConceptIds.add(Integer.valueOf(obrProblemListConceptId));
}
ORU_R01_PATIENT_RESULT patientResult = oru.getPATIENT_RESULT();
int numObr = patientResult.getORDER_OBSERVATIONReps();
for (int i = 0; i < numObr; i++) {
if (log.isDebugEnabled()) {
log.debug("Processing OBR (" + i + " of " + numObr + ")");
}
ORU_R01_ORDER_OBSERVATION orderObs = patientResult.getORDER_OBSERVATION(i);
// the parent obr
OBR obr = orderObs.getOBR();
if (!StringUtils.hasText(obr.getUniversalServiceIdentifier().getIdentifier().getValue())) {
throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.errorInvalidOBR ", new Object[] { messageControlId }, null));
}
// if we're not ignoring this obs group, create an
// Obs grouper object that the underlying obs objects will use
Obs obsGrouper = null;
Concept obrConcept = getConcept(obr.getUniversalServiceIdentifier(), messageControlId);
if (obrConcept != null && !ignoredConceptIds.contains(obrConcept.getId())) {
// maybe check for a parent obs group from OBR-29 Parent ?
// create an obs for this obs group too
obsGrouper = new Obs();
obsGrouper.setConcept(obrConcept);
obsGrouper.setPerson(encounter.getPatient());
obsGrouper.setEncounter(encounter);
Date datetime = getDatetime(obr);
if (datetime == null) {
datetime = encounter.getEncounterDatetime();
}
obsGrouper.setObsDatetime(datetime);
obsGrouper.setLocation(encounter.getLocation());
obsGrouper.setCreator(encounter.getCreator());
// set comments if there are any
StringBuilder comments = new StringBuilder();
ORU_R01_ORDER_OBSERVATION parent = (ORU_R01_ORDER_OBSERVATION) obr.getParent();
int totalNTEs = parent.getNTEReps();
for (int iNTE = 0; iNTE < totalNTEs; iNTE++) {
for (FT obxComment : parent.getNTE(iNTE).getComment()) {
if (comments.length() > 0) {
comments.append(" ");
}
comments.append(obxComment.getValue());
}
}
// only set comments if there are any
if (StringUtils.hasText(comments.toString())) {
obsGrouper.setComment(comments.toString());
}
// add this obs as another row in the obs table
encounter.addObs(obsGrouper);
}
// loop over the obs and create each object, adding it to the encounter
int numObs = orderObs.getOBSERVATIONReps();
HL7Exception errorInHL7Queue = null;
for (int j = 0; j < numObs; j++) {
if (log.isDebugEnabled()) {
log.debug("Processing OBS (" + j + " of " + numObs + ")");
}
OBX obx = orderObs.getOBSERVATION(j).getOBX();
try {
log.debug("Parsing observation");
Obs obs = parseObs(encounter, obx, obr, messageControlId);
if (obs != null) {
// the creator/dateCreated from the encounter
if (encounter.getEncounterId() != null) {
obs.setCreator(getEnterer(orc));
obs.setDateCreated(new Date());
}
// set the obsGroup on this obs
if (obsGrouper != null) {
// set the obs to the group. This assumes the group is already
// on the encounter and that when the encounter is saved it will
// propagate to the children obs
obsGrouper.addGroupMember(obs);
} else {
// set this obs on the encounter object that we
// will be saving later
log.debug("Obs is not null. Adding to encounter object");
encounter.addObs(obs);
log.debug("Done with this obs");
}
}
} catch (ProposingConceptException proposingException) {
Concept questionConcept = proposingException.getConcept();
String value = proposingException.getValueName();
// if the sender never specified any text for the proposed concept
if (!StringUtils.isEmpty(value)) {
conceptProposals.add(createConceptProposal(encounter, questionConcept, value));
} else {
errorInHL7Queue = new HL7Exception(Context.getMessageSourceService().getMessage("Hl7.proposed.concept.name.empty"), proposingException);
// stop any further processing of current message
break;
}
} catch (HL7Exception e) {
errorInHL7Queue = e;
} finally {
// Handle obs-level exceptions
if (errorInHL7Queue != null) {
throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.improperlyFormattedOBX", new Object[] { PipeParser.encode(obx, new EncodingCharacters('|', "^~\\&")) }, null), HL7Exception.DATA_TYPE_ERROR, errorInHL7Queue);
}
}
}
}
if (log.isDebugEnabled()) {
log.debug("Finished creating observations");
log.debug("Current thread: " + Thread.currentThread());
log.debug("Creating the encounter object");
}
Context.getEncounterService().saveEncounter(encounter);
// now that the encounter is saved
for (ConceptProposal proposal : conceptProposals) {
Context.getConceptService().saveConceptProposal(proposal);
}
return oru;
}
use of ca.uhn.hl7v2.app.Application in project openmrs-core by openmrs.
the class HL7ServiceTest method processHL7InQueue_shouldParseOruR01MessageUsingOverriddenParserProvidedByAModule.
/**
* @see HL7Service#processHL7InQueue(HL7InQueue)
*/
@Test
@Ignore("TRUNK-3945")
public void processHL7InQueue_shouldParseOruR01MessageUsingOverriddenParserProvidedByAModule() throws Exception {
executeDataSet("org/openmrs/hl7/include/ORUTest-initialData.xml");
Properties props = super.getRuntimeProperties();
props.setProperty(ModuleConstants.RUNTIMEPROPERTY_MODULE_LIST_TO_LOAD, "org/openmrs/hl7/include/examplehl7handlers-0.1.omod");
// the above module provides a handler for messages of type "ADR" with trigger "A19"
ModuleUtil.startup(props);
// the application context cannot restart here to load in the moduleApplicationContext that
// calls the setHL7Handlers method so we're doing it manually here
Class<Application> c = (Class<Application>) Context.loadClass("org.openmrs.module.examplehl7handlers.AlternateORUR01Handler");
Application classInstance = c.newInstance();
HashMap<String, Application> map = new HashMap<>();
map.put("ORU_R01", classInstance);
HL7ServiceImpl.getInstance().setHL7Handlers(map);
HL7Service hl7service = Context.getHL7Service();
// a valid ORU_R01
HL7InQueue queueItem = hl7service.getHL7InQueue(1);
// this will create 1 HL7InError item
hl7service.processHL7InQueue(queueItem);
List<HL7InError> errors = hl7service.getAllHL7InErrors();
// get the last error, the one made by this test presumably
HL7InError error = errors.get(errors.size() - 1);
Assert.assertTrue(error.getErrorDetails().contains("In alternate oru r01 parser"));
ModuleUtil.shutdown();
}
Aggregations