use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class DefaultEventDataQueryService method getQueryItemFromDimension.
private QueryItem getQueryItemFromDimension(String dimension, Program program) {
String[] split = dimension.split(ITEM_SEP);
String item = split[0];
LegendSet legendSet = split.length > 1 && split[1] != null ? legendSetService.getLegendSet(split[1]) : null;
DataElement de = dataElementService.getDataElement(item);
if (de != null && program.containsDataElement(de)) {
ValueType valueType = legendSet != null ? ValueType.TEXT : de.getValueType();
return new QueryItem(de, legendSet, valueType, de.getAggregationType(), de.getOptionSet());
}
TrackedEntityAttribute at = attributeService.getTrackedEntityAttribute(item);
if (at != null && program.containsAttribute(at)) {
ValueType valueType = legendSet != null ? ValueType.TEXT : at.getValueType();
return new QueryItem(at, legendSet, valueType, at.getAggregationType(), at.getOptionSet());
}
ProgramIndicator pi = programIndicatorService.getProgramIndicatorByUid(item);
if (pi != null && program.getProgramIndicators().contains(pi)) {
return new QueryItem(pi, legendSet, ValueType.NUMBER, pi.getAggregationType(), null);
}
throw new IllegalQueryException("Item identifier does not reference any data element, attribute or indicator part of the program: " + item);
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class EventQueryParams method fromDataQueryParams.
public static EventQueryParams fromDataQueryParams(DataQueryParams dataQueryParams) {
EventQueryParams params = new EventQueryParams();
dataQueryParams.copyTo(params);
EventQueryParams.Builder builder = new EventQueryParams.Builder(params);
for (DimensionalItemObject object : dataQueryParams.getProgramDataElements()) {
ProgramDataElementDimensionItem element = (ProgramDataElementDimensionItem) object;
DataElement dataElement = element.getDataElement();
QueryItem item = new QueryItem(dataElement, (dataElement.getLegendSets().isEmpty() ? null : dataElement.getLegendSets().get(0)), dataElement.getValueType(), dataElement.getAggregationType(), dataElement.getOptionSet());
item.setProgram(element.getProgram());
builder.addItem(item);
}
for (DimensionalItemObject object : dataQueryParams.getProgramAttributes()) {
ProgramTrackedEntityAttributeDimensionItem element = (ProgramTrackedEntityAttributeDimensionItem) object;
TrackedEntityAttribute attribute = element.getAttribute();
QueryItem item = new QueryItem(attribute, (attribute.getLegendSets().isEmpty() ? null : attribute.getLegendSets().get(0)), attribute.getValueType(), attribute.getAggregationType(), attribute.getOptionSet());
item.setProgram(element.getProgram());
builder.addItem(item);
}
for (DimensionalItemObject object : dataQueryParams.getFilterProgramDataElements()) {
ProgramDataElementDimensionItem element = (ProgramDataElementDimensionItem) object;
DataElement dataElement = element.getDataElement();
QueryItem item = new QueryItem(dataElement, (dataElement.getLegendSets().isEmpty() ? null : dataElement.getLegendSets().get(0)), dataElement.getValueType(), dataElement.getAggregationType(), dataElement.getOptionSet());
item.setProgram(element.getProgram());
builder.addItemFilter(item);
}
for (DimensionalItemObject object : dataQueryParams.getFilterProgramAttributes()) {
ProgramTrackedEntityAttributeDimensionItem element = (ProgramTrackedEntityAttributeDimensionItem) object;
TrackedEntityAttribute attribute = element.getAttribute();
QueryItem item = new QueryItem(attribute, (attribute.getLegendSets().isEmpty() ? null : attribute.getLegendSets().get(0)), attribute.getValueType(), attribute.getAggregationType(), attribute.getOptionSet());
builder.addItemFilter(item);
}
for (DimensionalItemObject object : dataQueryParams.getProgramIndicators()) {
ProgramIndicator programIndicator = (ProgramIndicator) object;
builder.addItemProgramIndicator(programIndicator);
}
return builder.withAggregateData(true).removeDimension(DATA_X_DIM_ID).build();
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method registerRelative.
@Override
public Patient registerRelative(Patient patient, int orgUnitId, String programId) throws NotAllowedException {
TrackedEntityInstance patientWeb = new TrackedEntityInstance();
patientWeb.setOrganisationUnit(organisationUnitService.getOrganisationUnit(orgUnitId));
Set<TrackedEntityAttribute> patientAttributeSet = new HashSet<>();
Set<TrackedEntityAttributeValue> patientAttributeValues = new HashSet<>();
Collection<org.hisp.dhis.api.mobile.model.PatientAttribute> attributesMobile = patient.getAttributes();
if (attributesMobile != null) {
for (org.hisp.dhis.api.mobile.model.PatientAttribute paAtt : attributesMobile) {
TrackedEntityAttribute patientAttribute = attributeService.getTrackedEntityAttributeByName(paAtt.getName());
patientAttributeSet.add(patientAttribute);
TrackedEntityAttributeValue patientAttributeValue = new TrackedEntityAttributeValue();
patientAttributeValue.setEntityInstance(patientWeb);
patientAttributeValue.setAttribute(patientAttribute);
patientAttributeValue.setValue(paAtt.getValue());
patientAttributeValues.add(patientAttributeValue);
}
}
patientWeb.setTrackedEntity(trackedEntityService.getTrackedEntityByName(patient.getTrackedEntityName()));
if (patient.getIdToAddRelative() != 0) {
TrackedEntityInstance relative = entityInstanceService.getTrackedEntityInstance(patient.getIdToAddRelative());
if (relative == null) {
throw new NotAllowedException("relative does not exist");
}
patientId = entityInstanceService.createTrackedEntityInstance(patientWeb, relative.getUid(), patient.getRelTypeIdToAdd(), patientAttributeValues);
} else {
patientId = entityInstanceService.createTrackedEntityInstance(patientWeb, null, null, patientAttributeValues);
}
TrackedEntityInstance newTrackedEntityInstance = entityInstanceService.getTrackedEntityInstance(this.patientId);
String errorMsg = null;
try {
for (org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramInstance mobileProgramInstance : patient.getEnrollmentPrograms()) {
Date incidentDate = DateUtils.getMediumDate(mobileProgramInstance.getDateOfIncident());
enrollProgram(patientId + "-" + mobileProgramInstance.getProgramId(), mobileProgramInstance.getProgramStageInstances(), incidentDate);
}
Program program = programService.getProgram(Integer.parseInt(programId));
String[] errorCode = entityInstanceService.validateTrackedEntityInstance(newTrackedEntityInstance, program).split("_");
int code = Integer.parseInt(errorCode[0]);
if (code >= 1) {
entityInstanceService.deleteTrackedEntityInstance(newTrackedEntityInstance);
if (code == TrackedEntityInstanceService.ERROR_DUPLICATE_IDENTIFIER) {
errorMsg = "Duplicate value of " + attributeService.getTrackedEntityAttribute(Integer.parseInt(errorCode[1])).getDisplayName();
} else {
errorMsg = "Validation error";
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (errorMsg != null) {
throw new NotAllowedException(errorMsg);
}
if (patient.getEnrollmentRelationship() != null) {
org.hisp.dhis.api.mobile.model.LWUITmodel.Relationship enrollmentRelationship = patient.getEnrollmentRelationship();
enrollmentRelationship.setPersonBId(newTrackedEntityInstance.getId());
addRelationship(enrollmentRelationship, orgUnitId);
}
return getPatientModel(newTrackedEntityInstance);
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method getAttsForMobile.
@Override
public List<org.hisp.dhis.api.mobile.model.PatientAttribute> getAttsForMobile() {
List<org.hisp.dhis.api.mobile.model.PatientAttribute> list = new ArrayList<>();
for (TrackedEntityAttribute patientAtt : getPatientAtts(null)) {
PatientAttribute patientAttribute = new PatientAttribute(patientAtt.getName(), null, null, false, patientAtt.getDisplayInListNoProgram(), new OptionSet());
patientAttribute.setType(patientAtt.getValueType());
list.add(patientAttribute);
}
return list;
}
use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.
the class DefaultDimensionService method getProgramAttributeDimensionItem.
/**
* Returns a {@link ProgramTrackedEntityAttributeDimensionItem}.
*
* @param idScheme the identifier scheme.
* @param programId the program identifier.
* @param attributeId the attribute identifier.
*/
private ProgramTrackedEntityAttributeDimensionItem getProgramAttributeDimensionItem(IdScheme idScheme, String programId, String attributeId) {
Program program = idObjectManager.getObject(Program.class, idScheme, programId);
TrackedEntityAttribute attribute = idObjectManager.getObject(TrackedEntityAttribute.class, idScheme, attributeId);
if (program == null || attribute == null) {
return null;
}
return new ProgramTrackedEntityAttributeDimensionItem(program, attribute);
}
Aggregations