diff --git a/app/crud/patient_mobility_crud.py b/app/crud/patient_mobility_crud.py deleted file mode 100644 index af0dfe9..0000000 --- a/app/crud/patient_mobility_crud.py +++ /dev/null @@ -1,59 +0,0 @@ -from datetime import datetime, timezone -from sqlalchemy.orm import Session -from ..models.patient_mobility_model import PatientMobility -from ..schemas.patient_mobility import PatientMobilityCreate, PatientMobilityUpdate - -def get_patient_mobility(db: Session, patient_id: int): - return db.query(PatientMobility).filter(PatientMobility.patient_id == patient_id).all() - -def create_patient_mobility(db: Session, mobility: PatientMobilityCreate): - db_mobility = PatientMobility(**mobility.dict()) - db.add(db_mobility) - db.commit() - db.refresh(db_mobility) - return db_mobility - -# def update_patient_mobility(db: Session, mobility_id: int, mobility: PatientMobilityUpdate): -# db_mobility = db.query(PatientMobility).filter(PatientMobility.id == mobility_id).first() -# if db_mobility: -# for key, value in mobility.dict().items(): -# setattr(db_mobility, key, value) -# db.commit() -# db.refresh(db_mobility) -# return db_mobility - -def update_patient_mobility_by_patient_id(db: Session, patient_id: int, mobilityListId: int): - # Find the mobility record by patient_id - db_mobility = db.query(PatientMobility).filter(PatientMobility.patient_id == patient_id).first() - # If record is found, update the mobilityListId - if db_mobility: - db_mobility.mobilityListId = mobilityListId - db.commit() - db.refresh(db_mobility) - - return db_mobility - -# def delete_patient_mobility(db: Session, mobility_id: int, mobility: PatientMobilityUpdate): -# db_mobility = db.query(PatientMobility).filter(PatientMobility.id == mobility_id).first() -# if db_mobility: -# for key, value in mobility.dict().items(): -# setattr(db_mobility, key, value) -# db.commit() -# db.refresh(db_mobility) -# return db_mobility -def delete_patient_mobility(db: Session, mobilityListId: int): - # Find the mobility record by its ID - db_mobility = db.query(PatientMobility).filter(PatientMobility.mobilityListId == mobilityListId).first() - - if db_mobility: - # Set the 'active' status to 'N' to indicate it is no longer active - db_mobility.active = 0 - - # Update the modified date to the current time - db_mobility.modifiedDate = datetime.now(timezone.utc) # Fix the datetime.now usage - - # Commit the changes to the database - db.commit() - db.refresh(db_mobility) - - return db_mobility \ No newline at end of file diff --git a/app/crud/patient_mobility_list_crud.py b/app/crud/patient_mobility_list_crud.py new file mode 100644 index 0000000..4d29ce2 --- /dev/null +++ b/app/crud/patient_mobility_list_crud.py @@ -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 diff --git a/app/main.py b/app/main.py index 3a5fa04..9c9f355 100644 --- a/app/main.py +++ b/app/main.py @@ -1,7 +1,7 @@ from fastapi import FastAPI,Request from fastapi.exceptions import RequestValidationError from fastapi.responses import JSONResponse - +from sqlalchemy.orm import clear_mappers # Import clear_mappers from .database import engine, Base from app.routers import ( allergy_reaction_type_router, @@ -25,6 +25,8 @@ from dotenv import load_dotenv load_dotenv() +# clear_mappers() + app = FastAPI( title="NTU FYP PEAR PATIENT SERVICE", @@ -60,8 +62,7 @@ async def validation_exception_handler(request: Request, exc: RequestValidationE status_code=400, content={"detail": exc.errors(), "body": exc.body}, ) - - +# Base.metadata.drop_all(bind=engine) Base.metadata.create_all(bind=engine) # Include the routers with prefixes and tags diff --git a/app/models/patient_list_model.py b/app/models/patient_list_model.py index aedfdfa..552facf 100644 --- a/app/models/patient_list_model.py +++ b/app/models/patient_list_model.py @@ -22,6 +22,6 @@ class PatientList(Base): # allergy_reactions = relationship("PatientAllergy", back_populates="allergy_reaction_list", foreign_keys="[PatientAllergy.allergyReactionListId]") photos = relationship("PatientPhoto", back_populates="album_category") # dementia_assignments = relationship("PatientAssignedDementia", back_populates="dementia_type") - mobility_records = relationship("PatientMobility", back_populates="mobility_list") + # mobility_records = relationship("PatientMobility", back_populates="mobility_list") # prescriptions = relationship("PatientPrescription", back_populates="prescription_list") # social_history_mappings = relationship("PatientSocialHistoryListMapping", back_populates="list_entry") \ No newline at end of file diff --git a/app/models/patient_mobility_list_model.py b/app/models/patient_mobility_list_model.py index 1a3bc26..0eadb67 100644 --- a/app/models/patient_mobility_list_model.py +++ b/app/models/patient_mobility_list_model.py @@ -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" + ) diff --git a/app/models/patient_mobility_mapping_model.py b/app/models/patient_mobility_mapping_model.py new file mode 100644 index 0000000..32a82fe --- /dev/null +++ b/app/models/patient_mobility_mapping_model.py @@ -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") diff --git a/app/models/patient_mobility_model.py b/app/models/patient_mobility_model.py deleted file mode 100644 index 5349196..0000000 --- a/app/models/patient_mobility_model.py +++ /dev/null @@ -1,21 +0,0 @@ -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" - - id = Column(Integer, primary_key=True, index=True) # Changed to Integer - active = Column(Boolean, default=False, nullable=False) # used to check if record is active or not, substitute isDeleted column - patient_id = Column(Integer, ForeignKey('PATIENT.id'), nullable=False) # Ensure this field exists - mobilityListId = Column(Integer, ForeignKey('PATIENT_LIST.id')) # Changed to Integer - status = Column(String(255)) - - createdDate = Column(DateTime, nullable=False, default=DateTime) - modifiedDate = Column(DateTime, nullable=False, default=DateTime) - createdById = Column(Integer, nullable=False) # Changed to Integer - modifiedById = Column(Integer, nullable=False) # Changed to Integer - - patient = relationship("Patient", back_populates="mobility_records") - mobility_list = relationship("PatientList", back_populates="mobility_records") diff --git a/app/models/patient_mobility_patient_mobility_list_model.py b/app/models/patient_mobility_patient_mobility_list_model.py deleted file mode 100644 index f0414c6..0000000 --- a/app/models/patient_mobility_patient_mobility_list_model.py +++ /dev/null @@ -1,16 +0,0 @@ -from sqlalchemy import Column, Integer, String, DateTime, ForeignKey -from sqlalchemy.orm import relationship -from datetime import datetime, timezone -from app.database import Base - -class PatientMobility_MobilityList(Base): - __tablename__ = "PATIENT_MOBILITY_PATIENT_MOBILITY_LIST" - - id = Column(Integer, primary_key=True, index=True) - patient_id = Column(Integer, ForeignKey('PATIENT_MOBILITY.id'), nullable=False) - mobilityListId = Column(Integer, ForeignKey('PATIENT_MOBILITY_LIST_MAPPING.id'), nullable=False) - - createdDate = Column(DateTime, nullable=False, default=DateTime) - modifiedDate = Column(DateTime, nullable=False, default=DateTime) - createdById = Column(Integer, nullable=False) - modifiedById = Column(Integer, nullable=False) diff --git a/app/routers/patient_mobility_router.py b/app/routers/patient_mobility_router.py index d7925b2..14a8b84 100644 --- a/app/routers/patient_mobility_router.py +++ b/app/routers/patient_mobility_router.py @@ -1,46 +1,44 @@ from fastapi import APIRouter, Depends, HTTPException from sqlalchemy.orm import Session from ..database import get_db -from ..crud import patient_mobility_crud as crud_mobility -from ..schemas import patient_mobility as schemas_mobility +from ..crud import patient_mobility_list_crud as crud_mobility_list, patient_mobility_list_crud as crud_mobility +from ..schemas import patient_mobility_mapping as schemas_mobility +from ..schemas import patient_mobility_list as schemas_mobility_list router = APIRouter() -@router.get("/Mobility/PatientMobility", response_model=list[schemas_mobility.PatientMobility]) -def get_patient_mobility(patient_id: int, db: Session = Depends(get_db)): - return crud_mobility.get_patient_mobility(db, patient_id) +# Routes for PATIENT_MOBILITY_LIST -@router.post("/Mobility/add", response_model=schemas_mobility.PatientMobility) -def create_patient_mobility(mobility: schemas_mobility.PatientMobilityCreate, db: Session = Depends(get_db)): - return crud_mobility.create_patient_mobility(db, mobility) +# Get all mobility list entries +@router.get("/Mobility/List", response_model=list[schemas_mobility_list.PatientMobilityList]) +def get_all_mobility_lists(db: Session = Depends(get_db)): + return crud_mobility_list.get_all_mobility_list_entries(db) -# @router.put("/Mobility/update", response_model=schemas_mobility.PatientMobility) -# def update_patient_mobility(mobility_id: int, mobility: schemas_mobility.PatientMobilityUpdate, db: Session = Depends(get_db)): -# db_mobility = crud_mobility.update_patient_mobility(db, mobility_id, mobility) -# if not db_mobility: -# raise HTTPException(status_code=404, detail="Patient mobility not found") -# return db_mobility -# Ask if another other updates are needed -@router.put("/Mobility/update", response_model=schemas_mobility.PatientMobility) -def update_patient_mobility(patient_id: int, mobilityListId: int, db: Session = Depends(get_db)): - db_mobility = crud_mobility.update_patient_mobility_by_patient_id(db, patient_id, mobilityListId) - if not db_mobility: - raise HTTPException(status_code=404, detail="Patient mobility not found") - - return db_mobility +# Get a single mobility list entry by ID +@router.get("/Mobility/List/{mobility_list_id}", response_model=schemas_mobility_list.PatientMobilityList) +def get_mobility_list_by_id(mobility_list_id: int, db: Session = Depends(get_db)): + mobility_list = crud_mobility_list.get_mobility_list_entry_by_id(db, mobility_list_id) + if not mobility_list: + raise HTTPException(status_code=404, detail="Mobility list entry not found") + return mobility_list +# Create a new mobility list entry +@router.post("/Mobility/List", response_model=schemas_mobility_list.PatientMobilityList) +def create_mobility_list_entry(mobility_list: schemas_mobility_list.PatientMobilityListCreate, db: Session = Depends(get_db)): + return crud_mobility_list.create_mobility_list_entry(db, mobility_list, created_by=1) # Replace 1 with dynamic user ID if needed -# @router.put("/Mobility/delete", response_model=schemas_mobility.PatientMobility) -# def delete_patient_mobility(mobility_id: int, mobility: schemas_mobility.PatientMobilityUpdate, db: Session = Depends(get_db)): -# db_mobility = crud_mobility.delete_patient_mobility(db, mobility_id, mobility) -# if not db_mobility: -# raise HTTPException(status_code=404, detail="Patient mobility not found") -# return db_mobility -@router.put("/Mobility/delete", response_model=schemas_mobility.PatientMobility) -def delete_patient_mobility(mobilityListId: int, db: Session = Depends(get_db)): - db_mobility = crud_mobility.delete_patient_mobility(db, mobilityListId) - - if not db_mobility: - raise HTTPException(status_code=404, detail="Patient mobility not found") - - return db_mobility \ No newline at end of file +# Update a mobility list entry +@router.put("/Mobility/List/{mobility_list_id}", response_model=schemas_mobility_list.PatientMobilityList) +def update_mobility_list_entry(mobility_list_id: int, mobility_list: schemas_mobility_list.PatientMobilityListUpdate, db: Session = Depends(get_db)): + updated_entry = crud_mobility_list.update_mobility_list_entry(db, mobility_list_id, mobility_list, modified_by=1) # Replace 1 with dynamic user ID if needed + if not updated_entry: + raise HTTPException(status_code=404, detail="Mobility list entry not found") + return updated_entry + +# Soft delete a mobility list entry +@router.delete("/Mobility/List/delete/{mobility_list_id}", response_model=schemas_mobility_list.PatientMobilityList) +def delete_mobility_list_entry(mobility_list_id: int, db: Session = Depends(get_db)): + deleted_entry = crud_mobility_list.delete_mobility_list_entry(db, mobility_list_id, modified_by=1) # Replace 1 with dynamic user ID if needed + if not deleted_entry: + raise HTTPException(status_code=404, detail="Mobility list entry not found") + return deleted_entry diff --git a/app/schemas/patient_mobility_list.py b/app/schemas/patient_mobility_list.py index 6f3ee73..f152dc8 100644 --- a/app/schemas/patient_mobility_list.py +++ b/app/schemas/patient_mobility_list.py @@ -3,11 +3,13 @@ from typing import Optional class PatientMobilityListBase(BaseModel): - mobilityListId: int - IsDeleted: bool - createdDate: datetime - modifiedDate: datetime - value: str + MobilityListId: int + IsDeleted: int + CreatedDateTime: datetime + ModifiedDateTime: datetime + CreatedById: int + ModifiedById: int + Value: str class PatientMobilityListCreate(PatientMobilityListBase): pass @@ -16,7 +18,7 @@ class PatientMobilityListUpdate(PatientMobilityListBase): pass class PatientMobilityList(PatientMobilityListBase): - id: int + pass class Config: from_attributes = True diff --git a/app/schemas/patient_mobility.py b/app/schemas/patient_mobility_mapping.py similarity index 93% rename from app/schemas/patient_mobility.py rename to app/schemas/patient_mobility_mapping.py index c6175dc..c54fc01 100644 --- a/app/schemas/patient_mobility.py +++ b/app/schemas/patient_mobility_mapping.py @@ -1,29 +1,29 @@ -from pydantic import BaseModel -from datetime import datetime -from typing import Optional - -class PatientMobilityBase(BaseModel): - active: int - patient_id: int - mobilityListId: int - status: Optional[str] = None - -class PatientMobilityCreate(PatientMobilityBase): - createdDate: datetime - modifiedDate: datetime - createdById: int - modifiedById: int - -class PatientMobilityUpdate(PatientMobilityBase): - modifiedDate: datetime - modifiedById: int - -class PatientMobility(PatientMobilityBase): - id: int - createdDate: datetime - modifiedDate: datetime - createdById: int - modifiedById: int - - class Config: - from_attributes = True +from pydantic import BaseModel +from datetime import datetime +from typing import Optional + +class PatientMobilityBase(BaseModel): + IsDeleted: int + patient_id: int + mobilityListId: int + status: Optional[str] = None + +class PatientMobilityCreate(PatientMobilityBase): + createdDate: datetime + modifiedDate: datetime + createdById: int + modifiedById: int + +class PatientMobilityUpdate(PatientMobilityBase): + modifiedDate: datetime + modifiedById: int + +class PatientMobility(PatientMobilityBase): + id: int + createdDate: datetime + modifiedDate: datetime + createdById: int + modifiedById: int + + class Config: + from_attributes = True diff --git a/app/schemas/patient_mobility_patient_mobility_list.py b/app/schemas/patient_mobility_patient_mobility_list.py deleted file mode 100644 index 7170e24..0000000 --- a/app/schemas/patient_mobility_patient_mobility_list.py +++ /dev/null @@ -1,22 +0,0 @@ -from pydantic import BaseModel -from datetime import datetime - -class PatientMobility_MobilityListBase(BaseModel): - patient_id: int - mobilityListId: int - createdDate: datetime - modifiedDate: datetime - createdById: int - modifiedById: int - -class PatientMobility_MobilityListCreate(PatientMobility_MobilityListBase): - pass - -class PatientMobility_MobilityListUpdate(PatientMobility_MobilityListBase): - pass - -class PatientMobility_MobilityList(PatientMobility_MobilityListBase): - id: int - - class Config: - from_attributes = True diff --git a/app/schemas/patient_social_history.py b/app/schemas/patient_social_history.py index 2785668..cc0dea5 100644 --- a/app/schemas/patient_social_history.py +++ b/app/schemas/patient_social_history.py @@ -3,7 +3,7 @@ from typing import Optional class PatientSocialHistoryBase(BaseModel): - active: Optional[str] = 'Y' + IsDeleted: Optional[str] = '0' patientId: int sexuallyActive: Optional[str] = None secondHandSmoker: Optional[str] = None diff --git a/create_table_dev.py b/create_table_dev.py index 43cdad9..af37859 100644 --- a/create_table_dev.py +++ b/create_table_dev.py @@ -1,4 +1,8 @@ +from sqlalchemy.orm import clear_mappers from app.database import engine, Base + +clear_mappers() + from app.models import ( patient_allergy_mapping_model, # Import all models to ensure they are registered patient_allocation_model, @@ -7,7 +11,7 @@ patient_guardian_model, patient_highlight_model, patient_list_model, - patient_mobility_model, + patient_mobility_mapping_model, patient_model, patient_photo_model, patient_prescription_list_model, @@ -16,7 +20,6 @@ patient_social_history_list_mapping_model, patient_vital_model, patient_mobility_list_model, - patient_mobility_patient_mobility_list_model, patient_list_language_model, patient_guardian_relationship_mapping_model, patient_patient_guardian_model, diff --git a/sql/3_patient_mobility_05_10_2024/insert_mobility_record.sql b/sql/3_patient_mobility_05_10_2024/insert_mobility_record.sql deleted file mode 100644 index 5824a87..0000000 --- a/sql/3_patient_mobility_05_10_2024/insert_mobility_record.sql +++ /dev/null @@ -1,12 +0,0 @@ -SET IDENTITY_INSERT [patient_service_dev].[dbo].[PATIENT_MOBILITY] ON; - -INSERT INTO [patient_service_dev].[dbo].[PATIENT_MOBILITY] - (id, active, patient_id, mobilityListId, status, createdDate, modifiedDate, createdById, modifiedById) -VALUES - (1, 1, 1, 1, 'Active', '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 1, 1), - (2, 1, 2, 2, 'Active', '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 2, 2), - (3, 1, 3, 3, 'Inactive', '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 3, 3), - (4, 1, 4, 4, 'Active', '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 4, 4), - (5, 1, 5, 5, 'Inactive', '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 5, 5); - -SET IDENTITY_INSERT [patient_service_dev].[dbo].[PATIENT_MOBILITY] OFF; diff --git a/sql/3_patient_mobility_05_10_2024/insert_patient_mobility_list.sql b/sql/3_patient_mobility_05_10_2024/insert_patient_mobility_list.sql index f90e96a..64cb9d2 100644 --- a/sql/3_patient_mobility_05_10_2024/insert_patient_mobility_list.sql +++ b/sql/3_patient_mobility_05_10_2024/insert_patient_mobility_list.sql @@ -1,18 +1,11 @@ -INSERT INTO [patient_service_dev].[dbo].[PATIENT_MOBILITY_LIST_MAPPING] - (mobilityListId, IsDeleted, createdDate, modifiedDate, value) +-- Insert realistic data into PATIENT_MOBILITY_LIST +INSERT INTO [dbo].[PATIENT_MOBILITY_LIST] (IsDeleted, Value, CreatedDateTime, ModifiedDateTime, CreatedById, ModifiedById) VALUES - (1, 0, '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 'Mobility List 1'), - (2, 0, '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 'Mobility List 2'), - (3, 0, '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 'Mobility List 3'), - (4, 0, '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 'Mobility List 4'), - (5, 0, '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 'Mobility List 5'); ---- --- PATIENT_MOBILITY_PATIENT_MOBILITY_LIST -INSERT INTO [patient_service_dev].[dbo].[PATIENT_MOBILITY_PATIENT_MOBILITY_LIST] - (patient_id, mobilityListId, createdDate, modifiedDate, createdById, modifiedById) -VALUES - (1, 1, '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 1, 1), - (2, 2, '2021-01-02 00:00:00.000', '2021-01-02 00:00:00.000', 2, 2), - (3, 3, '2021-01-03 00:00:00.000', '2021-01-03 00:00:00.000', 3, 3), - (4, 4, '2021-01-04 00:00:00.000', '2021-01-04 00:00:00.000', 4, 4), - (5, 5, '2021-01-05 00:00:00.000', '2021-01-05 00:00:00.000', 5, 5); + ('0', 'Cane', GETDATE(), GETDATE(), 1, 1), + ('0', 'Crutches', GETDATE(), GETDATE(), 1, 1), + ('0', 'Walkers', GETDATE(), GETDATE(), 1, 1), + ('0', 'Gait trainers', GETDATE(), GETDATE(), 1, 1), + ('0', 'Scooter', GETDATE(), GETDATE(), 1, 1), + ('0', 'Wheelchairs', GETDATE(), GETDATE(), 1, 1); + + diff --git a/sql/3_patient_mobility_05_10_2024/insert_patient_mobility_mapping.sql b/sql/3_patient_mobility_05_10_2024/insert_patient_mobility_mapping.sql new file mode 100644 index 0000000..7ffff96 --- /dev/null +++ b/sql/3_patient_mobility_05_10_2024/insert_patient_mobility_mapping.sql @@ -0,0 +1,8 @@ +-- Insert realistic data into PATIENT_MOBILITY_MAPPING +INSERT INTO [dbo].[PATIENT_MOBILITY_MAPPING] (PatientID, MobilityListId, MobilityRemarks, IsRecovered, IsDeleted, CreatedDateTime, ModifiedDateTime, CreatedById, ModifiedById) +VALUES + (1, 1, 'Not Recovered', 0, '0', GETDATE(), GETDATE(), 1, 1), + (2, 2, 'Not Recovered', 0, '0', GETDATE(), GETDATE(), 1, 1), + (3, 3, 'Not Recovered', 0, '0', GETDATE(), GETDATE(), 1, 1), + (4, 4, 'Not Recovered', 0, '0', GETDATE(), GETDATE(), 1, 1), + (5, 5, 'Not Recovered', 0, '0', GETDATE(), GETDATE(), 1, 1); \ No newline at end of file diff --git a/sql/3_patient_mobility_05_10_2024/insert_social_history.sql b/sql/3_patient_mobility_05_10_2024/insert_social_history.sql deleted file mode 100644 index 7466569..0000000 --- a/sql/3_patient_mobility_05_10_2024/insert_social_history.sql +++ /dev/null @@ -1,29 +0,0 @@ --- Turn IDENTITY_INSERT ON for the PATIENT_SOCIAL_HISTORY table -SET IDENTITY_INSERT patient_service_dev.dbo.PATIENT_SOCIAL_HISTORY ON; - --- Insert data into the PATIENT_SOCIAL_HISTORY table -INSERT INTO patient_service_dev.dbo.PATIENT_SOCIAL_HISTORY ( - id, - active, - patientId, - sexuallyActive, - secondHandSmoker, - alcoholUse, - caffeineUse, - tobaccoUse, - drugUse, - exercise, - createdDate, - modifiedDate, - createdById, - modifiedById -) VALUES -(1, '1', 1, '1', '1', '0', '1', '0', '1', '1', '2021-01-01 00:00:00.000', '2024-04-29 15:35:57.350', 6, 10), -(2, '0', 2, '0', '0', '1', '0', '0', '0', '1', '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 1, 2), -(3, '1', 3, '1', '1', '0', '0', '0', '0', '0', '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 2, 2), -(4, '0', 4, '0', '0', '0', '0', '0', '0', '0', '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 4, 2), -(5, '1', 5, '0', '0', '0', '0', '1', '1', '1', '2021-01-01 00:00:00.000', '2021-01-01 00:00:00.000', 5, 2); - --- Turn IDENTITY_INSERT OFF for the PATIENT_SOCIAL_HISTORY table ---SET IDENTITY_INSERT fyp_dev_john.dbo.PATIENT_SOCIAL_HISTORY OFF; --- SELECT id FROM fyp_dev_john.dbo.PATIENT;