use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class ProgramStageInstanceServiceTest method setUpTest.
@Override
public void setUpTest() {
mockFormat = new MockI18nFormat();
organisationUnitA = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnitA);
organisationUnitB = createOrganisationUnit('B');
organisationUnitService.addOrganisationUnit(organisationUnitB);
entityInstanceA = createTrackedEntityInstance('A', organisationUnitA);
entityInstanceService.addTrackedEntityInstance(entityInstanceA);
entityInstanceB = createTrackedEntityInstance('B', organisationUnitB);
entityInstanceService.addTrackedEntityInstance(entityInstanceB);
TrackedEntityAttribute attribute = createTrackedEntityAttribute('A');
attribute.setValueType(ValueType.PHONE_NUMBER);
attributeService.addTrackedEntityAttribute(attribute);
TrackedEntityAttributeValue attributeValue = createTrackedEntityAttributeValue('A', entityInstanceA, attribute);
attributeValue.setValue("123456789");
attributeValueService.addTrackedEntityAttributeValue(attributeValue);
entityInstanceA.getTrackedEntityAttributeValues().add(attributeValue);
entityInstanceService.updateTrackedEntityInstance(entityInstanceA);
/**
* Program A
*/
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programService.addProgram(programA);
stageA = createProgramStage('A', 0);
stageA.setProgram(programA);
stageA.setSortOrder(1);
programStageService.saveProgramStage(stageA);
stageB = new ProgramStage("B", programA);
stageB.setSortOrder(2);
programStageService.saveProgramStage(stageB);
Set<ProgramStage> programStages = new HashSet<>();
programStages.add(stageA);
programStages.add(stageB);
programA.setProgramStages(programStages);
programService.updateProgram(programA);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
stageDataElementA = new ProgramStageDataElement(stageA, dataElementA, false, 1);
stageDataElementB = new ProgramStageDataElement(stageA, dataElementB, false, 2);
stageDataElementC = new ProgramStageDataElement(stageB, dataElementA, false, 1);
stageDataElementD = new ProgramStageDataElement(stageB, dataElementB, false, 2);
programStageDataElementService.addProgramStageDataElement(stageDataElementA);
programStageDataElementService.addProgramStageDataElement(stageDataElementB);
programStageDataElementService.addProgramStageDataElement(stageDataElementC);
programStageDataElementService.addProgramStageDataElement(stageDataElementD);
/**
* Program B
*/
Program programB = createProgram('B', new HashSet<>(), organisationUnitB);
programService.addProgram(programB);
stageC = new ProgramStage("C", programB);
stageC.setSortOrder(1);
programStageService.saveProgramStage(stageC);
stageD = new ProgramStage("D", programB);
stageB.setSortOrder(2);
stageC.setRepeatable(true);
programStageService.saveProgramStage(stageD);
programStages = new HashSet<>();
programStages.add(stageC);
programStages.add(stageD);
programB.setProgramStages(programStages);
programService.updateProgram(programB);
/**
* Program Instance and Program Stage Instance
*/
DateTime testDate1 = DateTime.now();
testDate1.withTimeAtStartOfDay();
testDate1 = testDate1.minusDays(70);
incidenDate = testDate1.toDate();
DateTime testDate2 = DateTime.now();
testDate2.withTimeAtStartOfDay();
enrollmentDate = testDate2.toDate();
programInstanceA = new ProgramInstance(enrollmentDate, incidenDate, entityInstanceA, programA);
programInstanceA.setUid("UID-PIA");
programInstanceService.addProgramInstance(programInstanceA);
programInstanceB = new ProgramInstance(enrollmentDate, incidenDate, entityInstanceB, programB);
programInstanceService.addProgramInstance(programInstanceB);
programStageInstanceA = new ProgramStageInstance(programInstanceA, stageA);
programStageInstanceA.setDueDate(enrollmentDate);
programStageInstanceA.setUid("UID-A");
programStageInstanceB = new ProgramStageInstance(programInstanceA, stageB);
programStageInstanceB.setDueDate(enrollmentDate);
programStageInstanceB.setUid("UID-B");
programStageInstanceC = new ProgramStageInstance(programInstanceB, stageC);
programStageInstanceC.setDueDate(enrollmentDate);
programStageInstanceC.setUid("UID-C");
programStageInstanceD1 = new ProgramStageInstance(programInstanceB, stageD);
programStageInstanceD1.setDueDate(enrollmentDate);
programStageInstanceD1.setUid("UID-D1");
programStageInstanceD2 = new ProgramStageInstance(programInstanceB, stageD);
programStageInstanceD2.setDueDate(enrollmentDate);
programStageInstanceD2.setUid("UID-D2");
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class AuditController method getTrackedEntityAttributeValueAudit.
@RequestMapping(value = "trackedEntityAttributeValue", method = RequestMethod.GET)
@ResponseBody
public RootNode getTrackedEntityAttributeValueAudit(@RequestParam(required = false, defaultValue = "") List<String> tea, @RequestParam(required = false, defaultValue = "") List<String> tei, @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"));
List<TrackedEntityAttribute> trackedEntityAttributes = getTrackedEntityAttributes(tea);
List<TrackedEntityInstance> trackedEntityInstances = getTrackedEntityInstances(tei);
List<TrackedEntityAttributeValueAudit> attributeValueAudits;
Pager pager = null;
if (skipPaging) {
attributeValueAudits = trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType);
} else {
int total = trackedEntityAttributeValueAuditService.countTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType);
pager = new Pager(page, total, pageSize);
attributeValueAudits = trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType, pager.getOffset(), pager.getPageSize());
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("trackedEntityAttributeValueAudits", true));
trackedEntityAttributeValueAudits.addChildren(fieldFilterService.filter(TrackedEntityAttributeValueAudit.class, attributeValueAudits, fields).getChildren());
return rootNode;
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class AbstractEnrollmentService method validateAttributeType.
private List<ImportConflict> validateAttributeType(Attribute attribute, ImportOptions importOptions) {
List<ImportConflict> importConflicts = Lists.newArrayList();
TrackedEntityAttribute teAttribute = getTrackedEntityAttribute(importOptions.getIdSchemes(), attribute.getAttribute());
if (teAttribute == null) {
importConflicts.add(new ImportConflict("Attribute.attribute", "Does not point to a valid attribute."));
return importConflicts;
}
String errorMessage = trackedEntityAttributeService.validateValueType(teAttribute, attribute.getValue());
if (errorMessage != null) {
importConflicts.add(new ImportConflict("Attribute.value", errorMessage));
}
return importConflicts;
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class JdbcEventAnalyticsTableManager method getDimensionColumns.
@Override
public List<AnalyticsTableColumn> getDimensionColumns(AnalyticsTable table) {
final String dbl = statementBuilder.getDoubleColumnType();
final String numericClause = " and value " + statementBuilder.getRegexpMatch() + " '" + NUMERIC_LENIENT_REGEXP + "'";
final String dateClause = " and value " + statementBuilder.getRegexpMatch() + " '" + DATE_REGEXP + "'";
//TODO dateClause regular expression
List<AnalyticsTableColumn> columns = new ArrayList<>();
if (table.getProgram().hasCategoryCombo()) {
List<DataElementCategory> categories = table.getProgram().getCategoryCombo().getCategories();
for (DataElementCategory category : categories) {
if (category.isDataDimension()) {
columns.add(new AnalyticsTableColumn(quote(category.getUid()), "character(11)", "acs." + quote(category.getUid()), category.getCreated()));
}
}
}
List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
List<CategoryOptionGroupSet> attributeCategoryOptionGroupSets = categoryService.getAttributeCategoryOptionGroupSetsNoAcl();
for (OrganisationUnitLevel level : levels) {
String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
columns.add(new AnalyticsTableColumn(column, "character(11)", "ous." + column, level.getCreated()));
}
for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "ougs." + quote(groupSet.getUid()), groupSet.getCreated()));
}
for (CategoryOptionGroupSet groupSet : attributeCategoryOptionGroupSets) {
columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "acs." + quote(groupSet.getUid()), groupSet.getCreated()));
}
for (PeriodType periodType : PeriodType.getAvailablePeriodTypes()) {
String column = quote(periodType.getName().toLowerCase());
columns.add(new AnalyticsTableColumn(column, "character varying(15)", "dps." + column));
}
for (DataElement dataElement : table.getProgram().getDataElements()) {
ValueType valueType = dataElement.getValueType();
String dataType = getColumnType(valueType);
String dataClause = dataElement.isNumericType() ? numericClause : dataElement.getValueType().isDate() ? dateClause : "";
String select = getSelectClause(valueType);
boolean skipIndex = NO_INDEX_VAL_TYPES.contains(dataElement.getValueType()) && !dataElement.hasOptionSet();
String sql = "(select " + select + " from trackedentitydatavalue where programstageinstanceid=psi.programstageinstanceid " + "and dataelementid=" + dataElement.getId() + dataClause + ") as " + quote(dataElement.getUid());
columns.add(new AnalyticsTableColumn(quote(dataElement.getUid()), dataType, sql, skipIndex));
}
for (DataElement dataElement : table.getProgram().getDataElementsWithLegendSet()) {
for (LegendSet legendSet : dataElement.getLegendSets()) {
String column = quote(dataElement.getUid() + PartitionUtils.SEP + legendSet.getUid());
String select = getSelectClause(dataElement.getValueType());
String sql = "(select l.uid from maplegend l " + "inner join trackedentitydatavalue dv on l.startvalue <= " + select + " " + "and l.endvalue > " + select + " " + "and l.maplegendsetid=" + legendSet.getId() + " " + "and dv.programstageinstanceid=psi.programstageinstanceid " + "and dv.dataelementid=" + dataElement.getId() + numericClause + ") as " + column;
columns.add(new AnalyticsTableColumn(column, "character(11)", sql));
}
}
for (TrackedEntityAttribute attribute : table.getProgram().getNonConfidentialTrackedEntityAttributes()) {
String dataType = getColumnType(attribute.getValueType());
String dataClause = attribute.isNumericType() ? numericClause : attribute.isDateType() ? dateClause : "";
String select = getSelectClause(attribute.getValueType());
boolean skipIndex = NO_INDEX_VAL_TYPES.contains(attribute.getValueType()) && !attribute.hasOptionSet();
String sql = "(select " + select + " from trackedentityattributevalue where trackedentityinstanceid=pi.trackedentityinstanceid " + "and trackedentityattributeid=" + attribute.getId() + dataClause + ") as " + quote(attribute.getUid());
columns.add(new AnalyticsTableColumn(quote(attribute.getUid()), dataType, sql, skipIndex));
}
for (TrackedEntityAttribute attribute : table.getProgram().getNonConfidentialTrackedEntityAttributesWithLegendSet()) {
for (LegendSet legendSet : attribute.getLegendSets()) {
String column = quote(attribute.getUid() + PartitionUtils.SEP + legendSet.getUid());
String select = getSelectClause(attribute.getValueType());
String sql = "(select l.uid from maplegend l " + "inner join trackedentityattributevalue av on l.startvalue <= " + select + " " + "and l.endvalue > " + select + " " + "and l.maplegendsetid=" + legendSet.getId() + " " + "and av.trackedentityinstanceid=pi.trackedentityinstanceid " + "and av.trackedentityattributeid=" + attribute.getId() + numericClause + ") as " + column;
columns.add(new AnalyticsTableColumn(column, "character(11)", sql));
}
}
AnalyticsTableColumn psi = new AnalyticsTableColumn(quote("psi"), "character(11) not null", "psi.uid");
AnalyticsTableColumn pi = new AnalyticsTableColumn(quote("pi"), "character(11) not null", "pi.uid");
AnalyticsTableColumn ps = new AnalyticsTableColumn(quote("ps"), "character(11) not null", "ps.uid");
AnalyticsTableColumn ao = new AnalyticsTableColumn(quote("ao"), "character(11) not null", "ao.uid");
AnalyticsTableColumn erd = new AnalyticsTableColumn(quote("enrollmentdate"), "timestamp", "pi.enrollmentdate");
AnalyticsTableColumn id = new AnalyticsTableColumn(quote("incidentdate"), "timestamp", "pi.incidentdate");
AnalyticsTableColumn ed = new AnalyticsTableColumn(quote("executiondate"), "timestamp", "psi.executiondate");
AnalyticsTableColumn dd = new AnalyticsTableColumn(quote("duedate"), "timestamp", "psi.duedate");
AnalyticsTableColumn cd = new AnalyticsTableColumn(quote("completeddate"), "timestamp", "psi.completeddate");
AnalyticsTableColumn pes = new AnalyticsTableColumn(quote("pistatus"), "character(25)", "pi.status");
AnalyticsTableColumn es = new AnalyticsTableColumn(quote("psistatus"), "character(25)", "psi.status");
AnalyticsTableColumn longitude = new AnalyticsTableColumn(quote("longitude"), dbl, "psi.longitude");
AnalyticsTableColumn latitude = new AnalyticsTableColumn(quote("latitude"), dbl, "psi.latitude");
AnalyticsTableColumn ou = new AnalyticsTableColumn(quote("ou"), "character(11) not null", "ou.uid");
AnalyticsTableColumn oun = new AnalyticsTableColumn(quote("ouname"), "character varying(230) not null", "ou.name");
AnalyticsTableColumn ouc = new AnalyticsTableColumn(quote("oucode"), "character varying(50)", "ou.code");
columns.addAll(Lists.newArrayList(psi, pi, ps, ao, erd, id, ed, dd, cd, pes, es, longitude, latitude, ou, oun, ouc));
if (databaseInfo.isSpatialSupport()) {
String alias = "(select ST_SetSRID(ST_MakePoint(psi.longitude, psi.latitude), 4326)) as geom";
columns.add(new AnalyticsTableColumn(quote("geom"), "geometry(Point, 4326)", alias, false, "gist"));
}
if (table.hasProgram() && table.getProgram().isRegistration()) {
columns.add(new AnalyticsTableColumn(quote("tei"), "character(11)", "tei.uid"));
}
return filterDimensionColumns(columns);
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class DefaultEventDataQueryService method getValueDimension.
private DimensionalItemObject getValueDimension(String value) {
if (value == null) {
return null;
}
DataElement de = dataElementService.getDataElement(value);
if (de != null && de.isNumericType()) {
return de;
}
TrackedEntityAttribute at = attributeService.getTrackedEntityAttribute(value);
if (at != null && at.isNumericType()) {
return at;
}
throw new IllegalQueryException("Value identifier does not reference any " + "data element or attribute which are numeric type and part of the program: " + value);
}
Aggregations