Search in sources :

Example 1 with TrackedEntity

use of org.hisp.dhis.trackedentity.TrackedEntity in project dhis2-core by dhis2.

the class AbstractTrackedEntityInstanceService method getTrackedEntityInstance.

public org.hisp.dhis.trackedentity.TrackedEntityInstance getTrackedEntityInstance(TrackedEntityInstance trackedEntityInstance, ImportOptions importOptions, ImportSummary importSummary) {
    if (StringUtils.isEmpty(trackedEntityInstance.getOrgUnit())) {
        importSummary.getConflicts().add(new ImportConflict(trackedEntityInstance.getTrackedEntityInstance(), "No org unit ID in tracked entity instance object."));
        return null;
    }
    org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = new org.hisp.dhis.trackedentity.TrackedEntityInstance();
    OrganisationUnit organisationUnit = getOrganisationUnit(importOptions.getIdSchemes(), trackedEntityInstance.getOrgUnit());
    if (organisationUnit == null) {
        importSummary.getConflicts().add(new ImportConflict(trackedEntityInstance.getTrackedEntityInstance(), "Invalid org unit ID: " + trackedEntityInstance.getOrgUnit()));
        return null;
    }
    entityInstance.setOrganisationUnit(organisationUnit);
    TrackedEntity trackedEntity = getTrackedEntity(importOptions.getIdSchemes(), trackedEntityInstance.getTrackedEntity());
    if (trackedEntity == null) {
        importSummary.getConflicts().add(new ImportConflict(trackedEntityInstance.getTrackedEntityInstance(), "Invalid tracked entity ID: " + trackedEntityInstance.getTrackedEntity()));
        return null;
    }
    entityInstance.setTrackedEntity(trackedEntity);
    entityInstance.setUid(CodeGenerator.isValidUid(trackedEntityInstance.getTrackedEntityInstance()) ? trackedEntityInstance.getTrackedEntityInstance() : CodeGenerator.generateUid());
    return entityInstance;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 2 with TrackedEntity

use of org.hisp.dhis.trackedentity.TrackedEntity in project dhis2-core by dhis2.

the class DhisConvenienceTest method createTrackedEntity.

public static TrackedEntity createTrackedEntity(char uniqueChar) {
    TrackedEntity trackedEntity = new TrackedEntity();
    trackedEntity.setAutoFields();
    trackedEntity.setName("TrackedEntity" + uniqueChar);
    trackedEntity.setDescription("TrackedEntity" + uniqueChar + " description");
    return trackedEntity;
}
Also used : TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity)

Example 3 with TrackedEntity

use of org.hisp.dhis.trackedentity.TrackedEntity in project dhis2-core by dhis2.

the class AbstractTrackedEntityInstanceService method checkTrackedEntity.

private List<ImportConflict> checkTrackedEntity(TrackedEntityInstance trackedEntityInstance, ImportOptions importOptions) {
    List<ImportConflict> importConflicts = new ArrayList<>();
    if (trackedEntityInstance.getTrackedEntity() == null) {
        importConflicts.add(new ImportConflict("TrackedEntityInstance.trackedEntity", "Missing required property trackedEntity"));
        return importConflicts;
    }
    TrackedEntity trackedEntity = getTrackedEntity(importOptions.getIdSchemes(), trackedEntityInstance.getTrackedEntity());
    if (trackedEntity == null) {
        importConflicts.add(new ImportConflict("TrackedEntityInstance.trackedEntity", "Invalid trackedEntity" + trackedEntityInstance.getTrackedEntity()));
    }
    return importConflicts;
}
Also used : TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) ArrayList(java.util.ArrayList) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 4 with TrackedEntity

use of org.hisp.dhis.trackedentity.TrackedEntity in project dhis2-core by dhis2.

