Search in sources :

Example 31 with Concept

use of org.openmrs.Concept in project openmrs-module-pihcore by PIH.

the class CleanPrescriptionConstructAction method applyAction.

@Override
public void applyAction(FormEntrySession formEntrySession) {
    Concept prescriptionConstructConcept = Context.getConceptService().getConceptByMapping(CleanPrescriptionConstructAction.PRESCRIPTION_CONSTRUCT_CONCEPT, "PIH");
    Concept medicationOrdersConcept = Context.getConceptService().getConceptByMapping(CleanPrescriptionConstructAction.MEDICATION_ORDERS_CONCEPT, "PIH");
    Encounter encounter = formEntrySession.getEncounter();
    boolean updateEncounter = false;
    for (Obs obsGroup : encounter.getObsAtTopLevel(false)) {
        if (obsGroup.getConcept().equals(prescriptionConstructConcept)) {
            // we found a prescription medication construct
            Set<Obs> groupMembers = obsGroup.getGroupMembers();
            if (groupMembers != null && groupMembers.size() > 0) {
                boolean hasMedicationOrders = false;
                for (Obs member : groupMembers) {
                    if (member.getConcept().equals(medicationOrdersConcept)) {
                        hasMedicationOrders = true;
                    }
                }
                if (!hasMedicationOrders) {
                    // we do not have a medication order but have other dangling construct obs
                    removeGivenObsAndTheirGroupMembersFromEncounter(Arrays.asList(obsGroup), encounter);
                    updateEncounter = true;
                }
            }
        }
    }
    if (updateEncounter) {
        Context.getEncounterService().saveEncounter(encounter);
    }
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Encounter(org.openmrs.Encounter)

Example 32 with Concept

use of org.openmrs.Concept in project openmrs-module-pihcore by PIH.

the class ConditionListVelocityContextContentProvider method getActiveConditionsConcepts.

protected List<Concept> getActiveConditionsConcepts(Patient patient) {
    List<Condition> conditionList = getActiveConditions(patient);
    List<Concept> conditionListConcepts = new ArrayList<Concept>();
    for (Condition condition : conditionList) {
        if (condition.getCondition().getCoded() != null) {
            conditionListConcepts.add(condition.getCondition().getCoded());
        }
    }
    return conditionListConcepts;
}
Also used : Condition(org.openmrs.Condition) Concept(org.openmrs.Concept) ArrayList(java.util.ArrayList)

Example 33 with Concept

use of org.openmrs.Concept in project openmrs-module-pihcore by PIH.

the class ConditionListVelocityContextContentProvider method populateContext.

@Override
public void populateContext(FormEntrySession formEntrySession, VelocityContext velocityContext) {
    Patient patient = formEntrySession.getPatient();
    List<Condition> conditionList = getActiveConditions(patient);
    List<Concept> conditionListConcepts = getActiveConditionsConcepts(patient);
    velocityContext.put("conditionList", conditionList);
    velocityContext.put("conditionListConcepts", conditionListConcepts);
}
Also used : Condition(org.openmrs.Condition) Concept(org.openmrs.Concept) Patient(org.openmrs.Patient)

Example 34 with Concept

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

the class ProgramEditor method setAsText.

/**
 * @should set using concept id
 * @should set using concept uuid
 * @should set using program id
 * @should set using program uuid
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
    if (StringUtils.hasText(text)) {
        try {
            if (text.startsWith("concept.")) {
                Integer conceptId = Integer.valueOf(text.substring(text.indexOf('.') + 1));
                Concept c = Context.getConceptService().getConcept(conceptId);
                setValue(Context.getProgramWorkflowService().getProgramByName(c.getName().getName()));
            } else {
                Integer programId = Integer.valueOf(text);
                setValue(Context.getProgramWorkflowService().getProgram(programId));
            }
        } catch (Exception ex) {
            Program p;
            if (text.startsWith("concept.")) {
                Concept c = Context.getConceptService().getConceptByUuid(text.substring(text.indexOf('.') + 1));
                p = Context.getProgramWorkflowService().getProgramByName(c.getName().getName());
            } else {
                p = Context.getProgramWorkflowService().getProgramByUuid(text);
            }
            setValue(p);
            if (p == null) {
                log.error("Error setting text: " + text, ex);
                throw new IllegalArgumentException("Program not found: " + text, ex);
            }
        }
    } else {
        setValue(null);
    }
}
Also used : Concept(org.openmrs.Concept) Program(org.openmrs.Program)

Example 35 with Concept

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

the class ConceptAnswersEditor method setAsText.

/**
 * loops over the textbox assigned to this property. The textbox is assumed to be a string of
 * conceptIds^drugIds separated by spaces.
 *
 * @param text list of conceptIds (not conceptAnswerIds)
 * @should set the sort weights with the least possible changes
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
    if (StringUtils.hasText(text)) {
        ConceptService cs = Context.getConceptService();
        String[] conceptIds = text.split(" ");
        List<String> requestConceptIds = new ArrayList<>();
        // set up parameter answer Set for easier add/delete functions and removal of duplicates
        for (String id : conceptIds) {
            id = id.trim();
            if (!("".equals(id)) && !requestConceptIds.contains(id)) {
                // remove whitespace, blank lines, and duplicates
                requestConceptIds.add(id);
            }
        }
        Collection<ConceptAnswer> deletedConceptAnswers = new HashSet<>();
        // loop over original concept answers to find any deleted answers
        for (ConceptAnswer origConceptAnswer : originalConceptAnswers) {
            boolean answerDeleted = true;
            for (String conceptId : requestConceptIds) {
                Integer id = getConceptId(conceptId);
                Integer drugId = getDrugId(conceptId);
                Drug answerDrug = origConceptAnswer.getAnswerDrug();
                if (id.equals(origConceptAnswer.getAnswerConcept().getConceptId())) {
                    if (drugId == null && answerDrug == null) {
                        answerDeleted = false;
                    } else if ((drugId != null && answerDrug != null) && drugId.equals(origConceptAnswer.getAnswerDrug().getDrugId())) {
                        answerDeleted = false;
                    }
                }
            }
            if (answerDeleted) {
                deletedConceptAnswers.add(origConceptAnswer);
            }
        }
        // loop over those deleted answers to delete them
        for (ConceptAnswer conceptAnswer : deletedConceptAnswers) {
            originalConceptAnswers.remove(conceptAnswer);
        }
        // loop over concept ids in the request to add any that are new
        for (String conceptId : requestConceptIds) {
            Integer id = getConceptId(conceptId);
            Integer drugId = getDrugId(conceptId);
            boolean newAnswerConcept = true;
            for (ConceptAnswer origConceptAnswer : originalConceptAnswers) {
                Drug answerDrug = origConceptAnswer.getAnswerDrug();
                if (id.equals(origConceptAnswer.getAnswerConcept().getConceptId())) {
                    if (drugId == null && answerDrug == null) {
                        newAnswerConcept = false;
                    } else if ((drugId != null && answerDrug != null) && drugId.equals(answerDrug.getDrugId())) {
                        newAnswerConcept = false;
                    }
                }
            }
            // if the current request answer is new, add it to the originals
            if (newAnswerConcept) {
                Concept answer = cs.getConcept(id);
                Drug drug = null;
                if (drugId != null) {
                    drug = cs.getDrug(drugId);
                }
                ConceptAnswer ac = new ConceptAnswer(answer, drug);
                originalConceptAnswers.add(ac);
            }
        }
        // loop over to set the order
        // as the list comes into 'requestConceptIds' in the order the user wants
        // there are 2 conditions that will require the sort_weights to be reassigned
        // 1) any ConceptAnswer.sortWeight == NULL (meaning it is just added)
        // 2) the list is not in ASCENDING order (example sort order of the list is 1, 2, 10, 9)
        // -startIdx (start index) is where in this list we will start to reassign the sort_weights
        Double lastWeightSeen = null;
        // the idx to start at, if we have a NULL sort weight (new concept answer) or sort weights are not ascending
        int startIdx = -1;
        for (int i = 0; i < requestConceptIds.size() - 1; i++) {
            Integer id1 = getConceptId(requestConceptIds.get(i));
            ConceptAnswer ca1 = getConceptAnswerFromOriginal(id1);
            if (ca1.getSortWeight() == null) {
                if (lastWeightSeen == null) {
                    // start at 1, we're at the beginning
                    lastWeightSeen = 1d;
                } else {
                    // we start at +1
                    lastWeightSeen += 1;
                }
                startIdx = i;
                break;
            }
            Integer id2 = getConceptId(requestConceptIds.get(i + 1));
            ConceptAnswer ca2 = getConceptAnswerFromOriginal(id2);
            int c = ca1.compareTo(ca2);
            if (c > 0) {
                startIdx = i;
                lastWeightSeen = ca1.getSortWeight();
                break;
            }
            lastWeightSeen = ca1.getSortWeight();
        }
        if (startIdx != -1) {
            // then we need to re-weight
            for (int i = startIdx; i < requestConceptIds.size(); i++) {
                Integer id = getConceptId(requestConceptIds.get(i));
                ConceptAnswer ca = getConceptAnswerFromOriginal(id);
                ca.setSortWeight(lastWeightSeen++);
            }
        }
        log.debug("originalConceptAnswers.getConceptId(): ");
        for (ConceptAnswer a : originalConceptAnswers) {
            log.debug("id: " + a.getAnswerConcept().getConceptId());
        }
        log.debug("requestConceptIds: ");
        for (String i : requestConceptIds) {
            log.debug("id: " + i);
        }
    } else {
        originalConceptAnswers.clear();
    }
    setValue(originalConceptAnswers);
}
Also used : Drug(org.openmrs.Drug) Concept(org.openmrs.Concept) ConceptAnswer(org.openmrs.ConceptAnswer) ArrayList(java.util.ArrayList) ConceptService(org.openmrs.api.ConceptService) HashSet(java.util.HashSet)

Aggregations

Concept (org.openmrs.Concept)294 Test (org.junit.Test)210 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)176 ConceptName (org.openmrs.ConceptName)62 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)62 Obs (org.openmrs.Obs)49 Date (java.util.Date)48 Patient (org.openmrs.Patient)42 ConceptDescription (org.openmrs.ConceptDescription)33 Locale (java.util.Locale)32 ConceptDatatype (org.openmrs.ConceptDatatype)32 OrderUtilTest (org.openmrs.order.OrderUtilTest)29 ConceptClass (org.openmrs.ConceptClass)27 ArrayList (java.util.ArrayList)26 BindException (org.springframework.validation.BindException)26 DrugOrder (org.openmrs.DrugOrder)25 Encounter (org.openmrs.Encounter)25 Errors (org.springframework.validation.Errors)25 ConceptMapBuilder (org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder)21 Location (org.openmrs.Location)19