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);
}
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;
}
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);
}
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;
}
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 );
}
Aggregations