Search in sources :

Example 11 with ConceptAnswer

use of org.openmrs.ConceptAnswer in project openmrs-module-coreapps by openmrs.

the class MarkPatientDeadPageController method getConceptAnswers.

private Collection<ConceptAnswer> getConceptAnswers(Integer conceptId) {
    Collection<ConceptAnswer> conceptAnswers = null;
    Concept concept = Context.getConceptService().getConcept(conceptId);
    if (concept != null) {
        conceptAnswers = concept.getAnswers();
    }
    return conceptAnswers;
}
Also used : Concept(org.openmrs.Concept) ConceptAnswer(org.openmrs.ConceptAnswer)

Example 12 with ConceptAnswer

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

the class ConceptServiceImpl method convertBooleanConceptToCoded.

/**
 * @see org.openmrs.api.ConceptService#convertBooleanConceptToCoded(org.openmrs.Concept)
 */
@Override
public void convertBooleanConceptToCoded(Concept conceptToChange) throws APIException {
    if (conceptToChange != null) {
        if (!conceptToChange.getDatatype().isBoolean()) {
            throw new APIException("Concept.datatype.invalid", (Object[]) null);
        }
        conceptToChange.setDatatype(getConceptDatatypeByName("Coded"));
        conceptToChange.addAnswer(new ConceptAnswer(getTrueConcept()));
        conceptToChange.addAnswer(new ConceptAnswer(getFalseConcept()));
        Context.getConceptService().saveConcept(conceptToChange);
    }
}
Also used : APIException(org.openmrs.api.APIException) ConceptAnswer(org.openmrs.ConceptAnswer)

Example 13 with ConceptAnswer

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

the class ProgramWorkflowServiceImpl method getPossibleOutcomes.

/**
 * @see org.openmrs.api.ProgramWorkflowService#getPossibleOutcomes(Integer)
 */
@Override
@Transactional(readOnly = true)
public List<Concept> getPossibleOutcomes(Integer programId) {
    List<Concept> possibleOutcomes = new ArrayList<>();
    Program program = Context.getProgramWorkflowService().getProgram(programId);
    if (program == null) {
        return possibleOutcomes;
    }
    Concept outcomesConcept = program.getOutcomesConcept();
    if (outcomesConcept == null) {
        return possibleOutcomes;
    }
    if (!outcomesConcept.getAnswers().isEmpty()) {
        for (ConceptAnswer conceptAnswer : outcomesConcept.getAnswers()) {
            possibleOutcomes.add(conceptAnswer.getAnswerConcept());
        }
        return possibleOutcomes;
    }
    if (!outcomesConcept.getSetMembers().isEmpty()) {
        return outcomesConcept.getSetMembers();
    }
    return possibleOutcomes;
}
Also used : Concept(org.openmrs.Concept) PatientProgram(org.openmrs.PatientProgram) Program(org.openmrs.Program) ConceptAnswer(org.openmrs.ConceptAnswer) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with ConceptAnswer

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

the class ConceptServiceTest method getConceptAnswerByUuid_shouldFindObjectGivenValidUuid.

/**
 * @see ConceptService#getConceptAnswerByUuid(String)
 */
@Test
public void getConceptAnswerByUuid_shouldFindObjectGivenValidUuid() {
    String uuid = "b1230431-2fe5-49fc-b535-ae42bc849747";
    ConceptAnswer conceptAnswer = Context.getConceptService().getConceptAnswerByUuid(uuid);
    Assert.assertEquals(1, (int) conceptAnswer.getConceptAnswerId());
}
Also used : ConceptAnswer(org.openmrs.ConceptAnswer) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 15 with ConceptAnswer

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

the class HibernateConceptDAO method newConceptNameLuceneQuery.

private LuceneQuery<ConceptName> newConceptNameLuceneQuery(final String phrase, boolean searchKeywords, List<Locale> locales, boolean searchExactLocale, boolean includeRetired, List<ConceptClass> requireClasses, List<ConceptClass> excludeClasses, List<ConceptDatatype> requireDatatypes, List<ConceptDatatype> excludeDatatypes, Concept answersToConcept) {
    final StringBuilder query = new StringBuilder();
    if (!StringUtils.isBlank(phrase)) {
        final Set<Locale> searchLocales;
        if (locales == null) {
            searchLocales = new HashSet<>(Collections.singletonList(Context.getLocale()));
        } else {
            searchLocales = new HashSet<>(locales);
        }
        query.append(newConceptNameQuery(phrase, searchKeywords, searchLocales, searchExactLocale));
    }
    LuceneQuery<ConceptName> luceneQuery = LuceneQuery.newQuery(ConceptName.class, sessionFactory.getCurrentSession(), query.toString()).include("concept.conceptClass.conceptClassId", transformToIds(requireClasses)).exclude("concept.conceptClass.conceptClassId", transformToIds(excludeClasses)).include("concept.datatype.conceptDatatypeId", transformToIds(requireDatatypes)).exclude("concept.datatype.conceptDatatypeId", transformToIds(excludeDatatypes));
    if (answersToConcept != null) {
        Collection<ConceptAnswer> answers = answersToConcept.getAnswers(false);
        if (answers != null && !answers.isEmpty()) {
            List<Integer> ids = new ArrayList<>();
            for (ConceptAnswer conceptAnswer : answersToConcept.getAnswers(false)) {
                ids.add(conceptAnswer.getAnswerConcept().getId());
            }
            luceneQuery.include("concept.conceptId", ids.toArray(new Object[0]));
        }
    }
    if (!includeRetired) {
        luceneQuery.include("concept.retired", false);
    }
    luceneQuery.skipSame("concept.conceptId");
    return luceneQuery;
}
Also used : Locale(java.util.Locale) ConceptAnswer(org.openmrs.ConceptAnswer) ArrayList(java.util.ArrayList) ConceptName(org.openmrs.ConceptName) OpenmrsObject(org.openmrs.OpenmrsObject)

Aggregations

ConceptAnswer (org.openmrs.ConceptAnswer)17 Concept (org.openmrs.Concept)12 Test (org.junit.Test)8 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)6 ArrayList (java.util.ArrayList)5 ConceptName (org.openmrs.ConceptName)4 Date (java.util.Date)2 HashSet (java.util.HashSet)2 Locale (java.util.Locale)2 Map (java.util.Map)2 ConceptMap (org.openmrs.ConceptMap)2 Drug (org.openmrs.Drug)2 ConceptService (org.openmrs.api.ConceptService)2 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)2 HL7Exception (ca.uhn.hl7v2.HL7Exception)1 Type (ca.uhn.hl7v2.model.Type)1 Varies (ca.uhn.hl7v2.model.Varies)1 CE (ca.uhn.hl7v2.model.v25.datatype.CE)1 CWE (ca.uhn.hl7v2.model.v25.datatype.CWE)1 DT (ca.uhn.hl7v2.model.v25.datatype.DT)1