Exemplo n.º 1
0
    def parser(workflow, message="", sender=""):
        """
           Parsing Workflow Filter.
           Called by parse_import() in s3msg.py.
        """
        settings = current.deployment_settings
        auth = current.auth
        session = current.session
        s3db = current.s3db
        T = current.T
        db = current.db
        msg = current.msg
        rtable = s3db.irs_ireport_human_resource
        ctable = s3db.pr_contact
        htable = s3db.hrm_human_resource
        ptable = s3db.pr_person_user
        stable = s3db.msg_session

        Parse = AuthParse()
        check_login = Parse.parse_login
        check_session = Parse.is_session_alive

        is_session_alive = check_session(sender)
        if is_session_alive:
            email = is_session_alive
            auth.s3_impersonate(email)
        else:
            if check_login(message, sender):
                (email, password) = check_login(message, sender)
                auth.login_bare(email, password)
                expiration = session.auth["expiration"]
                stable.insert(email = email, expiration_time = expiration, \
                              sender = sender)
                return "Authenticated!"

        import sys
        parser = settings.get_msg_parser()
        application = current.request.application
        module_name = 'applications.%s.private.templates.%s.parser' \
            %(application, parser)
        __import__(module_name)
        mymodule = sys.modules[module_name]
        S3Parsing = mymodule.S3Parsing()

        import inspect
        parsers = inspect.getmembers(S3Parsing, predicate=inspect.isfunction)
        parse_opts = []
        for parser in parsers:
            parse_opts += [parser[0]]

        for parser in parse_opts:
            if parser == workflow:
                parse = False

                # Equivalent keywords in one list
                primary_keywords = ["get", "give", "show"]
                contact_keywords = [
                    "email", "mobile", "facility", "clinical", "security",
                    "phone", "status", "hospital", "person", "organisation"
                ]

                pkeywords = primary_keywords + contact_keywords
                keywords = string.split(message)
                pquery = []
                name = ""

                for word in keywords:
                    match = None
                    for key in pkeywords:
                        if soundex(key) == soundex(word):
                            match = key
                            break
                    if match:
                        pquery.append(match)
                    else:
                        name = word

                if workflow == "parse_ireport":
                    (lat, lon, code, text) = msg.parse_opengeosms(message)
                    if code == "SI":
                        result = getattr(S3Parsing, parser)
                        return result(lat, lon, text, message, sender)
                    else:
                        result = getattr(S3Parsing, parser)
                        return result(message=message, sender=sender)

                # --------------------------------------------------------------
                # Person Search [get name person phone email]
                elif "person" in pquery and workflow == "parse_person":
                    parse = True

                # --------------------------------------------------------------
                #  Hospital Search [example: get name hospital facility status ]
                elif "hospital" in pquery and workflow == "parse_hospital":
                    parse = True
                # --------------------------------------------------------------
                # Organization search [example: get name organisation phone]
                elif "organisation" in pquery and workflow == "parse_org":
                    parse = True

                if parse:
                    result = getattr(S3Parsing, parser)
                    return result(pquery, name, sender)
                else:
                    return "Please provide one of the keywords \
Exemplo n.º 2
0
    def parser(workflow, message = "", sender=""):
        """
           Parsing Workflow Filter.
           Called by parse_import() in s3msg.py.
        """
        settings = current.deployment_settings
	auth = current.auth
	session = current.session
        s3db = current.s3db
        T = current.T
        db = current.db
        msg = current.msg
        rtable = s3db.irs_ireport_human_resource
        ctable = s3db.pr_contact
        htable = s3db.hrm_human_resource
        ptable = s3db.pr_person_user
	stable = s3db.msg_session
	
	Parse = AuthParse()
	check_login = Parse.parse_login
	check_session = Parse.is_session_alive
	
	is_session_alive = check_session(sender)
	if is_session_alive:
	    email = is_session_alive
	    auth.s3_impersonate(email)
	else:
	    if check_login(message, sender):
		(email,password) = check_login(message, sender)
		auth.login_bare(email,password)
		expiration = session.auth["expiration"]
		stable.insert(email = email, expiration_time = expiration, \
		              sender = sender)
		return "Authenticated!"
	
        import sys
        parser = settings.get_msg_parser()
        application = current.request.application
        module_name = 'applications.%s.private.templates.%s.parser' \
            %(application, parser)
        __import__(module_name)
        mymodule = sys.modules[module_name]
        S3Parsing = mymodule.S3Parsing()
        
        import inspect
        parsers = inspect.getmembers(S3Parsing, predicate=inspect.isfunction)
        parse_opts = []
        for parser in parsers:
            parse_opts += [parser[0]]

        for parser in parse_opts:
            if parser == workflow :
                parse = False
		    
                # Equivalent keywords in one list
                primary_keywords = ["get", "give", "show"] 
                contact_keywords = ["email", "mobile", "facility", "clinical",
		                    "security", "phone", "status", "hospital",
		                    "person", "organisation"]
		
                pkeywords = primary_keywords + contact_keywords
                keywords = string.split(message)
                pquery = []
                name = ""
		
                for word in keywords:
                    match = None
                    for key in pkeywords:
                        if soundex(key) == soundex(word):
                            match = key
                            break
                    if match:
                        pquery.append(match)
                    else:
                        name = word
		
                if workflow == "parse_ireport":
                    (lat, lon, code, text) = msg.parse_opengeosms(message)
                    if code == "SI":
                        result = getattr(S3Parsing, parser)
                        return result(lat, lon, text, message, sender)
                    else:
                        result = getattr(S3Parsing, parser)
                        return result(message=message, sender=sender)
				    
                # --------------------------------------------------------------
                # Person Search [get name person phone email]
                elif "person" in pquery and workflow == "parse_person":
                    parse = True
    
                # --------------------------------------------------------------
                #  Hospital Search [example: get name hospital facility status ]
                elif "hospital" in pquery and workflow == "parse_hospital":
                    parse = True
                # --------------------------------------------------------------
                # Organization search [example: get name organisation phone]
                elif "organisation" in pquery and workflow == "parse_org":
                    parse = True
		
		
		    
                if parse:
                    result = getattr(S3Parsing, parser)
                    return result(pquery, name, sender)
                else:
                    return "Please provide one of the keywords \
Exemplo n.º 3
0
    def parse_org(message=""):
        """
           Search for Organisations
        """

        if not message:
            return None

        T = current.T
        db = current.db
        s3db = current.s3db

        primary_keywords = ["get", "give", "show"] # Equivalent keywords in one list
        contact_keywords = ["email", "mobile", "facility", "clinical",
                            "security", "phone", "status", "hospital",
                            "person", "organisation"]

        pkeywords = primary_keywords + contact_keywords
        keywords = string.split(message)
        pquery = []
        name = ""
        reply = ""
        for word in keywords:
            match = None
            for key in pkeywords:
                if soundex(key) == soundex(word):
                    match = key
                    break
            if match:
                pquery.append(match)
            else:
                name = word
                
        # ---------------------------------------------------------------------
        # Organization search [example: get name organisation phone]
        if "organisation" in pquery:
            table = s3db.org_organisation
            rows = db(table.deleted == False).select(table.id,
                                                     table.name,
                                                     table.donation_phone,
                                                     table.acronym)
            _name = soundex(str(name))
            for row in rows:
                result = []
                if (_name == soundex(row.name)) or \
                   (_name == soundex(row.acronym)):
                    result.append(row)
                    break

            if len(result) > 1:
                return T("Multiple Matches")

            if len(result) == 1:
                org = result[0]
                reply = "%s %s (%s) " % (reply, org.name,
                                         T("Organization"))
                if "phone" in pquery:
                    reply = reply + "Phone->" + str(org.donation_phone)
                if "office" in pquery:
                    otable = s3db.org_office
                    office = db(table.organisation_id == org.id).select(otable.address,
                                                                        limitby=(0, 1)).first()
                    reply = reply + "Address->" + office.address
            if len(reply) == 0:
                return T("No Match")

            return reply

        return "Please provide one of the keywords - person, hospital, organisation"
