Search in sources :

Example 11 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class AddValidationCriteriaAction method execute.

// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    ValidationCriteria criteria = new ValidationCriteria();
    criteria.setName(StringUtils.trimToNull(name));
    criteria.setDescription(StringUtils.trimToNull(description));
    criteria.setProperty(property);
    criteria.setOperator(operator);
    criteria.setValue(value);
    validationCriteriaService.saveValidationCriteria(criteria);
    Program program = programService.getProgram(programId);
    program.getValidationCriteria().add(criteria);
    programService.updateProgram(program);
    return SUCCESS;
}
Also used : Program(org.hisp.dhis.program.Program) ValidationCriteria(org.hisp.dhis.validation.ValidationCriteria)

Example 12 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class ShowUpdateProgramFormAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    program = programService.getProgram(id);
    attributeValues = AttributeUtils.getAttributeValueMap(program.getAttributeValues());
    availableAttributes = trackedEntityAttributeService.getAllTrackedEntityAttributes();
    for (ProgramTrackedEntityAttribute programTrackedEntityAttribute : program.getProgramAttributes()) {
        availableAttributes.remove(programTrackedEntityAttribute.getAttribute());
    }
    Collections.sort(availableAttributes);
    programs = programService.getAllPrograms();
    programs.removeAll(programService.getPrograms(ProgramType.WITHOUT_REGISTRATION));
    programs.remove(program);
    Collections.sort(programs);
    userGroups = userGroupService.getAllUserGroups();
    relationshipTypes = relationshipTypeService.getAllRelationshipTypes();
    Collections.sort(relationshipTypes);
    trackedEntities = trackedEntityService.getAllTrackedEntity();
    Collections.sort(trackedEntities);
    attributes = attributeService.getAttributes(Program.class);
    categoryCombos = new ArrayList<>(categoryService.getAttributeCategoryCombos());
    workflows = new ArrayList<>(dataApprovalService.getAllWorkflows());
    Collections.sort(workflows);
    periodTypes = periodService.getAllPeriodTypes();
    return SUCCESS;
}
Also used : Program(org.hisp.dhis.program.Program) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute)

Example 13 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class ValidateProgramAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    name = name.trim();
    Program match = programService.getProgramByName(name);
    if (match != null && (id == null || match.getId() != id.intValue())) {
        message = i18n.getString("duplicate_names");
        return ERROR;
    }
    message = i18n.getString("everything_is_ok");
    return SUCCESS;
}
Also used : Program(org.hisp.dhis.program.Program)

