use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class TrackedEntityInstanceController method getTrackedEntityInstances.
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody
public RootNode getTrackedEntityInstances(@RequestParam(required = false) String query, @RequestParam(required = false) Set<String> attribute, @RequestParam(required = false) Set<String> filter, @RequestParam(required = false) String ou, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) String program, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) Date programStartDate, @RequestParam(required = false) Date programEnrollmentStartDate, @RequestParam(required = false) Date programEndDate, @RequestParam(required = false) Date programEnrollmentEndDate, @RequestParam(required = false) Date programIncidentStartDate, @RequestParam(required = false) Date programIncidentEndDate, @RequestParam(required = false) String trackedEntity, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) EventStatus eventStatus, @RequestParam(required = false) Date eventStartDate, @RequestParam(required = false) Date eventEndDate, @RequestParam(required = false) boolean skipMeta, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false) boolean includeDeleted, @RequestParam(required = false) String order) throws Exception {
programEnrollmentStartDate = ObjectUtils.firstNonNull(programEnrollmentStartDate, programStartDate);
programEnrollmentEndDate = ObjectUtils.firstNonNull(programEnrollmentEndDate, programEndDate);
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.add(":all");
}
Set<String> orgUnits = TextUtils.splitToArray(ou, TextUtils.SEMICOLON);
RootNode rootNode = NodeUtils.createMetadata();
List<TrackedEntityInstance> trackedEntityInstances;
TrackedEntityInstanceQueryParams queryParams = instanceService.getFromUrl(query, attribute, filter, orgUnits, ouMode, program, programStatus, followUp, lastUpdatedStartDate, lastUpdatedEndDate, programEnrollmentStartDate, programEnrollmentEndDate, programIncidentStartDate, programIncidentEndDate, trackedEntity, eventStatus, eventStartDate, eventEndDate, skipMeta, page, pageSize, totalPages, skipPaging, includeDeleted, getOrderParams(order));
if (trackedEntityInstance == null) {
trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, getTrackedEntityInstanceParams(fields));
} else {
Set<String> trackedEntityInstanceIds = TextUtils.splitToArray(trackedEntityInstance, TextUtils.SEMICOLON);
trackedEntityInstances = trackedEntityInstanceIds != null ? trackedEntityInstanceIds.stream().map(id -> trackedEntityInstanceService.getTrackedEntityInstance(id, getTrackedEntityInstanceParams(fields))).collect(Collectors.toList()) : null;
}
if (queryParams.isPaging() && queryParams.isTotalPages()) {
int count = trackedEntityInstanceService.getTrackedEntityInstanceCount(queryParams);
Pager pager = new Pager(queryParams.getPageWithDefault(), count, queryParams.getPageSizeWithDefault());
rootNode.addChild(NodeUtils.createPager(pager));
}
rootNode.addChild(fieldFilterService.filter(TrackedEntityInstance.class, trackedEntityInstances, fields));
return rootNode;
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class DefaultMetadataVersionServiceTest method testShouldCreateAValidVersionsNodeTree.
@Test
public void testShouldCreateAValidVersionsNodeTree() throws Exception {
List<MetadataVersion> versions = new ArrayList<>();
versions.add(new MetadataVersion("test_version1", VersionType.ATOMIC));
versions.add(new MetadataVersion("test_version2", VersionType.BEST_EFFORT));
versions.add(new MetadataVersion("test_version3", VersionType.BEST_EFFORT));
RootNode root = versionService.getMetadataVersionsAsNode(versions);
ComplexNode[] versionNodes = getVersionFromNodeTree(root);
for (int i = 0; i < versionNodes.length; i++) {
assertEquals(versions.get(i).getName(), ((SimpleNode) versionNodes[i].getChildren().get(0)).getValue());
assertEquals(versions.get(i).getType(), ((SimpleNode) versionNodes[i].getChildren().get(1)).getValue());
}
assertEquals(versions.size(), versionNodes.length);
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class DefaultMetadataVersionServiceTest method testShouldCreateNodesWith_Name_Type_CreatedId_ImportDate.
@Test
public void testShouldCreateNodesWith_Name_Type_CreatedId_ImportDate() throws Exception {
MetadataVersion version = new MetadataVersion("test_version1", VersionType.ATOMIC);
version.setUid("myId");
Date date = new Date();
version.setImportDate(date);
version.setCreated(date);
version.setHashCode("2asda2d31asd3ads3dadasd");
List<MetadataVersion> versions = new ArrayList<>();
versions.add(version);
RootNode root = versionService.getMetadataVersionsAsNode(versions);
ComplexNode[] versionNodes = getVersionFromNodeTree(root);
assertEquals(version.getName(), ((SimpleNode) versionNodes[0].getChildren().get(0)).getValue());
assertEquals(version.getType(), ((SimpleNode) versionNodes[0].getChildren().get(1)).getValue());
assertEquals(version.getCreated(), ((SimpleNode) versionNodes[0].getChildren().get(2)).getValue());
assertEquals(version.getUid(), ((SimpleNode) versionNodes[0].getChildren().get(3)).getValue());
assertEquals(version.getImportDate(), ((SimpleNode) versionNodes[0].getChildren().get(4)).getValue());
assertEquals(version.getHashCode(), ((SimpleNode) versionNodes[0].getChildren().get(5)).getValue());
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class AuditController method getTrackedEntityDataValueAudit.
@RequestMapping(value = "trackedEntityDataValue", method = RequestMethod.GET)
@ResponseBody
public RootNode getTrackedEntityDataValueAudit(@RequestParam(required = false, defaultValue = "") List<String> de, @RequestParam(required = false, defaultValue = "") List<String> psi, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
List<DataElement> dataElements = getDataElements(de);
List<ProgramStageInstance> programStageInstances = getProgramStageInstances(psi);
List<TrackedEntityDataValueAudit> dataValueAudits;
Pager pager = null;
if (skipPaging) {
dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType);
} else {
int total = trackedEntityDataValueAuditService.countTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType);
pager = new Pager(page, total, pageSize);
dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType, pager.getOffset(), pager.getPageSize());
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("trackedEntityDataValueAudits", true));
trackedEntityAttributeValueAudits.addChildren(fieldFilterService.filter(TrackedEntityDataValueAudit.class, dataValueAudits, fields).getChildren());
return rootNode;
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class DataApprovalController method getApproval.
@RequestMapping(value = STATUS_PATH, method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getApproval(@RequestParam Set<String> ds, @RequestParam(required = false) String pe, @RequestParam Date startDate, @RequestParam Date endDate, @RequestParam Set<String> ou, @RequestParam(required = false) boolean children, HttpServletResponse response) throws IOException, WebMessageException {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
List<String> defaults = new ArrayList<>();
defaults.add("period[id,name,code],organisationUnit[id,name,created,lastUpdated],dataSet[code,name,created,lastUpdated,id]");
fields.addAll(defaults);
}
Set<DataSet> dataSets = parseDataSetsWithWorkflow(ds);
Set<Period> periods = new HashSet<>();
PeriodType periodType = periodService.getPeriodTypeByName(pe);
if (periodType != null) {
periods.addAll(periodService.getPeriodsBetweenDates(periodType, startDate, endDate));
} else {
periods.addAll(periodService.getPeriodsBetweenDates(startDate, endDate));
}
Set<OrganisationUnit> organisationUnits = new HashSet<>();
if (children) {
organisationUnits.addAll(organisationUnitService.getOrganisationUnitsWithChildren(ou));
} else {
organisationUnits.addAll(organisationUnitService.getOrganisationUnitsByUid(ou));
}
DataApprovalStateResponses dataApprovalStateResponses = new DataApprovalStateResponses();
for (DataSet dataSet : dataSets) {
for (OrganisationUnit organisationUnit : organisationUnits) {
for (Period period : periods) {
dataApprovalStateResponses.add(getDataApprovalStateResponse(dataSet, organisationUnit, period));
}
}
}
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
RootNode rootNode = NodeUtils.createMetadata();
rootNode.addChild(fieldFilterService.filter(DataApprovalStateResponse.class, dataApprovalStateResponses.getDataApprovalStateResponses(), fields));
return rootNode;
}
Aggregations