Exemplo n.º 4
0
    def parse_person(message=""):
        """
            Search for People
        """

        if not message:
            return None

        T = current.T
        db = current.db
        s3db = current.s3db

        primary_keywords = ["get", "give", "show"] # Equivalent keywords in one list
        contact_keywords = ["email", "mobile", "facility", "clinical",
                            "security", "phone", "status", "hospital",
                            "person", "organisation"]

        pkeywords = primary_keywords + contact_keywords
        keywords = string.split(message)
        pquery = []
        name = ""
        reply = ""
        for word in keywords:
            match = None
            for key in pkeywords:
                if soundex(key) == soundex(word):
                    match = key
                    break
            if match:
                pquery.append(match)
            else:
                name = word

        # ---------------------------------------------------------------------
        # Person Search [get name person phone email]
        if "person" in pquery:

            table = s3db.pr_person
            rows = db(table.deleted ==False).select(table.pe_id,
                                                    table.first_name,
                                                    table.middle_name,
                                                    table.last_name)
            _name = soundex(str(name))
            for row in rows:
                result = []
                if (_name == soundex(row.first_name)) or \
                   (_name == soundex(row.middle_name)) or \
                   (_name == soundex(row.last_name)):
                    presult = dict(name = row.first_name, id = row.pe_id)
                    result.append(presult)
                    break

            if len(result) > 1:
                return T("Multiple Matches")
            if len(result) == 1:
                reply = result[0]["name"]
                table = s3db.pr_contact
                if "email" in pquery:
                    query = (table.pe_id == result[0]["id"]) & \
                        (table.contact_method == "EMAIL")
                    recipient = db(query).select(table.value,
                                                 orderby = table.priority,
                                                 limitby=(0, 1)).first()
                    if recipient:
                        reply = "%s Email->%s" % (reply, recipient.value)
                if "phone" in pquery:
                    query = (table.pe_id == result[0]["id"]) & \
                        (table.contact_method == "SMS")
                    recipient = db(query).select(table.value,
                                                 orderby = table.priority,
                                                 limitby=(0, 1)).first()
                    if recipient:
                        reply = "%s Mobile->%s" % (reply,
                                               recipient.value)

            if len(result) == 0:
                return T("No Match")

            return reply
        return "Please provide one of the keywords - person, hospital, organisation"
