Search in sources :

Example 1 with Diagnosis

use of org.openmrs.Diagnosis in project openmrs-core by openmrs.

the class DiagnosisValidator method validate.

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should fail validation if rank is null or a non-positive integer
 * @should fail validation if certainty is null
 * @should fail validation if diagnosis is null
 * @should fail validation if encounter is null
 */
@Override
public void validate(Object o, Errors errors) {
    Diagnosis diagnosis = (Diagnosis) o;
    if (diagnosis == null) {
        throw new APIException("Diagnosis can't be null");
    } else if (diagnosis.getVoided()) {
        return;
    }
    if (diagnosis.getEncounter() == null) {
        errors.rejectValue("encounter", "error.null");
    }
    if (diagnosis.getDiagnosis() == null) {
        errors.rejectValue("diagnosis", "error.null");
    }
    if (diagnosis.getCertainty() == null) {
        errors.rejectValue("certainty", "error.null");
    }
    Integer rank = diagnosis.getRank();
    if (rank == null) {
        errors.rejectValue("rank", "error.null");
    } else if (rank < 0) {
        errors.rejectValue("rank", "error.rank.notPositiveInteger");
    }
}
Also used : APIException(org.openmrs.api.APIException) Diagnosis(org.openmrs.Diagnosis)

Example 2 with Diagnosis

use of org.openmrs.Diagnosis in project openmrs-core by openmrs.

the class DiagnosisValidatorTest method setUp.

@Before
public void setUp() {
    diagnosis = new Diagnosis();
    errors = new BindException(diagnosis, "diagnosis");
}
Also used : BindException(org.springframework.validation.BindException) Diagnosis(org.openmrs.Diagnosis) Before(org.junit.Before)

Example 3 with Diagnosis

use of org.openmrs.Diagnosis in project openmrs-core by openmrs.

the class DiagnosisServiceImplTest method getDiagnosisById_shouldFindDiagnosifGivenId.

/**
 * @see DiagnosisService#getDiagnosis(Integer)
 */
@Test
public void getDiagnosisById_shouldFindDiagnosifGivenId() {
    Integer diagnosisId = 1;
    Diagnosis diagnosis = diagnosisService.getDiagnosis(diagnosisId);
    Assert.assertEquals("68802cce-6880-17e4-6880-a68804d22fb7", diagnosis.getUuid());
    Assert.assertEquals(ConditionVerificationStatus.CONFIRMED, diagnosis.getCertainty());
    Assert.assertEquals(diagnosisId, diagnosis.getDiagnosisId());
}
Also used : Diagnosis(org.openmrs.Diagnosis) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with Diagnosis

use of org.openmrs.Diagnosis in project openmrs-core by openmrs.

the class DiagnosisServiceImplTest method getDiagnoses_shouldGetDiagnosesOfPatientWithoutDate.

/**
 * @see DiagnosisService#getDiagnoses(Patient, Date)
 */
@Test
public void getDiagnoses_shouldGetDiagnosesOfPatientWithoutDate() {
    Patient patient = patientService.getPatient(2);
    List<Diagnosis> diagnoses = diagnosisService.getDiagnoses(patient, null);
    Assert.assertEquals(3, diagnoses.size());
    Assert.assertEquals("68802cce-6880-17e4-6880-a68804d22fb7", diagnoses.get(0).getUuid());
    Assert.assertEquals("688804ce-6880-8804-6880-a68804d88047", diagnoses.get(1).getUuid());
    Assert.assertEquals("88042cce-8804-17e4-8804-a68804d22fb7", diagnoses.get(2).getUuid());
}
Also used : Patient(org.openmrs.Patient) Diagnosis(org.openmrs.Diagnosis) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with Diagnosis

use of org.openmrs.Diagnosis in project openmrs-core by openmrs.

the class DiagnosisServiceImplTest method unvoidDiagnosis_shouldUnvoidDiagnosisSuccessfully.

/**
 * @see DiagnosisService#unvoidDiagnosis(Diagnosis)
 */
@Test
public void unvoidDiagnosis_shouldUnvoidDiagnosisSuccessfully() {
    String uuid = "77009cce-8804-17e4-8804-a68804d22fb7";
    Diagnosis voidedDiagnosis = diagnosisService.getDiagnosisByUuid(uuid);
    Assert.assertTrue(voidedDiagnosis.getVoided());
    Assert.assertNotNull(voidedDiagnosis.getVoidReason());
    Assert.assertNotNull(voidedDiagnosis.getDateVoided());
    Assert.assertNotNull(voidedDiagnosis.getVoidedBy());
    diagnosisService.unvoidDiagnosis(voidedDiagnosis);
    Diagnosis unVoidedDiagnosis = diagnosisService.getDiagnosisByUuid(uuid);
    Assert.assertEquals(ConditionVerificationStatus.PROVISIONAL, unVoidedDiagnosis.getCertainty());
    Assert.assertEquals(uuid, unVoidedDiagnosis.getUuid());
    Assert.assertFalse(unVoidedDiagnosis.getVoided());
    Assert.assertNull(unVoidedDiagnosis.getVoidReason());
    Assert.assertNull(unVoidedDiagnosis.getDateVoided());
    Assert.assertNull(unVoidedDiagnosis.getVoidedBy());
}
Also used : Diagnosis(org.openmrs.Diagnosis) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Diagnosis (org.openmrs.Diagnosis)18 Test (org.junit.Test)15 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)15 Patient (org.openmrs.Patient)6 Encounter (org.openmrs.Encounter)3 Calendar (java.util.Calendar)2 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 CodedOrFreeText (org.openmrs.CodedOrFreeText)2 Condition (org.openmrs.Condition)2 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 Concept (org.openmrs.Concept)1 ConceptName (org.openmrs.ConceptName)1 User (org.openmrs.User)1 APIException (org.openmrs.api.APIException)1 Transactional (org.springframework.transaction.annotation.Transactional)1 BindException (org.springframework.validation.BindException)1