use of org.openmrs.hl7.HL7InArchive in project openmrs-core by openmrs.
the class HibernateHL7DAO method getHL7InArchiveByUuid.
/**
* @see org.openmrs.hl7.db.HL7DAO#getHL7InArchiveByUuid(java.lang.String)
*/
@Override
public HL7InArchive getHL7InArchiveByUuid(String uuid) throws DAOException {
Query query = sessionFactory.getCurrentSession().createQuery("from HL7InArchive where uuid = ?").setParameter(0, uuid, StandardBasicTypes.STRING);
Object record = query.uniqueResult();
if (record == null) {
return null;
}
return (HL7InArchive) record;
}
use of org.openmrs.hl7.HL7InArchive in project openmrs-core by openmrs.
the class HL7ServiceImpl method migrateHl7InArchivesToFileSystem.
/**
* @see org.openmrs.hl7.HL7Service#migrateHl7InArchivesToFileSystem(Map)
*/
@Override
public void migrateHl7InArchivesToFileSystem(Map<String, Integer> progressStatusMap) throws APIException {
int numberTransferred = 0;
int numberOfFailedTransfers = 0;
// HL7Constants.HL7_STATUS_ARCHIVED indicates the HL7 has been archived to the filesystem
List<HL7InArchive> hl7InArchives = getHL7InArchivesToMigrate();
// while we still we have any archives to be processed, process them
while (Hl7InArchivesMigrateThread.isActive() && Hl7InArchivesMigrateThread.getTransferStatus() == Status.RUNNING && hl7InArchives != null && !hl7InArchives.isEmpty()) {
Iterator<HL7InArchive> iterator = hl7InArchives.iterator();
while (Hl7InArchivesMigrateThread.isActive() && Hl7InArchivesMigrateThread.getTransferStatus() == Status.RUNNING && iterator.hasNext()) {
HL7InArchive archive = iterator.next();
try {
migrateHL7InArchive(archive);
progressStatusMap.put(HL7Constants.NUMBER_TRANSFERRED_KEY, numberTransferred++);
} catch (DAOException e) {
progressStatusMap.put(HL7Constants.NUMBER_OF_FAILED_TRANSFERS_KEY, numberOfFailedTransfers++);
}
}
// fetch more archives to be processed
hl7InArchives = getHL7InArchivesToMigrate();
}
if (log.isDebugEnabled()) {
log.debug("Transfer of HL7 archives has completed or has been stopped");
}
}
use of org.openmrs.hl7.HL7InArchive in project openmrs-core by openmrs.
the class HL7ServiceImpl method processHL7InQueue.
/**
* @see org.openmrs.hl7.HL7Service#processHL7InQueue(org.openmrs.hl7.HL7InQueue)
*/
@Override
public HL7InQueue processHL7InQueue(HL7InQueue hl7InQueue) throws HL7Exception {
if (hl7InQueue == null) {
throw new HL7Exception("hl7InQueue argument cannot be null");
}
// mark this queue object as processing so that it isn't processed twice
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);
}
if (log.isDebugEnabled()) {
log.debug("Processing HL7 inbound queue (id=" + hl7InQueue.getHL7InQueueId() + ",key=" + hl7InQueue.getHL7SourceKey() + ")");
}
// Parse the HL7 into an HL7Message or abort with failure
String hl7Message = hl7InQueue.getHL7Data();
try {
// Parse the inbound HL7 message using the parser
// NOT making a direct call here so that AOP can happen around this
// method
Message parsedMessage = Context.getHL7Service().parseHL7String(hl7Message);
// Send the parsed message to our receiver routine for processing
// into db
// NOT making a direct call here so that AOP can happen around this
// method
Context.getHL7Service().processHL7Message(parsedMessage);
// Move HL7 inbound queue entry into the archive before exiting
log.debug("Archiving HL7 inbound queue entry");
Context.getHL7Service().saveHL7InArchive(new HL7InArchive(hl7InQueue));
log.debug("Removing HL7 message from inbound queue");
Context.getHL7Service().purgeHL7InQueue(hl7InQueue);
} catch (HL7Exception e) {
boolean skipError = false;
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(OpenmrsConstants.GLOBAL_PROPERTY_IGNORE_MISSING_NONLOCAL_PATIENTS, "false"));
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"))) {
skipError = true;
}
if (!skipError) {
setFatalError(hl7InQueue, "Trouble parsing HL7 message (" + hl7InQueue.getHL7SourceKey() + ")", e);
}
} catch (Exception e) {
setFatalError(hl7InQueue, "Exception while attempting to process HL7 In Queue (" + hl7InQueue.getHL7SourceKey() + ")", e);
}
return hl7InQueue;
}
Aggregations