Exemplo n.º 5
0
    def parse_hospital(message=""):
        """
           Search for Hospitals
        """

        if not message:
            return None

        T = current.T
        db = current.db
        s3db = current.s3db

        primary_keywords = ["get", "give", "show"] # Equivalent keywords in one list
        contact_keywords = ["email", "mobile", "facility", "clinical",
                            "security", "phone", "status", "hospital",
                            "person", "organisation"]

        pkeywords = primary_keywords + contact_keywords
        keywords = string.split(message)
        pquery = []
        name = ""
        reply = ""
        for word in keywords:
            match = None
            for key in pkeywords:
                if soundex(key) == soundex(word):
                    match = key
                    break
            if match:
                pquery.append(match)
            else:
                name = word

        # ---------------------------------------------------------------------
        #  Hospital Search [example: get name hospital facility status ]
        if "hospital" in pquery:
            table = s3db.hms_hospital
            rows = db(table.deleted == False).select(table.id,
                                                     table.name,
                                                     table.aka1,
                                                     table.aka2,
                                                     table.phone_emergency,
                                                     table.clinical_status,
                                                     table.facility_status,
                                                     table.security_status,
                                                     )
            _name = soundex(str(name))
            for row in rows:
                result = []
                if (_name == soundex(row.name)) or \
                   (_name == soundex(row.aka1)) or \
                   (_name == soundex(row.aka2)):
                    result.append(row)
                    break

            if len(result) > 1:
                return T("Multiple Matches")

            if len(result) == 1:
                hospital = result[0]
                reply = "%s %s (%s) " % (reply, hospital.name,
                                         T("Hospital"))
                if "phone" in pquery:
                    reply = reply + "Phone->" + str(hospital.phone_emergency)
                if "facility" in pquery:
                    reply = reply + "Facility status " + \
                        str(table.facility_status.represent(hospital.facility_status))
                if "clinical" in pquery:
                    reply = reply + "Clinical status " + \
                        str(table.clinical_status.represent(hospital.clinical_status))
                if "security" in pquery:
                    reply = reply + "Security status " + \
                        str(table.security_status.represent(hospital.security_status))

            if len(result) == 0:
                return T("No Match")

            return reply

        return "Please provide one of the keywords - person, hospital, organisation"