Example 14 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class AddProgramStageAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    minDaysFromStart = (minDaysFromStart == null) ? 0 : minDaysFromStart;
    repeatable = (repeatable == null) ? false : repeatable;
    autoGenerateEvent = (autoGenerateEvent == null) ? false : autoGenerateEvent;
    validCompleteOnly = (validCompleteOnly == null) ? false : validCompleteOnly;
    displayGenerateEventBox = (displayGenerateEventBox == null) ? false : displayGenerateEventBox;
    captureCoordinates = (captureCoordinates == null) ? false : captureCoordinates;
    relatedEntityInstance = (relatedEntityInstance == null) ? false : relatedEntityInstance;
    generatedByEnrollmentDate = (generatedByEnrollmentDate == null) ? false : generatedByEnrollmentDate;
    blockEntryForm = (blockEntryForm == null) ? false : blockEntryForm;
    remindCompleted = (remindCompleted == null) ? false : remindCompleted;
    allowGenerateNextVisit = (allowGenerateNextVisit == null) ? false : allowGenerateNextVisit;
    openAfterEnrollment = (openAfterEnrollment == null) ? false : openAfterEnrollment;
    preGenerateUID = (preGenerateUID == null) ? false : preGenerateUID;
    hideDueDate = (hideDueDate == null) ? false : hideDueDate;
    ProgramStage programStage = new ProgramStage();
    Program program = programService.getProgram(id);
    programStage.setName(StringUtils.trimToNull(name));
    programStage.setDescription(StringUtils.trimToNull(description));
    programStage.setProgram(program);
    programStage.setStandardInterval(standardInterval);
    programStage.setExecutionDateLabel(StringUtils.trimToNull(excecutionDateLabel));
    programStage.setRepeatable(repeatable);
    programStage.setMinDaysFromStart(minDaysFromStart);
    programStage.setDisplayGenerateEventBox(displayGenerateEventBox);
    programStage.setValidCompleteOnly(validCompleteOnly);
    if (!hideDueDate) {
        programStage.setDueDateLabel(StringUtils.trimToNull(dueDateLabel));
    }
    periodTypeName = StringUtils.trimToNull(periodTypeName);
    if (periodTypeName != null) {
        PeriodType periodType = PeriodType.getPeriodTypeByName(periodTypeName);
        programStage.setPeriodType(periodService.getPeriodTypeByClass(periodType.getClass()));
    } else {
        programStage.setPeriodType(null);
    }
    if (program.isWithoutRegistration()) {
        programStage.setAutoGenerateEvent(true);
    } else {
        programStage.setAutoGenerateEvent(autoGenerateEvent);
    }
    programStage.setCaptureCoordinates(captureCoordinates);
    programStage.setBlockEntryForm(blockEntryForm);
    programStage.setRemindCompleted(remindCompleted);
    programStage.setGeneratedByEnrollmentDate(generatedByEnrollmentDate);
    programStage.setAllowGenerateNextVisit(allowGenerateNextVisit);
    programStage.setOpenAfterEnrollment(openAfterEnrollment);
    programStage.setReportDateToUse(reportDateToUse);
    programStage.setPreGenerateUID(preGenerateUID);
    programStage.setSortOrder(program.getProgramStages().size() + 1);
    programStage.setHideDueDate(hideDueDate);
    program.getProgramStages().add(programStage);
    if (jsonAttributeValues != null) {
        attributeService.updateAttributeValues(programStage, jsonAttributeValues);
    }
    programStageService.saveProgramStage(programStage);
    for (int i = 0; i < this.selectedDataElementsValidator.size(); i++) {
        DataElement dataElement = dataElementService.getDataElement(selectedDataElementsValidator.get(i));
        Boolean allowed = allowProvidedElsewhere.get(i) == null ? false : allowProvidedElsewhere.get(i);
        Boolean displayInReport = displayInReports.get(i) == null ? false : displayInReports.get(i);
        Boolean allowDate = allowFutureDates.get(i) == null ? false : allowFutureDates.get(i);
        ProgramStageDataElement programStageDataElement = new ProgramStageDataElement(programStage, dataElement, this.compulsories.get(i), new Integer(i));
        programStageDataElement.setAllowProvidedElsewhere(allowed);
        programStageDataElement.setDisplayInReports(displayInReport);
        programStageDataElement.setAllowFutureDate(allowDate);
        programStageDataElementService.addProgramStageDataElement(programStageDataElement);
    }
    return SUCCESS;
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) PeriodType(org.hisp.dhis.period.PeriodType) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) Program(org.hisp.dhis.program.Program) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 15 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class AbstractEventService method convertProgramStageInstance.

