Skip to content

Commit

Permalink
Merge pull request #188 from rcpch/openapi
Browse files Browse the repository at this point in the history
Openapi
  • Loading branch information
pacharanero authored Jan 4, 2023
2 parents 44a454b + 435a12f commit c800ce6
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 4.2.17
current_version = 4.2.18
tag = True
commit = True

Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from routers import trisomy_21, turners, uk_who, utilities


version='4.2.17' # this is set by bump version
version='4.2.18' # this is set by bump version

# Declare the FastAPI app
app = FastAPI(
Expand Down
34 changes: 6 additions & 28 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"title": "RCPCH Digital Growth API",
"description": "Returns SDS and centiles for child growth measurements using growth references. Currently provides calculations based on the UK-WHO, Turner's Syndrome and Trisomy-21 references.",
"version": "4.2.17"
"version": "4.2.18"
},
"paths": {
"/uk-who/calculation": {
Expand Down Expand Up @@ -72,7 +72,7 @@
"uk-who"
],
"summary": "Uk Who Chart Coordinates",
"description": "## UK-WHO Chart Coordinates data.\n\n* Returns coordinates for constructing the lines of a traditional growth chart, in JSON format\n* Requires a sex ('male' or 'female' lowercase) and a measurement_method ('height', 'weight' ,'bmi', 'ofc')\n* If custom centiles/sds collections (individually or as a collection) are required, accepts a list of float values (up to 15) as centile_format parameter\n* The is_sds boolean flag (default false) specifies if the custom list is of SDS or centiles.\n* In addition to the custom list, \"cole-nine-centiles\" or \"three-percent-centiles\" can be specified which are standard collections.\n* If no centile_format is supplied, \"cole-nine-centiles\" are returned as a default.\n",
"description": "## UK-WHO Chart Coordinates data.\n\n* Returns coordinates for constructing the lines of a traditional growth chart, in JSON format\n* Requires a sex ('male' or 'female' lowercase) and a measurement_method ('height', 'weight' ,'bmi', 'ofc')\n* If custom centiles/sds collections (individually or as a collection) are required, accepts a list of float values (up to 15) as centile_format parameter\n* The is_sds boolean flag (default false) specifies if the custom list is of SDS or centiles.\n* In addition to the custom list, \"cole-nine-centiles\" or \"three-percent-centiles\" can be specified which are standard collections.\n* If no centile_format is supplied, \"cole-nine-centiles\" are returned as a default.",
"operationId": "uk_who_chart_coordinates_uk_who_chart_coordinates_post",
"requestBody": {
"content": {
Expand Down Expand Up @@ -211,7 +211,7 @@
"turners-syndrome"
],
"summary": "Turner Chart Coordinates",
"description": "## Turner's Syndrome Chart Coordinates data.\n\n* Returns coordinates for constructing the lines of a traditional growth chart, in JSON format\n* Note height in girls conly be only returned. It is a post request to maintain consistency with other routes.\n* If custom centiles/sds collections (individually or as a collection) are required, accepts a list of float values (up to 15) as centile_format parameter\n* The is_sds boolean flag (default false) specifies if the custom list is of SDS or centiles.\n* In addition to the custom list, \"cole-nine-centiles\" or \"three-percent-centiles\" can be specified which are standard collections.\n* If no centile_format is supplied, \"cole-nine-centiles\" are returned as a default.\n",
"description": "## Turner's Syndrome Chart Coordinates data.\n\n* Returns coordinates for constructing the lines of a traditional growth chart, in JSON format\n* Note height in girls conly be only returned. It is a post request to maintain consistency with other routes.\n* If custom centiles/sds collections (individually or as a collection) are required, accepts a list of float values (up to 15) as centile_format parameter\n* The is_sds boolean flag (default false) specifies if the custom list is of SDS or centiles.\n* In addition to the custom list, \"cole-nine-centiles\" or \"three-percent-centiles\" can be specified which are standard collections.\n* If no centile_format is supplied, \"cole-nine-centiles\" are returned as a default.",
"operationId": "turner_chart_coordinates_turner_chart_coordinates_post",
"requestBody": {
"content": {
Expand Down Expand Up @@ -350,7 +350,7 @@
"trisomy-21"
],
"summary": "Trisomy 21 Chart Coordinates",
"description": "## Trisomy-21 Chart Coordinates Data.\n \n* Returns coordinates for constructing the lines of a traditional growth chart, in JSON format\n* Requires a sex ('male' or 'female' lowercase) and a measurement_method ('height', 'weight' ,'bmi', 'ofc')\n* If custom centiles/sds collections (individually or as a collection) are required, accepts a list of float values (up to 15) as centile_format parameter\n* The is_sds boolean flag (default false) specifies if the custom list is of SDS or centiles.\n* In addition to the custom list, \"cole-nine-centiles\" or \"three-percent-centiles\" can be specified which are standard collections.\n* If no centile_format is supplied, \"cole-nine-centiles\" are returned as a default.\n",
"description": "## Trisomy-21 Chart Coordinates Data.\n \n* Returns coordinates for constructing the lines of a traditional growth chart, in JSON format\n* Requires a sex ('male' or 'female' lowercase) and a measurement_method ('height', 'weight' ,'bmi', 'ofc')\n* If custom centiles/sds collections (individually or as a collection) are required, accepts a list of float values (up to 15) as centile_format parameter\n* The is_sds boolean flag (default false) specifies if the custom list is of SDS or centiles.\n* In addition to the custom list, \"cole-nine-centiles\" or \"three-percent-centiles\" can be specified which are standard collections.\n* If no centile_format is supplied, \"cole-nine-centiles\" are returned as a default.",
"operationId": "trisomy_21_chart_coordinates_trisomy_21_chart_coordinates_post",
"requestBody": {
"content": {
Expand Down Expand Up @@ -1393,13 +1393,13 @@
"properties": {
"height_paternal": {
"title": "Height Paternal",
"exclusiveMinimum": 0.0,
"minimum": 50.0,
"type": "number",
"description": "The height of the child's biological father, passed as float, measured in centimeters"
},
"height_maternal": {
"title": "Height Maternal",
"exclusiveMinimum": 0.0,
"minimum": 50.0,
"type": "number",
"description": "The height of the child's biological mother, passed as float, measured in centimeters"
},
Expand Down Expand Up @@ -1490,28 +1490,6 @@
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/Sex"
},
"uk90_preterm": {
"male": {
"height": [
{
"sds": -2.67,
"centile": 0.4,
"data": [
{
"l": "0.4",
"x": -0.2875,
"y": 27.7419
},
{
"l": "0.4",
"x": -0.2683,
"y": 28.7883
}
]
}
]
}
}
},
"SDSData": {
Expand Down
2 changes: 1 addition & 1 deletion requirements/common-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


# third party dependencies
fastapi
fastapi[all]
uvicorn[standard]
pydantic

Expand Down
75 changes: 51 additions & 24 deletions schemas/request_validation_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from rcpchgrowth.constants.reference_constants import COLE_TWO_THIRDS_SDS_NINE_CENTILES, THREE_PERCENT_CENTILES, CENTILE_FORMATS



class MeasurementRequest(BaseModel):
"""
This class definition creates a Python model which can be converted by FastAPI to openAPI3 schema.
Expand All @@ -33,12 +32,18 @@ class MeasurementRequest(BaseModel):
..., description="The value of the measurement supplied. This is supplied as a floating point number. All measurements should be supplied as **centimetres**, with the exception of Body Mass Index which is supplied as kilograms per metre squared (kg/m²).")
sex: Literal['male', 'female'] = Field(
..., description="The sex of the patient, as a string value which can either be `male` or `female`. Abbreviations or alternatives are not accepted.")
bone_age: Optional[float] = Field(None, description="Bone age in years. Age is paired with measurement taken at chronological age.")
bone_age_type: Optional[Literal['greulich-pyle', 'tanner-whitehouse-ii', 'tanner-whitehouse-iii', 'fels','bonexpert']] = Field(None, description="Method used to calculate bone age. Must be one of `'greulich-pyle`, `tanner-whitehouse-ii`, `tanner-whitehouse-iii`, `fels`,`bonexpert`")
bone_age_sds: Optional[float] = Field(None, description="The SDS of the bone age based on reference tables.")
bone_age_centile: Optional[float] = Field(None, description="The centile for the bone age based on reference tables.")
bone_age_text: Optional[str] = Field(None, description="Any report or contextual information relating to the bone age.")
events_text: Optional[list] = Field(None, description="A list of strings. Contextual text which are associated with each measurement.")
bone_age: Optional[float] = Field(
None, description="Bone age in years. Age is paired with measurement taken at chronological age.")
bone_age_type: Optional[Literal['greulich-pyle', 'tanner-whitehouse-ii', 'tanner-whitehouse-iii', 'fels', 'bonexpert']] = Field(
None, description="Method used to calculate bone age. Must be one of `'greulich-pyle`, `tanner-whitehouse-ii`, `tanner-whitehouse-iii`, `fels`,`bonexpert`")
bone_age_sds: Optional[float] = Field(
None, description="The SDS of the bone age based on reference tables.")
bone_age_centile: Optional[float] = Field(
None, description="The centile for the bone age based on reference tables.")
bone_age_text: Optional[str] = Field(
None, description="Any report or contextual information relating to the bone age.")
events_text: Optional[list] = Field(
None, description="A list of strings. Contextual text which are associated with each measurement.")

@validator("birth_date", pre=True)
def parse_date(cls, value):
Expand All @@ -50,6 +55,8 @@ def parse_date(cls, value):

cole_centiles = COLE_TWO_THIRDS_SDS_NINE_CENTILES
three_percent_centiles = THREE_PERCENT_CENTILES


class ChartCoordinateRequest(BaseModel):
sex: Literal['male', 'female'] = Field(
..., description="The sex of the patient, as a string value which can either be `male` or `female`. Abbreviations or alternatives are not accepted.")
Expand All @@ -59,44 +66,64 @@ class ChartCoordinateRequest(BaseModel):
False,
description="Boolean flag (default False) referring to centile_format. If custom lines requested as SDS, rather than as centiles, set this to True."
)
centile_format: Optional[Union[Literal["cole-nine-centiles", "three-percent-centiles"], List[float]]]=Field('cole-nine-centiles', description="Optional selection of centile format using 9 centile standard ['nine-centiles'], or older three-percent centile format ['three-percent-centiles'], or accepts a list of floats as a custom centile format e.g. [7/10/20/30/40/50/60/70/80/90/93]. Defaults to cole-nine-centiles")
centile_format: Optional[Union[Literal["cole-nine-centiles", "three-percent-centiles"], List[float]]] = Field(
'cole-nine-centiles', description="Optional selection of centile format using 9 centile standard ['nine-centiles'], or older three-percent centile format ['three-percent-centiles'], or accepts a list of floats as a custom centile format e.g. [7/10/20/30/40/50/60/70/80/90/93]. Defaults to cole-nine-centiles")

@validator('centile_format', 'is_sds')
def custom_centiles_must_not_exceed_fifteen(cls, v, values):
if (type(v) is list and len(v) > 15):
raise ValueError("Centile/SDS formats cannot exceed 15 items.")
if (type(v) is list and len(v) < 1):
raise ValueError("Empty list. Please provide at least one value or one of the standard collection flags.")
if(type(v) is list and values['is_sds'] is False):
raise ValueError(
"Empty list. Please provide at least one value or one of the standard collection flags.")
if (type(v) is list and values['is_sds'] is False):
for cent in v:
if cent < 0:
raise ValueError("Centile values cannot be negative.")
return v


class FictionalChildRequest(BaseModel):
measurement_method: Literal['height', 'weight', 'ofc', 'bmi'] = Field(
..., description="The type of measurement performed on the infant or child as a string which can be `height`, `weight`, `bmi` or `ofc`. The value of this measurement is supplied as the `observation_value` parameter. The measurements represent height **in centimetres**, weight *in kilograms**, body mass index **in kilograms/metre²** and occipitofrontal circumference (head circumference, OFC) **in centimetres**.")
sex: Literal['male', 'female'] = Field(
..., description="The sex of the patient, as a string value which can either be `male` or `female`. Abbreviations or alternatives are not accepted.")
start_chronological_age: Optional[float] = Field(0.0, description="Decimal age as a float. The age from which fictional data is to be generated.")
end_age: Optional[float] = Field(20.0, description="Decimal age as float. Age until which fictional data is returned.")
start_chronological_age: Optional[float] = Field(
0.0, description="Decimal age as a float. The age from which fictional data is to be generated.")
end_age: Optional[float] = Field(
20.0, description="Decimal age as float. Age until which fictional data is returned.")
gestation_weeks: Optional[int] = Field(
40, ge=limits.MINIMUM_GESTATION_WEEKS, le=limits.MAXIMUM_GESTATION_WEEKS, description="The number of completed weeks of gestation at which the patient was born, passed as an integer. Supplying this data enables Gestational Age correction if the child was not born at term. If no gestational age is passed then 40 weeks (term) is assumed. **IMPORTANT: See also the other parameter `gestation_days` - both are usually required.**")
gestation_days: Optional[int] = Field(
0, ge=0, le=6, description="The number of additional days _beyond the completed weeks of gestation_ at which the patient was born, passed as an integer. Supplying this data enables Gestational Age correction if the child was not born at term. If no gestational age is passed then term is assumed. IMPORTANT: See also the other parameter `gestation_weeks` - both are usually required.")
measurement_interval_type: Optional[Literal['d', 'day', 'days', 'w', 'week', 'weeks', 'm', 'month', 'months', 'y', 'year', 'years']] = Field("months", description="Interval type between fictional measurements as integer. Accepts days as ['d', 'day', 'days'], weeks as ['w', 'weeks', 'weeks'], months as ['m', 'month', 'months'] or years as ['y', 'year', 'years']")
measurement_interval_number: Optional[int] = Field(20, description="Interval length as integer between fictional measurements returned.")
start_sds: Optional[float] = Field(0, description="Starting SDS as float. SDS value at which fictional data starts.")
drift: bool = Field(False, description="Drift as boolean value. Default true. Selected if fictional measurements are intended to drift from starting SDS.")
drift_range: Optional[float] = Field(-0.05, description="Drift range as float. Default is -0.05. The SDS drift expected over the requested age period.")
noise: bool = Field(False, description="Noise as boolean. Default is false. Simulates measurement error.")
noise_range: Optional[float] = Field(0.005, description="Noise range as float. Prescribes the amount of measurement error generated randomly. Default is 0.5%")
reference: Optional[Literal["uk-who", "trisomy-21", "turners-syndrome"]] = Field('uk-who', description="Selected reference as string. Case sensitive and accepts only once of ['uk-who', 'trisomy-21', 'turners-syndrome']")

measurement_interval_type: Optional[Literal['d', 'day', 'days', 'w', 'week', 'weeks', 'm', 'month', 'months', 'y', 'year', 'years']] = Field(
"months", description="Interval type between fictional measurements as integer. Accepts days as ['d', 'day', 'days'], weeks as ['w', 'weeks', 'weeks'], months as ['m', 'month', 'months'] or years as ['y', 'year', 'years']")
measurement_interval_number: Optional[int] = Field(
20, description="Interval length as integer between fictional measurements returned.")
start_sds: Optional[float] = Field(
0, description="Starting SDS as float. SDS value at which fictional data starts.")
drift: bool = Field(
False, description="Drift as boolean value. Default true. Selected if fictional measurements are intended to drift from starting SDS.")
drift_range: Optional[float] = Field(
-0.05, description="Drift range as float. Default is -0.05. The SDS drift expected over the requested age period.")
noise: bool = Field(
False, description="Noise as boolean. Default is false. Simulates measurement error.")
noise_range: Optional[float] = Field(
0.005, description="Noise range as float. Prescribes the amount of measurement error generated randomly. Default is 0.5%")
reference: Optional[Literal["uk-who", "trisomy-21", "turners-syndrome"]] = Field(
'uk-who', description="Selected reference as string. Case sensitive and accepts only once of ['uk-who', 'trisomy-21', 'turners-syndrome']")


class MidParentalHeightRequest(BaseModel):
height_paternal: float = Field(
gt=0, description="The height of the child's biological father, passed as float, measured in centimeters")
ge=50, description="The height of the child's biological father, passed as float, measured in centimeters")
height_maternal: float = Field(
gt=0, description="The height of the child's biological mother, passed as float, measured in centimeters")
ge=50, description="The height of the child's biological mother, passed as float, measured in centimeters")
sex: Literal['male', 'female'] = Field(
..., description="The sex of the patient, as a string value which can either be `male` or `female`. Abbreviations or alternatives are not accepted.")



# the shortest man in the world was 54.6 cm Chandra Bahadur Dangi
# the shortest woman in the world is Jyoti Kishanji Amge at 62.8 cm
# lower limit to paternal and maternal height here therefore set at 50 cm
# this will need adding to the constants in RCPCHGrowth
Loading

0 comments on commit c800ce6

Please sign in to comment.