private void updateImmutableFieldsAndAssert(Obs obs, boolean assertion) throws Exception { //Set all fields to some random values via reflection List<Field> fields = Reflect.getAllFields(Obs.class); final Integer originalPersonId = obs.getPersonId(); //call each setter and check that dirty has been set to true for each for (Field field : fields) { String fieldName = field.getName(); if (IGNORED_FIELDS.contains(fieldName)) { continue; } if ("personId".equals(fieldName)) { //call setPersonId because it is protected so BeanUtils.setProperty won't work obs.setPersonId((Integer) generateValue(field, true)); } else { BeanUtils.setProperty(obs, fieldName, generateValue(field, true)); } assertEquals("Obs was not marked as dirty after changing: " + fieldName, obs.isDirty(), assertion); if ("person".equals(fieldName)) { //Because setPerson updates the personId we need to reset personId to its original value //that matches that of person otherwise the test will fail for the personId field obs.setPersonId(originalPersonId); } //reset for next field resetObs(obs); } }
public Patient[] dueDatesToWebServicePatients(List<Obs> dueDates) { List<Patient> wsPatients = new ArrayList<Patient>(); for (Obs dueDate : dueDates) { Integer patientId = dueDate.getPersonId(); org.openmrs.Patient patient = registrarBean.getPatientById(patientId); if (patient != null) { Patient wsPatient = patientToWebService(patient, true); wsPatient.setEstimateDueDate(dueDate.getValueDatetime()); wsPatients.add(wsPatient); } } return wsPatients.toArray(new Patient[wsPatients.size()]); }
if (obs.getPersonId() == null) { errors.rejectValue("person", "error.null");