Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date/time stamps and reference requested in response #37

Open
eatyourpeas opened this issue Oct 21, 2024 · 3 comments
Open

date/time stamps and reference requested in response #37

eatyourpeas opened this issue Oct 21, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@eatyourpeas
Copy link
Member

Now that multiple references are offered, there is currently no information in the response object either that the request was made or the reference that the return data corresponds to. I would be ideal to put in the body of the response with all the results but this would represent a breaking change for users, so the other option is to put it in the response header. Users can discard this, but also they can use this if they need.

FastAPI has this feature to add custom headers:

from fastapi import FastAPI, HTTPException, Response
from typing import List
from datetime import datetime
import constants

app = FastAPI()

@uk_who.post(
    "/fictional-child-data", tags=["uk-who"], response_model=List[MeasurementObject]
)
def fictional_child_data(fictional_child_request: FictionalChildRequest, response: Response):
    """
    ## UK-WHO Fictional Child Data Endpoint

    * Generates synthetic data for demonstration or testing purposes
    """
    try:
        life_course_fictional_child_data = generate_fictional_child_data(
            measurement_method=fictional_child_request.measurement_method,
            sex=fictional_child_request.sex,
            start_chronological_age=fictional_child_request.start_chronological_age,
            end_age=fictional_child_request.end_age,
            gestation_weeks=fictional_child_request.gestation_weeks,
            gestation_days=fictional_child_request.gestation_days,
            measurement_interval_type=fictional_child_request.measurement_interval_type,
            measurement_interval_number=fictional_child_request.measurement_interval_number,
            start_sds=fictional_child_request.start_sds,
            drift=fictional_child_request.drift,
            drift_range=fictional_child_request.drift_range,
            noise=fictional_child_request.noise,
            noise_range=fictional_child_request.noise_range,
            reference=constants.UK_WHO,
        )
        
        # Set response headers
        response.headers["X-Date-Time"] = datetime.utcnow().isoformat()
        response.headers["X-Reference"] = constants.UK_WHO

        return life_course_fictional_child_data
    except Exception as e:
        raise HTTPException(
            status_code=422,
            detail=f"Not possible to create UK-WHO fictional child data. Error: {str(e)}",
        )
@eatyourpeas eatyourpeas added the enhancement New feature or request label Oct 21, 2024
@mbarton
Copy link
Member

mbarton commented Oct 21, 2024

I would be ideal to put in the body of the response with all the results but this would represent a breaking change for users

Could we add new top level fields with this so it's not a breaking change?

@eatyourpeas
Copy link
Member Author

We have a typescript interface that matches the API specification of the Measurement class. If we add a new top level object might that not break it for people using older versions of the chart component?

@mbarton
Copy link
Member

mbarton commented Oct 28, 2024

Ah I see. Given it's a debugging option we could add it as a new always present field in the Open API spec and then as an optional field in the Typescript interface?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants