/** * Convenience constructor to build queue from a previously deleted queue entry * * @param hl7InArchive deleted entry from which queue entry will be constructed * @since 1.5 */ public HL7InQueue(HL7InArchive hl7InArchive) { setHL7Source(hl7InArchive.getHL7Source()); setHL7SourceKey(hl7InArchive.getHL7SourceKey()); setHL7Data(hl7InArchive.getHL7Data()); setMessageState(HL7Constants.HL7_STATUS_PENDING); }
/** * Convenience constructor to help convert a queue item into an exception */ public HL7InError(HL7InQueue hl7InQueue) { setHL7Source(hl7InQueue.getHL7Source()); setHL7SourceKey(hl7InQueue.getHL7SourceKey()); setHL7Data(hl7InQueue.getHL7Data()); }
/** * @see org.openmrs.hl7.HL7Service#saveHL7InQueue(org.openmrs.hl7.HL7InQueue) */ @Override public HL7InQueue saveHL7InQueue(HL7InQueue hl7InQueue) throws APIException { if (hl7InQueue.getDateCreated() == null) { hl7InQueue.setDateCreated(new Date()); } if (hl7InQueue.getMessageState() == null) { hl7InQueue.setMessageState(HL7Constants.HL7_STATUS_PENDING); } return dao.saveHL7InQueue(hl7InQueue); }
/** * Convenience constructor to build queue from a previously erred queue entry * * @param hl7InError erred entry from which queue entry will be constructed */ public HL7InQueue(HL7InError hl7InError) { setHL7Source(hl7InError.getHL7Source()); setHL7SourceKey(hl7InError.getHL7SourceKey()); setHL7Data(hl7InError.getHL7Data()); }
if (OpenmrsUtil.nullSafeEquals(HL7Constants.HL7_STATUS_PROCESSING, hl7InQueue.getMessageState())) { throw new HL7Exception("The hl7InQueue message with id: " + hl7InQueue.getHL7InQueueId() + " is already processing. " + ",key=" + hl7InQueue.getHL7SourceKey() + ")"); } else { hl7InQueue.setMessageState(HL7Constants.HL7_STATUS_PROCESSING); log.debug("Processing HL7 inbound queue (id=" + hl7InQueue.getHL7InQueueId() + ",key=" + hl7InQueue.getHL7SourceKey() + ")"); String hl7Message = hl7InQueue.getHL7Data(); try { log.debug("Unable to process hl7inqueue: " + hl7InQueue.getHL7InQueueId(), e); log.debug("Hl7inqueue source: " + hl7InQueue.getHL7Source()); log.debug("hl7_processor.ignore_missing_patient_non_local? " + Context.getAdministrationService().getGlobalProperty( if (e.getCause() != null && "Could not resolve patient".equals(e.getCause().getMessage()) && !"local".equals(hl7InQueue.getHL7Source().getName()) && "true".equals(Context.getAdministrationService().getGlobalProperty( OpenmrsConstants.GLOBAL_PROPERTY_IGNORE_MISSING_NONLOCAL_PATIENTS, "false"))) { setFatalError(hl7InQueue, "Trouble parsing HL7 message (" + hl7InQueue.getHL7SourceKey() + ")", e); setFatalError(hl7InQueue, "Exception while attempting to process HL7 In Queue (" + hl7InQueue.getHL7SourceKey() + ")", e);
/** * Creates new {@link HL7InQueue} instance from hl7 in queue message */ public IncomingHl7Message1_8(HL7InQueue message) { setSource(message.getHL7Source()); setSourceKey(message.getHL7SourceKey()); setData(message.getHL7Data()); setMessageState(message.getMessageState()); setUuid(message.getUuid()); }
@Test public void enqueHl7Message_shouldEnqueueHl7InQueueMessageInPlainFormat() throws Exception { int before = service.getAllHL7InQueues().size(); MockHttpServletRequest req = newPostRequest(getURI(), hl7Data); SimpleObject newHl7Message = deserialize(handle(req)); Util.log("Enqued hl7 message", newHl7Message); Assert.assertEquals(before + 1, service.getAllHL7InQueues().size()); for (HL7InQueue hl7InQueue : service.getAllHL7InQueues()) { if (hl7InQueue.getUuid().equals(newHl7Message.get("uuid"))) { Assert.assertEquals(hl7InQueue.getHL7Data(), hl7Data); } } }
log.debug("Processing HL7 inbound queue (id=" + hl7InQueue.getHL7InQueueId() + ",key=" + hl7InQueue.getHL7SourceKey() + ")");
/** * @throws HL7Exception * @see HL7Service#processHL7InQueue(HL7InQueue) */ @Test(expected = HL7Exception.class) public void processHL7InQueue_shouldFailIfGivenInQueueIsAlreadyMarkedAsProcessing() throws HL7Exception { executeDataSet("org/openmrs/hl7/include/ORUTest-initialData.xml"); HL7Service hl7service = Context.getHL7Service(); HL7InQueue queueItem = hl7service.getHL7InQueue(1); queueItem.setMessageState(HL7Constants.HL7_STATUS_PROCESSING); // set this to processing hl7service.processHL7InQueue(queueItem); }
@Test public void enqueHl7Message_shouldEnqueueHl7InQueueMessageInJSONFormat() throws Exception { int before = service.getAllHL7InQueues().size(); SimpleObject hl7Message = new SimpleObject(); hl7Message.add("hl7", hl7Data); MockHttpServletRequest req = newPostRequest(getURI(), hl7Message); SimpleObject newHl7Message = deserialize(handle(req)); Assert.assertEquals(before + 1, service.getAllHL7InQueues().size()); for (HL7InQueue hl7InQueue : service.getAllHL7InQueues()) { if (hl7InQueue.getUuid().equals(newHl7Message.get("uuid"))) { Assert.assertEquals(hl7InQueue.getHL7Data(), hl7Data); } } }
/** * @see HL7Service#saveHL7InQueue(HL7InQueue) */ @Test public void saveHL7InQueue_shouldAddGeneratedUuidIfUuidIsNull() { HL7InQueue hl7 = new HL7InQueue(); hl7.setHL7Data("dummy data"); hl7.setHL7Source(new HL7Source(1)); hl7.setHL7SourceKey("a random key"); hl7.setMessageState(HL7Constants.HL7_STATUS_PROCESSING); Context.getHL7Service().saveHL7InQueue(hl7); Assert.assertNotNull(hl7.getUuid()); }
/** * Convenience constructor to build archive from an existing queue entry * * @param hl7InQueue queue entry from which archive entry will be constructed */ public HL7InArchive(HL7InQueue hl7InQueue) { setHL7Source(hl7InQueue.getHL7Source()); setHL7SourceKey(hl7InQueue.getHL7SourceKey()); setHL7Data(hl7InQueue.getHL7Data()); setMessageState(HL7Constants.HL7_STATUS_PROCESSED); }
/** * Creates new {@link HL7InQueue} instance from itself * * @return new {@link HL7InQueue} instance */ public HL7InQueue toHL7InQueue() { HL7InQueue result = new HL7InQueue(); result.setHL7Source(getSource()); result.setHL7SourceKey(getSourceKey()); result.setHL7Data(getData()); if (getMessageState() != null) result.setMessageState(getMessageState()); else result.setMessageState(HL7Constants.HL7_STATUS_PENDING); return result; }
@Override public IncomingHl7Message1_8 newObject() { HL7InQueue msg = new HL7InQueue(); msg.setHL7Data("hl7Data"); msg.setHL7SourceKey("sourceKey"); msg.setHL7Source(Context.getHL7Service().getHL7SourceByName(RestTestConstants1_8.HL7_SOURCE_NAME)); Context.getHL7Service().saveHL7InQueue(msg); return new IncomingHl7Message1_8(msg); }