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;
}
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);
}
}
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;
}
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());
}
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;
}
Aggregations