private Event convertProgramStageInstance(ProgramStageInstance programStageInstance) {
    if (programStageInstance == null) {
        return null;
    }
    Event event = new Event();
    event.setEvent(programStageInstance.getUid());
    if (programStageInstance.getProgramInstance().getEntityInstance() != null) {
        event.setTrackedEntityInstance(programStageInstance.getProgramInstance().getEntityInstance().getUid());
    }
    event.setFollowup(programStageInstance.getProgramInstance().getFollowup());
    event.setEnrollmentStatus(EnrollmentStatus.fromProgramStatus(programStageInstance.getProgramInstance().getStatus()));
    event.setStatus(programStageInstance.getStatus());
    event.setEventDate(DateUtils.getIso8601NoTz(programStageInstance.getExecutionDate()));
    event.setDueDate(DateUtils.getIso8601NoTz(programStageInstance.getDueDate()));
    event.setStoredBy(programStageInstance.getStoredBy());
    event.setCompletedBy(programStageInstance.getCompletedBy());
    event.setCompletedDate(DateUtils.getIso8601NoTz(programStageInstance.getCompletedDate()));
    event.setCreated(DateUtils.getIso8601NoTz(programStageInstance.getCreated()));
    event.setCreatedAtClient(DateUtils.getIso8601NoTz(programStageInstance.getCreatedAtClient()));
    event.setLastUpdated(DateUtils.getIso8601NoTz(programStageInstance.getLastUpdated()));
    event.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(programStageInstance.getLastUpdatedAtClient()));
    UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials();
    OrganisationUnit ou = programStageInstance.getOrganisationUnit();
    if (ou != null) {
        if (!organisationUnitService.isInUserHierarchy(ou)) {
            if (!userCredentials.isSuper() && !userCredentials.isAuthorized("F_TRACKED_ENTITY_INSTANCE_SEARCH_IN_ALL_ORGUNITS")) {
                throw new IllegalQueryException("User has no access to organisation unit: " + ou.getUid());
            }
        }
        event.setOrgUnit(ou.getUid());
        event.setOrgUnitName(ou.getName());
    }
    Program program = programStageInstance.getProgramInstance().getProgram();
    if (!userCredentials.isSuper() && !userCredentials.getAllPrograms().contains(program)) {
        throw new IllegalQueryException("User has no access to program: " + program.getUid());
    }
    event.setProgram(program.getUid());
    event.setEnrollment(programStageInstance.getProgramInstance().getUid());
    event.setProgramStage(programStageInstance.getProgramStage().getUid());
    event.setAttributeOptionCombo(programStageInstance.getAttributeOptionCombo().getUid());
    event.setAttributeCategoryOptions(String.join(";", programStageInstance.getAttributeOptionCombo().getCategoryOptions().stream().map(DataElementCategoryOption::getUid).collect(Collectors.toList())));
    if (programStageInstance.getProgramInstance().getEntityInstance() != null) {
        event.setTrackedEntityInstance(programStageInstance.getProgramInstance().getEntityInstance().getUid());
    }
    if (programStageInstance.getProgramStage().getCaptureCoordinates()) {
        Coordinate coordinate = null;
        if (programStageInstance.getLongitude() != null && programStageInstance.getLatitude() != null) {
            coordinate = new Coordinate(programStageInstance.getLongitude(), programStageInstance.getLatitude());
            try {
                List<Double> list = OBJECT_MAPPER.readValue(coordinate.getCoordinateString(), new TypeReference<List<Double>>() {
                });
                coordinate.setLongitude(list.get(0));
                coordinate.setLatitude(list.get(1));
            } catch (IOException ignored) {
            }
        }
        if (coordinate != null && coordinate.isValid()) {
            event.setCoordinate(coordinate);
        }
    }
    Collection<TrackedEntityDataValue> dataValues = dataValueService.getTrackedEntityDataValues(programStageInstance);
    for (TrackedEntityDataValue dataValue : dataValues) {
        DataValue value = new DataValue();
        value.setCreated(DateUtils.getIso8601NoTz(dataValue.getCreated()));
        value.setLastUpdated(DateUtils.getIso8601NoTz(dataValue.getLastUpdated()));
        value.setDataElement(dataValue.getDataElement().getUid());
        value.setValue(dataValue.getValue());
        value.setProvidedElsewhere(dataValue.getProvidedElsewhere());
        value.setStoredBy(dataValue.getStoredBy());
        event.getDataValues().add(value);
    }
    List<TrackedEntityComment> comments = programStageInstance.getComments();
    for (TrackedEntityComment comment : comments) {
        Note note = new Note();
        note.setValue(comment.getCommentText());
        note.setStoredBy(comment.getCreator());
        if (comment.getCreatedDate() != null) {
            note.setStoredDate(DateUtils.getIso8601NoTz(comment.getCreatedDate()));
        }
        event.getNotes().add(note);
    }
    return event;
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) TrackedEntityDataValue(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue) TrackedEntityDataValue(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) IOException(java.io.IOException) UserCredentials(org.hisp.dhis.user.UserCredentials) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

Program (org.hisp.dhis.program.Program)344 Test (org.junit.jupiter.api.Test)160 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)123 ProgramStage (org.hisp.dhis.program.ProgramStage)109 ProgramInstance (org.hisp.dhis.program.ProgramInstance)79 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)68 Date (java.util.Date)47 Collectors (java.util.stream.Collectors)44 User (org.hisp.dhis.user.User)44 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)42 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)42 BeforeEach (org.junit.jupiter.api.BeforeEach)42 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)41 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)41 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)40 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)39 CategoryCombo (org.hisp.dhis.category.CategoryCombo)39 DataElement (org.hisp.dhis.dataelement.DataElement)39 Event (org.hisp.dhis.tracker.domain.Event)38 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)37