Search in sources :

Example 1 with PatientAttribute

use of org.hisp.dhis.api.mobile.model.PatientAttribute in project dhis2-core by dhis2.

the class ActivityReportingServiceImpl method savePatient.

@Override
public Patient savePatient(org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patient, int orgUnitId, String programIdText) 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()));
    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(programIdText));
        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);
    }
    return getPatientModel(newTrackedEntityInstance);
}
Also used : Program(org.hisp.dhis.program.Program) NotAllowedException(org.hisp.dhis.api.mobile.NotAllowedException) 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) PatientAttribute(org.hisp.dhis.api.mobile.model.PatientAttribute) HashSet(java.util.HashSet)

Example 2 with PatientAttribute

use of org.hisp.dhis.api.mobile.model.PatientAttribute in project dhis2-core by dhis2.

the class ActivityReportingServiceImpl method getPatientAttributesForMobile.

@Override
public List<org.hisp.dhis.api.mobile.model.PatientAttribute> getPatientAttributesForMobile(String programId) {
    List<org.hisp.dhis.api.mobile.model.PatientAttribute> list = new ArrayList<>();
    for (TrackedEntityAttribute pa : getPatientAtts(programId)) {
        PatientAttribute patientAttribute = new PatientAttribute();
        String name = pa.getName();
        patientAttribute.setName(name);
        patientAttribute.setType(pa.getValueType());
        patientAttribute.setValue("");
        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)

Example 3 with PatientAttribute

use of org.hisp.dhis.api.mobile.model.PatientAttribute 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 4 with PatientAttribute

use of org.hisp.dhis.api.mobile.model.PatientAttribute 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 5 with PatientAttribute

use of org.hisp.dhis.api.mobile.model.PatientAttribute in project dhis2-core by dhis2.

the class Patient method serialize.

// -------------------------------------------------------------------------
// Override Methods
// -------------------------------------------------------------------------
@Override
public void serialize(DataOutputStream dout) throws IOException {
    //        ByteArrayOutputStream bout = new ByteArrayOutputStream();
    //        DataOutputStream dout = new DataOutputStream( bout );
    dout.writeInt(this.getId());
    dout.writeUTF(this.getOrganisationUnitName());
    dout.writeUTF(this.getTrackedEntityName());
    // Write Patient Attribute
    dout.writeInt(attributes.size());
    for (PatientAttribute patientAtt : attributes) {
        patientAtt.serialize(dout);
    }
    // Write Enrollment Programs
    dout.writeInt(enrollmentPrograms.size());
    for (ProgramInstance program : enrollmentPrograms) {
        program.serialize(dout);
    }
    // Write completed Programs
    dout.writeInt(completedPrograms.size());
    for (ProgramInstance each : completedPrograms) {
        each.serialize(dout);
    }
    // Write Relationships
    dout.writeInt(relationships.size());
    for (Relationship each : relationships) {
        each.serialize(dout);
    }
    dout.writeInt(this.getIdToAddRelative());
    dout.writeInt(this.getRelTypeIdToAdd());
    if (enrollmentRelationship != null) {
        dout.writeInt(1);
        enrollmentRelationship.serialize(dout);
    } else {
        dout.writeInt(0);
    }
//        bout.flush();
//        bout.writeTo( out );
}
Also used : PatientAttribute(org.hisp.dhis.api.mobile.model.PatientAttribute)

Aggregations

PatientAttribute (org.hisp.dhis.api.mobile.model.PatientAttribute)10 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)4 ArrayList (java.util.ArrayList)3 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)3 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)3 Date (java.util.Date)2 HashSet (java.util.HashSet)2 NotAllowedException (org.hisp.dhis.api.mobile.NotAllowedException)2 OptionSet (org.hisp.dhis.api.mobile.model.OptionSet)2 Program (org.hisp.dhis.program.Program)2 Patient (org.hisp.dhis.api.mobile.model.LWUITmodel.Patient)1 TrackedEntityAttributeValueSortOrderComparator (org.hisp.dhis.api.mobile.model.comparator.TrackedEntityAttributeValueSortOrderComparator)1 ProgramInstance (org.hisp.dhis.program.ProgramInstance)1 ProgramInstanceQueryParams (org.hisp.dhis.program.ProgramInstanceQueryParams)1 Relationship (org.hisp.dhis.relationship.Relationship)1