Search in sources :

Example 1 with Language

use of org.motechproject.mots.domain.enums.Language in project mots by motech-implementations.

the class CommunityHealthWorkerService method saveHealthWorker.

/**
 * Update CHW and IVR Subscriber.
 * @param chw CHW to update
 * @return saved CHW
 */
@PreAuthorize(RoleNames.HAS_CHW_WRITE_ROLE)
public CommunityHealthWorker saveHealthWorker(CommunityHealthWorker chw) {
    String ivrId = chw.getIvrId();
    String phoneNumber = chw.getPhoneNumber();
    String name = chw.getCombinedName();
    Language preferredLanguage = chw.getPreferredLanguage();
    try {
        ivrService.updateSubscriber(ivrId, phoneNumber, name, preferredLanguage);
    } catch (IvrException ex) {
        String message = "Could not update CHW, because of IVR subscriber update error. \n\n" + ex.getClearVotoInfo();
        throw new ChwException(message, ex);
    }
    return healthWorkerRepository.save(chw);
}
Also used : ChwException(org.motechproject.mots.exception.ChwException) IvrException(org.motechproject.mots.exception.IvrException) Language(org.motechproject.mots.domain.enums.Language) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with Language

use of org.motechproject.mots.domain.enums.Language 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;
}
Also used : AssignedModules(org.motechproject.mots.domain.AssignedModules) ChwException(org.motechproject.mots.exception.ChwException) IvrException(org.motechproject.mots.exception.IvrException) Language(org.motechproject.mots.domain.enums.Language) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

Language (org.motechproject.mots.domain.enums.Language)2 ChwException (org.motechproject.mots.exception.ChwException)2 IvrException (org.motechproject.mots.exception.IvrException)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 AssignedModules (org.motechproject.mots.domain.AssignedModules)1