Package org.openmrs

Examples of org.openmrs.Concept


                    + parameters);
        }
        String conceptIds = parameters.get("conceptIds");
        for (StringTokenizer st = new StringTokenizer(conceptIds, ","); st.hasMoreTokens(); ) {
            String s = st.nextToken().trim();
            Concept concept = HtmlFormEntryUtil.getConcept(s);
            if (concept == null)
                throw new IllegalArgumentException("Cannot find concept value " + s + " in conceptIds attribute value. Parameters: " + parameters);
            concepts.add(concept);
        }
        if (concepts.size() == 0)
View Full Code Here


        } else { // dropdown
            valueWidget = new DropdownWidget();
            ((DropdownWidget) valueWidget).addOption(new Option());
        }
        for (int i = 0; i < concepts.size(); ++i) {
            Concept c = concepts.get(i);
            String label = null;
            if (conceptLabels != null && i < conceptLabels.size()) {
                label = conceptLabels.get(i);
            } else {
                label = c.getBestName(Context.getLocale()).getName();
            }
            ((SingleOptionWidget) valueWidget).addOption(new Option(
                label, c.getConceptId().toString(), false));
        }
        if (existingObs != null) {
            valueWidget.setInitialValue(existingObs.getConcept());
        }
        context.registerWidget(valueWidget);
View Full Code Here

        otherReasonWidget = new TextFieldWidget();
        otherReasonErrorWidget = new ErrorWidget();

        // setting the initial values
        String conceptId = Context.getAdministrationService().getGlobalProperty("concept.reasonExitedCare");
        Concept reasonExitConcept = Context.getConceptService().getConcept(conceptId);
        Concept initialAnswer = null;
        List<Obs> obsList = Context.getObsService().getObservationsByPersonAndConcept(patient, reasonExitConcept);
        if (obsList != null && obsList.size() == 1) {
            dateWidget.setInitialValue(obsList.get(0).getObsDatetime());
            initialAnswer = obsList.get(0).getValueCoded();
            reasonForExitWidget.setInitialValue(initialAnswer.getDisplayString());
        }

        // populating with exit reason answer options
        boolean initialValueIsSet = !(reasonForExitWidget.getInitialValue() == null);
        reasonForExitWidget.addOption(new Option(Context.getMessageSourceService().getMessage("htmlformentry.chooseAReasonForExit"), "", !initialValueIsSet));

        if (reasonExitConcept != null) {
            for (ConceptAnswer conceptAnswer : reasonExitConcept.getAnswers()) {
                Concept answerConcept = conceptAnswer.getAnswerConcept();
                Option answerOption = new Option(answerConcept.getDisplayString(), answerConcept.getId().toString(), answerConcept.equals(initialAnswer));
                reasonForExitWidget.addOption(answerOption);
            }
        }

        // set the cause for the death and reason for death fields if the reason for the patient's exit is, that the
        // patient has died
        String causeOfDeathConId = Context.getAdministrationService().getGlobalProperty("concept.causeOfDeath");
        Concept causeOfDeathConcept = Context.getConceptService().getConcept(causeOfDeathConId);
        List<Obs> obsDeath = Context.getObsService().getObservationsByPersonAndConcept(patient, causeOfDeathConcept);
        Concept initialCauseOfDeath = null;

        if (obsDeath != null && obsDeath.size() == 1) {
            initialCauseOfDeath = obsDeath.get(0).getValueCoded();
            causeOfDeathWidget.setInitialValue(initialCauseOfDeath.getDisplayString());
            if (obsDeath.get(0).getValueText() != null) {
                otherReasonWidget.setInitialValue(obsDeath.get(0).getValueText());
            }
        }

        // populating with cause of death answer options
        boolean causeOfDeathIsSet = !(causeOfDeathWidget.getInitialValue() == null);
        causeOfDeathWidget.addOption(new Option(Context.getMessageSourceService().getMessage("htmlformentry.chooseACauseToDeath"), "", !causeOfDeathIsSet));

        if (causeOfDeathConcept != null) {
            for (ConceptAnswer conceptAnswer : causeOfDeathConcept.getAnswers()) {
                Concept answerConcept = conceptAnswer.getAnswerConcept();
                Option answerOption = new Option(answerConcept.getDisplayString(), answerConcept.getId().toString(), answerConcept.equals(initialCauseOfDeath));
                causeOfDeathWidget.addOption(answerOption);
            }
        }

        context.registerWidget(dateWidget);
