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