Search in sources :

Example 11 with ProgramInstance

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

the class NoRegistrationSingleEventServiceTest method setUpTest.

@Override
protected void setUpTest() throws Exception {
    userService = _userService;
    organisationUnitA = createOrganisationUnit('A');
    identifiableObjectManager.save(organisationUnitA);
    dataElementA = createDataElement('A');
    dataElementA.setValueType(ValueType.INTEGER);
    identifiableObjectManager.save(dataElementA);
    programStageA = createProgramStage('A', 0);
    identifiableObjectManager.save(programStageA);
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programA.setProgramType(ProgramType.WITHOUT_REGISTRATION);
    identifiableObjectManager.save(programA);
    ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
    programStageDataElement.setDataElement(dataElementA);
    programStageDataElement.setProgramStage(programStageA);
    programStageDataElementService.addProgramStageDataElement(programStageDataElement);
    programStageA.getProgramStageDataElements().add(programStageDataElement);
    programStageA.setProgram(programA);
    programA.getProgramStages().add(programStageA);
    identifiableObjectManager.update(programStageA);
    identifiableObjectManager.update(programA);
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setProgram(programA);
    programInstance.setIncidentDate(new Date());
    programInstance.setEnrollmentDate(new Date());
    programInstanceService.addProgramInstance(programInstance);
    identifiableObjectManager.update(programA);
    createUserAndInjectSecurityContext(true);
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Date(java.util.Date) HashSet(java.util.HashSet)

Example 12 with ProgramInstance

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

the class AbstractTrackedEntityInstanceService method getTrackedEntityInstance.

@Override
public TrackedEntityInstance getTrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance, TrackedEntityInstanceParams params) {
    if (entityInstance == null) {
        return null;
    }
    TrackedEntityInstance trackedEntityInstance = new TrackedEntityInstance();
    trackedEntityInstance.setTrackedEntityInstance(entityInstance.getUid());
    trackedEntityInstance.setOrgUnit(entityInstance.getOrganisationUnit().getUid());
    trackedEntityInstance.setTrackedEntity(entityInstance.getTrackedEntity().getUid());
    trackedEntityInstance.setCreated(DateUtils.getIso8601NoTz(entityInstance.getCreated()));
    trackedEntityInstance.setCreatedAtClient(DateUtils.getIso8601NoTz(entityInstance.getLastUpdatedAtClient()));
    trackedEntityInstance.setLastUpdated(DateUtils.getIso8601NoTz(entityInstance.getLastUpdated()));
    trackedEntityInstance.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(entityInstance.getLastUpdatedAtClient()));
    trackedEntityInstance.setInactive(entityInstance.isInactive());
    if (params.isIncludeRelationships()) {
        //TODO include relationships in data model and void transactional query in for-loop
        Collection<Relationship> relationships = relationshipService.getRelationshipsForTrackedEntityInstance(entityInstance);
        for (Relationship entityRelationship : relationships) {
            org.hisp.dhis.dxf2.events.trackedentity.Relationship relationship = new org.hisp.dhis.dxf2.events.trackedentity.Relationship();
            relationship.setDisplayName(entityRelationship.getRelationshipType().getDisplayName());
            relationship.setTrackedEntityInstanceA(entityRelationship.getEntityInstanceA().getUid());
            relationship.setTrackedEntityInstanceB(entityRelationship.getEntityInstanceB().getUid());
            relationship.setRelationship(entityRelationship.getRelationshipType().getUid());
            // we might have cases where A <=> A, so we only include the relative if the UIDs do not match
            if (!entityRelationship.getEntityInstanceA().getUid().equals(entityInstance.getUid())) {
                relationship.setRelative(getTrackedEntityInstance(entityRelationship.getEntityInstanceA(), TrackedEntityInstanceParams.FALSE));
            } else if (!entityRelationship.getEntityInstanceB().getUid().equals(entityInstance.getUid())) {
                relationship.setRelative(getTrackedEntityInstance(entityRelationship.getEntityInstanceB(), TrackedEntityInstanceParams.FALSE));
            }
            trackedEntityInstance.getRelationships().add(relationship);
        }
    }
    if (params.isIncludeEnrollments()) {
        for (ProgramInstance programInstance : entityInstance.getProgramInstances()) {
            trackedEntityInstance.getEnrollments().add(enrollmentService.getEnrollment(programInstance, params));
        }
    }
    for (TrackedEntityAttributeValue attributeValue : entityInstance.getTrackedEntityAttributeValues()) {
        Attribute attribute = new Attribute();
        attribute.setCreated(DateUtils.getIso8601NoTz(attributeValue.getCreated()));
        attribute.setLastUpdated(DateUtils.getIso8601NoTz(attributeValue.getLastUpdated()));
        attribute.setDisplayName(attributeValue.getAttribute().getDisplayName());
        attribute.setAttribute(attributeValue.getAttribute().getUid());
        attribute.setValueType(attributeValue.getAttribute().getValueType());
        attribute.setCode(attributeValue.getAttribute().getCode());
        attribute.setValue(attributeValue.getValue());
        trackedEntityInstance.getAttributes().add(attribute);
    }
    return trackedEntityInstance;
}
Also used : TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) Relationship(org.hisp.dhis.relationship.Relationship)

Example 13 with ProgramInstance

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

the class AbstractEnrollmentService method updateEnrollment.