View Full Code Here

     * @should allow to submit a form if exit from care section is initially not filled
     */
    public Collection<FormSubmissionError> validateSubmission(FormEntryContext context, HttpServletRequest submission) {
        List<FormSubmissionError> ret = new ArrayList<FormSubmissionError>();
        Date exitDate = null;
        Concept exitReasonAnswerConcept = null;
        Concept causeOfDeathAnswerConcept = null;

        Patient patient = context.getExistingPatient();
        String reasonConId = Context.getAdministrationService().getGlobalProperty("concept.reasonExitedCare");
        Concept reasonExitConcept = Context.getConceptService().getConcept(reasonConId);
        List<Obs> obsList = Context.getObsService().getObservationsByPersonAndConcept(patient, reasonExitConcept);

        String causeOfDeathConId = Context.getAdministrationService().getGlobalProperty("concept.causeOfDeath");
        Concept causeOfDeathConcept = Context.getConceptService().getConcept(causeOfDeathConId);
        List<Obs> obsDeath = Context.getObsService().getObservationsByPersonAndConcept(patient, causeOfDeathConcept);

        String patientDiedConId = Context.getAdministrationService().getGlobalProperty("concept.patientDied");
        Concept patientDiedConcept = Context.getConceptService().getConcept(patientDiedConId);
        String otherNonCodedConId = Context.getAdministrationService().getGlobalProperty("concept.otherNonCoded");
        Concept otherNonCodedConcept = Context.getConceptService().getConcept(otherNonCodedConId);

        if (dateWidget != null) {
            exitDate = dateWidget.getValue(context, submission);
            if (exitDate != null) {
                if (OpenmrsUtil.compare(exitDate, new Date()) > 0) {
                    ret.add(new FormSubmissionError(context.getFieldName(dateErrorWidget), Context.getMessageSourceService()
                            .getMessage("htmlformentry.error.cannotBeInFuture")));

                }
            }

            if (obsList != null && obsList.size() == 0) {
                if (exitDate == null) {
                    if (reasonForExitWidget != null &&
                            HtmlFormEntryUtil.convertToType(reasonForExitWidget.getValue(context, submission).toString().trim(), Concept.class) != null) {
                        ret.add(new FormSubmissionError(context.getFieldName(dateErrorWidget), Context.getMessageSourceService()
                                .getMessage("htmlformentry.error.required")));
                    }
                }
            }
        }

        if (reasonForExitWidget != null) {
            Object value = reasonForExitWidget.getValue(context, submission);
            exitReasonAnswerConcept = (Concept) HtmlFormEntryUtil.convertToType(value.toString().trim(), Concept.class);
            if (obsList != null && obsList.size() == 0) {
                if (exitReasonAnswerConcept == null) {
                    if (dateWidget != null && dateWidget.getValue(context, submission) != null) {
                        ret.add(new FormSubmissionError(context.getFieldName(reasonForExitErrorWidget), Context.getMessageSourceService()
                                .getMessage("htmlformentry.error.required")));
                    }
                } else if (exitReasonAnswerConcept != null && exitReasonAnswerConcept.getConceptId().equals(patientDiedConcept.getConceptId())) {
                    if (causeOfDeathWidget == null ||
                            HtmlFormEntryUtil.convertToType(causeOfDeathWidget.getValue(context, submission).toString().trim(), Concept.class) == null) {
                        ret.add(new FormSubmissionError(context.getFieldName(causeOfDeathErrorWidget), Context.getMessageSourceService()
                                .getMessage("htmlformentry.error.required")));
                    }
                } else if (exitReasonAnswerConcept != null && !exitReasonAnswerConcept.getConceptId().equals(patientDiedConcept.getConceptId())) {
                    if (causeOfDeathWidget != null &&
                            HtmlFormEntryUtil.convertToType(causeOfDeathWidget.getValue(context, submission).toString().trim(), Concept.class) != null) {
                        ret.add(new FormSubmissionError(context.getFieldName(causeOfDeathErrorWidget), Context.getMessageSourceService()
                                .getMessage("htmlformentry.error.cannotEnterAValue")));
                    }
                }
            }
        }

        if (causeOfDeathWidget != null) {
            Object value = causeOfDeathWidget.getValue(context, submission);
            causeOfDeathAnswerConcept = (Concept) HtmlFormEntryUtil.convertToType(value.toString().trim(), Concept.class);
            String valueString = otherReasonWidget.getValue(context, submission);

            if (obsDeath != null && obsDeath.size() == 0) {
                if (causeOfDeathAnswerConcept == null) {
                    if (otherReasonWidget != null && !valueString.equals("")) {
                        ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
                                .getMessage("htmlformentry.error.cannotEnterAValue")));
                    }
                } else if (causeOfDeathAnswerConcept != null && causeOfDeathAnswerConcept.getConceptId().equals(otherNonCodedConcept.getConceptId())) {
                    if (otherReasonWidget == null || valueString.equals("")) {
                        ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
                                .getMessage("htmlformentry.error.required")));
                    }
                } else if (causeOfDeathAnswerConcept != null && !causeOfDeathAnswerConcept.getConceptId().equals(otherNonCodedConcept.getConceptId())) {
                    if (otherReasonWidget != null && !valueString.equals("")) {
                        ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
                                .getMessage("htmlformentry.error.cannotEnterAValue")));
                    }
                }
            }
        }

        // this validation is added to avoid user resetting the 'exit from care'
        if (obsList != null && obsList.size() == 1) {
            if (exitDate == null) {
                ret.add(new FormSubmissionError(context.getFieldName(dateErrorWidget), Context.getMessageSourceService()
                        .getMessage("htmlformentry.error.required")));
            } else if (exitReasonAnswerConcept == null) {
                ret.add(new FormSubmissionError(context.getFieldName(reasonForExitErrorWidget), Context.getMessageSourceService()
                        .getMessage("htmlformentry.error.required")));
            } else if (exitReasonAnswerConcept != null && exitReasonAnswerConcept.getConceptId().equals(patientDiedConcept.getConceptId())) {
                if (causeOfDeathWidget == null ||
                        HtmlFormEntryUtil.convertToType(causeOfDeathWidget.getValue(context, submission).toString().trim(), Concept.class) == null) {
                    ret.add(new FormSubmissionError(context.getFieldName(causeOfDeathErrorWidget), Context.getMessageSourceService()
                            .getMessage("htmlformentry.error.required")));
                }
            } else if (exitReasonAnswerConcept != null && !exitReasonAnswerConcept.getConceptId().equals(patientDiedConcept.getConceptId())) {
                if (causeOfDeathWidget != null &&
                        HtmlFormEntryUtil.convertToType(causeOfDeathWidget.getValue(context, submission).toString().trim(), Concept.class) != null) {
                    ret.add(new FormSubmissionError(context.getFieldName(causeOfDeathErrorWidget), Context.getMessageSourceService()
                            .getMessage("htmlformentry.error.cannotEnterAValue")));
                }
            }
        }

        // this validation is added to avoid user resetting the 'patient died' incident
        String valueString = otherReasonWidget.getValue(context, submission);

        if (obsDeath != null && obsDeath.size() == 1) {
            if (causeOfDeathAnswerConcept != null && causeOfDeathAnswerConcept.getConceptId().equals(otherNonCodedConcept.getConceptId())) {
                if (otherReasonWidget == null || valueString.equals("")) {
                    ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
                            .getMessage("htmlformentry.error.required")));
                }
            } else if (causeOfDeathAnswerConcept != null && !causeOfDeathAnswerConcept.getConceptId().equals(otherNonCodedConcept.getConceptId())) {
                if (otherReasonWidget != null && !valueString.equals("")) {
                    ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
                            .getMessage("htmlformentry.error.cannotEnterAValue")));
                }
            }
