Search in sources :

Example 16 with TrackedEntityAttribute

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);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) LegendSet(org.hisp.dhis.legend.LegendSet)

Example 17 with TrackedEntityAttribute

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();
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) QueryItem(org.hisp.dhis.common.QueryItem) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 18 with TrackedEntityAttribute

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);
}
Also used : NotAllowedException(org.hisp.dhis.api.mobile.NotAllowedException) PatientAttribute(org.hisp.dhis.api.mobile.model.PatientAttribute) HashSet(java.util.HashSet) Program(org.hisp.dhis.program.Program) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) PatientAttribute(org.hisp.dhis.api.mobile.model.PatientAttribute) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Date(java.util.Date) NotAllowedException(org.hisp.dhis.api.mobile.NotAllowedException)

Example 19 with TrackedEntityAttribute

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;
}
Also used : TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) PatientAttribute(org.hisp.dhis.api.mobile.model.PatientAttribute) ArrayList(java.util.ArrayList) OptionSet(org.hisp.dhis.api.mobile.model.OptionSet)

Example 20 with TrackedEntityAttribute

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);
}
Also used : Program(org.hisp.dhis.program.Program) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem)

Aggregations

TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)38 DataElement (org.hisp.dhis.dataelement.DataElement)10 Program (org.hisp.dhis.program.Program)10 ArrayList (java.util.ArrayList)9 ProgramTrackedEntityAttribute (org.hisp.dhis.program.ProgramTrackedEntityAttribute)9 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)9 Date (java.util.Date)8 HashSet (java.util.HashSet)5 List (java.util.List)5 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)5 NotAllowedException (org.hisp.dhis.api.mobile.NotAllowedException)4 PatientAttribute (org.hisp.dhis.api.mobile.model.PatientAttribute)4 Grid (org.hisp.dhis.common.Grid)4 QueryItem (org.hisp.dhis.common.QueryItem)4 PeriodType (org.hisp.dhis.period.PeriodType)4 TrackedEntity (org.hisp.dhis.trackedentity.TrackedEntity)4 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)4 PatientList (org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList)3 ProgramInstance (org.hisp.dhis.program.ProgramInstance)3 ProgramStage (org.hisp.dhis.program.ProgramStage)3