use of org.openmrs.Patient in project openmrs-core by openmrs.
the class EncounterValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see EncounterValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
encounter.setEncounterType(new EncounterType());
encounter.setPatient(new Patient());
encounter.setEncounterDatetime(new Date());
encounter.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 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 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");
encounterValidator.validate(encounter, errors);
Assert.assertTrue(errors.hasFieldErrors("voidReason"));
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class EncounterValidatorTest method validate_shouldFailIfThePatientsForTheVisitAndTheEncounterDontMatch.
/**
* @see EncounterValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfThePatientsForTheVisitAndTheEncounterDontMatch() {
encounter.setPatient(new Patient(2));
Visit visit = new Visit();
visit.setPatient(new Patient(3));
encounter.setVisit(visit);
encounterValidator.validate(encounter, errors);
Assert.assertEquals("Encounter.visit.patients.dontMatch", errors.getFieldError("visit").getCode());
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class EncounterValidatorTest method validate_shouldFailIfTheVisitHasNoPatient.
/**
* @see EncounterValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfTheVisitHasNoPatient() {
encounter.setPatient(new Patient(2));
Visit visit = new Visit();
encounter.setVisit(visit);
encounterValidator.validate(encounter, errors);
Assert.assertEquals("Encounter.visit.patients.dontMatch", errors.getFieldError("visit").getCode());
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class ObsServiceImpl method getObservations.
/**
* This implementation queries the obs table comparing the given <code>searchString</code> with
* the patient's identifier, encounterId, and obsId
*
* @see org.openmrs.api.ObsService#getObservations(java.lang.String)
*/
@Override
@Transactional(readOnly = true)
public List<Obs> getObservations(String searchString) {
// search on patient identifier
PatientService ps = Context.getPatientService();
List<Patient> patients = ps.getPatients(searchString);
List<Person> persons = new ArrayList<>(patients);
// try to search on encounterId
EncounterService es = Context.getEncounterService();
List<Encounter> encounters = new ArrayList<>();
try {
Encounter e = es.getEncounter(Integer.valueOf(searchString));
if (e != null) {
encounters.add(e);
}
} catch (NumberFormatException e) {
// pass
}
List<Obs> returnList = new ArrayList<>();
if (!encounters.isEmpty() || !persons.isEmpty()) {
returnList = Context.getObsService().getObservations(persons, encounters, null, null, null, null, null, null, null, null, null, false);
}
// try to search on obsId
try {
Obs o = getObs(Integer.valueOf(searchString));
if (o != null) {
returnList.add(o);
}
} catch (NumberFormatException e) {
// pass
}
return returnList;
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class PatientProgramValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see PatientProgramValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
ProgramWorkflowService pws = Context.getProgramWorkflowService();
Patient patient = Context.getPatientService().getPatient(6);
PatientProgram pp = new PatientProgram();
pp.setPatient(patient);
pp.setProgram(pws.getProgram(1));
pp.setDateEnrolled(new Date());
pp.setVoidReason("voidReason");
BindException errors = new BindException(pp, "program");
new PatientProgramValidator().validate(pp, errors);
Assert.assertEquals(false, errors.hasErrors());
}
Aggregations