Exemple #1
0
    def report_cdeath(self, message, ref_id, dod, cause, where, \
                      description=""):
        '''records a child death, the child should be already
        registered with childcount

        Format: death [patient_ID] [date of death ddmmyy]
        [cause P/B/A/I/S] [location H/C/T/O] [description]
        '''
        #Is the child registered with us?
        case = self.find_case(ref_id)
        age = case.age()
        if age[len(age) - 1].upper() == 'Y':
            age = int(age[:len(age) - 1]) * 12
        else:
            age = int(age[:len(age) - 1])

        if len(dod) != 6:
            # There have been cases where a date like 30903 have been sent and
            # when saved it gives some date that is way off
            raise HandlerFailed(_("Date must be in the format ddmmyy:"\
                                  " %(dod)s") % {'dod': dod})
        else:
            dod = re.sub(r'\D', '', dod)
            try:
                dod = time.strptime(dod, "%d%m%y")
            except ValueError:
                try:
                    dod = time.strptime(dod, "%d%m%Y")
                except ValueError:
                    raise HandlerFailed(_("Couldn't understand date: %(dod)s")\
                                         % {'dod': dod})
            dod = datetime.date(*dod[:3])
        if description is None:
            description = "No description"
        reporter = message.persistant_connection.reporter
        death = ReportDeath(last_name=case.last_name.upper(), \
                            first_name=case.first_name.upper(), \
                            gender=case.gender.upper(), \
                            age=age, reporter=reporter, where=where.upper(), \
                            cause=cause.upper(), \
                            description=description, dod=dod, case=case)
        #Perform Location checks
        if death.get_where() is None:
            raise HandlerFailed(_("Location `%(loc)s` is not known. "\
                        "Please try again with a known location") % \
                        {'loc': where})
        #Perform Cause Check
        if death.get_cause() is None:
            raise HandlerFailed(_("Cause `%(cause)s` is not known. "\
                        "Please try again with a known death cause") % \
                        {'cause': cause})

        death.save()
        case.set_status(Case.STATUS_DEAD)
        case.save()
        info = death.get_dictionary()
        message.respond(_("%(name)s [%(age)s] died on %(dod)s of %(cause)s "\
                          "at %(where)s") % info)
        return True
Exemple #2
0
    def report_death(self, message, last, first, gender, age, dod, \
                     cause, where, description=""):
        '''reports a death

        Format: death [last_name] [first_name] [gender m/f] [age[m/y]]
        [date of death ddmmyy] [cause P/B/A/I/S] [location H/C/T/O]
        [description]
        '''
        if age[len(age) - 1].upper() == 'Y':
            age = int(age[:len(age) - 1]) * 12
        else:
            age = int(age[:len(age) - 1])

        if len(dod) != 6:
            # There have been cases where a date like 30903 have been sent and
            # when saved it gives some date that is way off
            raise HandlerFailed(_("Date must be in the format ddmmyy:"\
                                  " %(dod)s") % {'dod': dod})
        else:
            dod = re.sub(r'\D', '', dod)
            try:
                dod = time.strptime(dod, "%d%m%y")
            except ValueError:
                try:
                    dod = time.strptime(dod, "%d%m%Y")
                except ValueError:
                    raise HandlerFailed(_("Couldn't understand date: %(dod)s")\
                                         % {'dod': dod})
            dod = datetime.date(*dod[:3])
        if description is None:
            description = "No description"
        reporter = message.persistant_connection.reporter
        death = ReportDeath(last_name=last, first_name=first, \
                    gender=gender.upper(), \
                    age=age, reporter=reporter, where=where.upper(), \
                    cause=cause.upper(), description=description, dod=dod)
        #Perform Location checks
        if death.get_where() is None:
            raise HandlerFailed(_("Location `%(loc)s` is not known. "\
                        "Please try again with a known location") % \
                        {'loc': where})
        #Perform Cause Check
        if death.get_cause() is None:
            raise HandlerFailed(_("Cause `%(cause)s` is not known. "\
                    "Please try again with a known death cause") % \
                    {'cause': cause})

        death.save()
        info = death.get_dictionary()
        message.respond(_("%(name)s [%(age)s] died on %(dod)s of "\
                          "%(cause)s at %(where)s") % info)
        return True
Exemple #3
0
 def report_cdeath(self, message, ref_id, dod, cause, where, description=""):
     #Is the child registered with us?
     case = self.find_case(ref_id)
     age = case.age()
     if age[len(age)-1].upper() == 'Y':
         age = int(age[:len(age)-1])*12
     else:
         age = int(age[:len(age)-1])
         
             
     if len(dod) != 6:
         # There have been cases where a date like 30903 have been sent and
         # when saved it gives some date that is way off
         raise HandlerFailed(_("Date must be in the format ddmmyy: %s") % dod)
     else:
         dod = re.sub(r'\D', '', dod)
         try:
             dod = time.strptime(dod, "%d%m%y")
         except ValueError:
             try:
                 dod = time.strptime(dod, "%d%m%Y")
             except ValueError:
                 raise HandlerFailed(_("Couldn't understand date: %s") % dod)
         dod = datetime.date(*dod[:3])        
     reporter = message.persistant_connection.reporter
     death = ReportDeath(last_name=case.last_name.upper(),first_name=case.first_name.upper(),gender=case.gender.upper(),
                         age=age, reporter=reporter, where=where.upper(),cause=cause.upper(),
                         description=description, dod=dod, case=case)
     #Perform Location checks
     if death.get_where() is None:
         raise HandlerFailed(_("Location `%s` is not known. Please try again with a known location") % where)
     #Perform Cause Check  
     if death.get_cause() is None:
         raise HandlerFailed(_("Cause `%s` is not known. Please try again with a known death cause") % cause)
     
     death.save()
     case.set_status(Case.STATUS_DEAD);
     case.save()
     info = death.get_dictionary()
     message.respond(_("%(name)s [%(age)s] died on %(dod)s of %(cause)s at %(where)s")%info)
     return True