Search in sources :

Example 11 with Diagnosis

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

the class HibernateDiagnosisDAOTest method shouldGetDiagnosisById.

@Test
public void shouldGetDiagnosisById() {
    Diagnosis diagnosis = diagnosisDAO.getDiagnosisById(1);
    assertEquals("4e663d66-6b78-11e0-93c3-18a905e044dc", diagnosis.getUuid());
}
Also used : Diagnosis(org.openmrs.Diagnosis) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 12 with Diagnosis

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

the class DiagnosisServiceImpl method getUniqueDiagnoses.

/**
 * Gets unique diagnoses since date, sorted in reverse chronological order
 *
 * @param patient  the patient whose diagnosis we are to get
 * @param fromDate the date used to filter diagnosis which happened from this date and later
 * @return the list of diagnoses
 */
@Override
@Transactional(readOnly = true)
public List<Diagnosis> getUniqueDiagnoses(Patient patient, Date fromDate) {
    List<Diagnosis> diagnoses = getDiagnoses(patient, fromDate);
    Set<CodedOrFreeText> answers = new HashSet<CodedOrFreeText>();
    Iterator<Diagnosis> iterator = diagnoses.iterator();
    while (iterator.hasNext()) {
        Diagnosis diagnosis = iterator.next();
        if (!answers.add(diagnosis.getDiagnosis())) {
            iterator.remove();
        }
    }
    return diagnoses;
}
Also used : Diagnosis(org.openmrs.Diagnosis) CodedOrFreeText(org.openmrs.CodedOrFreeText) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with Diagnosis

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

the class DiagnosisServiceImplTest method purgeDiagnosis_shouldPurgeDiagnosis.

/**
 * @see DiagnosisService#purgeDiagnosis(Diagnosis)
 */
@Test
public void purgeDiagnosis_shouldPurgeDiagnosis() {
    String uuid = "77009cce-8804-17e4-8804-a68804d22fb7";
    Diagnosis diagnosis = diagnosisService.getDiagnosisByUuid(uuid);
    Assert.assertNotNull(diagnosis);
    diagnosisService.purgeDiagnosis(diagnosis);
    Diagnosis purgedDiagnosis = diagnosisService.getDiagnosisByUuid(uuid);
    Assert.assertNull(purgedDiagnosis);
}
Also used : Diagnosis(org.openmrs.Diagnosis) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 14 with Diagnosis

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

the class DiagnosisServiceImplTest method getDiagnoses_shouldGetDiagnosesOfPatientWithDifferentDate.

/**
 * @see DiagnosisService#getDiagnoses(Patient, Date)
 */
@Test
public void getDiagnoses_shouldGetDiagnosesOfPatientWithDifferentDate() {
    Calendar calendar = new GregorianCalendar(2016, 12, 1, 0, 0, 0);
    Patient patient = patientService.getPatient(2);
    List<Diagnosis> diagnoses = diagnosisService.getDiagnoses(patient, calendar.getTime());
    Assert.assertEquals(1, diagnoses.size());
    Assert.assertEquals("68802cce-6880-17e4-6880-a68804d22fb7", diagnoses.get(0).getUuid());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Patient(org.openmrs.Patient) Diagnosis(org.openmrs.Diagnosis) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 15 with Diagnosis

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

the class DiagnosisServiceImplTest method saveDiagnosis_shouldSaveNewDiagnosis.

/**
 * @see DiagnosisService#save(Diagnosis)
 */
@Test
public void saveDiagnosis_shouldSaveNewDiagnosis() {
    String uuid = "a303bbfb-w5w4-25d1-9f11-4f33f99d456r";
    Condition condition = conditionService.getConditionByUuid("2cc6880e-2c46-15e4-9038-a6c5e4d22fb7");
    Encounter encounter = encounterService.getEncounterByUuid("y403fafb-e5e4-42d0-9d11-4f52e89d123r");
    Patient patient = patientService.getPatient(2);
    Diagnosis diagnosis = new Diagnosis();
    diagnosis.setUuid(uuid);
    diagnosis.setEncounter(encounter);
    diagnosis.setCondition(condition);
    diagnosis.setCertainty(ConditionVerificationStatus.CONFIRMED);
    diagnosis.setPatient(patient);
    diagnosis.setRank(2);
    diagnosisService.save(diagnosis);
    Diagnosis savedDiagnosis = diagnosisService.getDiagnosisByUuid(uuid);
    Assert.assertEquals(uuid, savedDiagnosis.getUuid());
    Assert.assertEquals(condition, savedDiagnosis.getCondition());
    Assert.assertEquals(encounter, savedDiagnosis.getEncounter());
    Assert.assertEquals(patient, savedDiagnosis.getPatient());
    Assert.assertEquals(ConditionVerificationStatus.CONFIRMED, savedDiagnosis.getCertainty());
    Assert.assertEquals(new Integer(2), savedDiagnosis.getRank());
}
Also used : Condition(org.openmrs.Condition) Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) 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