nested inline schemas
This commit is contained in:
@@ -22,6 +22,7 @@ from models import (
|
|||||||
Parent, ParentCreate,
|
Parent, ParentCreate,
|
||||||
Vet, VetCreate,
|
Vet, VetCreate,
|
||||||
Treatment, TreatmentCreate,
|
Treatment, TreatmentCreate,
|
||||||
|
Procedure, ProcedureNotes,
|
||||||
Pet, PetCreate,
|
Pet, PetCreate,
|
||||||
Appointment, AppointmentCreate,
|
Appointment, AppointmentCreate,
|
||||||
)
|
)
|
||||||
@@ -158,6 +159,7 @@ def create_treatment(payload: TreatmentCreate) -> Treatment:
|
|||||||
id=_treatments_next_id,
|
id=_treatments_next_id,
|
||||||
label=payload.label,
|
label=payload.label,
|
||||||
description=payload.description,
|
description=payload.description,
|
||||||
|
procedures=payload.procedures,
|
||||||
metadata={"createdOn": now, "updatedOn": now} if payload.metadata else None,
|
metadata={"createdOn": now, "updatedOn": now} if payload.metadata else None,
|
||||||
)
|
)
|
||||||
_treatments[_treatments_next_id] = treatment
|
_treatments[_treatments_next_id] = treatment
|
||||||
@@ -174,6 +176,7 @@ def update_treatment(treatment_id: int, payload: TreatmentCreate) -> Treatment:
|
|||||||
id=treatment_id,
|
id=treatment_id,
|
||||||
label=payload.label,
|
label=payload.label,
|
||||||
description=payload.description if payload.description is not None else current.description,
|
description=payload.description if payload.description is not None else current.description,
|
||||||
|
procedures=payload.procedures,
|
||||||
metadata={"createdOn": current.metadata["createdOn"] if current.metadata else None, "updatedOn": now},
|
metadata={"createdOn": current.metadata["createdOn"] if current.metadata else None, "updatedOn": now},
|
||||||
)
|
)
|
||||||
_treatments[treatment_id] = updated
|
_treatments[treatment_id] = updated
|
||||||
@@ -321,11 +324,21 @@ def _seed_data():
|
|||||||
_vets[3] = Vet(id=3, name="Emily Davis", specialty="General Practice", email="emily@clinic.com", phone="555-0203", metadata=meta)
|
_vets[3] = Vet(id=3, name="Emily Davis", specialty="General Practice", email="emily@clinic.com", phone="555-0203", metadata=meta)
|
||||||
_vets_next_id = 4
|
_vets_next_id = 4
|
||||||
|
|
||||||
_treatments[1] = Treatment(id=1, label="Annual Checkup", description="Full physical examination", metadata=meta)
|
_treatments[1] = Treatment(id=1, label="Annual Checkup", description="Full physical examination",
|
||||||
_treatments[2] = Treatment(id=2, label="Vaccination", description="Core vaccines for common diseases", metadata=meta)
|
procedures=[Procedure(name="Physical Exam", cost=50.0), Procedure(name="Heart Rate", notes=ProcedureNotes(summary="Normal rhythm"))],
|
||||||
_treatments[3] = Treatment(id=3, label="Dental Cleaning", description="Scaling, polishing, and oral exam", metadata=meta)
|
metadata=meta)
|
||||||
_treatments[4] = Treatment(id=4, label="Spay/Neuter", description="Surgical sterilization", metadata=meta)
|
_treatments[2] = Treatment(id=2, label="Vaccination", description="Core vaccines for common diseases",
|
||||||
_treatments[5] = Treatment(id=5, label="Blood Panel", description="Complete blood count and chemistry", metadata=meta)
|
procedures=[Procedure(name="DHPP Vaccine", cost=35.0), Procedure(name="Rabies Vaccine", cost=45.0)],
|
||||||
|
metadata=meta)
|
||||||
|
_treatments[3] = Treatment(id=3, label="Dental Cleaning", description="Scaling, polishing, and oral exam",
|
||||||
|
procedures=[Procedure(name="Scaling", cost=80.0), Procedure(name="Polishing", cost=40.0, notes=ProcedureNotes(summary="High-speed polish"))],
|
||||||
|
metadata=meta)
|
||||||
|
_treatments[4] = Treatment(id=4, label="Spay/Neuter", description="Surgical sterilization",
|
||||||
|
procedures=[Procedure(name="Pre-op Exam", cost=30.0), Procedure(name="Surgery", cost=200.0), Procedure(name="Post-op Care", cost=50.0)],
|
||||||
|
metadata=meta)
|
||||||
|
_treatments[5] = Treatment(id=5, label="Blood Panel", description="Complete blood count and chemistry",
|
||||||
|
procedures=[Procedure(name="CBC", cost=25.0), Procedure(name="Chemistry Panel", cost=60.0, notes=ProcedureNotes(summary="Fasting required"))],
|
||||||
|
metadata=meta)
|
||||||
_treatments_next_id = 6
|
_treatments_next_id = 6
|
||||||
|
|
||||||
_pets[1] = Pet(id=1, name="Max", species="dog", age=4, weight=25.5, birthDate=date(2022, 3, 15), parents=[_parents[1]], metadata=meta)
|
_pets[1] = Pet(id=1, name="Max", species="dog", age=4, weight=25.5, birthDate=date(2022, 3, 15), parents=[_parents[1]], metadata=meta)
|
||||||
|
|||||||
@@ -38,9 +38,22 @@ class Vet(VetBase):
|
|||||||
id: int
|
id: int
|
||||||
|
|
||||||
|
|
||||||
|
class ProcedureNotes(BaseModel):
|
||||||
|
summary: str | None = None
|
||||||
|
details: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class Procedure(BaseModel):
|
||||||
|
name: str | None = None
|
||||||
|
description: str | None = None
|
||||||
|
cost: float | None = None
|
||||||
|
notes: ProcedureNotes | None = None
|
||||||
|
|
||||||
|
|
||||||
class TreatmentBase(BaseModel):
|
class TreatmentBase(BaseModel):
|
||||||
label: str
|
label: str
|
||||||
description: str | None = None
|
description: str | None = None
|
||||||
|
procedures: list[Procedure] = []
|
||||||
metadata: Metadata | None = None
|
metadata: Metadata | None = None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,41 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
format: date-time
|
format: date-time
|
||||||
|
|
||||||
|
Procedure:
|
||||||
|
type: object
|
||||||
|
x-display-format: "{name} — ${cost}"
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
x-order: 1
|
||||||
|
x-label: "Procedure Name"
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
x-order: 2
|
||||||
|
x-label: "Description"
|
||||||
|
cost:
|
||||||
|
type: number
|
||||||
|
format: float
|
||||||
|
x-order: 3
|
||||||
|
x-label: "Cost"
|
||||||
|
notes:
|
||||||
|
$ref: '#/components/schemas/ProcedureNotes'
|
||||||
|
x-order: 4
|
||||||
|
x-label: "Notes"
|
||||||
|
|
||||||
|
ProcedureNotes:
|
||||||
|
type: object
|
||||||
|
x-display-format: "{summary}"
|
||||||
|
properties:
|
||||||
|
summary:
|
||||||
|
type: string
|
||||||
|
x-order: 1
|
||||||
|
x-label: "Summary"
|
||||||
|
details:
|
||||||
|
type: string
|
||||||
|
x-order: 2
|
||||||
|
x-label: "Details"
|
||||||
|
|
||||||
Parent:
|
Parent:
|
||||||
type: object
|
type: object
|
||||||
x-resource: parents
|
x-resource: parents
|
||||||
@@ -131,6 +166,13 @@ components:
|
|||||||
x-order: 2
|
x-order: 2
|
||||||
x-label: "Description"
|
x-label: "Description"
|
||||||
x-description: "Detailed description of the treatment"
|
x-description: "Detailed description of the treatment"
|
||||||
|
procedures:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Procedure'
|
||||||
|
x-order: 3
|
||||||
|
x-label: "Procedures"
|
||||||
|
x-description: "List of procedures performed during this treatment"
|
||||||
metadata:
|
metadata:
|
||||||
$ref: '#/components/schemas/Metadata'
|
$ref: '#/components/schemas/Metadata'
|
||||||
x-order: 4
|
x-order: 4
|
||||||
|
|||||||
Reference in New Issue
Block a user