/** * This method will be used for remote registration. Registered patient information will be placed * into an xml file for the FormEntry processor. * * @param paramPatient * @param paramString1 * @param paramString2 * @throws APIException */ public void registerPatient(Patient paramPatient, String paramString1, String paramString2) throws APIException { File localFile1 = OpenmrsUtil.getDirectoryInApplicationDataDirectory("amrsregistration"); File localFile2 = new File(localFile1, "registrationTemplate.xml"); try { String str1 = OpenmrsUtil.getFileAsString(localFile2); Properties localProperties = new Properties(); localProperties.setProperty("resource.loader", "class"); localProperties.setProperty( "class.resource.loader.description", "VelocityClasspathResourceLoader"); localProperties.setProperty( "class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); localProperties.setProperty( "runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem"); Velocity.init(localProperties); VelocityContext localVelocityContext = new VelocityContext(); localVelocityContext.put("locale", Context.getLocale()); localVelocityContext.put( "patient", Context.getPatientService().getPatient(paramPatient.getPatientId())); localVelocityContext.put("user", Context.getAuthenticatedUser()); localVelocityContext.put("fn", new DataExportFunctions()); localVelocityContext.put("dateEntered", new Date()); localVelocityContext.put("sid", paramString1); localVelocityContext.put("uid", paramString2); StringWriter localStringWriter = new StringWriter(); Velocity.evaluate(localVelocityContext, localStringWriter, super.getClass().getName(), str1); String str2 = Context.getAdministrationService().getGlobalProperty("remoteformentry.pending_queue_dir"); File localFile3 = OpenmrsUtil.getDirectoryInApplicationDataDirectory(str2); Date localDate = new Date(); String str3 = "amrsregistration_" + localDate.toString(); File localFile4 = new File(localFile3, str3); try { FileWriter localFileWriter = new FileWriter(localFile4); localFileWriter.write(localStringWriter.toString()); localFileWriter.flush(); localFileWriter.close(); } catch (IOException localIOException) { log.error("Unable to write amrsregistration output file.", localIOException); } } catch (Exception localException) { log.error("Unable to create amrsregistration output file", localException); throw new APIException(localException); } }
/** * Gets the xml that this queue item holds. If formData is null and fileSystemUrl is not null, the * data is "lazy loaded" from the filesystem * * @return Returns the formData. */ public String getFormData() { if (formData == null && fileSystemUrl != null) { // lazy load the form data from the filesystem File file = new File(fileSystemUrl); if (file.exists()) { try { formData = OpenmrsUtil.getFileAsString(file); return formData; } catch (IOException io) { log.warn("Unable to lazy load the formData from: " + fileSystemUrl, io); } } else { log.warn( "File system url does not exist for formentry archive item. Url: '" + fileSystemUrl + "'"); } } return formData; }
/** * Requires that the host system know how to compile/publish xsn files. If on linux, install * cabextract and lcab. * * @throws Exception */ @Test public void shouldUpdateXslFileButKeepNamesAsTriplets() throws Exception { executeDataSet("org/openmrs/include/standardTestDataset.xml"); executeDataSet("org/openmrs/module/formentry/test/include/extraConcepts.xml"); InputStream xslFileInputStream = getClass() .getClassLoader() .getResourceAsStream("org/openmrs/module/formentry/test/include/pre1.4.xsn"); Form form = PublishInfoPath.publishXSN(xslFileInputStream); FormEntryService formEntryService = (FormEntryService) Context.getService(FormEntryService.class); FormEntryXsn xsn = formEntryService.getFormEntryXsn(form); byte[] xsnbytes = xsn.getXsnData(); File tempDir = FormEntryUtil.expandXsnContents(xsn.getXsnData()); File xsl = new File(tempDir, "Page1.xsl"); String xslString = OpenmrsUtil.getFileAsString(xsl); // the concept names should have been inserted into the xsl file assertTrue(xslString.contains("xd:onValue=\"1142^MTCT STAFF^99DCT\"")); assertTrue(xslString.contains("\"obs/pay_category/value="1142^MTCT STAFF^99DCT"\"")); tempDir.delete(); }