Beispiel #1
0
    def register_provider (self, message, role, password, last, first, alias, mobile):
        ''' Adds people into the system 
            JOIN CHW PASSWORD LAST FIRST ALIAS'''
        
        # If error in role, assume CHW
        role    = role.upper()
        if role == 'PHA':
            role    = Provider.PHA_ROLE
        else:
            role    = Provider.CHW_ROLE

        # retrieve clinic
        clinic      = Facility.by_alias(password)
        
        # PHA _must_ be affiliated to a Clinic
        if role == Provider.PHA_ROLE and clinic == None:
            message.respond(_(u"Registration Failed. PHA needs correct clinic ID. '%(input)s' is not.") % {'input': password})
            return True

        # Verify alias availability
        dumb    = Provider.by_alias(alias)
        if not dumb == None:
            message.respond(_(u"Registration Failed. Alias already in use by %(prov)s") % {'prov': dumb.display_full()})
            return True

        # Verify mobile slot
        dumb    = Provider.by_mobile(mobile)
        if not dumb == None:
            message.respond(_(u"Registration Failed. mobile number already in use by %(prov)s") % {'prov': dumb.display_full()})
            return True
        
        # Create provier
        provider    = Provider(alias=alias, first_name=first, last_name=last, role=role, active=True, clinic=clinic, mobile=mobile)
        provider.save()

        # send notifications
        message.respond(_(u"SUCCESS. %(prov)s has been registered with alias %(al)s.") % {'prov': provider.display_full(), 'al': provider.alias})
        
        if not provider.mobile == None:
            message.forward(provider.mobile, _(u"Welcome %(prov)s. You have been registered with alias %(al)s.") % {'prov': provider.display_full(), 'al': provider.alias})
    
        return True