Пример #1
0
def nut_followup(message, args, sub_cmd, cmd):

    """ Incomming:
            nut fol hc_code reporting_d  patient_id weight height
                oedema muac nb_plumpy_nut(optional), is_ureni
        exple: 'nut fol sab3 20121004 sam 23 5 65 YES 120 2 1'

        Outgoing:
            [SUCCES] Donnees nutrition mise a jour pour full_name #id
            or error message """

    try:
        hc_code, reporting_d, type_uren, patient_id, weight, height, oedema, muac, nb_plumpy_nut, is_ureni = args.split()
    except:
        return resp_error(message, u"suivi")

    try:
        patient_id = clean_up_pid(patient_id)
        patient = Patient.get_patient_nut_id(hc_code, type_uren.lower(), patient_id)
    except:
        msg = u"[ERREUR] Aucun patient trouve pour ID#%s" % patient_id
        message.respond()
        send_sms(FOL_NUMBER, msg)
        return True

    try:
        followup_date = formatdate(reporting_d)
        followup_datetime = formatdate(reporting_d, True)
    except ValueError as e:
        return resp_error(message, e)

    # creating a followup event
    is_ureni = bool(int(is_ureni))
    weight = float(weight)
    height = float(height)
    oedema = {'yes': NutritionalData.OEDEMA_YES,
              'no': NutritionalData.OEDEMA_NO,
              'unknown': NutritionalData.OEDEMA_UNKNOWN}[oedema.lower()]
    muac = int(muac)
    nb_plumpy_nut = int(nb_plumpy_nut) if not nb_plumpy_nut.lower() == '-' else 0

    if patient.last_data_nut().date == followup_date:
        last_data_nut = patient.last_data_nut()
        last_data_nut.weight = weight
        last_data_nut.height = height
        last_data_nut.oedema = oedema
        last_data_nut.muac = muac
        last_data_nut.nb_plumpy_nut = nb_plumpy_nut
        last_data_nut.is_ureni = is_ureni
        last_data_nut.save()
        message.respond(u"[SUCCES] Donnees nutrition mise a jour pour "
                        u"%(full_name)s" % {'full_name': patient.full_name_id()})
        return True

    if patient.last_data_nut().date > followup_date:
        msg = u"[ERREUR] La date du dernier suivi pour" \
              u" %(full_name)s est superieur que la date utilise" % {'full_name': patient.full_name_id()}
        message.respond(msg)
        send_sms(FOL_NUMBER, msg)
        return True

    if patient.last_data_event().event == ProgramIO.OUT:
        programio = ProgramIO()
        programio.patient = patient
        programio.event = programio.SUPPORT
        programio.date = followup_datetime
        programio.save()

    datanut = add_followup_data(patient=patient, weight=weight,
                                height=height, oedema=oedema,
                                muac=muac, nb_plumpy_nut=nb_plumpy_nut,
                                is_ureni=is_ureni,
                                date=followup_date)
    if not datanut:
        return resp_error(message, u"suivi")

    message.respond(u"[SUCCES] Donnees nutrition enregistres pour "
                    u"%(full_name)s" % {'full_name': patient.full_name_id()})
    return True
Пример #2
0
def nut_disable(message, args, sub_cmd, cmd):
    """  Incomming:
            hc_code, date_disable, patient_id, weight, height, muac,
            reason
            example reason: (a= abandon, t = transfer ...)
            example data: 'nut off sab3 20120925 sam 23 - - - a'
         Outgoing:
            [SUCCES] full_name ne fait plus partie du programme.
            or error message """

    try:
        hc_code, date_disable, type_uren, patient_id, weight, height, muac, reason = args.split()
    except ValueError:
        # Todo: A supprimer une fois la version 07 de application java"
        # est deployé au cscom
        hc_code, date_disable, type_uren, patient_id, reason = args.split()
        weight = None
        height = None
        muac = None
    except:
        return resp_error(message, u"la sortie")

    try:
        quitting_date = formatdate(date_disable)
        quitting_datetime = formatdate(date_disable, True)
    except ValueError as e:
        return resp_error(message, e)

    try:
        patient_id = clean_up_pid(patient_id)
        patient = Patient.get_patient_nut_id(hc_code, type_uren.lower(), patient_id)
    except:
        msg = u"[ERREUR] Aucun patient trouve pour ID#%s" % patient_id
        message.respond(msg)
        send_sms(FOL_NUMBER, msg)
        return True

    if patient.last_data_nut().date > quitting_date:
        msg = u"[ERREUR] La date du dernier suivi pour ID# %s est " \
              u"superieur que la date utilise" % patient.nut_id
        message.respond(msg)
        send_sms(FOL_NUMBER, msg)
        return True

    if patient.last_data_event().event == ProgramIO.OUT:
        msg = u"/!\ %(full_name)s est deja sortie du programme." % {'full_name': patient.full_name()}
        message.respond(msg)
        send_sms(FOL_NUMBER, msg)
        return True

    if reason == ProgramIO.HEALING and weight:
        datanut = add_followup_data(patient=patient, weight=weight,
                                    height=height, muac=muac,
                                    oedema=NutritionalData.OEDEMA_NO,
                                    nb_plumpy_nut=0,
                                    date=quitting_date)
        if not datanut:
            message.respond(u"/!\ %(full_name)s enregistre avec ID#%(id)s."
                            u" Donnees nutrition non enregistres."
                            % {'full_name': patient.full_name(),
                               'id': patient_id})
            return True

    programio = ProgramIO()
    programio.patient = patient
    programio.event = programio.OUT
    programio.reason = reason
    programio.date = quitting_datetime
    programio.save()
    message.respond(u"[SUCCES] %(full_name)s ne fait plus partie "
                    u"du programme." % {'full_name': patient.full_name()})
    return True