the class UpdateProgramAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    displayProvidedOtherFacility = (displayProvidedOtherFacility == null) ? false : displayProvidedOtherFacility;
    displayIncidentDate = (displayIncidentDate == null) ? false : displayIncidentDate;
    generateBydEnrollmentDate = (generateBydEnrollmentDate == null) ? false : generateBydEnrollmentDate;
    ignoreOverdueEvents = (ignoreOverdueEvents == null) ? false : ignoreOverdueEvents;
    blockEntryForm = (blockEntryForm == null) ? false : blockEntryForm;
    remindCompleted = (remindCompleted == null) ? false : remindCompleted;
    selectEnrollmentDatesInFuture = (selectEnrollmentDatesInFuture == null) ? false : selectEnrollmentDatesInFuture;
    selectIncidentDatesInFuture = (selectIncidentDatesInFuture == null) ? false : selectIncidentDatesInFuture;
    Program program = programService.getProgram(id);
    program.setName(StringUtils.trimToNull(name));
    program.setShortName(StringUtils.trimToNull(shortName));
    program.setDescription(StringUtils.trimToNull(description));
    program.setEnrollmentDateLabel(StringUtils.trimToNull(enrollmentDateLabel));
    program.setIncidentDateLabel(StringUtils.trimToNull(incidentDateLabel));
    program.setProgramType(programType);
    program.setDisplayIncidentDate(displayIncidentDate);
    program.setOnlyEnrollOnce(onlyEnrollOnce);
    program.setSelectEnrollmentDatesInFuture(selectEnrollmentDatesInFuture);
    program.setSelectIncidentDatesInFuture(selectIncidentDatesInFuture);
    program.setSkipOffline(skipOffline);
    program.setDisplayFrontPageList(displayFrontPageList);
    program.setUseFirstStageDuringRegistration(useFirstStageDuringRegistration);
    program.setCaptureCoordinates(captureCoordinates);
    program.setExpiryDays(expiryDays);
    program.setCompleteEventsExpiryDays(completeEventsExpiryDays);
    if (program.isRegistration()) {
        program.setIgnoreOverdueEvents(ignoreOverdueEvents);
    } else {
        program.setIgnoreOverdueEvents(false);
    }
    periodTypeName = StringUtils.trimToNull(periodTypeName);
    if (periodTypeName != null) {
        PeriodType periodType = PeriodType.getPeriodTypeByName(periodTypeName);
        program.setExpiryPeriodType(periodService.getPeriodTypeByClass(periodType.getClass()));
    } else {
        program.setExpiryPeriodType(null);
    }
    if (relationshipTypeId != null) {
        RelationshipType relationshipType = relationshipTypeService.getRelationshipType(relationshipTypeId);
        program.setRelationshipType(relationshipType);
        program.setRelationshipFromA(relationshipFromA);
        program.setRelationshipText(relationshipText);
        Program relatedProgram = programService.getProgram(relatedProgramId);
        program.setRelatedProgram(relatedProgram);
    } else {
        program.setRelationshipType(null);
        program.setRelationshipFromA(null);
        program.setRelationshipText(null);
        program.setRelatedProgram(null);
    }
    if (trackedEntityId != null) {
        TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity(trackedEntityId);
        program.setTrackedEntity(trackedEntity);
    } else if (program.getTrackedEntity() != null) {
        program.setTrackedEntity(null);
    }
    if (program.getProgramAttributes() != null) {
        program.getProgramAttributes().clear();
    }
    int index = 0;
    for (String selectedPropertyId : selectedPropertyIds) {
        String[] ids = selectedPropertyId.split("_");
        if (ids[0].equals(TrackedEntityInstance.PREFIX_TRACKED_ENTITY_ATTRIBUTE)) {
            TrackedEntityAttribute attribute = trackedEntityAttributeService.getTrackedEntityAttribute(Integer.parseInt(ids[1]));
            ProgramTrackedEntityAttribute programAttribute = new ProgramTrackedEntityAttribute(program, attribute, personDisplayNames.get(index), mandatory.get(index), allowFutureDate.get(index));
            programAttribute.setRenderOptionsAsRadio(renderOptionsAsRadios.get(index));
            programAttribute.setAutoFields();
            program.getProgramAttributes().add(programAttribute);
        }
        index++;
    }
    //TODO make more fine-grained
    program.increaseVersion();
    if (jsonAttributeValues != null) {
        attributeService.updateAttributeValues(program, jsonAttributeValues);
    }
    if (categoryComboId != null) {
        program.setCategoryCombo(categoryService.getDataElementCategoryCombo(categoryComboId));
    }
    if (workflowId != null && workflowId > 0) {
        program.setWorkflow(dataApprovalService.getWorkflow(workflowId));
    } else {
        program.setWorkflow(null);
    }
    programService.updateProgram(program);
    return SUCCESS;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Program(org.hisp.dhis.program.Program) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Example 5 with TrackedEntity

use of org.hisp.dhis.trackedentity.TrackedEntity in project dhis2-core by dhis2.

