Beispiel #1
0
    def register_provider(self, message, role, clinic, name):
        """ Adds people into the system 
            JOIN CHW PASSWORD LAST FIRST ALIAS"""

        # If error in role, assume CHW
        try:
            role = Role.objects.get(code=role.lower())
        except Role.DoesNotExist:
            role = Role.objects.get(code="chw")

        # retrieve clinic
        try:
            clinic = Location.objects.get(code=clinic.lower())
        except Location.DoesNotExist:
            clinic = None

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

        # Create provier
        try:
            alias, fn, ln = Provider.parse_name(name)
            provider = Provider(alias=alias, first_name=fn, last_name=ln, location=clinic, role=role)
            provider.save()

            # attach the reporter to the current connection
            message.persistant_connection.reporter = provider
            message.persistant_connection.save()
        except Exception, e:
            message.respond(_(u"Registration failed: %(error)s") % {"error": e.args})