View Full Code Here

    @Override
    public void handleSubmission(FormEntrySession session, HttpServletRequest submission) {

        Date date = null;
        Concept exitReasonConcept = null;
        Concept causeOfDeathConcept = null;
        String otherReason = null;

        if (dateWidget != null) {
            date = dateWidget.getValue(session.getContext(), submission);
        }
View Full Code Here

        StringBuilder sb = new StringBuilder();

        Patient patient = context.getExistingPatient();

        String patientDiedConId = Context.getAdministrationService().getGlobalProperty("concept.patientDied");
        Concept patientDiedConcept = Context.getConceptService().getConcept(patientDiedConId);
        String otherNonCodedConId = Context.getAdministrationService().getGlobalProperty("concept.otherNonCoded");
        Concept otherNonCodedConcept = Context.getConceptService().getConcept(otherNonCodedConId);

        String reasonWidgetId = context.getFieldName(reasonForExitWidget);
        String causeWidgetId = context.getFieldName(causeOfDeathWidget);
        String otherTextWidgetId = context.getFieldName(otherReasonWidget);

        String reasonConId = Context.getAdministrationService().getGlobalProperty("concept.reasonExitedCare");
        Concept reasonExitConcept = Context.getConceptService().getConcept(reasonConId);
        List<Obs> obsList = Context.getObsService().getObservationsByPersonAndConcept(patient, reasonExitConcept);

        String causeOfDeathConId = Context.getAdministrationService().getGlobalProperty("concept.causeOfDeath");
        Concept causeOfDeathConcept = Context.getConceptService().getConcept(causeOfDeathConId);
        List<Obs> obsDeath = Context.getObsService().getObservationsByPersonAndConcept(patient, causeOfDeathConcept);


        if (reasonForExitWidget != null) {
            if (context.getMode() == FormEntryContext.Mode.VIEW) {
View Full Code Here

    context.registerErrorWidget(discontinuedDateWidget, discontinuedDateErrorWidget);
   
    //discontinue reasons
    if (parameters.get(FIELD_DISCONTINUED_REASON) != null){
        String discReasonConceptStr = (String) parameters.get(FIELD_DISCONTINUED_REASON);
        Concept discontineReasonConcept = HtmlFormEntryUtil.getConcept(discReasonConceptStr);
        if (discontineReasonConcept == null)
            throw new IllegalArgumentException("discontinuedReasonConceptId is not set to a valid conceptId or concept UUID");
        srf.setDiscontinuedReasonQuestion(discontineReasonConcept);
       
        discontinuedReasonWidget = new DropdownWidget();
        discontinuedReasonErrorWidget = new ErrorWidget();
       
        List<Option> discOptions = new ArrayList<Option>();
        discOptions.add(new Option("", "", false));
       
        if (parameters.get(FIELD_DISCONTINUED_REASON_ANSWERS) != null){
            //setup a list of the reason concepts
            List<Concept> discReasons = new ArrayList<Concept>();
            String discAnswersString = (String) parameters.get(FIELD_DISCONTINUED_REASON_ANSWERS);
            String[] strDiscAnswers = discAnswersString.split(",");
            for (int i = 0; i < strDiscAnswers.length; i++){
                String thisAnswer = strDiscAnswers[i];
                Concept answer = HtmlFormEntryUtil.getConcept(thisAnswer, "discontinueReasonAnswers includes a value that is not a valid conceptId or concept UUID");
                  discReasons.add(answer);
            }
          
            if (parameters.get(FIELD_DISCONTINUED_REASON_ANSWER_LABELS) != null){
                // use the listed discontinueReasons, and use labels:
View Full Code Here

        when(context.getMode()).thenReturn(FormEntryContext.Mode.VIEW);

        DynamicAutocompleteWidget dynamicAutocompleteWidget = new DynamicAutocompleteWidget(generateConceptList(), null);

        Concept initialValue = mock(Concept.class);
        when(initialValue.getDisplayString()).thenReturn("concept1");
        dynamicAutocompleteWidget.setInitialValue(initialValue);

        String html = dynamicAutocompleteWidget.generateHtml(context);

        TestUtil.assertFuzzyContains("concept1", html);
View Full Code Here

        when(context.getMode()).thenReturn(FormEntryContext.Mode.VIEW);

        DynamicAutocompleteWidget dynamicAutocompleteWidget = new DynamicAutocompleteWidget(generateConceptList(), null);

        Concept initialValue1 = mock(Concept.class);
        when(initialValue1.getDisplayString()).thenReturn("concept1");
        dynamicAutocompleteWidget.addInitialValue(initialValue1);

        Concept initialValue2 = mock(Concept.class);
        when(initialValue2.getDisplayString()).thenReturn("concept2");
        dynamicAutocompleteWidget.addInitialValue(initialValue2);

        String html = dynamicAutocompleteWidget.generateHtml(context);

        TestUtil.assertFuzzyContains("concept1;concept2;", html);
View Full Code Here

    private List<Concept> generateConceptList() {

        List<Concept>  conceptList = new ArrayList<Concept>();

        Concept concept1 = new Concept();
        concept1.setConceptId(1);
        ConceptName concept1Name = new ConceptName();
        concept1Name.setName("concept1");
        concept1.addName(concept1Name);
        conceptList.add(concept1);

        Concept concept2 = new Concept();
        concept2.setConceptId(2);
        ConceptName concept2Name = new ConceptName();
        concept1Name.setName("concept2");
        concept1.addName(concept2Name);
        conceptList.add(concept2);

        Concept concept3 = new Concept();
        concept3.setConceptId(3);
        ConceptName concept3Name = new ConceptName();
        concept1Name.setName("concept3");
        concept1.addName(concept3Name);
        conceptList.add(concept3);
View Full Code Here

TOP

Related Classes of org.openmrs.Concept

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.