-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'FBAPS-2-Patient-Highlights-API-CRUD' of https://github.…
…com/ntu-pear/PEAR_patient_service into FBAPS-2-Patient-Highlights-API-CRUD
- Loading branch information
Showing
26 changed files
with
1,032 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.