def stop_messaging(self, request, study_id=None): reason = request.data.get('reason','') sae = request.data.get('sae',False) instance = self.get_object() if sae is True: receive_sms = request.data.get('receive_sms',False) loss_date = utils.angular_datepicker(request.data.get('loss_date')) note=False status = 'loss' if receive_sms else 'sae' comment = "Changed loss opt-in status: {}".format(receive_sms) if instance.loss_date is None: # Set loss date if not set instance.loss_date = loss_date if instance.delivery_date is None: # Set delivery date to loss date if not already set instance.delivery_date = loss_date comment = "{}\nSAE event recorded by {}. Opt-In: {}".format(reason,request.user.practitioner,receive_sms) note=True print "SAE {} continue {}".format(loss_date,receive_sms) instance.set_status(status,comment=comment,note=note,user=request.user) elif instance.status == 'other': comment = "{}\nMessaging changed in web interface by {}".format(reason,request.user.practitioner) status = 'pregnant' if instance.delivery_date is None else 'post' instance.set_status(status, comment=comment) else: comment = "{}\nStopped in web interface by {}".format(reason,request.user.practitioner) instance.set_status('other', comment=comment) serializer = self.get_serializer(instance) return Response(serializer.data)
def partial_update(self, request, study_id=None, *args, **kwargs): ''' PATCH - partial update a participant ''' instance = self.get_object() instance.status = request.data['status'] instance.send_time = request.data['send_time'] instance.send_day = request.data['send_day'] instance.art_initiation = utils.angular_datepicker(request.data['art_initiation']) instance.due_date = utils.angular_datepicker(request.data['due_date']) instance.hiv_disclosed = request.data['hiv_disclosed'] instance.hiv_messaging = request.data['hiv_messaging'] instance.save() instance_serialized = ParticipantSerializer(cont.Contact.objects.get(pk=instance.pk),context={'request':request}).data return Response(instance_serialized)
def attended(self, request, pk): instance = self.get_object() instance.attended(request.data.get('arrived', None)) instance_serialized = VisitSerializer(instance, context={ 'request': request }).data cont.EventLog.objects.create(user=request.user, event='visit.attended', data={'visit_id': instance.id}) # Make next visit if needed next_visit_serialized = None if request.data.has_key('next'): print 'Next Visit', request.data['next'] next_visit = instance.participant.visit_set.create( scheduled=utils.angular_datepicker(request.data['next']), visit_type=request.data['type']) next_visit_serialized = VisitSerializer(next_visit, context={ 'request': request }).data return Response({ 'visit': instance_serialized, 'next': next_visit_serialized })
def attended(self, arrived=None): ''' Mark visted as attended on @arrived (default today) ''' if arrived is None: arrived = utils.today() else: arrived = utils.angular_datepicker(arrived) self.set_status('attended', arrived)
def partial_update(self, request, study_id=None, *args, **kwargs): ''' PATCH - partial update a participant ''' instance = self.get_object() instance.status = request.data['status'] instance.send_time = request.data['send_time'] instance.send_day = request.data['send_day'] instance.art_initiation = utils.angular_datepicker(request.data['art_initiation']) instance.due_date = utils.angular_datepicker(request.data['due_date']) instance.hiv_disclosed = request.data['hiv_disclosed'] instance.hiv_messaging = request.data['hiv_messaging'] instance.second_preg = request.data['second_preg'] == 'True' instance.save() instance_serialized = ParticipantSerializer(cont.Contact.objects.get(pk=instance.pk),context={'request':request}).data return Response(instance_serialized)
def edit(self, request, pk): instance = self.get_object() instance.scheduled = utils.angular_datepicker(request.data['scheduled']) instance.save() instance_serialized = self.get_serializer(instance) return Response(instance_serialized.data)
def edit(self, request, pk): instance = self.get_object() instance.scheduled = utils.angular_datepicker( request.data['scheduled']) instance.save() instance_serialized = self.get_serializer(instance) return Response(instance_serialized.data)
def attended(self, arrived=None): ''' Mark visted as attended on @arrived (default today) ''' if arrived is None: arrived = utils.today() else: arrived = utils.angular_datepicker(arrived) self.arrived = arrived self.skipped = False self.save()
def seen(self,seen=None): ''' Mark visit as seen today ''' if seen is None: seen = utils.today() else: seen = utils.angular_datepicker(seen) self.notify_count += 1 self.notification_last_seen = seen self.save()
def attended(self,arrived=None): ''' Mark visted as attended on @arrived (default today) ''' if arrived is None: arrived = utils.today() else: arrived = utils.angular_datepicker(arrived) self.arrived = arrived self.skipped = False self.save()
def seen(self, seen=None): ''' Mark visit as seen today ''' if seen is None: seen = utils.today() else: seen = utils.angular_datepicker(seen) self.notify_count += 1 self.notification_last_seen = seen self.save()
def add_call(self,outcome='answered',comment=None,length=None,is_outgoing=True, created=None,admin_user=None,scheduled=None): if created is None: created = utils.today() else: created = utils.angular_datepicker(created) new_call = PhoneCall.objects.create(outcome=outcome,contact=self,is_outgoing=is_outgoing, comment=comment,created=created,connection=self.connection(),length=length, scheduled=scheduled) return new_call
def delivery(self, request, study_id=None): instance = self.get_object() if not instance.is_pregnant(): return Response({'error':{'message':'Participant already post-partum'}}) comment = "Delivery notified via {0}. \n{1}".format(request.data.get('source'),request.data.get('comment','')) delivery_date = utils.angular_datepicker(request.data.get('delivery_date')) instance.delivery(delivery_date, comment=comment, user=request.user, source=request.data['source']) serializer = self.get_serializer(instance) return Response(serializer.data)
def visits(self, request, study_id=None, *args, **kwargs): if request.method == 'GET': # Return a serialized list of all visits visits = cont.Visit.objects.filter(participant__study_id=study_id) visits_serialized = VisitSerializer(visits,many=True,context={'request':request}) return Response(visits_serialized.data) elif request.method == 'POST': # Schedual a new visit instance = self.get_object() next_visit = instance.visit_set.create( scheduled=utils.angular_datepicker(request.data['next']), visit_type=request.data['type'] ) return Response(VisitSerializer(next_visit,context={'request':request}).data)
def visits(self, request, study_id=None, *args, **kwargs): if request.method == 'GET': # Return a serialized list of all visits instance = self.get_object() visits = instance.visit_set.exclude(status='deleted') visits_serialized = VisitSerializer(visits,many=True,context={'request':request}) return Response(visits_serialized.data) elif request.method == 'POST': # Schedual a new visit instance = self.get_object() next_visit = instance.visit_set.create( scheduled=utils.angular_datepicker(request.data['next']), visit_type=request.data['type'] ) return Response(VisitSerializer(next_visit,context={'request':request}).data)
def attended(self, request, pk): instance = self.get_object() instance.attended(request.data.get('arrived',None)) instance_serialized = VisitSerializer(instance,context={'request':request}).data cont.EventLog.objects.create(user=request.user,event='visit.attended',data={'visit_id':instance.id}) # Make next visit if needed next_visit_serialized = None if request.data.has_key('next'): print 'Next Visit',request.data['next'] next_visit = instance.participant.visit_set.create( scheduled=utils.angular_datepicker(request.data['next']), visit_type=request.data['type'] ) next_visit_serialized = VisitSerializer(next_visit,context={'request':request}).data return Response({'visit':instance_serialized,'next':next_visit_serialized})