• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gcivil-nyu-org / INT2-Monday-Spring2024-Team-1 / 1130

29 Apr 2024 09:15PM UTC coverage: 29.816% (-60.7%) from 90.503%
1130

cron

travis-pro

web-flow
Merge pull request #267 from gcivil-nyu-org/develop

Release 10: 04/29/2024

503 of 1687 relevant lines covered (29.82%)

0.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

10.71
/healthScore/user_utils.py
1
from django.utils import timezone
1✔
2
from datetime import datetime, timedelta
1✔
3
from django.forms.models import model_to_dict
1✔
4
import json
1✔
5
from django.contrib.auth.decorators import login_required
1✔
6

7
from .models import (
1✔
8
    User,
9
    HealthRecord,
10
    Hospital,
11
    HospitalStaff,
12
    Appointment,
13
)
14

15

16
@login_required(login_url="/")
1✔
17
def get_health_history_details(request):
1✔
18
    if request.method == "GET":
×
19
        userID = request.user
×
20
        history_list = HealthRecord.objects.filter(userID=userID)
×
21

22
        appointment_name = request.GET.get("appointment_name")
×
23
        if appointment_name:
×
24
            history_list = history_list.filter(
×
25
                appointmentId__name__icontains=appointment_name
26
            )
27

28
        healthcare_worker = request.GET.get("healthcare_worker")
×
29
        if healthcare_worker:
×
30
            doctor_ids = HospitalStaff.objects.filter(
×
31
                name__icontains=healthcare_worker
32
            ).values_list("id", flat=True)
33
            history_list = history_list.filter(doctorID__in=doctor_ids)
×
34

35
        filter_date = request.GET.get("date")
×
36
        if filter_date:
×
37
            filter_date = datetime.strptime(filter_date, "%Y-%m-%d").date()
×
38
            current_tz = timezone.get_current_timezone()
×
39
            start_of_day = timezone.make_aware(
×
40
                datetime.combine(filter_date, datetime.min.time()), current_tz
41
            )
42
            end_of_day = start_of_day + timedelta(days=1)
×
43
            history_list = history_list.filter(
×
44
                createdAt__range=(start_of_day, end_of_day)
45
            )
46

47
        healthcare_facility = request.GET.get("healthcare_facility")
×
48
        if healthcare_facility:
×
49
            hospital_ids = Hospital.objects.filter(
×
50
                name__icontains=healthcare_facility
51
            ).values_list("id", flat=True)
52
            history_list = history_list.filter(hospitalID__in=hospital_ids)
×
53

54
        # Filter records by status
55
        record_status = request.GET.get("record_status")
×
56
        if record_status:
×
57
            history_list = history_list.filter(status=record_status)
×
58

59
        detailed_history_list = []
×
60
        each_details = []
×
61
        for h in history_list:
×
62
            h_details = model_to_dict(h)
×
63
            each_details.append(h_details)
×
64
            # Fetch related appointment details
65
            appointment_details = Appointment.objects.get(id=h.appointmentId_id)
×
66
            appointment_name = appointment_details.name
×
67
            appointment_properties = json.loads(h.appointmentId.properties)
×
68
            appointment_type = (
×
69
                appointment_details.name
70
                if appointment_details.name is not None
71
                else "Unknown"
72
            )
73

74
            # Fetch healthcare worker details by Dr. ID
75
            doctor_details = HospitalStaff.objects.get(id=h.doctorID)
×
76
            doctor_name = doctor_details.name
×
77

78
            # Fetch hospital details by hospitalID
79
            hospital_details = Hospital.objects.get(id=h.hospitalID)
×
80
            hospital_name = hospital_details.name
×
81
            hospital_address = hospital_details.address
×
82

83
            # Append a dictionary for each record with all the details needed
84
            detailed_history_list.append(
×
85
                {
86
                    "record_id": h.id,
87
                    "doctor_name": doctor_name,
88
                    "hospital_name": hospital_name,
89
                    "hospital_address": hospital_address,
90
                    "createdAt": datetime.date(h.createdAt),
91
                    "updatedAt": datetime.date(h.updatedAt),
92
                    "appointment_name": appointment_name,
93
                    "appointment_type": appointment_type,
94
                    "rejectedReason": h.rejectedReason,
95
                    "record_status": h_details["status"],
96
                    "appointment_properties": json.dumps(appointment_properties),
97
                    "medicalFile": h.healthDocuments,
98
                }
99
            )
100

101
        zipped_details = zip(detailed_history_list, each_details)
×
102
        return zipped_details
×
103

104

105
def get_health_history_details_doctor(request):
1✔
106
    if request.method == "GET":
×
107
        userID = request.user
×
108
        history_list = HealthRecord.objects.filter(doctorID=userID.id)
×
109

110
        record_status = request.GET.get("record_status")
×
111
        if record_status:
×
112
            history_list = history_list.filter(status=record_status)
×
113

114
        appointment_name = request.GET.get("appointment_name")
×
115
        if appointment_name:
×
116
            history_list = history_list.filter(
×
117
                appointmentId__name__icontains=appointment_name
118
            )
119

120
        healthcare_worker = request.GET.get("healthcare_worker")
×
121
        if healthcare_worker:
×
122
            doctor_ids = HospitalStaff.objects.filter(
×
123
                name__icontains=healthcare_worker
124
            ).values_list("id", flat=True)
125
            history_list = history_list.filter(doctorID__in=doctor_ids)
×
126

127
        healthcare_facility = request.GET.get("healthcare_facility")
×
128
        if healthcare_facility:
×
129
            hospital_ids = Hospital.objects.filter(
×
130
                name__icontains=healthcare_facility
131
            ).values_list("id", flat=True)
132
            history_list = history_list.filter(hospitalID__in=hospital_ids)
×
133

134
        detailed_history_list = []
×
135
        each_details = []
×
136
        for h in history_list:
×
137
            h_details = model_to_dict(h)
×
138
            each_details.append(h_details)
×
139
            # Fetch related appointment details
140
            appointment_details = Appointment.objects.get(id=h.appointmentId_id)
×
141
            appointment_name = appointment_details.name
×
142
            appointment_properties = json.loads(h.appointmentId.properties)
×
143
            appointment_type = (
×
144
                appointment_details.name
145
                if appointment_details.name is not None
146
                else "Unknown"
147
            )
148

149
            # Fetch healthcare worker details by Dr. ID
150
            doctor_details = HospitalStaff.objects.get(id=h.doctorID)
×
151
            doctor_name = doctor_details.name
×
152

153
            # Fetch hospital details by hospitalID
154
            hospital_details = Hospital.objects.get(id=h.hospitalID)
×
155
            hospital_name = hospital_details.name
×
156
            hospital_address = hospital_details.address
×
157

158
            user_email = User.objects.get(id=h.userID_id).email
×
159

160
            # Append a dictionary for each record with all the details needed
161
            detailed_history_list.append(
×
162
                {
163
                    "record_id": h.id,
164
                    "user_id": user_email,
165
                    "doctor_name": doctor_name,
166
                    "hospital_name": hospital_name,
167
                    "hospital_address": hospital_address,
168
                    "createdAt": datetime.date(h.createdAt),
169
                    "updatedAt": datetime.date(h.updatedAt),
170
                    "appointment_name": appointment_name,
171
                    "appointment_type": appointment_type,
172
                    "rejectedReason": h.rejectedReason,
173
                    "record_status": h_details["status"],
174
                    "appointment_properties": json.dumps(appointment_properties),
175
                    "medicalFile": h.healthDocuments,
176
                }
177
            )
178

179
        return detailed_history_list
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc