use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.
the class TrackerPreheatServiceIntegration method setUpTest.
@Override
public void setUpTest() throws Exception {
userService = _userService;
// Set up placeholder OU; We add Code for testing idScheme.
OrganisationUnit ouA = createOrganisationUnit('A');
ouA.setCode("OUA");
organisationUnitService.addOrganisationUnit(ouA);
// Set up placeholder TET
TrackedEntityType tetA = createTrackedEntityType('A');
tetA.setUid(TET_UID);
trackedEntityTypeService.addTrackedEntityType(tetA);
// Set up attribute for program, to be used for testing idScheme.
Attribute attributeA = createAttribute('A');
attributeA.setUid(ATTRIBUTE_UID);
attributeA.setUnique(true);
attributeA.setProgramAttribute(true);
attributeService.addAttribute(attributeA);
// Set up placeholder Program, with attributeValue
Program programA = createProgram('A');
programA.addOrganisationUnit(ouA);
programA.setTrackedEntityType(tetA);
programA.setProgramType(ProgramType.WITH_REGISTRATION);
programA.setAttributeValues(Sets.newHashSet(new AttributeValue("PROGRAM1", attributeA)));
programService.addProgram(programA);
}
use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.
the class HibernateGenericStore method getAllValuesByAttributes.
@Override
public List<AttributeValue> getAllValuesByAttributes(List<Attribute> attributes) {
CriteriaBuilder builder = getCriteriaBuilder();
CriteriaQuery<String> query = builder.createQuery(String.class);
Root<T> root = query.from(getClazz());
CriteriaBuilder.Coalesce<String> coalesce = builder.coalesce();
attributes.stream().forEach(attribute -> coalesce.value(builder.function(FUNCTION_JSONB_EXTRACT_PATH, String.class, root.get("attributeValues"), builder.literal(attribute.getUid()))));
query.select(coalesce);
List<Predicate> predicates = attributes.stream().map(attribute -> builder.isNotNull(builder.function(FUNCTION_JSONB_EXTRACT_PATH, String.class, root.get("attributeValues"), builder.literal(attribute.getUid())))).collect(Collectors.toList());
query.where(builder.or(predicates.toArray(new Predicate[predicates.size()])));
List<String> result = getSession().createQuery(query).list();
return convertListJsonToListObject(JsonAttributeValueBinaryType.MAPPER, result, AttributeValue.class);
}
use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.
the class DhisConvenienceTest method createAttribute.
public static Attribute createAttribute(String name, ValueType valueType) {
Attribute attribute = new Attribute(name, valueType);
attribute.setAutoFields();
return attribute;
}
use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.
the class OrganisationUnitLocationController method getEntitiesWithinRange.
/**
* Get Organisation Units within a distance from a location
*/
@GetMapping(value = "/withinRange", produces = { "*/*", APPLICATION_JSON_VALUE })
@ResponseBody
public List<OrganisationUnit> getEntitiesWithinRange(@RequestParam Double longitude, @RequestParam Double latitude, @RequestParam Double distance, @RequestParam(required = false) String orgUnitGroupSetId) {
List<OrganisationUnit> entityList = new ArrayList<>(organisationUnitService.getOrganisationUnitWithinDistance(longitude, latitude, distance));
for (OrganisationUnit organisationUnit : entityList) {
Set<AttributeValue> attributeValues = organisationUnit.getAttributeValues();
attributeValues.clear();
if (orgUnitGroupSetId != null) {
for (OrganisationUnitGroup organisationUnitGroup : organisationUnit.getGroups()) {
for (OrganisationUnitGroupSet orgunitGroupSet : organisationUnitGroup.getGroupSets()) {
if (orgunitGroupSet.getUid().compareTo(orgUnitGroupSetId) == 0) {
AttributeValue attributeValue = new AttributeValue();
// attributeValue.setAttribute( new Attribute(
// ORGUNIGROUP_SYMBOL, ORGUNIGROUP_SYMBOL ) );
attributeValue.setAttribute(new Attribute(ORGUNIGROUP_SYMBOL, ValueType.TEXT));
attributeValue.setValue(organisationUnitGroup.getSymbol());
attributeValues.add(attributeValue);
}
}
}
}
organisationUnit.setAttributeValues(attributeValues);
// Clear out all data not needed for this task
organisationUnit.removeAllDataSets();
organisationUnit.removeAllUsers();
organisationUnit.removeAllOrganisationUnitGroups();
}
return entityList;
}
use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.
the class GeoFeatureService method getGeoFeatures.
/**
* Returns a list of {@link GeoFeature}. Returns null if not modified based
* on the request.
*
* @param parameters the {@link Parameters} passing from controller.
* @return a list of geo features or null.
*/
public List<GeoFeature> getGeoFeatures(Parameters parameters) {
Attribute geoJsonAttribute = validateCoordinateField(parameters.getCoordinateField());
Set<String> dimensionParams = new HashSet<>();
dimensionParams.add(parameters.getOrganisationUnit());
dimensionParams.add(parameters.getOrganisationUnitGroupId());
DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).aggregationType(AggregationType.SUM).displayProperty(parameters.getDisplayProperty()).relativePeriodDate(parameters.getRelativePeriodDate()).userOrgUnit(parameters.getUserOrgUnit()).apiVersion(parameters.getApiVersion()).build();
DataQueryParams params = dataQueryService.getFromRequest(dataQueryRequest);
boolean useOrgUnitGroup = parameters.getOrganisationUnit() == null;
DimensionalObject dimensionalObject = params.getDimension(useOrgUnitGroup ? ORGUNIT_GROUP_DIM_ID : ORGUNIT_DIM_ID);
if (dimensionalObject == null) {
throw new IllegalArgumentException("Dimension is present in query without any valid dimension options");
}
List<DimensionalItemObject> dimensionalItemObjects = DimensionalObjectUtils.asTypedList(dimensionalObject.getItems());
dimensionalItemObjects = dimensionalItemObjects.stream().filter(object -> validateDimensionalItemObject(object, geoJsonAttribute)).collect(Collectors.toList());
boolean modified = !ContextUtils.clearIfNotModified(parameters.getRequest(), parameters.getResponse(), dimensionalItemObjects);
if (!modified) {
return null;
}
return getGeoFeatures(params, dimensionalItemObjects, parameters.isIncludeGroupSets(), useOrgUnitGroup, geoJsonAttribute);
}
Aggregations