Search in sources :

Example 6 with TrackerTypeReport

use of org.hisp.dhis.tracker.report.TrackerTypeReport in project dhis2-core by dhis2.

the class DefaultTrackerObjectsDeletionService method deleteEvents.

@Override
public TrackerTypeReport deleteEvents(TrackerBundle bundle) {
    TrackerTypeReport typeReport = new TrackerTypeReport(TrackerType.EVENT);
    List<Event> events = bundle.getEvents();
    for (int idx = 0; idx < events.size(); idx++) {
        String uid = events.get(idx).getEvent();
        TrackerObjectReport objectReport = new TrackerObjectReport(TrackerType.EVENT, uid, idx);
        ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(uid);
        ProgramInstance programInstance = programStageInstance.getProgramInstance();
        programStageInstanceService.deleteProgramStageInstance(programStageInstance);
        if (programStageInstance.getProgramStage().getProgram().isRegistration()) {
            teiService.updateTrackedEntityInstance(programStageInstance.getProgramInstance().getEntityInstance());
            programInstance.getProgramStageInstances().remove(programStageInstance);
            programInstanceService.updateProgramInstance(programInstance);
        }
        typeReport.getStats().incDeleted();
        typeReport.addObjectReport(objectReport);
    }
    return typeReport;
}
Also used : TrackerTypeReport(org.hisp.dhis.tracker.report.TrackerTypeReport) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackerObjectReport(org.hisp.dhis.tracker.report.TrackerObjectReport) Event(org.hisp.dhis.tracker.domain.Event) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 7 with TrackerTypeReport

use of org.hisp.dhis.tracker.report.TrackerTypeReport in project dhis2-core by dhis2.

the class DefaultTrackerObjectsDeletionService method deleteRelationShips.

@Override
public TrackerTypeReport deleteRelationShips(TrackerBundle bundle) {
    TrackerTypeReport typeReport = new TrackerTypeReport(TrackerType.RELATIONSHIP);
    List<Relationship> relationships = bundle.getRelationships();
    for (int idx = 0; idx < relationships.size(); idx++) {
        String uid = relationships.get(idx).getRelationship();
        TrackerObjectReport objectReport = new TrackerObjectReport(TrackerType.RELATIONSHIP, uid, idx);
        org.hisp.dhis.relationship.Relationship relationship = relationshipService.getRelationship(uid);
        relationshipService.deleteRelationship(relationship);
        typeReport.getStats().incDeleted();
        typeReport.addObjectReport(objectReport);
    }
    return typeReport;
}
Also used : TrackerTypeReport(org.hisp.dhis.tracker.report.TrackerTypeReport) Relationship(org.hisp.dhis.tracker.domain.Relationship) TrackerObjectReport(org.hisp.dhis.tracker.report.TrackerObjectReport)

Aggregations

TrackerTypeReport (org.hisp.dhis.tracker.report.TrackerTypeReport)7 TrackerObjectReport (org.hisp.dhis.tracker.report.TrackerObjectReport)5 TrackerType (org.hisp.dhis.tracker.TrackerType)4 ProgramInstance (org.hisp.dhis.program.ProgramInstance)3 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)3 Event (org.hisp.dhis.tracker.domain.Event)3 Relationship (org.hisp.dhis.tracker.domain.Relationship)3 Lists (com.google.common.collect.Lists)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 AllArgsConstructor (lombok.AllArgsConstructor)2 ProgramInstanceService (org.hisp.dhis.program.ProgramInstanceService)2 ProgramStageInstanceService (org.hisp.dhis.program.ProgramStageInstanceService)2 RelationshipService (org.hisp.dhis.relationship.RelationshipService)2 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)2 TrackedEntityInstanceService (org.hisp.dhis.trackedentity.TrackedEntityInstanceService)2 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)2 EnrollmentTrackerConverterService (org.hisp.dhis.tracker.converter.EnrollmentTrackerConverterService)2 EventTrackerConverterService (org.hisp.dhis.tracker.converter.EventTrackerConverterService)2