-
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 'main' into feat/vital-threshold
- Loading branch information
Showing
27 changed files
with
584 additions
and
463 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,97 @@ | ||
from sqlalchemy.orm import Session | ||
from datetime import datetime | ||
from fastapi import HTTPException | ||
from ..models.patient_mobility_list_model import PatientMobilityList | ||
from ..models.patient_mobility_mapping_model import PatientMobility | ||
from ..schemas.patient_mobility_list import ( | ||
PatientMobilityListCreate, | ||
PatientMobilityListUpdate, | ||
) | ||
from ..schemas.patient_mobility_mapping import ( | ||
PatientMobilityCreate, | ||
PatientMobilityUpdate, | ||
) | ||
|
||
# CRUD for PATIENT_MOBILITY_LIST | ||
|
||
# Get all mobility list entries | ||
def get_all_mobility_list_entries(db: Session): | ||
try: | ||
entries = db.query(PatientMobilityList).filter(PatientMobilityList.IsDeleted == "0").all() | ||
if not entries: | ||
raise HTTPException(status_code=404, detail="No mobility list entries found.") | ||
return entries | ||
except Exception as e: | ||
raise HTTPException(status_code=500, detail=f"Error querying mobility list: {str(e)}") | ||
|
||
|
||
# Get a single mobility list entry by ID | ||
def get_mobility_list_entry_by_id(db: Session, mobility_list_id: int): | ||
entry = db.query(PatientMobilityList).filter( | ||
PatientMobilityList.MobilityListId == mobility_list_id, | ||
PatientMobilityList.IsDeleted == '0' | ||
).first() | ||
if not entry: | ||
raise HTTPException(status_code=404, detail=f"Mobility list entry with ID {mobility_list_id} not found.") | ||
return entry | ||
|
||
# Create a new mobility list entry | ||
def create_mobility_list_entry(db: Session, mobility_list_data: PatientMobilityListCreate, created_by: int): | ||
new_entry = PatientMobilityList( | ||
**mobility_list_data.dict(exclude={"CreatedDateTime", "ModifiedDateTime", "CreatedById", "ModifiedById"}), # Corrected set syntax | ||
CreatedDateTime=datetime.utcnow(), | ||
ModifiedDateTime=datetime.utcnow(), | ||
CreatedById=created_by, | ||
ModifiedById=created_by, | ||
) | ||
db.add(new_entry) | ||
db.commit() | ||
db.refresh(new_entry) | ||
return new_entry | ||
|
||
# Update a mobility list entry | ||
def update_mobility_list_entry( | ||
db: Session, mobility_list_id: int, mobility_list_data: PatientMobilityListUpdate, modified_by: int | ||
): | ||
db_entry = db.query(PatientMobilityList).filter( | ||
PatientMobilityList.MobilityListId == mobility_list_id, | ||
PatientMobilityList.IsDeleted == '0', | ||
).first() | ||
|
||
if db_entry: | ||
for key, value in mobility_list_data.dict(exclude={"MobilityListId"}).items(): # Exclude MobilityListId | ||
setattr(db_entry, key, value) | ||
|
||
db_entry.ModifiedDateTime = datetime.utcnow() | ||
db_entry.ModifiedById = modified_by | ||
|
||
db.commit() | ||
db.refresh(db_entry) | ||
return db_entry | ||
return None | ||
|
||
# Soft delete a mobility list entry (set IsDeleted to '1') | ||
|
||
def delete_mobility_list_entry(db: Session, mobility_list_id: int, modified_by: int): | ||
# Query for the entry to be deleted | ||
db_entry = db.query(PatientMobilityList).filter( | ||
PatientMobilityList.MobilityListId == mobility_list_id, | ||
PatientMobilityList.IsDeleted == "0" # Use boolean False for filtering | ||
).first() | ||
|
||
# Raise an exception if the entry is not found | ||
if not db_entry: | ||
raise HTTPException( | ||
status_code=404, | ||
detail=f"Mobility list entry with ID {mobility_list_id} not found." | ||
) | ||
|
||
# Soft delete the entry by setting IsDeleted to True | ||
db_entry.IsDeleted = "1" # Use boolean True | ||
db_entry.ModifiedDateTime = datetime.utcnow() | ||
db_entry.ModifiedById = modified_by | ||
|
||
# Commit the transaction to save the changes | ||
db.commit() | ||
db.refresh(db_entry) # Refresh the entry to return the updated instance | ||
return db_entry |
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,89 @@ | ||
from app.models.patient_mobility_list_model import PatientMobilityList | ||
from app.models.patient_model import Patient | ||
from sqlalchemy.orm import Session | ||
from datetime import datetime | ||
from fastapi import HTTPException | ||
from ..models.patient_mobility_mapping_model import PatientMobility | ||
from ..schemas.patient_mobility_mapping import ( | ||
PatientMobilityCreate, | ||
PatientMobilityUpdate, | ||
) | ||
|
||
# Get all mobility entries | ||
def get_all_mobility_entries(db: Session): | ||
return db.query(PatientMobility).filter(PatientMobility.IsDeleted == False).all() | ||
|
||
# Get a single mobility entry by ID | ||
def get_mobility_entry_by_id(db: Session, mobility_id: int): | ||
entry = db.query(PatientMobility).filter( | ||
PatientMobility.MobilityID == mobility_id, | ||
PatientMobility.IsDeleted == False | ||
).first() | ||
if not entry: | ||
raise HTTPException(status_code=404, detail=f"Mobility entry with ID {mobility_id} not found.") | ||
return entry | ||
|
||
# Create a new mobility entry | ||
def create_mobility_entry(db: Session, mobility_data: PatientMobilityCreate, created_by: int): | ||
# Validate PatientID | ||
patient = db.query(Patient).filter(Patient.id == mobility_data.PatientID).first() | ||
if not patient: | ||
raise HTTPException(status_code=400, detail="Invalid PatientID. No matching patient found.") | ||
|
||
# Validate MobilityListId | ||
mobility_list = db.query(PatientMobilityList).filter(PatientMobilityList.MobilityListId == mobility_data.MobilityListId).first() | ||
if not mobility_list: | ||
raise HTTPException(status_code=400, detail="Invalid MobilityListId. No matching mobility list found.") | ||
|
||
# Create entry | ||
new_entry = PatientMobility( | ||
**mobility_data.dict(), | ||
CreatedDateTime=datetime.utcnow(), | ||
ModifiedDateTime=datetime.utcnow(), | ||
CreatedById=created_by, | ||
ModifiedById=created_by, | ||
) | ||
db.add(new_entry) | ||
db.commit() | ||
db.refresh(new_entry) | ||
return new_entry | ||
|
||
|
||
# Update an existing mobility entry | ||
def update_mobility_entry( | ||
db: Session, mobility_id: int, mobility_data: PatientMobilityUpdate, modified_by: int | ||
): | ||
db_entry = db.query(PatientMobility).filter( | ||
PatientMobility.MobilityID == mobility_id, | ||
PatientMobility.IsDeleted == False, | ||
).first() | ||
|
||
if not db_entry: | ||
raise HTTPException(status_code=404, detail=f"Mobility entry with ID {mobility_id} not found.") | ||
|
||
for key, value in mobility_data.dict(exclude_unset=True).items(): | ||
setattr(db_entry, key, value) | ||
|
||
db_entry.ModifiedDateTime = datetime.utcnow() | ||
db_entry.ModifiedById = modified_by | ||
|
||
db.commit() | ||
db.refresh(db_entry) | ||
return db_entry | ||
|
||
# Soft delete a mobility entry | ||
def delete_mobility_entry(db: Session, mobility_id: int, modified_by: int): | ||
db_entry = db.query(PatientMobility).filter( | ||
PatientMobility.MobilityID == mobility_id, | ||
PatientMobility.IsDeleted == False, | ||
).first() | ||
|
||
if not db_entry: | ||
raise HTTPException(status_code=404, detail=f"Mobility entry with ID {mobility_id} not found.") | ||
|
||
db_entry.IsDeleted = True | ||
db_entry.ModifiedDateTime = datetime.utcnow() | ||
db_entry.ModifiedById = modified_by | ||
|
||
db.commit() | ||
return db_entry |
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,16 +1,21 @@ | ||
from sqlalchemy import Column, Integer, String, DateTime, Boolean, ForeignKey | ||
from sqlalchemy.orm import relationship | ||
from datetime import datetime, timezone | ||
from datetime import datetime | ||
from app.database import Base | ||
|
||
class PatientMobilityList(Base): | ||
__tablename__ = "PATIENT_MOBILITY_LIST_MAPPING" | ||
__tablename__ = "PATIENT_MOBILITY_LIST" | ||
|
||
id = Column(Integer, primary_key=True, index=True) | ||
mobilityListId = Column(Integer, ForeignKey('PATIENT_MOBILITY_LIST_MAPPING.id'), nullable=False) | ||
IsDeleted = Column(Boolean, default=False, nullable=False) | ||
createdDate = Column(DateTime, nullable=False, default=DateTime) | ||
modifiedDate = Column(DateTime, nullable=False, default=DateTime) | ||
value = Column(String(255), nullable=False) | ||
MobilityListId = Column(Integer, primary_key=True, index=True) | ||
IsDeleted = Column(Integer, default=False, nullable=False) | ||
CreatedDateTime = Column(DateTime, nullable=False, default=datetime.utcnow) | ||
ModifiedDateTime = Column(DateTime, nullable=False, default=datetime.utcnow) | ||
CreatedById = Column(Integer, nullable=False) # Changed to Integer | ||
ModifiedById = Column(Integer, nullable=False) # Changed to Integer | ||
Value = Column(String(255), nullable=False) | ||
|
||
mobility_records = relationship("PatientMobility", secondary="PATIENT_MOBILITY_PATIENT_MOBILITY_LIST", back_populates="mobility_lists") | ||
mobility_records = relationship( | ||
"PatientMobility", | ||
back_populates="mobility_list", | ||
primaryjoin="PatientMobility.MobilityListId == PatientMobilityList.MobilityListId" | ||
) |
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,27 @@ | ||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Boolean | ||
from sqlalchemy.orm import relationship | ||
from datetime import datetime, timezone | ||
from app.database import Base | ||
|
||
class PatientMobility(Base): | ||
__tablename__ = "PATIENT_MOBILITY_MAPPING" | ||
|
||
MobilityID = Column(Integer, primary_key=True, index=True) | ||
PatientID = Column(Integer, ForeignKey('PATIENT.id'), nullable=False) | ||
MobilityListId = Column(Integer, ForeignKey('PATIENT_MOBILITY_LIST.MobilityListId'), nullable=False) # Foreign Key | ||
MobilityRemarks = Column(String(255)) | ||
IsRecovered = Column(Boolean, default=False, nullable=False) | ||
IsDeleted = Column(Boolean, default=False, nullable=False) | ||
CreatedDateTime = Column(DateTime, nullable=False, default=datetime.utcnow) | ||
ModifiedDateTime = Column(DateTime, nullable=False, default=datetime.utcnow) | ||
CreatedById = Column(Integer, nullable=False) | ||
ModifiedById = Column(Integer, nullable=False) | ||
|
||
mobility_list = relationship( | ||
"PatientMobilityList", | ||
back_populates="mobility_records", | ||
primaryjoin="PatientMobility.MobilityListId == PatientMobilityList.MobilityListId" | ||
) | ||
|
||
# Relationship with Patient | ||
patient = relationship("Patient", back_populates="mobility_records") |
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
app/models/patient_mobility_patient_mobility_list_model.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.