コード例 #1
0
def find_patient(request):
    if 'patient_id' in request.GET:

        msisdn = request.GET.get('msisdn') or '0100000000'
        if msisdn:
            msisdn = normalize_msisdn(msisdn)

        patients = Patient.objects.in_group_with(request.user).filter(
            Q(te_id__icontains=request.GET.get('patient_id') or 'False')
            | Q(active_msisdn__msisdn__icontains=msisdn)
            | Q(name__contains=request.GET.get('name') or 'False')
            | Q(surname__icontains=request.GET.get('surname') or 'False'))

        if patients.count() == 1:
            next = request.GET.get('next')
            if next:
                next = '%s?patient_id=%s' % (next, patients[0].pk)
            else:
                next = reverse('bookings:admin:edit_patient',
                               kwargs={'patient_id': patients[0].pk})
            return HttpResponseRedirect(next)
        else:
            return render_to_response('bookings_admin/patient/results.html', {
                'patients': patients,
                'next': request.GET.get('next')
            },
                                      context_instance=RequestContext(request))
    else:
        return render_to_response('bookings_admin/patient/find.html',
                                  {'next': request.GET.get('next')},
                                  context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: praekelt/txtalert
def find_patient(request):
    if "patient_id" in request.GET:

        msisdn = request.GET.get("msisdn") or "0100000000"
        if msisdn:
            msisdn = normalize_msisdn(msisdn)

        patients = Patient.objects.in_group_with(request.user).filter(
            Q(te_id__icontains=request.GET.get("patient_id") or "False")
            | Q(active_msisdn__msisdn__icontains=msisdn)
            | Q(name__contains=request.GET.get("name") or "False")
            | Q(surname__icontains=request.GET.get("surname") or "False")
        )

        if patients.count() == 1:
            next = request.GET.get("next")
            if next:
                next = "%s?patient_id=%s" % (next, patients[0].pk)
            else:
                next = reverse("bookings:admin:edit_patient", kwargs={"patient_id": patients[0].pk})
            return HttpResponseRedirect(next)
        else:
            return render_to_response(
                "bookings_admin/patient/results.html",
                {"patients": patients, "next": request.GET.get("next")},
                context_instance=RequestContext(request),
            )
    else:
        return render_to_response(
            "bookings_admin/patient/find.html",
            {"next": request.GET.get("next")},
            context_instance=RequestContext(request),
        )
コード例 #3
0
ファイル: views.py プロジェクト: graemeglass/txtalert
def request_call(request):
    if request.POST:
        form = RequestCallForm(request.POST)
        if form.is_valid():
            clinic = form.cleaned_data['clinic']
            # normalize
            msisdn = normalize_msisdn(form.cleaned_data['msisdn'])
            # orm object
            msisdn_record, _ = MSISDN.objects.get_or_create(msisdn=msisdn)
            pcm = PleaseCallMe(user=clinic.user, clinic=clinic, 
                msisdn=msisdn_record, timestamp=datetime.now(), 
                message='Please call me!', notes='Call request issued via txtAlert Bookings')
            pcm.save()
            messages.add_message(request, messages.INFO, 
                        'Your call request has been registered. '\
                        'The clinic will call you back as soon as possible.')
            return HttpResponseRedirect(reverse('bookings:request_call'))
    else:
        form = RequestCallForm(initial={
            'msisdn': '' if request.user.is_anonymous() else request.user.username
        })
    
    if request.user.is_anonymous():
        profile = patient = None
    else:
        profile = request.user.get_profile()
        patient = profile.patient
    
    return render_to_response('request_call.html', {
        'profile': profile,
        'patient': patient,
        'form': form,
    }, context_instance=RequestContext(request))
コード例 #4
0
    def read(self, request):
        if "patient_id" in request.GET and "msisdn" in request.GET:

            try:
                msisdn = normalize_msisdn(request.GET.get("msisdn"))
                patient_id = request.GET.get("patient_id")
                patient = Patient.objects.get(active_msisdn__msisdn=msisdn, te_id=patient_id)
                try:
                    visit = patient.next_visit()
                    visit_info = [visit.date.year, visit.date.month, visit.date.day]
                    clinic_name = visit.clinic.name
                except Visit.DoesNotExist:
                    visit = None
                    visit_info = []
                    clinic_name = ""

                visits = patient.visit_set.all()

                return {
                    "msisdn": msisdn,
                    "patient_id": patient_id,
                    "name": patient.name,
                    "surname": patient.surname,
                    "next_appointment": visit_info,
                    "visit_id": visit.pk if visit else "",
                    "clinic": clinic_name,
                    "attendance": int((1.0 - patient.risk_profile) * 100),
                    "total": visits.count(),
                    "attended": visits.filter(status="a").count(),
                    "rescheduled": visits.filter(status="r").count(),
                    "missed": visits.filter(status="m").count(),
                }
            except Patient.DoesNotExist:
                pass
        return {}
コード例 #5
0
ファイル: views.py プロジェクト: sanyaade/txtalert
def find_patient(request):
    if 'patient_id' in request.GET:
        
        msisdn = request.GET.get('msisdn') or '0100000000'
        if msisdn:
            msisdn = normalize_msisdn(msisdn)
        
        patients = Patient.objects.filter(
            Q(te_id__icontains=request.GET.get('patient_id') or 'False') |
            Q(active_msisdn__msisdn__icontains=msisdn) |
            Q(name__contains=request.GET.get('name') or 'False') | 
            Q(surname__icontains=request.GET.get('surname') or 'False'))
        
        if patients.count() == 1:
            next = request.GET.get('next')
            if next:
                next = '%s?patient_id=%s' % (next, patients[0].pk)
            else:
                next = reverse('bookings:admin:edit_patient', 
                    kwargs={'patient_id': patients[0].pk})
            return HttpResponseRedirect(next)
        else:
            return render_to_response('bookings_admin/patient/results.html', {
                'patients': patients,
                'next': request.GET.get('next')
            }, context_instance=RequestContext(request))
    else:
        return render_to_response('bookings_admin/patient/find.html', {
            'next': request.GET.get('next')
        }, context_instance=RequestContext(request))
コード例 #6
0
ファイル: handlers.py プロジェクト: graemeglass/txtalert
 def create(self, request):
     msisdn = normalize_msisdn(request.POST.get('msisdn'))
     msisdn_record, _ = MSISDN.objects.get_or_create(msisdn=msisdn)
     pcm = CorePleaseCallMe(user=request.user, msisdn=msisdn_record,
             timestamp=datetime.now(), message='Please call me!',
             notes='Call request issued via txtAlert Bookings USSD')
     pcm.save()
     return pcm
コード例 #7
0
ファイル: handlers.py プロジェクト: sakho3600/txtalert
 def create(self, request):
     msisdn = normalize_msisdn(request.POST.get('msisdn'))
     msisdn_record, _ = MSISDN.objects.get_or_create(msisdn=msisdn)
     pcm = CorePleaseCallMe(
         user=request.user,
         msisdn=msisdn_record,
         timestamp=datetime.now(),
         message='Please call me!',
         notes='Call request issued via txtAlert Bookings USSD')
     pcm.save()
     return pcm
コード例 #8
0
def load_cd4_records(sender, **kwargs):
    created = kwargs.get('created', False)
    instance = kwargs.get('instance')
    
    if created:
        for row in read_cd4_document(instance.original.path):
            normalized_msisdn = normalize_msisdn(row[MSISDN][1])
            instance.record_set.create(
                # string
                lab_id_number = row[LAB_ID_NUMBER][1],
                # Excel will probably store this as a float
                # cast to int, saved as string in db
                msisdn = normalized_msisdn,
                cd4count = row[CD4_COUNT][1]
            )
コード例 #9
0
ファイル: handlers.py プロジェクト: sakho3600/txtalert
    def read(self, request):

        patient_id = request.GET.get('patient_id') or None
        msisdn = request.GET.get('msisdn') or None

        if patient_id and msisdn:
            try:
                normalized_msisdn = normalize_msisdn(msisdn)
                patient = Patient.objects.get(
                    active_msisdn__msisdn=normalized_msisdn, te_id=patient_id)
                try:
                    visit = patient.next_visit()
                    visit_info = [
                        visit.date.year, visit.date.month, visit.date.day
                    ]
                    clinic_name = visit.clinic.name
                except Visit.DoesNotExist:
                    visit = None
                    visit_info = []
                    clinic_name = ''

                visits = patient.visit_set.all()
                attended = visits.filter(status='a').count()
                rescheduled = visits.filter(status='r').count()
                missed = visits.filter(status='m').count()
                total = visits.filter(date__lt=date.today()).count()
                if total:
                    attendance = int(float(attended) / float(total) * 100)
                else:
                    attendance = 0.0

                return {
                    'msisdn': msisdn,
                    'patient_id': patient_id,
                    'name': patient.name,
                    'surname': patient.surname,
                    'next_appointment': visit_info,
                    'visit_id': visit.pk if visit else '',
                    'clinic': clinic_name,
                    'attendance': attendance,
                    'total': total,
                    'attended': attended,
                    'rescheduled': rescheduled,
                    'missed': missed,
                }
            except Patient.DoesNotExist:
                pass
        return {}
コード例 #10
0
ファイル: backends.py プロジェクト: graemeglass/txtalert
 def authenticate(self, username, password):
     try:
         # get the msisdn
         msisdn, patient_id = normalize_msisdn(username), password
         # try and find the patient
         patient = Patient.objects.get(active_msisdn__msisdn=msisdn, te_id=patient_id)
         try:
             return patient.authprofile.user
         except AuthProfile.DoesNotExist, e:
             user = User(username=msisdn)
             user.set_password(patient_id)
             user.save()
             AuthProfile.objects.create(user=user, patient=patient)
             return user
     except Patient.DoesNotExist, e:
         pass
コード例 #11
0
ファイル: handlers.py プロジェクト: graemeglass/txtalert
    def read(self, request):

        patient_id = request.GET.get('patient_id') or None
        msisdn = request.GET.get('msisdn') or None

        if patient_id and msisdn:
            try:
                normalized_msisdn = normalize_msisdn(msisdn)
                patient = Patient.objects.get(active_msisdn__msisdn=normalized_msisdn,
                                                te_id=patient_id)
                try:
                    visit = patient.next_visit()
                    visit_info = [visit.date.year, visit.date.month, visit.date.day]
                    clinic_name = visit.clinic.name
                except Visit.DoesNotExist:
                    visit = None
                    visit_info = []
                    clinic_name = ''

                visits = patient.visit_set.all()
                attended = visits.filter(status='a').count()
                rescheduled = visits.filter(status='r').count()
                missed = visits.filter(status='m').count()
                total = visits.filter(date__lt=date.today()).count()
                if total:
                    attendance = int(float(attended) / float(total) * 100)
                else:
                    attendance = 0.0

                return {
                    'msisdn': msisdn,
                    'patient_id': patient_id,
                    'name': patient.name,
                    'surname': patient.surname,
                    'next_appointment': visit_info,
                    'visit_id': visit.pk if visit else '',
                    'clinic': clinic_name,
                    'attendance': attendance,
                    'total': total,
                    'attended': attended,
                    'rescheduled': rescheduled,
                    'missed': missed,
                }
            except Patient.DoesNotExist:
                pass
        return {}
コード例 #12
0
ファイル: backends.py プロジェクト: sakho3600/txtalert
 def authenticate(self, username, password):
     try:
         # get the msisdn
         msisdn, patient_id = normalize_msisdn(username), password
         # try and find the patient
         patient = Patient.objects.get(active_msisdn__msisdn=msisdn,
                                       te_id=patient_id)
         try:
             return patient.authprofile.user
         except AuthProfile.DoesNotExist, e:
             user = User(username=msisdn)
             user.set_password(patient_id)
             user.save()
             AuthProfile.objects.create(user=user, patient=patient)
             return user
     except Patient.DoesNotExist, e:
         pass
コード例 #13
0
ファイル: models.py プロジェクト: sakho3600/txtalert
def load_cd4_records(sender, **kwargs):
    created = kwargs.get('created', False)
    instance = kwargs.get('instance')

    if created:
        for row in read_cd4_document(instance.original.path):
            if not row[MSISDN][1]:
                continue
            normalized_msisdn = normalize_msisdn(int(row[MSISDN][1]))
            instance.record_set.create(
                # string
                lab_id_number = row[LAB_ID_NUMBER][1],
                # Excel will probably store this as a float
                # cast to int, saved as string in db
                msisdn = normalized_msisdn,
                cd4count = row[CD4_COUNT][1]
            )
コード例 #14
0
def widget_landing(request):
    if 'patient_id' in request.GET \
        and 'msisdn' in request.GET:

        try:
            msisdn = normalize_msisdn(request.GET.get('msisdn'))
            patient_id = request.GET.get('patient_id')
            patient = Patient.objects.get(active_msisdn__msisdn=msisdn,
                                          te_id=patient_id)
            try:
                visit = patient.next_visit()
            except Visit.DoesNotExist:
                visit = None

            visits = patient.visit_set.all()

            context = {
                'msisdn': msisdn,
                'patient_id': patient_id,
                'patient': patient,
                'name': patient.name,
                'surname': patient.surname,
                'next_appointment': visit.date if visit else '',
                'visit_id': visit.pk if visit else '',
                'clinic': visit.clinic.name if visit else '',
                'attendance': int((1.0 - patient.risk_profile) * 100),
                'total': visits.count(),
                'attended': visits.filter(status='a').count(),
                'rescheduled': visits.filter(status='r').count(),
                'missed': visits.filter(status='m').count(),
            }
        except Patient.DoesNotExist:
            context = {
                'patient_id': patient_id,
                'msisdn': msisdn,
            }
    else:
        context = {
            'patient_id': request.GET.get('patient_id', ''),
            'msisdn': request.GET.get('msisdn', ''),
        }
    print context
    return render_to_response('widget_landing.html',
                              context,
                              context_instance=RequestContext(request))
コード例 #15
0
ファイル: views.py プロジェクト: graemeglass/txtalert
def widget_landing(request):
    if 'patient_id' in request.GET \
        and 'msisdn' in request.GET:
        
        try:
            msisdn = normalize_msisdn(request.GET.get('msisdn'))
            patient_id = request.GET.get('patient_id')
            patient = Patient.objects.get(active_msisdn__msisdn=msisdn,
                                            te_id=patient_id)
            try:
                visit = patient.next_visit()
            except Visit.DoesNotExist:
                visit = None
            
            visits = patient.visit_set.all()
            
            context = {
                'msisdn': msisdn,
                'patient_id': patient_id,
                'patient': patient,
                'name': patient.name,
                'surname': patient.surname,
                'next_appointment': visit.date if visit else '',
                'visit_id': visit.pk if visit else '',
                'clinic': visit.clinic.name if visit else '',
                'attendance': int((1.0 - patient.risk_profile) * 100),
                'total': visits.count(),
                'attended': visits.filter(status='a').count(),
                'rescheduled': visits.filter(status='r').count(),
                'missed': visits.filter(status='m').count(),
            }
        except Patient.DoesNotExist:
            context = {
                'patient_id': patient_id,
                'msisdn': msisdn,
            }
    else:
        context = {
            'patient_id': request.GET.get('patient_id', ''),
            'msisdn': request.GET.get('msisdn', ''),
        }
    print context
    return render_to_response('widget_landing.html', context, 
        context_instance=RequestContext(request))
コード例 #16
0
def request_call(request):
    if request.POST:
        form = RequestCallForm(request.POST)
        if form.is_valid():
            clinic = form.cleaned_data['clinic']
            # normalize
            msisdn = normalize_msisdn(form.cleaned_data['msisdn'])
            # orm object
            msisdn_record, _ = MSISDN.objects.get_or_create(msisdn=msisdn)
            pcm = PleaseCallMe(
                user=clinic.user,
                clinic=clinic,
                msisdn=msisdn_record,
                timestamp=datetime.now(),
                message='Please call me!',
                notes='Call request issued via txtAlert Bookings')
            pcm.save()
            messages.add_message(request, messages.INFO,
                        'Your call request has been registered. '\
                        'The clinic will call you back as soon as possible.')
            return HttpResponseRedirect(reverse('bookings:request_call'))
    else:
        form = RequestCallForm(initial={
            'msisdn':
            '' if request.user.is_anonymous() else request.user.username
        })

    if request.user.is_anonymous():
        profile = patient = None
    else:
        profile = request.user.get_profile()
        patient = profile.patient

    return render_to_response('request_call.html', {
        'profile': profile,
        'patient': patient,
        'form': form,
    },
                              context_instance=RequestContext(request))
コード例 #17
0
ファイル: views.py プロジェクト: ontiyonke/google_spreadsheet
def request_call(request):
    if request.POST:
        form = RequestCallForm(request.POST)
        if form.is_valid():
            clinic = form.cleaned_data["clinic"]
            # normalize
            msisdn = normalize_msisdn(form.cleaned_data["msisdn"])
            # orm object
            msisdn_record, _ = MSISDN.objects.get_or_create(msisdn=msisdn)
            pcm = PleaseCallMe(
                user=clinic.user,
                clinic=clinic,
                msisdn=msisdn_record,
                timestamp=datetime.now(),
                message="Called request via txtAlert Bookings",
            )
            pcm.save()
            messages.add_message(
                request,
                messages.INFO,
                "Your call request has been registered. " "The clinic will call you back as soon as possible.",
            )
            return HttpResponseRedirect(reverse("bookings:request_call"))
    else:
        form = RequestCallForm(initial={"msisdn": "" if request.user.is_anonymous() else request.user.username})

    if request.user.is_anonymous():
        profile = patient = None
    else:
        profile = request.user.get_profile()
        patient = profile.patient

    return render_to_response(
        "request_call.html",
        {"profile": profile, "patient": patient, "form": form},
        context_instance=RequestContext(request),
    )
コード例 #18
0
 def clean_msisdn(self):
     raw_msisdn = self.cleaned_data['msisdn']
     return normalize_msisdn(raw_msisdn)
コード例 #19
0
 def clean_active_msisdn(self):
     raw_msisdn = self.cleaned_data['active_msisdn']
     msisdn, created = MSISDN.objects.get_or_create(
         msisdn=normalize_msisdn(raw_msisdn))
     return msisdn