Search in sources :

Example 1 with CodedOrFreeText

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

the class ConditionValidatorTest method shouldPassIfConditionClassIsPassedWithRequiredConditionProperties.

@Test
public void shouldPassIfConditionClassIsPassedWithRequiredConditionProperties() {
    Condition condition = new Condition();
    condition.setCondition(new CodedOrFreeText(new Concept(), new ConceptName("name", new Locale("en")), "nonCoded"));
    condition.setClinicalStatus(ConditionClinicalStatus.ACTIVE);
    validator.validate(condition, errors);
    Assert.assertFalse(errors.hasFieldErrors("condition"));
    Assert.assertFalse(errors.hasFieldErrors("clinicalStatus"));
}
Also used : Condition(org.openmrs.Condition) Concept(org.openmrs.Concept) Locale(java.util.Locale) ConceptName(org.openmrs.ConceptName) CodedOrFreeText(org.openmrs.CodedOrFreeText) Test(org.junit.Test)

Example 2 with CodedOrFreeText

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

the class DiagnosisValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsAreSupplied.

@Test
public void validate_shouldPassValidationIfAllRequiredFieldsAreSupplied() {
    diagnosis.setEncounter(new Encounter());
    diagnosis.setDiagnosis(new CodedOrFreeText());
    diagnosis.setCertainty(ConditionVerificationStatus.CONFIRMED);
    diagnosis.setRank(1);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Encounter(org.openmrs.Encounter) CodedOrFreeText(org.openmrs.CodedOrFreeText) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with CodedOrFreeText

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

the class HibernateConditionDAOTest method shouldSaveCondition.

@Test
public void shouldSaveCondition() {
    CodedOrFreeText codedOrFreeText = new CodedOrFreeText(new Concept(4), new ConceptName(5089), "non coded");
    ConditionClinicalStatus clinicalStatus = ConditionClinicalStatus.ACTIVE;
    ConditionVerificationStatus verificationStatus = ConditionVerificationStatus.CONFIRMED;
    Patient patient = new Patient(2);
    Date onsetDate = new Date();
    Date endDate = new Date();
    Condition previousVersion = dao.getConditionByUuid("2cc6880e-2c46-15e4-9038-a6c5e4d22fb7");
    String additionalDetail = "additionalDetail";
    int conditionId = 20;
    Condition condition = new Condition();
    condition.setConditionId(conditionId);
    condition.setCondition(codedOrFreeText);
    condition.setClinicalStatus(clinicalStatus);
    condition.setVerificationStatus(verificationStatus);
    condition.setPreviousVersion(previousVersion);
    condition.setAdditionalDetail(additionalDetail);
    condition.setOnsetDate(onsetDate);
    condition.setEndDate(endDate);
    condition.setPatient(patient);
    dao.saveCondition(condition);
    Condition savedCondition = dao.getCondition(conditionId);
    assertEquals(additionalDetail, savedCondition.getAdditionalDetail());
    assertEquals(conditionId, (int) savedCondition.getConditionId());
    assertEquals(onsetDate, savedCondition.getOnsetDate());
    assertEquals(endDate, savedCondition.getEndDate());
    assertEquals(clinicalStatus, savedCondition.getClinicalStatus());
    assertEquals(verificationStatus, savedCondition.getVerificationStatus());
    assertEquals(previousVersion, savedCondition.getPreviousVersion());
    assertEquals(patient, savedCondition.getPatient());
}
Also used : Concept(org.openmrs.Concept) Condition(org.openmrs.Condition) ConditionVerificationStatus(org.openmrs.ConditionVerificationStatus) ConditionClinicalStatus(org.openmrs.ConditionClinicalStatus) ConceptName(org.openmrs.ConceptName) Patient(org.openmrs.Patient) CodedOrFreeText(org.openmrs.CodedOrFreeText) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with CodedOrFreeText

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

the class ConditionServiceImplTest method saveCondition_shouldSaveNewCondition.

/**
 * @see ConditionService#saveCondition(Condition)
 */
@Test
public void saveCondition_shouldSaveNewCondition() {
    Integer patientId = 2;
    String uuid = "08002000-4469-12q3-551f-0339000c9a76";
    CodedOrFreeText codedOrFreeText = new CodedOrFreeText();
    Condition condition = new Condition();
    condition.setCondition(codedOrFreeText);
    condition.setClinicalStatus(ConditionClinicalStatus.ACTIVE);
    condition.setUuid(uuid);
    condition.setPatient(new Patient(patientId));
    conditionService.saveCondition(condition);
    Condition savedCondition = conditionService.getConditionByUuid(uuid);
    Assert.assertEquals(patientId, savedCondition.getPatient().getPatientId());
    Assert.assertEquals(uuid, savedCondition.getUuid());
    Assert.assertEquals(codedOrFreeText, savedCondition.getCondition());
    Assert.assertEquals(ConditionClinicalStatus.ACTIVE, savedCondition.getClinicalStatus());
    Assert.assertNotNull(savedCondition.getConditionId());
}
Also used : Condition(org.openmrs.Condition) Patient(org.openmrs.Patient) CodedOrFreeText(org.openmrs.CodedOrFreeText) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with CodedOrFreeText

use of org.openmrs.CodedOrFreeText 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)

Aggregations

CodedOrFreeText (org.openmrs.CodedOrFreeText)6 Test (org.junit.Test)5 Condition (org.openmrs.Condition)4 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)4 Concept (org.openmrs.Concept)3 ConceptName (org.openmrs.ConceptName)3 Patient (org.openmrs.Patient)3 Date (java.util.Date)2 Diagnosis (org.openmrs.Diagnosis)2 Encounter (org.openmrs.Encounter)2 HashSet (java.util.HashSet)1 Locale (java.util.Locale)1 ConditionClinicalStatus (org.openmrs.ConditionClinicalStatus)1 ConditionVerificationStatus (org.openmrs.ConditionVerificationStatus)1 User (org.openmrs.User)1 Transactional (org.springframework.transaction.annotation.Transactional)1