the class AddProgramAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    displayIncidentDate = (displayIncidentDate == null) ? false : displayIncidentDate;
    ignoreOverdueEvents = (ignoreOverdueEvents == null) ? false : ignoreOverdueEvents;
    onlyEnrollOnce = (onlyEnrollOnce == null) ? false : onlyEnrollOnce;
    selectEnrollmentDatesInFuture = (selectEnrollmentDatesInFuture == null) ? false : selectEnrollmentDatesInFuture;
    selectIncidentDatesInFuture = (selectIncidentDatesInFuture == null) ? false : selectIncidentDatesInFuture;
    Program program = new Program();
    program.setName(StringUtils.trimToNull(name));
    program.setShortName(StringUtils.trimToNull(shortName));
    program.setDescription(StringUtils.trimToNull(description));
    program.setVersion(1);
    program.setEnrollmentDateLabel(StringUtils.trimToNull(enrollmentDateLabel));
    program.setIncidentDateLabel(StringUtils.trimToNull(incidentDateLabel));
    program.setProgramType(programType);
    program.setDisplayIncidentDate(displayIncidentDate);
    program.setOnlyEnrollOnce(onlyEnrollOnce);
    program.setSelectEnrollmentDatesInFuture(selectEnrollmentDatesInFuture);
    program.setSelectIncidentDatesInFuture(selectIncidentDatesInFuture);
    program.setSkipOffline(skipOffline);
    program.setDisplayFrontPageList(displayFrontPageList);
    program.setUseFirstStageDuringRegistration(useFirstStageDuringRegistration);
    program.setCaptureCoordinates(captureCoordinates);
    program.setExpiryDays(expiryDays);
    program.setCompleteEventsExpiryDays(completeEventsExpiryDays);
    if (programType == ProgramType.WITH_REGISTRATION) {
        program.setIgnoreOverdueEvents(ignoreOverdueEvents);
    } else {
        program.setIgnoreOverdueEvents(false);
    }
    periodTypeName = StringUtils.trimToNull(periodTypeName);
    if (periodTypeName != null) {
        PeriodType periodType = PeriodType.getPeriodTypeByName(periodTypeName);
        program.setExpiryPeriodType(periodService.getPeriodTypeByClass(periodType.getClass()));
    } else {
        program.setExpiryPeriodType(null);
    }
    if (relationshipTypeId != null) {
        RelationshipType relationshipType = relationshipTypeService.getRelationshipType(relationshipTypeId);
        program.setRelationshipType(relationshipType);
        program.setRelationshipFromA(relationshipFromA);
        program.setRelationshipText(relationshipText);
        Program relatedProgram = programService.getProgram(relatedProgramId);
        program.setRelatedProgram(relatedProgram);
    } else {
        program.setRelationshipType(null);
        program.setRelationshipFromA(null);
        program.setRelationshipText(null);
        program.setRelatedProgram(null);
    }
    if (trackedEntityId != null) {
        TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity(trackedEntityId);
        program.setTrackedEntity(trackedEntity);
    }
    if (categoryComboId != null) {
        program.setCategoryCombo(categoryService.getDataElementCategoryCombo(categoryComboId));
    }
    if (workflowId != null && workflowId > 0) {
        program.setWorkflow(dataApprovalService.getWorkflow(workflowId));
    }
    programService.addProgram(program);
    int index = 0;
    for (String selectedPropertyId : selectedPropertyIds) {
        String[] ids = selectedPropertyId.split("_");
        if (ids[0].equals(TrackedEntityInstance.PREFIX_TRACKED_ENTITY_ATTRIBUTE)) {
            TrackedEntityAttribute attribute = trackedEntityAttributeService.getTrackedEntityAttribute(Integer.parseInt(ids[1]));
            ProgramTrackedEntityAttribute programAttribute = new ProgramTrackedEntityAttribute(program, attribute, personDisplayNames.get(index), mandatory.get(index), allowFutureDate.get(index));
            programAttribute.setRenderOptionsAsRadio(renderOptionsAsRadios.get(index));
            programAttribute.setAutoFields();
            program.getProgramAttributes().add(programAttribute);
        }
        index++;
    }
    if (jsonAttributeValues != null) {
        attributeService.updateAttributeValues(program, jsonAttributeValues);
    }
    programService.updateProgram(program);
    if (program.isWithoutRegistration()) {
        ProgramStage programStage = new ProgramStage();
        programStage.setName(name);
        programStage.setDescription(description);
        programStage.setProgram(program);
        programStage.setMinDaysFromStart(0);
        programStage.setAutoGenerateEvent(true);
        programStage.setExecutionDateLabel(REPORT_DATE_DESCRIPTION);
        programStageService.saveProgramStage(programStage);
    }
    if (program.isWithoutRegistration()) {
        // Add a new program-instance
        ProgramInstance programInstance = new ProgramInstance();
        programInstance.setEnrollmentDate(new Date());
        programInstance.setIncidentDate(new Date());
        programInstance.setProgram(program);
        programInstance.setStatus(ProgramStatus.ACTIVE);
        programInstanceService.addProgramInstance(programInstance);
    }
    return SUCCESS;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Program(org.hisp.dhis.program.Program) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) ProgramInstance(org.hisp.dhis.program.ProgramInstance) RelationshipType(org.hisp.dhis.relationship.RelationshipType) ProgramStage(org.hisp.dhis.program.ProgramStage) Date(java.util.Date)

Aggregations

TrackedEntity (org.hisp.dhis.trackedentity.TrackedEntity)8 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)4 ArrayList (java.util.ArrayList)3 Program (org.hisp.dhis.program.Program)3 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)3 Date (java.util.Date)2 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 PeriodType (org.hisp.dhis.period.PeriodType)2 ProgramTrackedEntityAttribute (org.hisp.dhis.program.ProgramTrackedEntityAttribute)2 RelationshipType (org.hisp.dhis.relationship.RelationshipType)2 List (java.util.List)1 NotAllowedException (org.hisp.dhis.api.mobile.NotAllowedException)1 PatientList (org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList)1 PatientAttribute (org.hisp.dhis.api.mobile.model.PatientAttribute)1 Grid (org.hisp.dhis.common.Grid)1 GridHeader (org.hisp.dhis.common.GridHeader)1 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)1 QueryFilter (org.hisp.dhis.common.QueryFilter)1 QueryItem (org.hisp.dhis.common.QueryItem)1