1+ """
2+ RCPCHGrowth Command Line Tool
3+ """
4+
5+
6+ # standard imports
7+ from datetime import date
8+
9+ # third party imports
110import click
2- from datetime import datetime , date
11+ import pyfiglet
312from scipy import stats
13+
14+ # RCPCH imports
415from rcpchgrowth import date_calculations
516from rcpchgrowth .global_functions import centile , measurement_from_sds , sds_for_measurement as sfm , mid_parental_height
6- import pyfiglet
17+
718
819@click .group ()
920def methods ():
@@ -13,15 +24,16 @@ def methods():
1324 """
1425 pass
1526
27+
1628@click .command ()
1729@click .argument ('birth_date' , type = click .DateTime (formats = ['%Y-%m-%d' ]),
18- default = str (date .today ()))
30+ default = str (date .today ()))
1931@click .argument ('observation_date' , type = click .DateTime (formats = ['%Y-%m-%d' ]),
20- default = str (date .today ()))
32+ default = str (date .today ()))
2133@click .argument ('gestation_weeks' , type = click .INT , default = 40 , required = False )
2234@click .argument ('gestation_days' , type = click .INT , default = 0 , required = False )
2335@click .option ('--adjustment' , '-a' , is_flag = True , default = False , help = "Include if adjusting for gestational age." )
24- def age_calculation (birth_date , observation_date , gestation_weeks , gestation_days , adjustment ):
36+ def age_calculation (birth_date , observation_date , gestation_weeks , gestation_days , adjustment ):
2537 """
2638 Calculates decimal age, either chronological or corrected for gestation if the adjustment flag is true.\n
2739 Essential parameters are birth_date [format YY-M-DD],
@@ -31,27 +43,32 @@ def age_calculation (birth_date, observation_date, gestation_weeks, gestation_da
3143 If correction is required, supply the gestation and the --adjustment flag
3244 """
3345 click .echo ("Calculates decimal age, either chronological or corrected for gestation if the adjustment flag is true. Params: birth_date, observation_date, gestation_weeks, gestation_days" )
34- decimal_age = 0
35- calendar_age = ""
46+ decimal_age = 0
47+ calendar_age = ""
3648 if adjustment :
37- decimal_age = date_calculations .corrected_decimal_age (
49+ decimal_age = date_calculations .corrected_decimal_age (
3850 birth_date = birth_date ,
3951 observation_date = observation_date ,
4052 gestation_weeks = gestation_weeks ,
4153 gestation_days = gestation_days )
42- calendar_age = date_calculations .chronological_calendar_age (
54+ corrected_birth_date = date_calculations .estimated_date_delivery (
4355 birth_date = birth_date ,
56+ gestation_weeks = gestation_weeks ,
57+ gestation_days = gestation_days )
58+ calendar_age = date_calculations .chronological_calendar_age (
59+ birth_date = corrected_birth_date ,
4460 observation_date = observation_date )
4561 click .echo (f"Adjusted: { decimal_age } y,\n { calendar_age } " )
4662 else :
47- decimal_age = date_calculations .chronological_decimal_age (
63+ decimal_age = date_calculations .chronological_decimal_age (
4864 birth_date = birth_date ,
4965 observation_date = observation_date )
50- calendar_age = date_calculations .chronological_calendar_age (
66+ calendar_age = date_calculations .chronological_calendar_age (
5167 birth_date = birth_date ,
5268 observation_date = observation_date )
5369 click .echo (f"Unadjusted: { decimal_age } y,\n { calendar_age } " )
5470
71+
5572@click .command ()
5673@click .argument ('decimal_age' , type = click .FLOAT )
5774@click .argument ('measurement_method' , default = "height" , type = click .Choice (['height' , 'weight' , 'bmi' , 'ofc' ]))
@@ -69,7 +86,7 @@ def sds_for_measurement(decimal_age, measurement_method, observation_value, sex,
6986 The reference is optional - default is UK-WHO\n
7087 To change the reference pass --reference with one of "uk-who", "trisomy-21", "turners-syndrome"
7188 """
72-
89+
7390 result = sfm (
7491 reference = reference ,
7592 age = decimal_age ,
@@ -82,6 +99,7 @@ def sds_for_measurement(decimal_age, measurement_method, observation_value, sex,
8299 click .echo (f"Reference: { reference_to_string (reference )} " )
83100 click .echo (f"SDS: { result } \n Centile: { round (cent ,1 )} %\n " )
84101
102+
85103@click .command ()
86104@click .argument ('decimal_age' , type = click .FLOAT )
87105@click .argument ('measurement_method' , default = "height" , type = click .Choice (['height' , 'weight' , 'bmi' , 'ofc' ]))
@@ -97,7 +115,7 @@ def measurement_for_centile(decimal_age, sex, measurement_method, centile, refer
97115 centile as a float value,
98116 To change the reference pass --reference with one of "uk-who", "trisomy-21", "turners-syndrome"
99117 """
100-
118+
101119 # convert centile to SDS
102120 sds = stats .norm .ppf (centile / 100 )
103121
@@ -109,14 +127,16 @@ def measurement_for_centile(decimal_age, sex, measurement_method, centile, refer
109127 sex = sex ,
110128 age = decimal_age
111129 )
112-
113- suffix = "cm"
114- if measurement_method == "weight" :
115- suffix = "kg"
116- elif measurement_method == "bmi" :
117- suffix = "kg/m2"
130+
131+ suffix = "cm"
132+ if measurement_method == "weight" :
133+ suffix = "kg"
134+ elif measurement_method == "bmi" :
135+ suffix = "kg/m2"
118136 click .echo (f"Reference: { reference_to_string (reference )} " )
119- click .echo (f"SDS { round (sds , 3 )} \n Centile: { centile } %\n { measurement_method } : { result } { suffix } " )
137+ click .echo (
138+ f"SDS { round (sds , 3 )} \n Centile: { centile } %\n { measurement_method } : { result } { suffix } " )
139+
120140
121141@click .command ()
122142@click .argument ('decimal_age' , type = click .FLOAT )
@@ -134,20 +154,22 @@ def measurement_for_sds(reference, decimal_age, sex, measurement_method, sds):
134154 To change the reference pass --reference with one of "uk-who", "trisomy-21", "turners-syndrome"
135155 """
136156 result = measurement_from_sds (
137- reference = reference ,
157+ reference = reference ,
138158 requested_sds = sds ,
139159 measurement_method = measurement_method ,
140160 sex = sex ,
141161 age = decimal_age
142162 )
143163 cent = centile (sds )
144- suffix = "cm"
145- if measurement_method == "weight" :
146- suffix = "kg"
147- elif measurement_method == "bmi" :
148- suffix = "kg/m2"
164+ suffix = "cm"
165+ if measurement_method == "weight" :
166+ suffix = "kg"
167+ elif measurement_method == "bmi" :
168+ suffix = "kg/m2"
149169 click .echo (f"Reference: { reference_to_string (reference )} " )
150- click .echo (f"SDS { sds } \n Centile: { round (cent ,3 )} %\n { measurement_method } : { result } { suffix } " )
170+ click .echo (
171+ f"SDS { sds } \n Centile: { round (cent ,3 )} %\n { measurement_method } : { result } { suffix } " )
172+
151173
152174@click .command ()
153175@click .argument ("maternal_height" , type = click .FLOAT )
0 commit comments