Skip to content

Commit

Permalink
Merge branch 'FBAPS-2-Patient-Highlights-API-CRUD' of https://github.…
Browse files Browse the repository at this point in the history
…com/ntu-pear/PEAR_patient_service into FBAPS-2-Patient-Highlights-API-CRUD
  • Loading branch information
weikangg committed Jan 17, 2025
2 parents 42c216f + b776148 commit cba4c08
Show file tree
Hide file tree
Showing 26 changed files with 1,032 additions and 349 deletions.
42 changes: 41 additions & 1 deletion app/crud/allergy_reaction_type_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,60 @@
AllergyReactionTypeCreate,
AllergyReactionTypeUpdate,
)
from ..schemas.allergy_reaction_type import (
AllergyReactionTypeCreate,
AllergyReactionTypeUpdate,
)
from datetime import datetime



def get_all_reaction_types(db: Session):
return db.query(AllergyReactionType).all()
return db.query(AllergyReactionType).filter(AllergyReactionType.IsDeleted == "0").all()


def get_reaction_type_by_id(db: Session, allergy_reaction_type_id: int):
return (
db.query(AllergyReactionType)
.filter(AllergyReactionType.AllergyReactionTypeID == allergy_reaction_type_id, AllergyReactionType.IsDeleted == "0")
.first()
)

return (
db.query(AllergyReactionType)
.filter(AllergyReactionType.AllergyReactionTypeID == allergy_reaction_type_id)
.first()
)


def create_reaction_type(
db: Session, reaction_type: AllergyReactionTypeCreate, created_by: int
):
def create_reaction_type(
db: Session, reaction_type: AllergyReactionTypeCreate, created_by: int
):
db_reaction_type = AllergyReactionType(
**reaction_type.model_dump(), CreatedById=created_by, ModifiedById=created_by
**reaction_type.model_dump(), CreatedById=created_by, ModifiedById=created_by
)
db.add(db_reaction_type)
db.commit()
db.refresh(db_reaction_type)
return db_reaction_type


def update_reaction_type(
db: Session,
allergy_reaction_type_id: int,
reaction_type: AllergyReactionTypeUpdate,
modified_by: int,
):
db_reaction_type = (
db.query(AllergyReactionType)
.filter(AllergyReactionType.AllergyReactionTypeID == allergy_reaction_type_id)
.first()
)

