Search in sources :

Example 66 with Patient

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"));
}
Also used : Patient(org.openmrs.Patient) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 67 with Patient

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());
}
Also used : Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 68 with Patient

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());
}
Also used : Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 69 with Patient

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;
}
Also used : Obs(org.openmrs.Obs) PatientService(org.openmrs.api.PatientService) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Person(org.openmrs.Person) EncounterService(org.openmrs.api.EncounterService) Transactional(org.springframework.transaction.annotation.Transactional)

Example 70 with Patient

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());
}
Also used : ProgramWorkflowService(org.openmrs.api.ProgramWorkflowService) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Patient (org.openmrs.Patient)389 Test (org.junit.Test)345 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)284 Date (java.util.Date)106 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)91 Encounter (org.openmrs.Encounter)76 PatientIdentifier (org.openmrs.PatientIdentifier)60 Location (org.openmrs.Location)57 OrderUtilTest (org.openmrs.order.OrderUtilTest)47 PersonName (org.openmrs.PersonName)43 DrugOrder (org.openmrs.DrugOrder)42 BindException (org.springframework.validation.BindException)38 Concept (org.openmrs.Concept)37 Order (org.openmrs.Order)36 PatientIdentifierType (org.openmrs.PatientIdentifierType)33 Errors (org.springframework.validation.Errors)33 Visit (org.openmrs.Visit)29 ArrayList (java.util.ArrayList)28 Obs (org.openmrs.Obs)28 TestOrder (org.openmrs.TestOrder)28