ComplexData complexData = obs.getComplexData(); if (complexData == null) { log.error("Cannot save complex data where obsId=" + obs.getObsId() + " because its ComplexData is null."); fout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfile), StandardCharsets.UTF_8)); Reader tempRd; Object data = obs.getComplexData().getData(); if (data instanceof char[]) { fout.write((char[]) data);
/** * @see org.openmrs.obs.ComplexObsHandler#saveObs(org.openmrs.Obs) */ @Override public Obs saveObs(Obs obs) throws APIException { try { // Write the File to the File System String fileName = obs.getComplexData().getTitle(); File outfile = getOutputFileToWrite(obs); OutputStream out = new FileOutputStream(outfile, false); FileInputStream mediaStream = (FileInputStream) obs.getComplexData().getData(); OpenmrsUtil.copyFile(mediaStream, out); // Store the filename in the Obs obs.setComplexData(null); obs.setValueComplex(fileName + "|" + outfile.getName()); // close the stream out.close(); } catch (IOException ioe) { throw new APIException("Obs.error.trying.write.complex", null, ioe); } return obs; }
/** * @see ComplexObsHandler#saveObs(Obs) */ @Override public Obs saveObs(Obs obs) throws APIException { try { // Write the File to the File System String fileName = obs.getComplexData().getTitle(); InputStream in = (InputStream) obs.getComplexData().getData(); File outfile = getOutputFileToWrite(obs); OutputStream out = new FileOutputStream(outfile, false); OpenmrsUtil.copyFile(in, out); // Store the filename in the Obs obs.setComplexData(null); obs.setValueComplex(fileName + "|" + outfile.getName()); // close the stream out.close(); } catch (Exception e) { throw new APIException("Obs.error.writing.binary.data.complex", null, e); } return obs; }
public Obs saveObs(Obs obs) throws APIException { ComplexData complexData = obs.getComplexData(); if (complexData == null) { log.error("Cannot save complex data where obsId=" + obs.getObsId() + " because its ComplexData is null."); fout = new FileOutputStream(outfile); Object data = obs.getComplexData().getData(); if (data instanceof byte[]) { fout.write((byte[]) data);
/** * Returns a {@link File} for the given obs complex data to be written to. The output file * location is determined off of the {@link OpenmrsConstants#GLOBAL_PROPERTY_COMPLEX_OBS_DIR} * and the file name is determined off the current obs.getComplexData().getTitle(). * * @param obs the Obs with a non-null complex data on it * @return File that the complex data should be written to */ public File getOutputFileToWrite(Obs obs) throws IOException { String title = obs.getComplexData().getTitle(); String titleWithoutExtension = FilenameUtils.removeExtension(title); String extension = "." + StringUtils.defaultIfEmpty(FilenameUtils.getExtension(title), "dat"); String uuid = obs.getUuid(); String filename; if (StringUtils.isNotBlank(titleWithoutExtension)) { filename = titleWithoutExtension + "_" + uuid + extension; } else { filename = uuid + extension; } File dir = OpenmrsUtil.getDirectoryInApplicationDataDirectory( Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_COMPLEX_OBS_DIR)); File outputfile = new File(dir, filename); return outputfile; }
Object data = obs.getComplexData().getData(); if (data instanceof BufferedImage) { img = (BufferedImage) obs.getComplexData().getData(); } else if (data instanceof InputStream) { try { outfile = getOutputFileToWrite(obs); String extension = getExtension(obs.getComplexData().getTitle());
private void handleExistingObsWithComplexConcept(Obs obs) { ComplexData complexData = obs.getComplexData(); Concept concept = obs.getConcept(); if (null != concept && concept.isComplex() && null != complexData && null != complexData.getData()) { // save or update complexData object on this obs // this is done before the database save so that the obs.valueComplex // can be filled in by the handler. ComplexObsHandler handler = getHandler(obs); if (null != handler) { handler.saveObs(obs); } else { throw new APIException("unknown.handler", new Object[] {concept}); } } }
Obs complexObs2 = handler.getObs(obs2, "RAW_VIEW"); assertEquals(complexObs1.getComplexData().getMimeType(), mimetype); assertEquals(complexObs2.getComplexData().getMimeType(), mimetype);
Obs complexObs2 = handler.getObs(obs2, "RAW_VIEW"); assertEquals(complexObs1.getComplexData().getMimeType(), mimetype); assertEquals(complexObs2.getComplexData().getMimeType(), mimetype);
Obs complexObs2 = handler.getObs(obs2, "RAW_VIEW"); assertEquals(complexObs1.getComplexData().getMimeType(), mimetype); assertEquals(complexObs2.getComplexData().getMimeType(), mimetype);
Obs complexObs2 = handler.getObs(obs2, "RAW_VIEW"); assertEquals(complexObs1.getComplexData().getMimeType(), mimetype); assertEquals(complexObs2.getComplexData().getMimeType(), mimetype);
Assert.assertTrue(complexObs.isComplex()); Assert.assertNotNull(complexObs.getValueComplex()); Assert.assertNotNull(complexObs.getComplexData()); Assert.assertEquals(complexObs, os.getObsByUuid(complexObs.getUuid()));
Obs complexObs2 = handler.getObs(obs2, "RAW_VIEW"); assertEquals(complexObs1.getComplexData().getMimeType(), mimetype); assertEquals(complexObs2.getComplexData().getMimeType(), mimetype);
/** * @see ObsService#purgeObs(Obs) */ @Test public void purgeObs_shouldDeleteTheGivenObsFromTheDatabase() { ObsService obsService = Context.getObsService(); Obs obs = obsService.getObs(7); obsService.purgeObs(obs); Assert.assertNull(obsService.getObs(7)); executeDataSet(COMPLEX_OBS_XML); Obs complexObs = obsService.getComplexObs(44, ComplexObsHandler.RAW_VIEW); // obs #44 is coded by the concept complex #8473 pointing to ImageHandler // ImageHandler inherits AbstractHandler which handles complex data files on disk assertNotNull(complexObs.getComplexData()); AdministrationService as = Context.getAdministrationService(); File complexObsDir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(as .getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_COMPLEX_OBS_DIR)); for (File file : complexObsDir.listFiles()) { file.delete(); } obsService.purgeObs(complexObs); assertNull(obsService.getObs(obs.getObsId())); }
/** * @see ORUR01Handler#processMessage(Message) * */ @Test public void processMessage_shouldSetComplexDataForObsWithComplexConcepts() throws Exception { ObsHandler handler = new ObsHandler(); final String handlerName = "NeigborHandler"; final String data = "{\"firstname\":\"Horatio\"}"; Context.getObsService().registerHandler(handlerName, handler); try { String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||3^^^^||John3^Doe^||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|ED|6043^uiNEIHBOR^99DCT||^^^^" + data + "|||||||||20080206\r"; Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); } finally { Context.getObsService().removeHandler(handlerName); } Assert.assertEquals(data, handler.getCreatedObs().getComplexData().getData()); }
ComplexData complexData = obs.getComplexData();
&& obs.getValueComplex() == null && obs.getValueDatetime() == null && obs.getValueDrug() == null && obs.getValueModifier() == null && obs.getValueNumeric() == null && obs.getValueText() == null && obs.getComplexData() == null) { errors.reject("error.noValue");
newObs.setComplexData(obsToCopy.getComplexData()); newObs.setFormField(obsToCopy.getFormFieldNamespace(),obsToCopy.getFormFieldPath());
} else if (HtmlFormEntryConstants.COMPLEX_UUID.equals(dt.getUuid())) { obs.setComplexData((ComplexData) value); obs.setValueComplex(obs.getComplexData().getTitle()); } else if (dt.isText()) { if (value instanceof Location) {