Last active
December 3, 2019 14:01
-
-
Save fredkingham/c23f76cfe853cbce215f36deeec3feef to your computer and use it in GitHub Desktop.
UDA and UOA 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
from django.core.management.base import BaseCommand | |
from odonto.episode_categories import FP17Episode, FP17OEpisode | |
# FP17O calculations | |
def get_date(episode): | |
ass_date = episode.orthodonticassessment_set.get().date_of_assessment | |
if ass_date: | |
return ass_date | |
return episode.category.get_sign_off_date() | |
def get_age(episode): | |
dt = get_date(episode) | |
if not dt: | |
return | |
dob = episode.patient.demographics().date_of_birth | |
sm = (dt.month, dt.day,) | |
dm = (dob.month, dob.day,) | |
return dt.year - dob.year - (sm < dm) | |
def get_accept_treatment(qs): | |
return qs.filter(orthodonticassessment__assess_and_appliance_fitted=True) | |
def get_accept_over_under_10(qs): | |
qs = get_accept_treatment(qs) | |
with_ages = [i for i in qs if get_age(i)] | |
return len([i for i in with_ages if get_age(i) < 10]) | |
def get_accept_over_10_to_17(qs): | |
qs = get_accept_treatment(qs) | |
with_ages = [i for i in qs if get_age(i)] | |
return len([i for i in with_ages if get_age(i) > 9 and get_age(i) < 18]) | |
def get_accept_over_18(qs): | |
qs = get_accept_treatment(qs) | |
with_ages = [i for i in qs if get_age(i)] | |
return len([i for i in with_ages if get_age(i) > 17]) | |
def get_assessment_and_review(qs): | |
return qs.filter(orthodonticassessment__assessment_and_review=True).count() | |
def get_assess_and_refuse_treatment(qs): | |
return qs.filter(orthodonticassessment__assess_and_refuse_treatment=True).count() | |
def get_repair(qs): | |
return qs.filter(orthodontictreatment__repair=True).count() | |
def get_uoa(): | |
total = 0 | |
submitted = FP17OEpisode.get_submitted_episodes() | |
fields = ( | |
("Assessment & Review", 1, get_assessment_and_review), | |
("Assess & Refuse Treatment", 1, get_assess_and_refuse_treatment), | |
("Assess & Accept for Treatment (patient < 10 years)", 4, get_accept_over_under_10), | |
("Assess & Accept for Treatment (patient 10 - 17 yrs)", 21, get_accept_over_10_to_17), | |
("Assess & Accept for Treatment (patient 18+)", 23, get_accept_over_18), | |
("Repair of dental appliance", 0.8, get_repair), | |
) | |
print("=" * 20) | |
print("UOA") | |
for name, uoa, method in fields: | |
count = method(submitted) | |
uoa_amount = count * uoa | |
print(f"{name} {uoa_amount} ({count})") | |
total += uoa_amount | |
print(total) | |
print("=" * 10) | |
return total | |
# FP17 Calculations | |
def get_band_1(qs): | |
return qs.filter(fp17treatmentcategory__treatment_category='Band 1').exclude( | |
fp17treatmentcategory__urgent_treatment=True | |
).count() | |
def get_band_1_urgent(qs): | |
return qs.filter(fp17treatmentcategory__treatment_category='Band 1').filter( | |
fp17treatmentcategory__urgent_treatment=True | |
).count() | |
def get_band_2(qs): | |
return qs.filter(fp17treatmentcategory__treatment_category='Band 2').count() | |
def get_band_3(qs): | |
return qs.filter(fp17treatmentcategory__treatment_category='Band 3').count() | |
def regulation_11(qs): | |
return qs.filter(fp17treatmentcategory__regulation_11_replacement_appliance=True).count() | |
def get_uda(): | |
total = 0 | |
submitted = FP17Episode.get_submitted_episodes() | |
fields = ( | |
("Band 1", 1, get_band_1), | |
("Band 1 URGENT", 1.2, get_band_1_urgent), | |
("Band 2", 3, get_band_2), | |
("Band 3", 12, get_band_3), | |
("Regulation 11", 12, regulation_11), | |
) | |
print("=" * 20) | |
print("UDA") | |
for name, uda, method in fields: | |
count = method(submitted) | |
uda_amount = count * uda | |
print(f"{name} {uda_amount} ({count})") | |
total += uda_amount | |
print(total) | |
print("=" * 10) | |
return total | |
class Command(BaseCommand): | |
def handle(self, *args, **kwargs): | |
get_uoa() | |
get_uda() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment