use of org.hisp.dhis.api.mobile.model.LWUITmodel.Patient in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method findPatient.
@Override
public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient findPatient(String patientId) throws NotAllowedException {
TrackedEntityInstance patient = entityInstanceService.getTrackedEntityInstance(patientId);
// Temporary fix
if (patient == null) {
patient = entityInstanceService.getTrackedEntityInstance(Integer.parseInt(patientId));
}
org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel(patient);
return patientMobile;
}
use of org.hisp.dhis.api.mobile.model.LWUITmodel.Patient in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method getPatientModel.
// get patient model for LWUIT
private org.hisp.dhis.api.mobile.model.LWUITmodel.Patient getPatientModel(TrackedEntityInstance patient) {
org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientModel = new org.hisp.dhis.api.mobile.model.LWUITmodel.Patient();
List<org.hisp.dhis.api.mobile.model.PatientAttribute> patientAtts = new ArrayList<>();
List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramInstance> mobileProgramInstanceList = new ArrayList<>();
List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramInstance> mobileCompletedProgramInstanceList = new ArrayList<>();
patientModel.setId(patient.getId());
if (patient.getOrganisationUnit() != null) {
patientModel.setOrganisationUnitName(patient.getOrganisationUnit().getName());
}
if (patient.getTrackedEntity() != null) {
patientModel.setTrackedEntityName(patient.getTrackedEntity().getName());
} else {
patientModel.setTrackedEntityName("");
}
List<TrackedEntityAttributeValue> atts = new ArrayList<>(patient.getTrackedEntityAttributeValues());
for (TrackedEntityAttributeValue value : atts) {
if (value != null) {
org.hisp.dhis.api.mobile.model.PatientAttribute patientAttribute = new org.hisp.dhis.api.mobile.model.PatientAttribute(value.getAttribute().getName(), value.getValue(), null, false, value.getAttribute().getDisplayInListNoProgram(), new OptionSet());
patientAttribute.setType(value.getAttribute().getValueType());
patientAtts.add(patientAttribute);
}
}
patientModel.setAttributes(patientAtts);
List<ProgramInstance> listOfProgramInstance = new ArrayList<>(programInstanceService.getProgramInstances(new ProgramInstanceQueryParams().setTrackedEntityInstance(patient).setProgramStatus(ProgramStatus.ACTIVE).setOrganisationUnitMode(OrganisationUnitSelectionMode.ALL)));
if (listOfProgramInstance.size() > 0) {
for (ProgramInstance each : listOfProgramInstance) {
mobileProgramInstanceList.add(getMobileProgramInstance(each));
}
}
patientModel.setEnrollmentPrograms(mobileProgramInstanceList);
List<ProgramInstance> listOfCompletedProgramInstance = new ArrayList<>(programInstanceService.getProgramInstances(new ProgramInstanceQueryParams().setTrackedEntityInstance(patient).setProgramStatus(ProgramStatus.COMPLETED).setOrganisationUnitMode(OrganisationUnitSelectionMode.ALL)));
if (listOfCompletedProgramInstance.size() > 0) {
for (ProgramInstance each : listOfCompletedProgramInstance) {
mobileCompletedProgramInstanceList.add(getMobileProgramInstance(each));
}
}
patientModel.setCompletedPrograms(mobileCompletedProgramInstanceList);
// Set Relationship
Collection<Relationship> relationships = relationshipService.getRelationshipsForTrackedEntityInstance(patient);
List<org.hisp.dhis.api.mobile.model.LWUITmodel.Relationship> relationshipList = new ArrayList<>();
for (Relationship eachRelationship : relationships) {
org.hisp.dhis.api.mobile.model.LWUITmodel.Relationship relationshipMobile = new org.hisp.dhis.api.mobile.model.LWUITmodel.Relationship();
relationshipMobile.setId(eachRelationship.getId());
if (eachRelationship.getEntityInstanceA().getId() == patient.getId()) {
relationshipMobile.setName(eachRelationship.getRelationshipType().getaIsToB());
relationshipMobile.setaIsToB(eachRelationship.getRelationshipType().getaIsToB());
relationshipMobile.setbIsToA(eachRelationship.getRelationshipType().getbIsToA());
relationshipMobile.setPersonBId(eachRelationship.getEntityInstanceB().getId());
} else {
relationshipMobile.setName(eachRelationship.getRelationshipType().getbIsToA());
relationshipMobile.setaIsToB(eachRelationship.getRelationshipType().getbIsToA());
relationshipMobile.setbIsToA(eachRelationship.getRelationshipType().getaIsToB());
relationshipMobile.setPersonBId(eachRelationship.getEntityInstanceA().getId());
}
// get relative's name
TrackedEntityInstance relative = entityInstanceService.getTrackedEntityInstance(relationshipMobile.getPersonBId());
List<TrackedEntityAttributeValue> attributes = new ArrayList<>(relative.getTrackedEntityAttributeValues());
List<TrackedEntityAttributeValue> attributesInList = new ArrayList<>();
for (TrackedEntityAttributeValue value : attributes) {
if (value != null && value.getAttribute().getDisplayInListNoProgram()) {
attributesInList.add(value);
}
}
Collections.sort(attributesInList, new TrackedEntityAttributeValueSortOrderComparator());
String relativeName = "";
for (TrackedEntityAttributeValue value : attributesInList) {
if (value != null && value.getAttribute().getDisplayInListNoProgram()) {
relativeName += value.getValue() + " ";
}
}
relationshipMobile.setPersonBName(relativeName);
relationshipList.add(relationshipMobile);
}
patientModel.setRelationships(relationshipList);
return patientModel;
}
Aggregations