def update_reaction_type(
db: Session,
allergy_reaction_type_id: int,
Expand All @@ -45,12 +72,15 @@ def update_reaction_type(

if db_reaction_type:
# Update other fields from the request body
for key, value in reaction_type.model_dump(exclude_unset=True).items():
for key, value in reaction_type.model_dump(exclude_unset=True).items():
setattr(db_reaction_type, key, value)

# Set UpdatedDateTime to the current datetime
db_reaction_type.UpdatedDateTime = datetime.now()

# Update the modifiedById field
db_reaction_type.ModifiedById = modified_by
# Update the modifiedById field
db_reaction_type.ModifiedById = modified_by

Expand All @@ -61,6 +91,13 @@ def update_reaction_type(
return None


def delete_reaction_type(db: Session, allergy_reaction_type_id: int, modified_by: int):
db_reaction_type = (
db.query(AllergyReactionType)
.filter(AllergyReactionType.AllergyReactionTypeID == allergy_reaction_type_id)
.first()
)

def delete_reaction_type(db: Session, allergy_reaction_type_id: int, modified_by: int):
db_reaction_type = (
db.query(AllergyReactionType)
Expand All @@ -71,7 +108,10 @@ def delete_reaction_type(db: Session, allergy_reaction_type_id: int, modified_by
if db_reaction_type:
setattr(db_reaction_type, "IsDeleted", "1")
db_reaction_type.ModifiedById = modified_by
setattr(db_reaction_type, "IsDeleted", "1")
db_reaction_type.ModifiedById = modified_by

db.commit()
return db_reaction_type
return None

5 changes: 2 additions & 3 deletions app/crud/allergy_type_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@


def get_all_allergy_types(db: Session):
return db.query(AllergyType).all()
return db.query(AllergyType).filter(AllergyType.IsDeleted == "0").all()


def get_allergy_type_by_id(db: Session, allergy_type_id: int):
return (
db.query(AllergyType)
.filter(AllergyType.AllergyTypeID == allergy_type_id)
.filter(AllergyType.AllergyTypeID == allergy_type_id,AllergyType.IsDeleted == "0")
.first()
)


def create_allergy_type(db: Session, allergy_type: AllergyTypeCreate, created_by: int):
db_allergy_type = AllergyType(
**allergy_type.model_dump(), CreatedById=created_by, ModifiedById=created_by
Expand Down
4 changes: 2 additions & 2 deletions app/crud/patient_allergy_mapping_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_all_allergies(db: Session):
.all()
)

# Handle "Active" logic
# Filter soft deleted entries
patient_allergies = []
for result in results:
allergy_type_value = (
Expand Down Expand Up @@ -96,7 +96,7 @@ def get_patient_allergies(db: Session, patient_id: int):
.all()
)

# Handle "Active" logic
# Filter soft deleted entries
patient_allergies = []
for result in results:
allergy_type_value = (
Expand Down
60 changes: 38 additions & 22 deletions app/crud/patient_highlight_crud.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
from sqlalchemy.orm import Session
from ..models.patient_highlight_model import PatientHighlight
from ..schemas.patient_highlight import HighlightCreate, HighlightUpdate
from ..schemas.patient_highlight import PatientHighlightCreate, PatientHighlightUpdate
from datetime import datetime
from fastapi import HTTPException

def get_highlights(db: Session, skip: int = 0, limit: int = 100):
return db.query(PatientHighlight).order_by(PatientHighlight.id).offset(skip).limit(limit).all()
def get_all_highlights(db: Session):
return db.query(PatientHighlight).filter(PatientHighlight.IsDeleted == "0").all()

def get_highlight(db: Session, highlight_id: int):
return db.query(PatientHighlight).filter(PatientHighlight.id == highlight_id).first()
def get_highlights_by_patient(db: Session, patient_id: int):
return (
db.query(PatientHighlight)
.filter(PatientHighlight.PatientId == patient_id, PatientHighlight.IsDeleted == "0")
.all()
)

def get_highlights_grouped_by_patient(db: Session):
return db.query(PatientHighlight).all() # Adjust this query as needed to group by patient_id

def create_highlight(db: Session, highlight: HighlightCreate):
db_highlight = PatientHighlight(**highlight.dict())
def create_highlight(db: Session, highlight_data: PatientHighlightCreate, created_by: int):
db_highlight = PatientHighlight(
**highlight_data.dict(), CreatedById=created_by, ModifiedById=created_by
)
db.add(db_highlight)
db.commit()
db.refresh(db_highlight)
return db_highlight

def update_highlight(db: Session, highlight_id: int, highlight: HighlightUpdate):
db_highlight = db.query(PatientHighlight).filter(PatientHighlight.id == highlight_id).first()
if db_highlight:
for key, value in highlight.dict().items():
setattr(db_highlight, key, value)
db.commit()
db.refresh(db_highlight)
def update_highlight(db: Session, highlight_id: int, highlight_data: PatientHighlightUpdate, modified_by: int):
db_highlight = db.query(PatientHighlight).filter(PatientHighlight.Id == highlight_id).first()

if not db_highlight or db_highlight.IsDeleted == "1":
raise HTTPException(status_code=404, detail="Highlight not found")

for key, value in highlight_data.dict(exclude_unset=True).items():
setattr(db_highlight, key, value)

db_highlight.ModifiedDate = datetime.now()
db_highlight.ModifiedById = modified_by
db.commit()
db.refresh(db_highlight)
return db_highlight

def delete_highlight(db: Session, highlight_id: int):
db_highlight = db.query(PatientHighlight).filter(PatientHighlight.id == highlight_id).first()
if db_highlight:
db.delete(db_highlight)
db.commit()
def delete_highlight(db: Session, highlight_id: int, modified_by: int):
db_highlight = db.query(PatientHighlight).filter(PatientHighlight.Id == highlight_id).first()

if not db_highlight or db_highlight.IsDeleted == "1":
raise HTTPException(status_code=404, detail="Highlight not found")

db_highlight.IsDeleted = "1"
db_highlight.ModifiedDate = datetime.now()
db_highlight.ModifiedById = modified_by
db.commit()
return db_highlight
67 changes: 67 additions & 0 deletions app/crud/patient_highlight_type_crud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from sqlalchemy.orm import Session
from ..models.patient_highlight_type_model import HighlightType
from ..schemas.patient_highlight_type import HighlightTypeCreate, HighlightTypeUpdate
from datetime import datetime

def get_all_highlight_types(db: Session):
return db.query(HighlightType).filter(HighlightType.IsDeleted == "0").all()

def get_highlight_type_by_id(db: Session, highlight_type_id: int):
return (
db.query(HighlightType)
.filter(HighlightType.HighlightTypeID == highlight_type_id, HighlightType.IsDeleted == "0")
.first()
)

def create_highlight_type(db: Session, highlight_type: HighlightTypeCreate, created_by: int):
db_highlight_type = HighlightType(
**highlight_type.model_dump(), CreatedById=created_by, ModifiedById=created_by
)
db.add(db_highlight_type)
db.commit()
db.refresh(db_highlight_type)
return db_highlight_type

def update_highlight_type(
db: Session,
highlight_type_id: int,
highlight_type: HighlightTypeUpdate,
modified_by: int,
):
db_highlight_type = (
db.query(HighlightType)
.filter(HighlightType.HighlightTypeID == highlight_type_id)
.first()
)

if db_highlight_type:
# Update other fields from the request body
for key, value in highlight_type.model_dump(exclude_unset=True).items():
setattr(db_highlight_type, key, value)

# Set UpdatedDateTime to the current datetime
db_highlight_type.UpdatedDateTime = datetime.now()

# Update the ModifiedById field
db_highlight_type.ModifiedById = modified_by

# Commit and refresh the object
db.commit()
db.refresh(db_highlight_type)
return db_highlight_type
return None

def delete_highlight_type(db: Session, highlight_type_id: int, modified_by: int):
db_highlight_type = (
db.query(HighlightType)
.filter(HighlightType.HighlightTypeID == highlight_type_id)
.first()
)

if db_highlight_type:
setattr(db_highlight_type, "IsDeleted", "1")
db_highlight_type.ModifiedById = modified_by

db.commit()
return db_highlight_type
return None
3 changes: 1 addition & 2 deletions app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
DB_URL_LOCAL = os.getenv("DB_URL_LOCAL")
DB_DRIVER_DEV = os.getenv("DB_DRIVER_DEV")

## TODO: CHANGE THIS BACK
DB_SERVER_DEV = "10.96.188.172" # os.getenv("DB_SERVER_DEV")
DB_SERVER_DEV = os.getenv("DB_SERVER_DEV")

DB_DATABASE_DEV = os.getenv("DB_DATABASE_DEV")
DB_DATABASE_PORT = os.getenv("DB_DATABASE_PORT")
Expand Down
51 changes: 32 additions & 19 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
patient_doctor_note_router,
patient_guardian_router,
patient_highlight_router,
patient_highlight_type_router,
patient_list_router,
patient_mobility_router,
patient_photo_router,
Expand Down Expand Up @@ -66,38 +67,50 @@ async def validation_exception_handler(request: Request, exc: RequestValidationE
# Base.metadata.drop_all(bind=engine)
Base.metadata.create_all(bind=engine)

# Include the routers with prefixes and tags
app.include_router(patient_router.router, prefix="/api/v1", tags=["patients"])
app.include_router(patient_allergy_mapping_router.router, prefix="/api/v1", tags=["Patient Allergies"])
app.include_router(allergy_type_router.router, prefix="/api/v1", tags=["Allergy Types"])
app.include_router(allergy_reaction_type_router.router, prefix="/api/v1", tags=["Allergy Reaction Types"])
API_VERSION_PREFIX = "/api/v1"

app.include_router(patient_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Patients"])

app.include_router(
allergy_type_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Allergy Types"]
)
app.include_router(
patient_assigned_dementia_list_router.router,
prefix="/api/v1",
tags=["Dementia List"]
allergy_reaction_type_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Allergy Reaction Types"]
)
app.include_router(
patient_assigned_dementia_mapping_router.router, prefix="/api/v1", tags=["Patient Assigned Dementia"]
patient_assigned_dementia_list_router.router, prefix=f"{API_VERSION_PREFIX}",tags=["Dementia List"]
)
app.include_router(
patient_doctor_note_router.router, prefix="/api/v1", tags=["doctor notes"]
patient_assigned_dementia_mapping_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Patient Assigned Dementia"]
)
app.include_router(patient_guardian_router.router, prefix="/api/v1", tags=["guardians"])
app.include_router(
patient_highlight_router.router, prefix="/api/v1", tags=["highlights"]
patient_allergy_mapping_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Patient Allergies"]
)
app.include_router(patient_list_router.router, prefix="/api/v1", tags=["patient lists"])
app.include_router(patient_mobility_router.router, prefix="/api/v1", tags=["mobility"])
app.include_router(patient_mobility_mapping_router.router, prefix="/api/v1", tags=["Patient Mobility Mapping"],
app.include_router(
patient_doctor_note_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Doctor Notes"]
)
app.include_router(patient_guardian_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Guardians"])

# highlights
app.include_router(
patient_highlight_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Highlights"]
)
app.include_router(
patient_highlight_type_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Highlights Type"]
)

app.include_router(
patient_list_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Patient Lists"]
)
app.include_router(patient_photo_router.router, prefix="/api/v1", tags=["photos"])
app.include_router(patient_mobility_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Mobility"])
app.include_router(patient_photo_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Photos"])
app.include_router(
patient_prescription_router.router, prefix="/api/v1", tags=["prescriptions"]
patient_prescription_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Prescriptions"]
)
app.include_router(
patient_social_history_router.router, prefix="/api/v1", tags=["social history"]
patient_social_history_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Social History"]
)
app.include_router(patient_vital_router.router, prefix="/api/v1", tags=["vitals"])
app.include_router(patient_vital_router.router, prefix=f"{API_VERSION_PREFIX}", tags=["Vitals"])

@app.get("/")
def read_root():
Expand Down
Loading

0 comments on commit cba4c08

Please sign in to comment.