Search in sources :

Example 1 with DataSet

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));
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate)

Example 2 with DataSet

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());
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) DhisSpringTest(org.hisp.dhis.DhisSpringTest) Test(org.junit.Test)

Example 3 with DataSet

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;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSetCompletenessResult(org.hisp.dhis.completeness.DataSetCompletenessResult) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with DataSet

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;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) DimensionalObject(org.hisp.dhis.common.DimensionalObject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with DataSet

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Period(org.hisp.dhis.period.Period) Interpretation(org.hisp.dhis.interpretation.Interpretation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataSet (org.hisp.dhis.dataset.DataSet)199 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)82 Test (org.junit.jupiter.api.Test)69 DataElement (org.hisp.dhis.dataelement.DataElement)58 Period (org.hisp.dhis.period.Period)56 ArrayList (java.util.ArrayList)41 List (java.util.List)40 User (org.hisp.dhis.user.User)38 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)32 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)28 ClassPathResource (org.springframework.core.io.ClassPathResource)28 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)22 HashSet (java.util.HashSet)20 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)20 CategoryCombo (org.hisp.dhis.category.CategoryCombo)19 HashMap (java.util.HashMap)17 DhisSpringTest (org.hisp.dhis.DhisSpringTest)17 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)17 ReportingRate (org.hisp.dhis.common.ReportingRate)16 Section (org.hisp.dhis.dataset.Section)16