/** * @see org.openmrs.hl7.HL7Service#saveHL7InArchive(org.openmrs.hl7.HL7InArchive) */ @Override public HL7InArchive saveHL7InArchive(HL7InArchive hl7InArchive) throws APIException { if (hl7InArchive.getDateCreated() == null) { hl7InArchive.setDateCreated(new Date()); } return dao.saveHL7InArchive(hl7InArchive); }
/** * @see org.openmrs.hl7.HL7Service#loadHL7InArchiveData(HL7InArchive) */ @Override public void loadHL7InArchiveData(HL7InArchive archive) throws APIException { // quit early if there is no archive to work with if (archive == null) { return; } // quit early if the message is not migrated or already loaded if (!OpenmrsUtil.nullSafeEquals(archive.getMessageState(), HL7Constants.HL7_STATUS_MIGRATED) || archive.isLoaded()) { return; } try { archive.setHL7Data(OpenmrsUtil.getFileAsString(new File(new URI(archive.getHL7Data())))); archive.setLoaded(true); } catch (URISyntaxException e) { throw new APIException("Hl7Service.malformed.archive.location", new Object[] { archive.getHL7Data() }, e); } catch (IOException e) { throw new APIException("Hl7Service.unable.convert.archive", new Object[] { archive.getHL7Data() }, e); } }
/** * @see org.openmrs.OpenmrsObject#getId() * @since 1.5 */ @Override public Integer getId() { return getHL7InArchiveId(); }
calendar.setTime(hl7InArchive.getDateCreated()); File fileToWriteTo = new File(dayDir, hl7InArchive.getUuid() + (StringUtils.isBlank(hl7InArchive.getHL7SourceKey()) ? "" : "_" + hl7InArchive.getHL7SourceKey()) + ".txt"); writer.write(hl7InArchive.getHL7Data()); log.warn("An Error occured while writing hl7 archive with id '" + hl7InArchive.getHL7InArchiveId() + "' to the file system"); throw new APIException("Hl7Service.write.no.error", (Object[]) null); .warn("Failed to write hl7 archive with id '" + hl7InArchive.getHL7InArchiveId() + "' to the file system ", e); throw new APIException("Hl7Service.write.error", null, e);
/** * 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); }
/** * moves data to the filesystem from an HL7InArchive * * @param archive * @throws APIException */ private void migrateHL7InArchive(HL7InArchive archive) throws APIException { if (archive == null) { throw new APIException("Hl7Service.migrate.null.archive", (Object[]) null); } if (!OpenmrsUtil.nullSafeEquals(archive.getMessageState(), HL7Constants.HL7_STATUS_PROCESSED)) { throw new APIException("Hl7Service.migrate.archive.state", (Object[]) null); } try { URI uri = writeHL7InArchiveToFileSystem(archive); archive.setHL7Data(uri.toString()); archive.setMessageState(HL7Constants.HL7_STATUS_MIGRATED); saveHL7InArchive(archive); } catch (APIException e) { throw new APIException("Hl7Service.migrate.archive", null, e); } }
Context.getHL7Service().saveHL7InArchive(new HL7InArchive(hl7InQueue));