示例#1
0
    def update_local_coming_visit(self, owner, clinic, remote_visit):
        # I'm assuming we'll always have the patient being referenced
        # in the Visit object, if not - raise hell
        patient = Patient.objects.get(te_id=remote_visit.te_id, owner=owner)
        coming_date = iso8601.parse_date(remote_visit.scheduled_visit_date)

        # FIXME:    a lot of duplication between update_local_coming_visit and
        #           update_local_missed_visits with regard to the status of
        #           of the messages.

        try:
            visit = Visit.objects.get(te_visit_id=remote_visit.key_id)
            created = False
        except Visit.DoesNotExist:
            visit = Visit(te_visit_id=remote_visit.key_id)
            created = True

        # check if something actually changed in the visit, if not, immediately
        # return the visit - no use continuing
        if coming_date.date() == visit.date:
            return

        # it's a new visit
        if created:
            if coming_date.date() <= date.today():
                visit.status = 'm'
            else:
                visit.status = 's'
        # it's an existing visit
        else:
            if coming_date.date() > visit.date:
                visit.status = 'r'
            # due to opt-in issues, we can no longer infer missed visits from
            # overdue comming dates stored locally
            #else:
            #visit.status = 'm'

        visit.clinic = clinic
        visit.patient = patient
        visit.date = coming_date
        if visit.is_dirty():
            visit.save()

        if created:
            logger.debug('Creating new Visit: %s' % visit.id)
        else:
            logger.debug(
                'Updating existing Visit: %s / (%s vs %s)' %
                (visit.id, visit.get_dirty_fields(), visit._original_state))
        return visit
示例#2
0
 def update_local_coming_visit(self, owner, clinic, remote_visit):
     # I'm assuming we'll always have the patient being referenced
     # in the Visit object, if not - raise hell
     patient = Patient.objects.get(te_id=remote_visit.te_id, owner=owner)
     coming_date = iso8601.parse_date(remote_visit.scheduled_visit_date)
     
     # FIXME:    a lot of duplication between update_local_coming_visit and
     #           update_local_missed_visits with regard to the status of
     #           of the messages.
     
     try:
         visit = Visit.objects.get(te_visit_id=remote_visit.key_id)
         created = False
     except Visit.DoesNotExist:
         visit = Visit(te_visit_id=remote_visit.key_id)
         created = True
     
     # check if something actually changed in the visit, if not, immediately
     # return the visit - no use continuing
     if coming_date.date() == visit.date:
         return
     
     # it's a new visit
     if created:
         if coming_date.date() <= date.today():
             visit.status = 'm'
         else:
             visit.status = 's'
     # it's an existing visit
     else:
         if coming_date.date() > visit.date:
             visit.status = 'r'
         # due to opt-in issues, we can no longer infer missed visits from
         # overdue comming dates stored locally
         #else:
             #visit.status = 'm'
     
     visit.clinic = clinic
     visit.patient = patient
     visit.date = coming_date
     if visit.is_dirty():
         visit.save()
     
     if created:
         logger.debug('Creating new Visit: %s' % visit.id)
     else:
         logger.debug('Updating existing Visit: %s / (%s vs %s)' % (visit.id, visit.get_dirty_fields(), visit._original_state))
     return visit
示例#3
0
 def update_local_missed_visit(self, owner, clinic, remote_visit):
     # get the patient or raise error
     patient = Patient.objects.get(te_id=remote_visit.te_id, owner=owner)
     missed_date = iso8601.parse_date(remote_visit.missed_date).date()
     
     try:
         visit = Visit.objects.get(te_visit_id=remote_visit.key_id)
         created = False
     except Visit.DoesNotExist:
         visit = Visit(te_visit_id=remote_visit.key_id)
         created = True
     
     # check if something actually changed in the visit, if not, immediately
     # return the visit - no use continuing
     if missed_date == visit.date and visit.status == 'm':
         return
     
     # it's a new visit
     if created:
         if missed_date <= date.today():
             visit.status = 'm'
         else:
             visit.status = 'r'
     # it's an existing visit
     else:
         if missed_date > visit.date:
             visit.status = 'r'
         else:
             visit.status = 'm'
     
     visit.clinic = clinic
     visit.patient = patient
     visit.date = missed_date
     if visit.is_dirty():
         visit.save()
     
     if created:
         logger.debug('Creating new Visit: %s' % visit.id)
     else:
         logger.debug('Updating Visit:%s, date: %s, status: %s' % (
             visit.id,
             missed_date,
             visit.status
         ))
     
     return visit
示例#4
0
    def update_local_missed_visit(self, owner, clinic, remote_visit):
        # get the patient or raise error
        patient = Patient.objects.get(te_id=remote_visit.te_id, owner=owner)
        missed_date = iso8601.parse_date(remote_visit.missed_date).date()

        try:
            visit = Visit.objects.get(te_visit_id=remote_visit.key_id)
            created = False
        except Visit.DoesNotExist:
            visit = Visit(te_visit_id=remote_visit.key_id)
            created = True

        # check if something actually changed in the visit, if not, immediately
        # return the visit - no use continuing
        if missed_date == visit.date and visit.status == 'm':
            return

        # it's a new visit
        if created:
            if missed_date <= date.today():
                visit.status = 'm'
            else:
                visit.status = 'r'
        # it's an existing visit
        else:
            if missed_date > visit.date:
                visit.status = 'r'
            else:
                visit.status = 'm'

        visit.clinic = clinic
        visit.patient = patient
        visit.date = missed_date
        if visit.is_dirty():
            visit.save()

        if created:
            logger.debug('Creating new Visit: %s' % visit.id)
        else:
            logger.debug('Updating Visit:%s, date: %s, status: %s' %
                         (visit.id, missed_date, visit.status))

        return visit