Ejemplo n.º 1
0
    def __init__(self,
                 api_model,
                 api_version,
                 app_id,
                 app_key,
                 disable_groups=False):

        # Represent user data
        self.user_profile = self.UserProfile()
        self.actual_diagnosis = infermedica_api.Diagnosis(sex="", age=0)
        self.actual_diagnosis.set_extras(attribute="disable_groups",
                                         value=disable_groups)
        self.triage = None

        # Infermedica API configuration
        infermedica_api.configure(app_id=app_id,
                                  app_key=app_key,
                                  model=api_model,
                                  api_version=api_version)

        try:
            self.infermedica_api = infermedica_api.get_api()
        except MissingConfiguration as e:
            # TODO: esta excepcion no esta funcionando
            logger.critical(str(e))
            raise Exception
Ejemplo n.º 2
0
 def call_triage(self):
     """
     Get Triage with actual evidence
     :return:
     """
     try:
         self.triage = self.infermedica_api.triage(self.actual_diagnosis)
     except Exception as e:
         logger.critical(str(e))
Ejemplo n.º 3
0
 def call_risk_factor(self):
     """
     Get risk factor list
     :return:
     """
     try:
         return self.infermedica_api.risk_factors_list()
     except Exception as e:
         logger.critical(str(e))
Ejemplo n.º 4
0
 def call_diagnosis(self):
     """
     Send a diagnosis request with actual evidence. Get new questions to user
     :return:
     """
     try:
         self.actual_diagnosis = self.infermedica_api.diagnosis(
             self.actual_diagnosis)
     except Exception as e:
         logger.critical(str(e))
Ejemplo n.º 5
0
    def run(self):
        while not self._stop:
            if self.queue_in:  # type: list
                income_msg: WrapperMessage = self.queue_in.pop()
                _request: BasicMessage = income_msg.basic_message

                logger.debug("Processing new message...")
                try:
                    _begin_time = time.time()
                    responses = self.interview_engine.handle_message(request=_request)
                    logger.info("Time FSM : ", time.time() - _begin_time)

                except Exception as e:
                    logger.critical(str(e))
                else:
                    logger.debug("Message processed !")
                    if responses:
                        _begin_time = time.time()
                        self.send_response(responses)
                        logger.info("Time response : ", time.time() - _begin_time)
            time.sleep(0.5)
Ejemplo n.º 6
0
def start_triage():
    """
    The endpoint Slack will start a new triage when recive "/triage" command.
    If user already exist, restart it
    :return:
    """
    if verify_slack_token(request_token=request.form["token"]):
        if "command" in request.form and request.form["command"] == "/triage":
            channel_id = request.form["channel_id"]
            user_id = request.form["user_id"]

            if user_id in active_users:
                try:
                    active_users[user_id].stop_run()
                    # TODO: Puede que no sea necesario, al llamar el metodo de arriba ya se detiene
                    active_users[user_id].join()
                    logger.debug("Old thread {0} removed".format(user_id))
                except Exception as e:
                    logger.error(str(e))

            active_users[user_id] = InterviewThread(
                name="Thread {0}".format(user_id),
                user_id=user_id,
                channel_id=channel_id)

            # trigger to start CovidInterview FSM
            trigger_to_interview = WrapperMessage(basic_message=BasicMessage(
                user_id=user_id, _type=Types.TEXT, text="hola"))
            active_users[user_id].add_new_msg(trigger_to_interview)

            try:
                logger.debug("Starting Thread {0}".format(user_id))
                active_users[user_id].start()
            except Exception as e:
                logger.critical(str(e))
        return make_response("", 200)
    else:
        return make_response(
            "Request contains invalid Slack verification token", 403)
Ejemplo n.º 7
0
 def add_user_info(self, id, choice_id):
     try:
         self.user_profile.data[id] = choice_id
     except KeyError as e:
         logger.critical(str(e))
Ejemplo n.º 8
0
 def get_new_profile_questions(self):
     try:
         return next(self.user_profile.iter_dict_question)
     except StopIteration as e:
         logger.critical(str(e))