Пример #3
0
def nut_register(message, args, sub_cmd, cmd):
    """ Incomming:
            nut register hc_code, create_date, patient_id,
                         first_name, last_name, mother, sex, dob, contact
                         #weight height oed pb nbr, is_ureni
            exple: 'nut register sab3 20121004 23 Moussa Kone Camara M 7
                    35354#6 65 YES 111 25 0'
        Outgoing:
            [SUCCES] Le rapport de name_health_center a ete enregistre.
            Son id est 8.
            or  [ERREUR] Votre rapport n'a pas été enregistrer"""

    try:
        register_data, follow_up_data = args.split('#')

        hc_code, create_date, patient_id, first_name, last_name, mother, sex, dob, contact = register_data.split()

        weight, height, oedema, muac, nb_plumpy_nut, is_ureni = follow_up_data.split()
    except:
        return resp_error(message, u"enregistrement")
    try:
        # On essai prendre le seat
        hc = HealthCenter.objects.get(code=hc_code.lower())
    except:
        # On envoi un sms pour signaler que le code n'est pas valide
        msg = u"[ERREUR] %(hc)s n'est pas un code de Centre valide."\
              % {'hc': hc_code}
        message.respond(msg)
        send_sms(FOL_NUMBER, msg)
        return True

    # check date
    try:
        registration_date = formatdate(create_date, True)
    except ValueError as e:
        return resp_error(message, e)
    # Car on ne traite que les URENI pour l'instant
    type_uren = NutritionalData.SAM
    # True or False
    is_ureni = bool(int(is_ureni))

    if is_ureni:
        if hc_code in ["qmali", "cr"]:
            type_uren = NutritionalData.SAMP
        else:
            msg = u"[ERREUR] Seul les CSREF ont le droit " \
                  u"d'enregistrer les enfants URENI"
            message.respond(msg)
            send_sms(FOL_NUMBER, msg)
            return True
    try:
        patient_id = clean_up_pid(patient_id)
        nut_id = Patient.get_nut_id(hc_code, type_uren.lower(), patient_id)
    except ValueError as e:
        return resp_error(message, e)

    patient = Patient()
    patient.nut_id = nut_id
    patient.first_name = first_name.replace('_', ' ').title()
    patient.last_name = last_name.replace('_', ' ').title()
    patient.surname_mother = mother.replace('_', ' ').title()
    patient.create_date = registration_date
    try:
        patient.birth_date = formatdate(dob)
    except ValueError as e:
        message.respond(u"[ERREUR] %(e)s" % {'e': e})
        return True

    patient.sex = sex.upper()
    patient.contact = contact
    patient.health_center = hc
    try:
        patient.save()
    except IntegrityError:
        patient = Patient.objects.get(nut_id=nut_id)
        save_error(message, u"/!\ l'identifiant #%(id)s appartient déjà à"
                            u" %(full_name)s. enregistré au centre"
                            u" %(health_center)s le %(date)s"
                            u" Pour plus d'information, appelez ce numéro %(admin)s"
                   % {'full_name': patient.full_name(), 'id': nut_id,
                      'date': patient.create_date.strftime("%x %H: %Mmm %Ss"),
                      'health_center': patient.health_center.name,
                      'admin': FOL_NUMBER})
        return False
    except:
        return save_error(message, u"Impossible d'enregistrer ce rapport dans "
                                   u"la base des donnees")

    # adding patient to the program
    programio = ProgramIO()
    programio.patient = patient
    programio.event = programio.SUPPORT
    programio.date = registration_date
    try:
        programio.save()
    except:
        return resp_error(message, u"enregistrement")

    # creating a followup event
    weight = float(weight)
    height = float(height)
    oedema = {'yes': NutritionalData.OEDEMA_YES,
              'no': NutritionalData.OEDEMA_NO,
              'unknown': NutritionalData.OEDEMA_UNKNOWN}[oedema.lower()]
    muac = int(muac)
    nb_plumpy_nut = int(nb_plumpy_nut) if not str(nb_plumpy_nut).lower() == '-' else 0
    datanut = add_followup_data(patient=patient, weight=weight,
                                height=height, oedema=oedema, muac=muac,
                                nb_plumpy_nut=nb_plumpy_nut,
                                is_ureni=is_ureni,
                                date=registration_date)
    if not datanut:
        msg = u"/!\ %(full_name)s enregistre avec ID#%(id)s." \
              u" Donnees nutrition non enregistres." % {'full_name': patient.full_name(), 'id': nut_id}
        message.respond(msg)
        send_sms(FOL_NUMBER, msg)
        return True

    message.respond(u"[SUCCES] %(full_name)s enregistre avec ID#%(id)s."
                    u" Donnees nutrition enregistres." % {'full_name': patient.full_name_mother(), 'id': nut_id})
    return True