Spaces:
Runtime error
Runtime error
dylanglenister
commited on
Commit
·
c9573f1
1
Parent(s):
57635b5
Combining repository models into one file
Browse files- src/data/repositories/account.py +1 -1
- src/data/repositories/patient.py +1 -1
- src/data/repositories/session.py +1 -1
- src/models/account.py +0 -16
- src/models/common.py +0 -17
- src/models/patient.py +0 -22
- src/models/{session.py → repositories.py} +37 -5
src/data/repositories/account.py
CHANGED
|
@@ -25,7 +25,7 @@ from pymongo.errors import ConnectionFailure, PyMongoError, WriteError
|
|
| 25 |
|
| 26 |
from src.data.connection import (ActionFailed, Collections, get_collection,
|
| 27 |
setup_collection)
|
| 28 |
-
from src.models.
|
| 29 |
from src.utils.logger import logger
|
| 30 |
|
| 31 |
VALID_ROLES = [
|
|
|
|
| 25 |
|
| 26 |
from src.data.connection import (ActionFailed, Collections, get_collection,
|
| 27 |
setup_collection)
|
| 28 |
+
from src.models.repositories import Account
|
| 29 |
from src.utils.logger import logger
|
| 30 |
|
| 31 |
VALID_ROLES = [
|
src/data/repositories/patient.py
CHANGED
|
@@ -30,7 +30,7 @@ from pymongo.errors import ConnectionFailure, PyMongoError, WriteError
|
|
| 30 |
|
| 31 |
from src.data.connection import (ActionFailed, Collections, get_collection,
|
| 32 |
setup_collection)
|
| 33 |
-
from src.models.
|
| 34 |
from src.utils.logger import logger
|
| 35 |
|
| 36 |
|
|
|
|
| 30 |
|
| 31 |
from src.data.connection import (ActionFailed, Collections, get_collection,
|
| 32 |
setup_collection)
|
| 33 |
+
from src.models.repositories import Patient
|
| 34 |
from src.utils.logger import logger
|
| 35 |
|
| 36 |
|
src/data/repositories/session.py
CHANGED
|
@@ -28,7 +28,7 @@ from pymongo.errors import ConnectionFailure, PyMongoError, WriteError
|
|
| 28 |
|
| 29 |
from src.data.connection import (ActionFailed, Collections, get_collection,
|
| 30 |
setup_collection)
|
| 31 |
-
from src.models.
|
| 32 |
from src.utils.logger import logger
|
| 33 |
|
| 34 |
|
|
|
|
| 28 |
|
| 29 |
from src.data.connection import (ActionFailed, Collections, get_collection,
|
| 30 |
setup_collection)
|
| 31 |
+
from src.models.repositories import Message, Session
|
| 32 |
from src.utils.logger import logger
|
| 33 |
|
| 34 |
|
src/models/account.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
| 1 |
-
# src/models/account.py
|
| 2 |
-
|
| 3 |
-
from datetime import datetime
|
| 4 |
-
|
| 5 |
-
from src.models.common import BaseMongoModel
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
class Account(BaseMongoModel):
|
| 9 |
-
"""A Pydantic model for an account, used across all layers."""
|
| 10 |
-
# The '_id' field and base config are inherited from BaseMongoModel
|
| 11 |
-
name: str
|
| 12 |
-
role: str
|
| 13 |
-
specialty: str | None = None
|
| 14 |
-
created_at: datetime
|
| 15 |
-
updated_at: datetime
|
| 16 |
-
last_seen: datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/models/common.py
DELETED
|
@@ -1,17 +0,0 @@
|
|
| 1 |
-
# src/models/common.py
|
| 2 |
-
|
| 3 |
-
from typing import Annotated
|
| 4 |
-
|
| 5 |
-
from pydantic import BaseModel, BeforeValidator, ConfigDict, Field
|
| 6 |
-
|
| 7 |
-
PyObjectId = Annotated[str, BeforeValidator(str)]
|
| 8 |
-
|
| 9 |
-
class BaseMongoModel(BaseModel):
|
| 10 |
-
"""A base Pydantic model for all MongoDB documents."""
|
| 11 |
-
id: PyObjectId = Field(..., alias="_id")
|
| 12 |
-
|
| 13 |
-
model_config = ConfigDict(
|
| 14 |
-
frozen=True,
|
| 15 |
-
from_attributes=True,
|
| 16 |
-
arbitrary_types_allowed=True
|
| 17 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/models/patient.py
DELETED
|
@@ -1,22 +0,0 @@
|
|
| 1 |
-
# src/models/patient.py
|
| 2 |
-
|
| 3 |
-
from datetime import datetime
|
| 4 |
-
|
| 5 |
-
from src.models.common import BaseMongoModel, PyObjectId
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
class Patient(BaseMongoModel):
|
| 9 |
-
"""A Pydantic model for a patient, used across all layers."""
|
| 10 |
-
# The '_id' field and base config are inherited from BaseMongoModel
|
| 11 |
-
name: str
|
| 12 |
-
age: int
|
| 13 |
-
sex: str
|
| 14 |
-
ethnicity: str
|
| 15 |
-
created_at: datetime
|
| 16 |
-
updated_at: datetime
|
| 17 |
-
address: str | None = None
|
| 18 |
-
phone: str | None = None
|
| 19 |
-
email: str | None = None
|
| 20 |
-
medications: list[str] | None = None
|
| 21 |
-
past_assessment_summary: str | None = None
|
| 22 |
-
assigned_doctor_id: PyObjectId | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/models/{session.py → repositories.py}
RENAMED
|
@@ -1,11 +1,45 @@
|
|
| 1 |
-
# src/models/
|
| 2 |
|
| 3 |
from datetime import datetime
|
|
|
|
| 4 |
|
| 5 |
-
from pydantic import BaseModel, ConfigDict, Field
|
| 6 |
|
| 7 |
-
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
class Message(BaseModel):
|
| 11 |
"""A Pydantic sub-model for a single message within a session."""
|
|
@@ -18,10 +52,8 @@ class Message(BaseModel):
|
|
| 18 |
# Use a standard config for this sub-model
|
| 19 |
model_config = ConfigDict(frozen=True, from_attributes=True)
|
| 20 |
|
| 21 |
-
|
| 22 |
class Session(BaseMongoModel):
|
| 23 |
"""A Pydantic model for a chat session, including nested messages."""
|
| 24 |
-
# The '_id' field and base config are inherited from BaseMongoModel
|
| 25 |
account_id: PyObjectId
|
| 26 |
patient_id: PyObjectId
|
| 27 |
title: str
|
|
|
|
| 1 |
+
# src/models/repositories.py
|
| 2 |
|
| 3 |
from datetime import datetime
|
| 4 |
+
from typing import Annotated
|
| 5 |
|
| 6 |
+
from pydantic import BaseModel, BeforeValidator, ConfigDict, Field
|
| 7 |
|
| 8 |
+
PyObjectId = Annotated[str, BeforeValidator(str)]
|
| 9 |
|
| 10 |
+
class BaseMongoModel(BaseModel):
|
| 11 |
+
"""A base Pydantic model for all MongoDB documents."""
|
| 12 |
+
id: PyObjectId = Field(..., alias="_id")
|
| 13 |
+
|
| 14 |
+
model_config = ConfigDict(
|
| 15 |
+
frozen=True,
|
| 16 |
+
from_attributes=True,
|
| 17 |
+
arbitrary_types_allowed=True
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
class Account(BaseMongoModel):
|
| 21 |
+
"""A Pydantic model for an account."""
|
| 22 |
+
name: str
|
| 23 |
+
role: str
|
| 24 |
+
specialty: str | None = None
|
| 25 |
+
created_at: datetime
|
| 26 |
+
updated_at: datetime
|
| 27 |
+
last_seen: datetime
|
| 28 |
+
|
| 29 |
+
class Patient(BaseMongoModel):
|
| 30 |
+
"""A Pydantic model for a patient."""
|
| 31 |
+
name: str
|
| 32 |
+
age: int
|
| 33 |
+
sex: str
|
| 34 |
+
ethnicity: str
|
| 35 |
+
created_at: datetime
|
| 36 |
+
updated_at: datetime
|
| 37 |
+
address: str | None = None
|
| 38 |
+
phone: str | None = None
|
| 39 |
+
email: str | None = None
|
| 40 |
+
medications: list[str] | None = None
|
| 41 |
+
past_assessment_summary: str | None = None
|
| 42 |
+
assigned_doctor_id: PyObjectId | None = None
|
| 43 |
|
| 44 |
class Message(BaseModel):
|
| 45 |
"""A Pydantic sub-model for a single message within a session."""
|
|
|
|
| 52 |
# Use a standard config for this sub-model
|
| 53 |
model_config = ConfigDict(frozen=True, from_attributes=True)
|
| 54 |
|
|
|
|
| 55 |
class Session(BaseMongoModel):
|
| 56 |
"""A Pydantic model for a chat session, including nested messages."""
|
|
|
|
| 57 |
account_id: PyObjectId
|
| 58 |
patient_id: PyObjectId
|
| 59 |
title: str
|