use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class EventTrackerConverterService method from.
private ProgramStageInstance from(TrackerPreheat preheat, Event event, ProgramStageInstance programStageInstance) {
ProgramStage programStage = preheat.get(ProgramStage.class, event.getProgramStage());
Program program = preheat.get(Program.class, event.getProgram());
OrganisationUnit organisationUnit = preheat.get(OrganisationUnit.class, event.getOrgUnit());
Date now = new Date();
if (isNewEntity(programStageInstance)) {
programStageInstance = new ProgramStageInstance();
programStageInstance.setUid(!StringUtils.isEmpty(event.getEvent()) ? event.getEvent() : event.getUid());
programStageInstance.setCreated(now);
programStageInstance.setStoredBy(event.getStoredBy());
programStageInstance.setCreatedByUserInfo(UserInfoSnapshot.from(preheat.getUser()));
}
programStageInstance.setLastUpdatedByUserInfo(UserInfoSnapshot.from(preheat.getUser()));
programStageInstance.setLastUpdated(now);
programStageInstance.setDeleted(false);
programStageInstance.setCreatedAtClient(DateUtils.fromInstant(event.getCreatedAtClient()));
programStageInstance.setLastUpdatedAtClient(DateUtils.fromInstant(event.getUpdatedAtClient()));
programStageInstance.setProgramInstance(getProgramInstance(preheat, TrackerIdScheme.UID, event.getEnrollment(), program));
programStageInstance.setProgramStage(programStage);
programStageInstance.setOrganisationUnit(organisationUnit);
programStageInstance.setExecutionDate(DateUtils.fromInstant(event.getOccurredAt()));
programStageInstance.setDueDate(DateUtils.fromInstant(event.getScheduledAt()));
String attributeOptionCombo = event.getAttributeOptionCombo();
if (attributeOptionCombo != null) {
programStageInstance.setAttributeOptionCombo(preheat.get(CategoryOptionCombo.class, event.getAttributeOptionCombo()));
} else {
programStageInstance.setAttributeOptionCombo((CategoryOptionCombo) preheat.getDefaults().get(CategoryOptionCombo.class));
}
programStageInstance.setGeometry(event.getGeometry());
EventStatus previousStatus = programStageInstance.getStatus();
Date completedDate = DateUtils.fromInstant(event.getCompletedAt());
programStageInstance.setStatus(event.getStatus());
if (!Objects.equal(previousStatus, programStageInstance.getStatus()) && programStageInstance.isCompleted()) {
programStageInstance.setCompletedDate(completedDate == null ? new Date() : completedDate);
programStageInstance.setCompletedBy(event.getCompletedBy() != null ? event.getCompletedBy() : preheat.getUsername());
}
if (programStage.isEnableUserAssignment()) {
User assignedUser = preheat.get(User.class, event.getAssignedUser());
programStageInstance.setAssignedUser(assignedUser);
}
if (program.isRegistration() && programStageInstance.getDueDate() == null && programStageInstance.getExecutionDate() != null) {
programStageInstance.setDueDate(programStageInstance.getExecutionDate());
}
for (DataValue dataValue : event.getDataValues()) {
EventDataValue eventDataValue = new EventDataValue();
eventDataValue.setValue(dataValue.getValue());
eventDataValue.setCreated(DateUtils.fromInstant(dataValue.getCreatedAt()));
eventDataValue.setLastUpdated(new Date());
eventDataValue.setProvidedElsewhere(dataValue.isProvidedElsewhere());
// ensure dataElement is referred to by UID as multiple
// dataElementIdSchemes are supported
DataElement dataElement = preheat.get(DataElement.class, dataValue.getDataElement());
eventDataValue.setDataElement(dataElement.getUid());
eventDataValue.setLastUpdatedByUserInfo(UserInfoSnapshot.from(preheat.getUser()));
User createdBy = preheat.getUsers().get(dataValue.getCreatedBy());
eventDataValue.setCreatedByUserInfo(Optional.ofNullable(createdBy).map(u -> UserInfoSnapshot.from(createdBy)).orElseGet(() -> UserInfoSnapshot.from(preheat.getUser())));
programStageInstance.getEventDataValues().add(eventDataValue);
}
if (isNotEmpty(event.getNotes())) {
programStageInstance.getComments().addAll(notesConverterService.from(preheat, event.getNotes()));
}
return programStageInstance;
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class DbChangeEventHandler method getDataValueId.
private Serializable getDataValueId(SourceRecord sourceRecord) {
Schema schema = sourceRecord.keySchema();
List<Field> allIdFields = schema.fields();
Struct keyStruct = (Struct) sourceRecord.key();
Long dataElementId = (Long) getIdFromField(keyStruct, allIdFields.get(0));
Long periodId = (Long) getIdFromField(keyStruct, allIdFields.get(1));
Long organisationUnitId = (Long) getIdFromField(keyStruct, allIdFields.get(2));
Long categoryOptionComboId = (Long) getIdFromField(keyStruct, allIdFields.get(3));
Long attributeOptionComboId = (Long) getIdFromField(keyStruct, allIdFields.get(4));
DataElement dataElement = idObjectManager.get(DataElement.class, dataElementId);
OrganisationUnit organisationUnit = idObjectManager.get(OrganisationUnit.class, organisationUnitId);
CategoryOptionCombo categoryOptionCombo = idObjectManager.get(CategoryOptionCombo.class, categoryOptionComboId);
CategoryOptionCombo attributeOptionCombo = idObjectManager.get(CategoryOptionCombo.class, attributeOptionComboId);
Period period = periodService.getPeriod(periodId);
return new DataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class MinMaxDataElementStoreTest method testQuery.
@Test
void testQuery() {
OrganisationUnit source1 = createOrganisationUnit('A');
OrganisationUnit source2 = createOrganisationUnit('B');
organisationUnitService.addOrganisationUnit(source1);
organisationUnitService.addOrganisationUnit(source2);
DataElement dataElement1 = createDataElement('A');
DataElement dataElement2 = createDataElement('B');
DataElement dataElement3 = createDataElement('C');
DataElement dataElement4 = createDataElement('D');
dataElementService.addDataElement(dataElement1);
dataElementService.addDataElement(dataElement2);
dataElementService.addDataElement(dataElement3);
dataElementService.addDataElement(dataElement4);
CategoryOptionCombo optionCombo = categoryService.getDefaultCategoryOptionCombo();
MinMaxDataElement minMaxDataElement1 = new MinMaxDataElement(dataElement1, source1, optionCombo, 0, 100, false);
MinMaxDataElement minMaxDataElement2 = new MinMaxDataElement(dataElement2, source2, optionCombo, 0, 100, false);
MinMaxDataElement minMaxDataElement3 = new MinMaxDataElement(dataElement3, source2, optionCombo, 0, 100, false);
MinMaxDataElement minMaxDataElement4 = new MinMaxDataElement(dataElement4, source2, optionCombo, 0, 100, false);
minMaxDataElementStore.save(minMaxDataElement1);
minMaxDataElementStore.save(minMaxDataElement2);
minMaxDataElementStore.save(minMaxDataElement3);
minMaxDataElementStore.save(minMaxDataElement4);
MinMaxDataElementQueryParams params = new MinMaxDataElementQueryParams();
List<String> filters = Lists.newArrayList();
filters.add("dataElement.id:eq:" + dataElement1.getUid());
params.setFilters(filters);
List<MinMaxDataElement> result = minMaxDataElementStore.query(params);
assertNotNull(result);
assertEquals(1, result.size());
params = new MinMaxDataElementQueryParams();
filters.clear();
filters.add("min:eq:0");
params.setFilters(filters);
result = minMaxDataElementStore.query(params);
assertNotNull(result);
assertEquals(4, result.size());
filters.clear();
filters.add("dataElement.id:in:[" + dataElement1.getUid() + "," + dataElement2.getUid() + "]");
params.setFilters(filters);
result = minMaxDataElementStore.query(params);
assertNotNull(result);
assertEquals(2, result.size());
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class MinMaxDataElementStoreTest method testBasic.
@Test
void testBasic() {
OrganisationUnit source1 = createOrganisationUnit('A');
OrganisationUnit source2 = createOrganisationUnit('B');
organisationUnitService.addOrganisationUnit(source1);
organisationUnitService.addOrganisationUnit(source2);
DataElement dataElement1 = createDataElement('A');
DataElement dataElement2 = createDataElement('B');
DataElement dataElement3 = createDataElement('C');
DataElement dataElement4 = createDataElement('D');
dataElementService.addDataElement(dataElement1);
dataElementService.addDataElement(dataElement2);
dataElementService.addDataElement(dataElement3);
dataElementService.addDataElement(dataElement4);
CategoryOptionCombo optionCombo = categoryService.getDefaultCategoryOptionCombo();
MinMaxDataElement minMaxDataElement1 = new MinMaxDataElement(dataElement1, source1, optionCombo, 0, 100, false);
MinMaxDataElement minMaxDataElement2 = new MinMaxDataElement(dataElement2, source2, optionCombo, 0, 100, false);
MinMaxDataElement minMaxDataElement3 = new MinMaxDataElement(dataElement3, source2, optionCombo, 0, 100, false);
MinMaxDataElement minMaxDataElement4 = new MinMaxDataElement(dataElement4, source2, optionCombo, 0, 100, false);
minMaxDataElementStore.save(minMaxDataElement1);
long mmdeid1 = minMaxDataElement1.getId();
minMaxDataElementStore.save(minMaxDataElement2);
minMaxDataElementStore.save(minMaxDataElement3);
minMaxDataElementStore.save(minMaxDataElement4);
// ----------------------------------------------------------------------
// Assertions
// ----------------------------------------------------------------------
assertNotNull(minMaxDataElementStore.get(mmdeid1));
assertTrue(minMaxDataElementStore.get(mmdeid1).getMax() == 100);
List<DataElement> dataElements1 = new ArrayList<>();
dataElements1.add(dataElement1);
List<DataElement> dataElements2 = new ArrayList<>();
dataElements2.add(dataElement2);
dataElements2.add(dataElement3);
dataElements2.add(dataElement4);
assertNotNull(minMaxDataElementStore.get(source1, dataElement1, optionCombo));
assertNull(minMaxDataElementStore.get(source2, dataElement1, optionCombo));
assertEquals(1, minMaxDataElementStore.get(source1, dataElements1).size());
assertEquals(3, minMaxDataElementStore.get(source2, dataElements2).size());
minMaxDataElementStore.delete(minMaxDataElement1);
assertNull(minMaxDataElementStore.get(mmdeid1));
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class DataApprovalController method removeApproval.
// -------------------------------------------------------------------------
// Delete
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')")
@DeleteMapping(APPROVALS_PATH)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void removeApproval(@RequestParam(required = false) Set<String> ds, @RequestParam(required = false) Set<String> wf, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String aoc) throws WebMessageException {
Set<DataApprovalWorkflow> workflows = getAndValidateWorkflows(ds, wf);
Period period = getAndValidatePeriod(pe);
OrganisationUnit organisationUnit = getAndValidateOrgUnit(ou);
DataApprovalLevel dataApprovalLevel = getAndValidateApprovalLevel(organisationUnit);
CategoryOptionCombo optionCombo = getAndValidateAttributeOptionCombo(aoc);
User user = currentUserService.getCurrentUser();
List<DataApproval> dataApprovalList = new ArrayList<>();
for (DataApprovalWorkflow workflow : workflows) {
dataApprovalList.addAll(getApprovalsAsList(dataApprovalLevel, workflow, period, organisationUnit, optionCombo, false, new Date(), user));
}
dataApprovalService.unapproveData(dataApprovalList);
}
Aggregations