Created
June 17, 2021 10:27
-
-
Save fredkingham/7ae84c8d57aa5b9994e7ed57b1fe5e29 to your computer and use it in GitHub Desktop.
tb numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from plugins.labtests.models import LabTest | |
from opal.models import Patient | |
from elcid.utils import timing | |
from intrahospital_api.apis.prod_api import ProdApi as ProdAPI | |
from django.utils import timezone | |
from plugins.appointments.models import Appointment | |
from plugins.tb import episode_categories, constants | |
from plugins.tb.models import PatientConsultation | |
def tb_clinic_review(): | |
dates = [ | |
datetime.date(2021, 6, 8), | |
datetime.date(2021, 6, 1), | |
datetime.date(2021, 5, 25), | |
datetime.date(2021, 5, 18), | |
] | |
appointments_qs = Appointment.objects.filter( | |
start_datetime__date__in=dates | |
).exclude( | |
status_code__in=['Canceled', 'No Show'] | |
) | |
new_appointments = appointments_qs.filter( | |
derived_appointment_type="Thoracic TB New" | |
) | |
print(f"new appointments {len(new_appointments)}") | |
new_appointment_patient_ids = set(new_appointments.values_list( | |
"patient_id", flat=True | |
).distinct()) | |
new_appointment_clinical_advice = 0 | |
for appointment in new_appointments: | |
if PatientConsultation.objects.filter( | |
when__date=appointment.start_datetime.date(), | |
episode__patient_id=appointment.patient_id | |
).exists(): | |
new_appointment_clinical_advice += 1 | |
print(f"new appointments entered on elcid {new_appointment_clinical_advice}") | |
repeat_appointments = appointments_qs.filter( | |
derived_appointment_type="Thoracic TB F/Up" | |
).filter( | |
patient_id__in=new_appointment_patient_ids | |
) | |
print(f"repeat appointments count {len(repeat_appointments)}") | |
repeat_appointment_advice = 0 | |
for repeat_appointment in repeat_appointments: | |
if PatientConsultation.objects.filter( | |
when__date=repeat_appointment.start_datetime.date(), | |
episode__patient_id=repeat_appointment.patient_id | |
).exists(): | |
repeat_appointment_advice += 1 | |
print(f"repeat appointments entered on elcid {repeat_appointment_advice}") | |
new_appointment_clinical_advice = PatientConsultation.objects.filter( | |
episode__patient_id__in=new_appointment_patient_ids | |
) | |
telephone_appointments = appointments_qs.filter( | |
derived_appointment_type__in=[ | |
"Thoracic TB Telephone F/Up", | |
] | |
) | |
print(f"telephone appointments {telephone_appointments.count()}") | |
telephone_clinical_advice = 0 | |
for telephone_appointment in telephone_appointments: | |
if PatientConsultation.objects.filter( | |
when__date=telephone_appointment.start_datetime.date(), | |
episode__patient_id=telephone_appointment.patient_id | |
).exists(): | |
telephone_clinical_advice += 1 | |
print(f"telephone clinical advice {telephone_clinical_advice}") | |
total_tb_doctors_appointments = appointments_qs.filter( | |
derived_appointment_type__in=[ | |
"Thoracic TB F/Up", | |
"Thoracic TB New", | |
"Thoracic TB Telephone F/Up" | |
] | |
) | |
print(f"total tb doctors appointments {total_tb_doctors_appointments.count()}") | |
patient_consultations = PatientConsultation.objects.filter( | |
when__date__in=dates | |
) | |
patient_consultations = [i for i in patient_consultations if "nurse" not in i.reason_for_interaction.lower()] | |
print(f"total tb clinical advice {len(patient_consultations)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment