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
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