obs.setValueComplex(outfile.getName() + " file |" + outfile.getName());
obs.setValueComplex(outfile.getName() + " file |" + outfile.getName());
/** * @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; }
/** * @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; }
obs.setValueComplex(extension + " image |" + outfile.getName());
/** * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { Obs obs = new Obs(); obs.setPerson(Context.getPersonService().getPerson(2)); obs.setConcept(Context.getConceptService().getConcept(5089)); obs.setObsDatetime(new Date()); obs.setValueNumeric(1.0); obs.setAccessionNumber("AccessionNumber"); obs.setValueModifier("m"); obs.setValueComplex("ValueComplex"); obs.setVoidReason("VoidReason"); obs.setComment("comment"); Errors errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertFalse(errors.hasErrors()); }
/** * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { Obs obs = new Obs(); obs.setPerson(Context.getPersonService().getPerson(2)); obs.setConcept(Context.getConceptService().getConcept(5089)); obs.setObsDatetime(new Date()); obs.setValueNumeric(1.0); obs.setAccessionNumber("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); obs.setValueModifier("too long text"); obs.setValueComplex("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); obs.setVoidReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); obs.setComment("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); Errors errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertTrue(errors.hasFieldErrors("accessionNumber")); assertTrue(errors.hasFieldErrors("valueModifier")); assertTrue(errors.hasFieldErrors("valueComplex")); assertTrue(errors.hasFieldErrors("comment")); assertTrue(errors.hasFieldErrors("voidReason")); }
obs.setValueComplex("test"); obs.setValueDatetime(new Date()); obs.setValueDrug(Context.getConceptService().getDrug(3));
newObs.setInterpretation(obsToCopy.getInterpretation()); newObs.setValueComplex(obsToCopy.getValueComplex()); 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) {
private void clearAndSetValue(Obs obs, ObsType type, Object value) { obs.setValueCoded(type.equals(ObsType.CODED) ? (Concept) value : null); obs.setValueComplex(type.equals(ObsType.COMPLEX) ? (String) value : null); obs.setValueDatetime(type.equals(ObsType.DATETIME) ? (Date) value : null); obs.setValueDrug(type.equals(ObsType.DRUG) ? (Drug) value : null); obs.setValueNumeric(type.equals(ObsType.NUMERIC) ? (Double) value : null); obs.setValueText(type.equals(ObsType.TEXT) ? (String) value : null); }
@Override public Encounter getEncounterToView() throws Exception { Encounter e = new Encounter(); BufferedImage image = createImage(); e.setPatient(getPatient()); Date date = Context.getDateFormat().parse("11/08/2012"); e.setDateCreated(new Date()); e.setEncounterDatetime(date); e.setLocation(Context.getLocationService().getLocation(2)); e.setProvider(Context.getPersonService().getPerson(502)); Obs obs = new Obs(); obs.setConcept(Context.getConceptService().getConcept(6100)); obs.setComplexData(new ComplexData("complex_obs_image_test.gif", image)); obs.setValueComplex("gif image |complex_obs_image_test.gif"); e.addObs(obs); Context.getEncounterService().saveEncounter(e); return e; } }.run();