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);
}
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;
}
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;
}
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();
}
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());
}
Aggregations