use of org.hisp.dhis.trackedentity.TrackedEntity in project dhis2-core by dhis2.
the class RegistrationSingleEventServiceTest method setUpTest.
@Override
protected void setUpTest() throws Exception {
userService = _userService;
organisationUnitA = createOrganisationUnit('A');
organisationUnitB = createOrganisationUnit('B');
identifiableObjectManager.save(organisationUnitA);
identifiableObjectManager.save(organisationUnitB);
TrackedEntity trackedEntity = createTrackedEntity('A');
trackedEntityService.addTrackedEntity(trackedEntity);
maleA = createTrackedEntityInstance('A', organisationUnitA);
maleB = createTrackedEntityInstance('B', organisationUnitB);
femaleA = createTrackedEntityInstance('C', organisationUnitA);
femaleB = createTrackedEntityInstance('D', organisationUnitB);
maleA.setTrackedEntity(trackedEntity);
maleB.setTrackedEntity(trackedEntity);
femaleA.setTrackedEntity(trackedEntity);
femaleB.setTrackedEntity(trackedEntity);
identifiableObjectManager.save(maleA);
identifiableObjectManager.save(maleB);
identifiableObjectManager.save(femaleA);
identifiableObjectManager.save(femaleB);
trackedEntityInstanceMaleA = trackedEntityInstanceService.getTrackedEntityInstance(maleA);
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.WITH_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);
createUserAndInjectSecurityContext(true);
}
use of org.hisp.dhis.trackedentity.TrackedEntity in project dhis2-core by dhis2.
the class DefaultProgramInstanceService method getFromUrl.
@Override
public ProgramInstanceQueryParams getFromUrl(Set<String> ou, OrganisationUnitSelectionMode ouMode, Date lastUpdated, String program, ProgramStatus programStatus, Date programStartDate, Date programEndDate, String trackedEntity, String trackedEntityInstance, Boolean followUp, Integer page, Integer pageSize, boolean totalPages, boolean skipPaging) {
ProgramInstanceQueryParams params = new ProgramInstanceQueryParams();
if (ou != null) {
for (String orgUnit : ou) {
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(orgUnit);
if (organisationUnit == null) {
throw new IllegalQueryException("Organisation unit does not exist: " + orgUnit);
}
params.getOrganisationUnits().add(organisationUnit);
}
}
Program pr = program != null ? programService.getProgram(program) : null;
if (program != null && pr == null) {
throw new IllegalQueryException("Program does not exist: " + program);
}
TrackedEntity te = trackedEntity != null ? trackedEntityService.getTrackedEntity(trackedEntity) : null;
if (trackedEntity != null && te == null) {
throw new IllegalQueryException("Tracked entity does not exist: " + program);
}
TrackedEntityInstance tei = trackedEntityInstance != null ? trackedEntityInstanceService.getTrackedEntityInstance(trackedEntityInstance) : null;
if (trackedEntityInstance != null && tei == null) {
throw new IllegalQueryException("Tracked entity instance does not exist: " + program);
}
params.setProgram(pr);
params.setProgramStatus(programStatus);
params.setFollowUp(followUp);
params.setLastUpdated(lastUpdated);
params.setProgramStartDate(programStartDate);
params.setProgramEndDate(programEndDate);
params.setTrackedEntity(te);
params.setTrackedEntityInstance(tei);
params.setOrganisationUnitMode(ouMode);
params.setPage(page);
params.setPageSize(pageSize);
params.setTotalPages(totalPages);
params.setSkipPaging(skipPaging);
return params;
}
use of org.hisp.dhis.trackedentity.TrackedEntity in project dhis2-core by dhis2.
the class RegistrationMultiEventsServiceTest method setUpTest.
@Override
protected void setUpTest() throws Exception {
userService = _userService;
organisationUnitA = createOrganisationUnit('A');
organisationUnitB = createOrganisationUnit('B');
identifiableObjectManager.save(organisationUnitA);
identifiableObjectManager.save(organisationUnitB);
TrackedEntity trackedEntity = createTrackedEntity('A');
trackedEntityService.addTrackedEntity(trackedEntity);
maleA = createTrackedEntityInstance('A', organisationUnitA);
maleB = createTrackedEntityInstance('B', organisationUnitB);
femaleA = createTrackedEntityInstance('C', organisationUnitA);
femaleB = createTrackedEntityInstance('D', organisationUnitB);
maleA.setTrackedEntity(trackedEntity);
maleB.setTrackedEntity(trackedEntity);
femaleA.setTrackedEntity(trackedEntity);
femaleB.setTrackedEntity(trackedEntity);
identifiableObjectManager.save(maleA);
identifiableObjectManager.save(maleB);
identifiableObjectManager.save(femaleA);
identifiableObjectManager.save(femaleB);
trackedEntityInstanceMaleA = trackedEntityInstanceService.getTrackedEntityInstance(maleA);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementA.setValueType(ValueType.INTEGER);
dataElementB.setValueType(ValueType.INTEGER);
identifiableObjectManager.save(dataElementA);
identifiableObjectManager.save(dataElementB);
programStageA = createProgramStage('A', 0);
programStageB = createProgramStage('B', 0);
programStageB.setRepeatable(true);
identifiableObjectManager.save(programStageA);
identifiableObjectManager.save(programStageB);
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programA.setProgramType(ProgramType.WITH_REGISTRATION);
identifiableObjectManager.save(programA);
ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
programStageDataElement.setDataElement(dataElementA);
programStageDataElement.setProgramStage(programStageA);
programStageDataElementService.addProgramStageDataElement(programStageDataElement);
programStageA.getProgramStageDataElements().add(programStageDataElement);
programStageA.setProgram(programA);
programStageDataElement = new ProgramStageDataElement();
programStageDataElement.setDataElement(dataElementB);
programStageDataElement.setProgramStage(programStageB);
programStageDataElementService.addProgramStageDataElement(programStageDataElement);
programStageB.getProgramStageDataElements().add(programStageDataElement);
programStageB.setProgram(programA);
programStageB.setMinDaysFromStart(2);
programA.getProgramStages().add(programStageA);
programA.getProgramStages().add(programStageB);
identifiableObjectManager.update(programStageA);
identifiableObjectManager.update(programStageB);
identifiableObjectManager.update(programA);
createUserAndInjectSecurityContext(true);
}
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;
}
Aggregations