use of org.hisp.dhis.sms.command.SMSCommand in project dhis2-core by dhis2.
the class SmsInboundController method getUserByPhoneNumber.
// -------------------------------------------------------------------------
// SUPPORTIVE METHOD
// -------------------------------------------------------------------------
private User getUserByPhoneNumber(String phoneNumber, String text, User currentUser) throws WebMessageException {
SMSCommand unregisteredParser = smsCommandService.getSMSCommand(SmsUtils.getCommandString(text), ParserType.UNREGISTERED_PARSER);
List<User> users = userService.getUsersByPhoneNumber(phoneNumber);
if (SmsUtils.isBase64(text)) {
return handleCompressedCommands(currentUser, phoneNumber);
}
if (users == null || users.isEmpty()) {
if (unregisteredParser != null) {
return null;
}
// No user belong to this phone number
throw new WebMessageException(conflict("User's phone number is not registered in the system"));
}
return users.iterator().next();
}
use of org.hisp.dhis.sms.command.SMSCommand in project dhis2-core by dhis2.
the class HibernateSMSCommandStore method getSMSCommand.
@Override
public SMSCommand getSMSCommand(int id) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(SMSCommand.class);
criteria.add(Restrictions.eq("id", id));
if (criteria.list() != null && criteria.list().size() > 0) {
return (SMSCommand) criteria.list().get(0);
}
return null;
}
use of org.hisp.dhis.sms.command.SMSCommand 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);
}
use of org.hisp.dhis.sms.command.SMSCommand in project dhis2-core by dhis2.
the class ProgramStageDataEntrySMSListener method receive.
@Transactional
@Override
public void receive(IncomingSms sms) {
String message = sms.getText();
SMSCommand smsCommand = smsCommandService.getSMSCommand(SmsUtils.getCommandString(sms), ParserType.PROGRAM_STAGE_DATAENTRY_PARSER);
this.parse(message, smsCommand);
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());
}
}
}
use of org.hisp.dhis.sms.command.SMSCommand in project dhis2-core by dhis2.
the class CommandSMSListener method receive.
@Override
public void receive(IncomingSms sms) {
SMSCommand smsCommand = getSMSCommand(sms);
Map<String, String> parsedMessage = this.parseMessageInput(sms, smsCommand);
if (!hasCorrectFormat(sms, smsCommand) || !validateInputValues(parsedMessage, smsCommand, sms)) {
return;
}
postProcess(sms, smsCommand, parsedMessage);
}
Aggregations