@Override
public ImportSummary updateEnrollment(Enrollment enrollment, ImportOptions importOptions) {
    if (importOptions == null) {
        importOptions = new ImportOptions();
    }
    if (enrollment == null || enrollment.getEnrollment() == null) {
        return new ImportSummary(ImportStatus.ERROR, "No enrollment or enrollment ID was supplied").incrementIgnored();
    }
    ImportSummary importSummary = new ImportSummary(enrollment.getEnrollment());
    ProgramInstance programInstance = programInstanceService.getProgramInstance(enrollment.getEnrollment());
    if (programInstance == null) {
        return new ImportSummary(ImportStatus.ERROR, "Enrollment ID was not valid.").incrementIgnored();
    }
    Set<ImportConflict> importConflicts = new HashSet<>();
    importConflicts.addAll(checkAttributes(enrollment, importOptions));
    importSummary.setConflicts(importConflicts);
    if (!importConflicts.isEmpty()) {
        importSummary.setStatus(ImportStatus.ERROR);
        importSummary.getImportCount().incrementIgnored();
        return importSummary;
    }
    org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = getTrackedEntityInstance(enrollment.getTrackedEntityInstance());
    Program program = getProgram(importOptions.getIdSchemes(), enrollment.getProgram());
    programInstance.setProgram(program);
    programInstance.setEntityInstance(entityInstance);
    if (enrollment.getIncidentDate() != null) {
        programInstance.setIncidentDate(enrollment.getIncidentDate());
    }
    if (enrollment.getEnrollmentDate() != null) {
        programInstance.setEnrollmentDate(enrollment.getEnrollmentDate());
    }
    programInstance.setFollowup(enrollment.getFollowup());
    if (program.getDisplayIncidentDate() && programInstance.getIncidentDate() == null) {
        importSummary.setStatus(ImportStatus.ERROR);
        importSummary.setDescription("DisplayIncidentDate is true but IncidentDate is null ");
        importSummary.incrementIgnored();
        return importSummary;
    }
    if (program.getCaptureCoordinates()) {
        if (enrollment.getCoordinate() != null && enrollment.getCoordinate().isValid()) {
            programInstance.setLatitude(enrollment.getCoordinate().getLatitude());
            programInstance.setLongitude(enrollment.getCoordinate().getLongitude());
        } else {
            programInstance.setLatitude(null);
            programInstance.setLongitude(null);
        }
    }
    if (EnrollmentStatus.fromProgramStatus(programInstance.getStatus()) != enrollment.getStatus()) {
        if (EnrollmentStatus.CANCELLED == enrollment.getStatus()) {
            programInstanceService.cancelProgramInstanceStatus(programInstance);
        } else if (EnrollmentStatus.COMPLETED == enrollment.getStatus()) {
            programInstanceService.completeProgramInstanceStatus(programInstance);
        } else if (EnrollmentStatus.ACTIVE == enrollment.getStatus()) {
            programInstanceService.incompleteProgramInstanceStatus(programInstance);
        }
    }
    updateAttributeValues(enrollment, importOptions);
    updateDateFields(enrollment, programInstance);
    programInstanceService.updateProgramInstance(programInstance);
    manager.update(programInstance.getEntityInstance());
    saveTrackedEntityComment(programInstance, enrollment);
    importSummary.setReference(enrollment.getEnrollment());
    importSummary.getImportCount().incrementUpdated();
    importOptions.setStrategy(ImportStrategy.CREATE_AND_UPDATE);
    importSummary.setEvents(handleEvents(enrollment, programInstance, importOptions));
    return importSummary;
}
Also used : Program(org.hisp.dhis.program.Program) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) HashSet(java.util.HashSet) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 14 with ProgramInstance

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

the class AbstractEnrollmentService method deleteEnrollment.

// -------------------------------------------------------------------------
// DELETE
// -------------------------------------------------------------------------
@Override
public ImportSummary deleteEnrollment(String uid) {
    ProgramInstance programInstance = programInstanceService.getProgramInstance(uid);
    if (programInstance != null) {
        programInstanceService.deleteProgramInstance(programInstance);
        manager.update(programInstance.getEntityInstance());
        return new ImportSummary(ImportStatus.SUCCESS, "Deletion of enrollment " + uid + " was successful.").incrementDeleted();
    }
    return new ImportSummary(ImportStatus.ERROR, "ID " + uid + " does not point to a valid enrollment").incrementIgnored();
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance)

Example 15 with ProgramInstance

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

the class AbstractEnrollmentService method cancelEnrollment.

@Override
public void cancelEnrollment(String uid) {
    ProgramInstance programInstance = programInstanceService.getProgramInstance(uid);
    programInstanceService.cancelProgramInstanceStatus(programInstance);
    manager.update(programInstance.getEntityInstance());
}
Also used : ProgramInstance(org.hisp.dhis.program.ProgramInstance)

Aggregations

ProgramInstance (org.hisp.dhis.program.ProgramInstance)24 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)10 Date (java.util.Date)9 Program (org.hisp.dhis.program.Program)9 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 ProgramStage (org.hisp.dhis.program.ProgramStage)7 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)7 HashSet (java.util.HashSet)5 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)5 ArrayList (java.util.ArrayList)4 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)3 ProgramInstanceQueryParams (org.hisp.dhis.program.ProgramInstanceQueryParams)3 Patient (org.hisp.dhis.api.mobile.model.LWUITmodel.Patient)2 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)2 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)2 Relationship (org.hisp.dhis.relationship.Relationship)2 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)2 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)2 TrackedEntityDataValue (org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue)2 Lists (com.google.common.collect.Lists)1