|
|
|
|
@@ -52,7 +52,9 @@ def create_parent(payload: ParentCreate) -> Parent:
|
|
|
|
|
now = _now()
|
|
|
|
|
parent = Parent(
|
|
|
|
|
id=_parents_next_id,
|
|
|
|
|
**payload.model_dump(exclude={"id", "metadata"}),
|
|
|
|
|
name=payload.name,
|
|
|
|
|
email=payload.email,
|
|
|
|
|
phone=payload.phone,
|
|
|
|
|
metadata={"createdOn": now, "updatedOn": now} if payload.metadata else None,
|
|
|
|
|
)
|
|
|
|
|
_parents[_parents_next_id] = parent
|
|
|
|
|
@@ -64,13 +66,13 @@ def update_parent(parent_id: int, payload: ParentCreate) -> Parent:
|
|
|
|
|
if parent_id not in _parents:
|
|
|
|
|
raise KeyError(parent_id)
|
|
|
|
|
now = _now()
|
|
|
|
|
parent = _parents[parent_id]
|
|
|
|
|
updated = parent.model_copy(
|
|
|
|
|
update={
|
|
|
|
|
**payload.model_dump(exclude={"id", "metadata"}),
|
|
|
|
|
"metadata": {"createdOn": parent.metadata.get("createdOn", now), "updatedOn": now}
|
|
|
|
|
if parent.metadata else None,
|
|
|
|
|
}
|
|
|
|
|
current = _parents[parent_id]
|
|
|
|
|
updated = Parent(
|
|
|
|
|
id=parent_id,
|
|
|
|
|
name=payload.name,
|
|
|
|
|
email=payload.email,
|
|
|
|
|
phone=payload.phone if payload.phone is not None else current.phone,
|
|
|
|
|
metadata={"createdOn": current.metadata["createdOn"] if current.metadata else None, "updatedOn": now},
|
|
|
|
|
)
|
|
|
|
|
_parents[parent_id] = updated
|
|
|
|
|
return updated
|
|
|
|
|
@@ -101,7 +103,10 @@ def create_vet(payload: VetCreate) -> Vet:
|
|
|
|
|
now = _now()
|
|
|
|
|
vet = Vet(
|
|
|
|
|
id=_vets_next_id,
|
|
|
|
|
**payload.model_dump(exclude={"id", "metadata"}),
|
|
|
|
|
name=payload.name,
|
|
|
|
|
specialty=payload.specialty,
|
|
|
|
|
email=payload.email,
|
|
|
|
|
phone=payload.phone,
|
|
|
|
|
metadata={"createdOn": now, "updatedOn": now} if payload.metadata else None,
|
|
|
|
|
)
|
|
|
|
|
_vets[_vets_next_id] = vet
|
|
|
|
|
@@ -113,13 +118,14 @@ def update_vet(vet_id: int, payload: VetCreate) -> Vet:
|
|
|
|
|
if vet_id not in _vets:
|
|
|
|
|
raise KeyError(vet_id)
|
|
|
|
|
now = _now()
|
|
|
|
|
vet = _vets[vet_id]
|
|
|
|
|
updated = vet.model_copy(
|
|
|
|
|
update={
|
|
|
|
|
**payload.model_dump(exclude={"id", "metadata"}),
|
|
|
|
|
"metadata": {"createdOn": vet.metadata.get("createdOn", now), "updatedOn": now}
|
|
|
|
|
if vet.metadata else None,
|
|
|
|
|
}
|
|
|
|
|
current = _vets[vet_id]
|
|
|
|
|
updated = Vet(
|
|
|
|
|
id=vet_id,
|
|
|
|
|
name=payload.name,
|
|
|
|
|
specialty=payload.specialty if payload.specialty is not None else current.specialty,
|
|
|
|
|
email=payload.email,
|
|
|
|
|
phone=payload.phone if payload.phone is not None else current.phone,
|
|
|
|
|
metadata={"createdOn": current.metadata["createdOn"] if current.metadata else None, "updatedOn": now},
|
|
|
|
|
)
|
|
|
|
|
_vets[vet_id] = updated
|
|
|
|
|
return updated
|
|
|
|
|
@@ -150,7 +156,8 @@ def create_treatment(payload: TreatmentCreate) -> Treatment:
|
|
|
|
|
now = _now()
|
|
|
|
|
treatment = Treatment(
|
|
|
|
|
id=_treatments_next_id,
|
|
|
|
|
**payload.model_dump(exclude={"id", "metadata"}),
|
|
|
|
|
label=payload.label,
|
|
|
|
|
description=payload.description,
|
|
|
|
|
metadata={"createdOn": now, "updatedOn": now} if payload.metadata else None,
|
|
|
|
|
)
|
|
|
|
|
_treatments[_treatments_next_id] = treatment
|
|
|
|
|
@@ -162,13 +169,12 @@ def update_treatment(treatment_id: int, payload: TreatmentCreate) -> Treatment:
|
|
|
|
|
if treatment_id not in _treatments:
|
|
|
|
|
raise KeyError(treatment_id)
|
|
|
|
|
now = _now()
|
|
|
|
|
treatment = _treatments[treatment_id]
|
|
|
|
|
updated = treatment.model_copy(
|
|
|
|
|
update={
|
|
|
|
|
**payload.model_dump(exclude={"id", "metadata"}),
|
|
|
|
|
"metadata": {"createdOn": treatment.metadata.get("createdOn", now), "updatedOn": now}
|
|
|
|
|
if treatment.metadata else None,
|
|
|
|
|
}
|
|
|
|
|
current = _treatments[treatment_id]
|
|
|
|
|
updated = Treatment(
|
|
|
|
|
id=treatment_id,
|
|
|
|
|
label=payload.label,
|
|
|
|
|
description=payload.description if payload.description is not None else current.description,
|
|
|
|
|
metadata={"createdOn": current.metadata["createdOn"] if current.metadata else None, "updatedOn": now},
|
|
|
|
|
)
|
|
|
|
|
_treatments[treatment_id] = updated
|
|
|
|
|
return updated
|
|
|
|
|
@@ -197,9 +203,16 @@ def get_pet(pet_id: int) -> Pet:
|
|
|
|
|
def create_pet(payload: PetCreate) -> Pet:
|
|
|
|
|
global _pets_next_id
|
|
|
|
|
now = _now()
|
|
|
|
|
parents = [_parents[pid] for pid in payload.parent_ids]
|
|
|
|
|
pet = Pet(
|
|
|
|
|
id=_pets_next_id,
|
|
|
|
|
**payload.model_dump(exclude={"id", "metadata"}),
|
|
|
|
|
name=payload.name,
|
|
|
|
|
species=payload.species,
|
|
|
|
|
age=payload.age,
|
|
|
|
|
weight=payload.weight,
|
|
|
|
|
birthDate=payload.birthDate,
|
|
|
|
|
photo=payload.photo,
|
|
|
|
|
parents=parents,
|
|
|
|
|
metadata={"createdOn": now, "updatedOn": now} if payload.metadata else None,
|
|
|
|
|
)
|
|
|
|
|
_pets[_pets_next_id] = pet
|
|
|
|
|
@@ -211,13 +224,18 @@ def update_pet(pet_id: int, payload: PetCreate) -> Pet:
|
|
|
|
|
if pet_id not in _pets:
|
|
|
|
|
raise KeyError(pet_id)
|
|
|
|
|
now = _now()
|
|
|
|
|
pet = _pets[pet_id]
|
|
|
|
|
updated = pet.model_copy(
|
|
|
|
|
update={
|
|
|
|
|
**payload.model_dump(exclude={"id", "metadata"}),
|
|
|
|
|
"metadata": {"createdOn": pet.metadata.get("createdOn", now), "updatedOn": now}
|
|
|
|
|
if pet.metadata else None,
|
|
|
|
|
}
|
|
|
|
|
parents = [_parents[pid] for pid in payload.parent_ids]
|
|
|
|
|
current = _pets[pet_id]
|
|
|
|
|
updated = Pet(
|
|
|
|
|
id=pet_id,
|
|
|
|
|
name=payload.name,
|
|
|
|
|
species=payload.species,
|
|
|
|
|
age=payload.age if payload.age is not None else current.age,
|
|
|
|
|
weight=payload.weight if payload.weight is not None else current.weight,
|
|
|
|
|
birthDate=payload.birthDate if payload.birthDate is not None else current.birthDate,
|
|
|
|
|
photo=payload.photo if payload.photo is not None else current.photo,
|
|
|
|
|
parents=parents,
|
|
|
|
|
metadata={"createdOn": current.metadata["createdOn"] if current.metadata else None, "updatedOn": now},
|
|
|
|
|
)
|
|
|
|
|
_pets[pet_id] = updated
|
|
|
|
|
return updated
|
|
|
|
|
@@ -248,7 +266,11 @@ def create_appointment(payload: AppointmentCreate) -> Appointment:
|
|
|
|
|
now = _now()
|
|
|
|
|
appointment = Appointment(
|
|
|
|
|
id=_appointments_next_id,
|
|
|
|
|
**payload.model_dump(exclude={"id", "metadata"}),
|
|
|
|
|
date=payload.date,
|
|
|
|
|
notes=payload.notes,
|
|
|
|
|
pet=_pets[payload.pet_id],
|
|
|
|
|
vet=_vets[payload.vet_id],
|
|
|
|
|
treatment=_treatments[payload.treatment_id],
|
|
|
|
|
metadata={"createdOn": now, "updatedOn": now} if payload.metadata else None,
|
|
|
|
|
)
|
|
|
|
|
_appointments[_appointments_next_id] = appointment
|
|
|
|
|
@@ -260,13 +282,15 @@ def update_appointment(appointment_id: int, payload: AppointmentCreate) -> Appoi
|
|
|
|
|
if appointment_id not in _appointments:
|
|
|
|
|
raise KeyError(appointment_id)
|
|
|
|
|
now = _now()
|
|
|
|
|
appointment = _appointments[appointment_id]
|
|
|
|
|
updated = appointment.model_copy(
|
|
|
|
|
update={
|
|
|
|
|
**payload.model_dump(exclude={"id", "metadata"}),
|
|
|
|
|
"metadata": {"createdOn": appointment.metadata.get("createdOn", now), "updatedOn": now}
|
|
|
|
|
if appointment.metadata else None,
|
|
|
|
|
}
|
|
|
|
|
current = _appointments[appointment_id]
|
|
|
|
|
updated = Appointment(
|
|
|
|
|
id=appointment_id,
|
|
|
|
|
date=payload.date,
|
|
|
|
|
notes=payload.notes if payload.notes is not None else current.notes,
|
|
|
|
|
pet=_pets.get(payload.pet_id, current.pet),
|
|
|
|
|
vet=_vets.get(payload.vet_id, current.vet),
|
|
|
|
|
treatment=_treatments.get(payload.treatment_id, current.treatment),
|
|
|
|
|
metadata={"createdOn": current.metadata["createdOn"] if current.metadata else None, "updatedOn": now},
|
|
|
|
|
)
|
|
|
|
|
_appointments[appointment_id] = updated
|
|
|
|
|
return updated
|
|
|
|
|
@@ -304,17 +328,17 @@ def _seed_data():
|
|
|
|
|
_treatments[5] = Treatment(id=5, label="Blood Panel", description="Complete blood count and chemistry", metadata=meta)
|
|
|
|
|
_treatments_next_id = 6
|
|
|
|
|
|
|
|
|
|
_pets[1] = Pet(id=1, name="Max", species="dog", age=4, weight=25.5, birthDate=date(2022, 3, 15), parent_ids=[1], metadata=meta)
|
|
|
|
|
_pets[2] = Pet(id=2, name="Luna", species="cat", age=2, weight=4.2, birthDate=date(2024, 1, 10), parent_ids=[1, 2], metadata=meta)
|
|
|
|
|
_pets[3] = Pet(id=3, name="Charlie", species="dog", age=7, weight=18.0, birthDate=date(2019, 8, 22), parent_ids=[2], metadata=meta)
|
|
|
|
|
_pets[4] = Pet(id=4, name="Bella", species="bird", age=1, weight=0.3, birthDate=date(2025, 5, 1), parent_ids=[3], metadata=meta)
|
|
|
|
|
_pets[5] = Pet(id=5, name="Rocky", species="dog", age=3, weight=30.0, birthDate=date(2023, 11, 5), parent_ids=[4], 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)
|
|
|
|
|
_pets[2] = Pet(id=2, name="Luna", species="cat", age=2, weight=4.2, birthDate=date(2024, 1, 10), parents=[_parents[1], _parents[2]], metadata=meta)
|
|
|
|
|
_pets[3] = Pet(id=3, name="Charlie", species="dog", age=7, weight=18.0, birthDate=date(2019, 8, 22), parents=[_parents[2]], metadata=meta)
|
|
|
|
|
_pets[4] = Pet(id=4, name="Bella", species="bird", age=1, weight=0.3, birthDate=date(2025, 5, 1), parents=[_parents[3]], metadata=meta)
|
|
|
|
|
_pets[5] = Pet(id=5, name="Rocky", species="dog", age=3, weight=30.0, birthDate=date(2023, 11, 5), parents=[_parents[4]], metadata=meta)
|
|
|
|
|
_pets_next_id = 6
|
|
|
|
|
|
|
|
|
|
_appointments[1] = Appointment(id=1, date=datetime(2026, 6, 18, 9, 0, tzinfo=timezone.utc), notes="Annual checkup", pet_id=1, vet_id=1, treatment_id=1, metadata=meta)
|
|
|
|
|
_appointments[2] = Appointment(id=2, date=datetime(2026, 6, 18, 10, 30, tzinfo=timezone.utc), notes="Dental cleaning", pet_id=2, vet_id=2, treatment_id=3, metadata=meta)
|
|
|
|
|
_appointments[3] = Appointment(id=3, date=datetime(2026, 6, 19, 11, 0, tzinfo=timezone.utc), notes="Vaccination booster", pet_id=3, vet_id=3, treatment_id=2, metadata=meta)
|
|
|
|
|
_appointments[4] = Appointment(id=4, date=datetime(2026, 6, 20, 14, 0, tzinfo=timezone.utc), notes="Follow-up after surgery", pet_id=5, vet_id=1, treatment_id=4, metadata=meta)
|
|
|
|
|
_appointments[1] = Appointment(id=1, date=datetime(2026, 6, 18, 9, 0, tzinfo=timezone.utc), notes="Annual checkup", pet=_pets[1], vet=_vets[1], treatment=_treatments[1], metadata=meta)
|
|
|
|
|
_appointments[2] = Appointment(id=2, date=datetime(2026, 6, 18, 10, 30, tzinfo=timezone.utc), notes="Dental cleaning", pet=_pets[2], vet=_vets[2], treatment=_treatments[3], metadata=meta)
|
|
|
|
|
_appointments[3] = Appointment(id=3, date=datetime(2026, 6, 19, 11, 0, tzinfo=timezone.utc), notes="Vaccination booster", pet=_pets[3], vet=_vets[3], treatment=_treatments[2], metadata=meta)
|
|
|
|
|
_appointments[4] = Appointment(id=4, date=datetime(2026, 6, 20, 14, 0, tzinfo=timezone.utc), notes="Follow-up after surgery", pet=_pets[5], vet=_vets[1], treatment=_treatments[4], metadata=meta)
|
|
|
|
|
_appointments_next_id = 5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|