Search in sources :

Example 1 with HL7InArchive

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;
}
Also used : HL7InArchive(org.openmrs.hl7.HL7InArchive) Query(org.hibernate.Query)

Example 2 with HL7InArchive

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");
    }
}
Also used : DAOException(org.openmrs.api.db.DAOException) HL7InArchive(org.openmrs.hl7.HL7InArchive)

Example 3 with HL7InArchive

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;
}
Also used : HL7InArchive(org.openmrs.hl7.HL7InArchive) Message(ca.uhn.hl7v2.model.Message) HL7Exception(ca.uhn.hl7v2.HL7Exception) URISyntaxException(java.net.URISyntaxException) DAOException(org.openmrs.api.db.DAOException) FileNotFoundException(java.io.FileNotFoundException) APIException(org.openmrs.api.APIException) HL7Exception(ca.uhn.hl7v2.HL7Exception) EncodingNotSupportedException(ca.uhn.hl7v2.parser.EncodingNotSupportedException) IOException(java.io.IOException) PatientIdentifierException(org.openmrs.api.PatientIdentifierException) ApplicationException(ca.uhn.hl7v2.app.ApplicationException)

Aggregations

HL7InArchive (org.openmrs.hl7.HL7InArchive)3 DAOException (org.openmrs.api.db.DAOException)2 HL7Exception (ca.uhn.hl7v2.HL7Exception)1 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)1 Message (ca.uhn.hl7v2.model.Message)1 EncodingNotSupportedException (ca.uhn.hl7v2.parser.EncodingNotSupportedException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 Query (org.hibernate.Query)1 APIException (org.openmrs.api.APIException)1 PatientIdentifierException (org.openmrs.api.PatientIdentifierException)1