use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method findPatients.
@Override
public org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList findPatients(String patientIds) throws NotAllowedException {
PatientList patientlist = new PatientList();
while (patientIds.length() > 0) {
int patientId = Integer.parseInt(patientIds.substring(0, patientIds.indexOf("$")));
TrackedEntityInstance patient = entityInstanceService.getTrackedEntityInstance(patientId);
patientlist.getPatientList().add(getPatientModel(patient));
patientIds = patientIds.substring(patientIds.indexOf("$") + 1, patientIds.length());
}
return patientlist;
}
use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method enrollProgram.
@Override
public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient enrollProgram(String enrollInfo, List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage> mobileProgramStageList, Date incidentDate) throws NotAllowedException {
String[] enrollProgramInfo = enrollInfo.split("-");
int patientId = Integer.parseInt(enrollProgramInfo[0]);
int programId = Integer.parseInt(enrollProgramInfo[1]);
TrackedEntityInstance patient = entityInstanceService.getTrackedEntityInstance(patientId);
Program program = programService.getProgram(programId);
ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance(patient, program, new Date(), incidentDate, patient.getOrganisationUnit());
Iterator<ProgramStage> programStagesIterator = program.getProgramStages().iterator();
for (int i = 0; i < program.getProgramStages().size(); i++) {
ProgramStage programStage = programStagesIterator.next();
if (programStage.getAutoGenerateEvent()) {
ProgramStageInstance programStageInstance = programStageInstanceService.createProgramStageInstance(programInstance, programStage, new Date(), incidentDate, patient.getOrganisationUnit());
int programStageInstanceId = programStageInstance.getId();
// Inject Datavalue avaiable on-the-fly
if (mobileProgramStageList != null && mobileProgramStageList.size() > 0) {
org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage mobileProgramStage = mobileProgramStageList.get(i);
if (mobileProgramStage != null && mobileProgramStage.getDataElements().size() > 0) {
mobileProgramStage.setId(programStageInstanceId);
if (mobileProgramStage.isSingleEvent()) {
this.saveProgramStage(mobileProgramStage, patientId, patient.getOrganisationUnit().getId());
} else {
this.saveProgramStage(mobileProgramStage, patientId, 0);
}
}
}
programInstance.getProgramStageInstances().add(programStageInstance);
}
}
programInstanceService.updateProgramInstance(programInstance);
patient.getProgramInstances().add(programInstance);
entityInstanceService.updateTrackedEntityInstance(patient);
patient = entityInstanceService.getTrackedEntityInstance(patientId);
return getPatientModel(patient);
}
use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityRegistrationSMSListener method receive.
@Transactional
@Override
public void receive(IncomingSms sms) {
String message = sms.getText();
SMSCommand smsCommand = smsCommandService.getSMSCommand(SmsUtils.getCommandString(sms), ParserType.TRACKED_ENTITY_REGISTRATION_PARSER);
Map<String, String> parsedMessage = this.parse(message, smsCommand);
Date date = SmsUtils.lookForDate(message);
String senderPhoneNumber = StringUtils.replace(sms.getOriginator(), "+", "");
Collection<OrganisationUnit> orgUnits = SmsUtils.getOrganisationUnitsByPhoneNumber(senderPhoneNumber, userService.getUsersByPhoneNumber(senderPhoneNumber));
if (orgUnits == null || orgUnits.size() == 0) {
if (StringUtils.isEmpty(smsCommand.getNoUserMessage())) {
throw new SMSParserException(SMSCommand.NO_USER_MESSAGE);
} else {
throw new SMSParserException(smsCommand.getNoUserMessage());
}
}
OrganisationUnit orgUnit = SmsUtils.selectOrganisationUnit(orgUnits, parsedMessage, smsCommand);
TrackedEntityInstance trackedEntityInstance = new TrackedEntityInstance();
trackedEntityInstance.setOrganisationUnit(orgUnit);
trackedEntityInstance.setTrackedEntity(trackedEntityService.getTrackedEntityByName("Person"));
Set<TrackedEntityAttributeValue> patientAttributeValues = new HashSet<>();
for (SMSCode code : smsCommand.getCodes()) {
if (parsedMessage.containsKey(code.getCode().toUpperCase())) {
TrackedEntityAttributeValue trackedEntityAttributeValue = this.createTrackedEntityAttributeValue(parsedMessage, code, smsCommand, trackedEntityInstance);
patientAttributeValues.add(trackedEntityAttributeValue);
}
}
int trackedEntityInstanceId = 0;
if (patientAttributeValues.size() > 0) {
trackedEntityInstanceId = trackedEntityInstanceService.createTrackedEntityInstance(trackedEntityInstance, null, null, patientAttributeValues);
}
programInstanceService.enrollTrackedEntityInstance(trackedEntityInstanceService.getTrackedEntityInstance(trackedEntityInstanceId), smsCommand.getProgram(), new Date(), date, orgUnit);
smsSender.sendMessage(null, "Entity Registered Successfully ", senderPhoneNumber);
sms.setStatus(SmsMessageStatus.PROCESSED);
sms.setParsed(true);
incomingSmsService.update(sms);
}
Aggregations