Exemplo n.º 1
0
    def get(self, request, patient_id, spec):
        specialization = Specialization.objects.get(slug=spec)
        patient = Patient.objects.get(id=patient_id)
        medicals = Medical.objects.filter(
            specialization=specialization).order_by('surname')
        # li = Medical.objects.filter(email__contains='onet')
        # cs = Medical.objects.filter(consulting_room__gte=7)
        # cg = Medical.objects.filter(consulting_room__gte=2,consulting_room__lte=10)
        for medical in medicals:
            user = User.objects.get(username=medical.nickname)
            if user.is_active == False:
                medicals = medicals.exclude(pk=medical.id)
        visits = visits_list(patient=patient, date_of_visit__gte=date.today())

        if not medicals.exists():
            msg = r'No doctors in selected specialization ({})'
            messages.error(request, msg.format(spec))
            kwargs = {'patient_id': patient_id}
            return HttpResponseRedirect(
                reverse('registrations:register_patient_detail',
                        kwargs=kwargs))
        else:
            context = {
                'spec': spec,
                'visits': visits,
                'patient': patient,
                'medicals': medicals,
                'patient_id': patient_id
            }
            return render(request, 'medical_visit/medical_staff_list.html',
                          context)
Exemplo n.º 2
0
    def get(self, request, patient_id, spec, medical_id, date_of_visit):
        # hours of visit
        hours, minutes = (8, 12), (0, 41, 20)
        # permanent hours of medical visits list = phomv_list
        phomv_list = [
            str(time(x, y)) for x in range(*hours) for y in range(*minutes)
        ]
        patient = Patient.objects.get(id=patient_id)
        doctor = Medical.objects.get(id=medical_id)
        doc_visit_list = visits_list(doctor=doctor,
                                     date_of_visit=date_of_visit)
        visit_hour_list = visits_list(patient_id=patient_id,
                                      date_of_visit=date_of_visit)
        visits = MedicalVisit.objects.filter(patient=patient,
                                             date_of_visit=date_of_visit)
        valid_hour_list = {}

        if visits:
            for visit in visits:
                if visit.doctor.id != int(medical_id) and str(
                        visit.doctor.specialization) == spec:
                    visit_hour_list.remove(visit.hour_of_visit)
                    valid_hour_list = set(visit_hour_list + doc_visit_list)
                    valid_hour_list = sorted(list(valid_hour_list))

                else:
                    valid_hour_list = set(visit_hour_list + doc_visit_list)
                    valid_hour_list = sorted(list(valid_hour_list))
        else:
            valid_hour_list = doc_visit_list

        visits = visits_list(patient=patient, date_of_visit__gte=date.today())
        date_of_visit = datetime.strptime(date_of_visit, '%Y-%m-%d')
        date_of_visit = date_of_visit.date()
        context = {
            'spec': spec,
            'doctor': doctor,
            'visits': visits,
            'patient': patient,
            'medical_id': medical_id,
            'patient_id': patient_id,
            'date_of_visit': date_of_visit,
            'phomv_list': phomv_list,
            'valid_hour_list': valid_hour_list,
        }
        return render(request, 'medical_visit/visit_hour_register.html',
                      context)
Exemplo n.º 3
0
    def get(self, request, patient_id):
        patient = Patient.objects.get(id=patient_id)
        visits = visits_list(patient=patient, date_of_visit__gte=date.today())
        form = SpecializationForm()
        context = {
            'form': form,
            'visits': visits,
            'patient': patient,
            'patient_id': patient_id
        }

        return render(request, 'registration/patient_detail.html', context)
Exemplo n.º 4
0
 def get(self, request, patient_id, spec, medical_id):
     form = DateVisitRegisterForm()
     patient = Patient.objects.get(id=patient_id)
     medical = Medical.objects.get(id=medical_id)
     visits = visits_list(patient=patient, date_of_visit__gte=date.today())
     context = {
         'spec': spec,
         'form': form,
         'visits': visits,
         'patient': patient,
         'medical': medical,
         'patient_id': patient_id,
     }
     return render(request, 'medical_visit/visit_date_register.html',
                   context)
Exemplo n.º 5
0
    def post(self, request, patient_id, spec, medical_id, date_of_visit):
        date_of_visit = datetime.strptime(date_of_visit, '%Y-%m-%d')
        date_of_visit = date_of_visit.date()
        kwargs = {
            'spec': spec,
            'patient_id': patient_id,
            'medical_id': medical_id,
            'date_of_visit': date_of_visit
        }

        if len(request.POST) > 1:
            hour_of_visit = request.POST['hour_of_visit']
            patient = Patient.objects.get(id=patient_id)
            doctor = Medical.objects.get(id=medical_id)
            visits = MedicalVisit.objects.filter(patient=patient,
                                                 date_of_visit=date_of_visit)
            doc_id = None
            data = {
                'doctor': doctor,
                'patient': patient,
                'date_of_visit': date_of_visit,
                'hour_of_visit': hour_of_visit
            }

            if not visits.exists():
                MedicalVisit.objects.create(**data)
                msg = r'Successful create new medical visit for {} {}'
                messages.success(
                    request, msg.format(patient.first_name, patient.last_name))
            else:
                for visit in visits:
                    if str(visit.doctor.specialization) == spec:
                        doc_id = visit.doctor.id

                if doc_id:
                    values = {'doctor': doctor, 'hour_of_visit': hour_of_visit}
                    MedicalVisit.objects.filter(
                        doctor_id=doc_id,
                        patient=patient,
                        date_of_visit=date_of_visit).update(**values)
                    msg = r'Successful update medical visit for {} {}'
                    messages.success(
                        request,
                        msg.format(patient.first_name, patient.last_name))
                else:
                    MedicalVisit.objects.create(**data)
                    msg = r'Successful create new medical visit for {} {}'
                    messages.success(
                        request,
                        msg.format(patient.first_name, patient.last_name))

            visits = visits_list(patient=patient,
                                 date_of_visit__gte=date.today())
            context = {
                'spec': spec,
                'visits': visits,
                'doctor': doctor,
                'patient': patient,
                'patient_id': patient_id,
                'date_of_visit': date_of_visit,
                'hour_of_visit': hour_of_visit,
            }
            return render(request, 'medical_visit/visit_hour_register.html',
                          context)

        else:
            msg = r'Please select a visit hour...'
            messages.error(request, msg)
            return HttpResponseRedirect(
                reverse('medical_visit:visit_hour_register', kwargs=kwargs))