use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class DefaultDimensionService method getReportingRate.
/**
* Returns a {@link ReportingRate}.
*
* @param idScheme the identifier scheme.
* @param dataSetId the data set identifier.
* @param metric the reporting rate metric.
*/
private ReportingRate getReportingRate(IdScheme idScheme, String dataSetId, String metric) {
DataSet dataSet = idObjectManager.getObject(DataSet.class, idScheme, dataSetId);
boolean metricValid = isValidEnum(ReportingRateMetric.class, metric);
if (dataSet == null || !metricValid) {
return null;
}
return new ReportingRate(dataSet, ReportingRateMetric.valueOf(metric));
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class DataEntryFormStoreTest method testAddDataEntryForm.
// -------------------------------------------------------------------------
// DataEntryForm
// -------------------------------------------------------------------------
@Test
public void testAddDataEntryForm() {
DataSet dataSetA = createDataSet('A', periodType);
dataSetService.addDataSet(dataSetA);
DataEntryForm dataEntryFormA = createDataEntryForm('A');
dataEntryFormStore.save(dataEntryFormA);
int dataEntryFormAid = dataEntryFormA.getId();
dataEntryFormA = dataEntryFormStore.get(dataEntryFormAid);
assertEquals(dataEntryFormAid, dataEntryFormA.getId());
assertEquals("DataEntryFormA", dataEntryFormA.getName());
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class AbstractDataSetCompletenessService method getDataSetCompleteness.
@Override
@Transactional
public List<DataSetCompletenessResult> getDataSetCompleteness(int periodId, Collection<Integer> organisationUnitIds, int dataSetId, Set<Integer> groupIds) {
final DataSet dataSet = dataSetService.getDataSet(dataSetId);
final Period period = periodService.getPeriod(periodId);
final List<Integer> periodsBetweenDates = getIdentifiers(periodService.getPeriodsBetweenDates(dataSet.getPeriodType(), period.getStartDate(), period.getEndDate()));
final Map<Integer, OrganisationUnit> orgUnits = Maps.uniqueIndex(organisationUnitService.getOrganisationUnits(organisationUnitIds), OrganisationUnit::getId);
final Set<OrganisationUnitGroup> groups = groupIds != null ? Sets.newHashSet(idObjectManager.getObjects(OrganisationUnitGroup.class, groupIds)) : null;
final List<DataSetCompletenessResult> results = new ArrayList<>();
for (final Integer unitId : organisationUnitIds) {
final OrganisationUnit unit = orgUnits.get(unitId);
final Set<Integer> children = organisationUnitService.getOrganisationUnitHierarchy().getChildren(unit.getId());
final Set<Integer> relevantSources = getRelevantSources(dataSet, children, groups);
final DataSetCompletenessResult result = getDataSetCompleteness(period, periodsBetweenDates, unit, relevantSources, dataSet);
if (result.getSources() > 0) {
results.add(result);
}
}
return results;
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class DimensionController method getDimensionsForDataSet.
@RequestMapping(value = "/dataSet/{uid}", method = RequestMethod.GET)
@ResponseBody
public RootNode getDimensionsForDataSet(@PathVariable String uid, @RequestParam(value = "links", defaultValue = "true", required = false) Boolean links, Model model, HttpServletResponse response) throws WebMessageException {
WebMetadata metadata = new WebMetadata();
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
DataSet dataSet = identifiableObjectManager.get(DataSet.class, uid);
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.notFound("DataSet not found for uid: " + uid));
}
if (!dataSet.hasCategoryCombo()) {
throw new WebMessageException(WebMessageUtils.conflict("Data set does not have a category combination: " + uid));
}
List<DimensionalObject> dimensions = new ArrayList<>();
dimensions.addAll(dataSet.getCategoryCombo().getCategories());
dimensions.addAll(dataSet.getCategoryOptionGroupSets());
dimensions = dimensionService.getCanReadObjects(dimensions);
for (DimensionalObject dim : dimensions) {
metadata.getDimensions().add(dimensionService.getDimensionalObjectCopy(dim.getUid(), true));
}
if (links) {
linkService.generateLinks(metadata, false);
}
RootNode rootNode = NodeUtils.createMetadata();
rootNode.addChild(fieldFilterService.filter(getEntityClass(), metadata.getDimensions(), fields));
return rootNode;
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class InterpretationController method writeDataSetReportInterpretation.
@RequestMapping(value = "/dataSetReport/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
public void writeDataSetReportInterpretation(@PathVariable("uid") String dataSetUid, @RequestParam("pe") String isoPeriod, @RequestParam("ou") String orgUnitUid, @RequestBody String text, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
DataSet dataSet = idObjectManager.get(DataSet.class, dataSetUid);
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.conflict("Data set does not exist or is not accessible: " + dataSetUid));
}
Period period = PeriodType.getPeriodFromIsoString(isoPeriod);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Period identifier not valid: " + isoPeriod));
}
OrganisationUnit orgUnit = idObjectManager.get(OrganisationUnit.class, orgUnitUid);
if (orgUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("Organisation unit does not exist or is not accessible: " + orgUnitUid));
}
createIntepretation(new Interpretation(dataSet, period, orgUnit, text), request, response);
}
Aggregations