use of org.motechproject.mots.domain.AssignedModules in project mots by motech-implementations.
the class CommunityHealthWorkerService method selectHealthWorker.
/**
* Select CHW, create IVR Subscriber and assign it to CHW. Initiate empty AssignedModules
* instance for selected CHW.
* @param healthWorker CHW to be selected
* @return saved CHW
*/
@PreAuthorize(RoleNames.HAS_CHW_WRITE_ROLE)
public CommunityHealthWorker selectHealthWorker(CommunityHealthWorker healthWorker) {
if (healthWorker.getSelected()) {
throw new ChwException("Could not select CHW, because already selected");
}
healthWorker.setSelected(true);
String phoneNumber = healthWorker.getPhoneNumber();
String name = healthWorker.getCombinedName();
Language preferredLanguage = healthWorker.getPreferredLanguage();
try {
String ivrId = ivrService.createSubscriber(phoneNumber, name, preferredLanguage);
healthWorker.setIvrId(ivrId);
} catch (IvrException ex) {
String message = "Could not select CHW, because of IVR subscriber creation error. \n\n" + ex.getClearVotoInfo();
throw new ChwException(message, ex);
}
healthWorkerRepository.save(healthWorker);
AssignedModules emptyAssignedModulesInstance = new AssignedModules(healthWorker);
assignedModulesRepository.save(emptyAssignedModulesInstance);
return healthWorker;
}
Aggregations