Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update attendance record model #225

Merged
merged 13 commits into from
Dec 12, 2023
2 changes: 1 addition & 1 deletion backend/python/app/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def init_app(app):
from .access_type import AccessType
from .attendance_records import AttendanceRecords
from .attendance_records import AttendanceRecords, Transportation, VisitingMember
from .attendance_sheets import AttendanceSheets
from .branch import Branch
from .caregiver import Caregiver, relationship_to_child_enum
Expand Down
91 changes: 84 additions & 7 deletions backend/python/app/models/attendance_records.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
from sqlalchemy import *
from sqlalchemy.dialects.postgresql import ARRAY

from . import db
from .base_mixin import BaseMixin

supervision_enum = db.Enum("FULL", "PARTIAL", "UNSUPERVISED", name="supervision")

attendance_enum = db.Enum("PRESENT", "CANCELLED", "NO_SHOW", name="attendance")
attendance_enum = db.Enum("PRESENT", "CANCELLED", "NO_SHOW", name="visitAttendance")

attending_family_enum = db.Enum("MOM", "DAD", name="attending_family")
attending_family_enum = db.Enum(
"FOSTER_CAREGIVER",
"KINSHIP_CAREGIVER",
"BIOLOGICAL_FAMILY",
"ADOPTIVE_PARENT",
"FOSTER_PARENT",
"BIOLOGICAL_PARENT",
"STEP_PARENT",
"MATERNAL_GRANDPARENT",
"PATERNAL_GRANDPARENT",
"SIBLING",
"STEP_SIBLING",
"HALF_SIBLING",
"UNCLE/AUNT",
"OTHER_RELATIVE",
"OTHER",
name="visitorRelationship",
)


class AttendanceRecords(db.Model, BaseMixin):
Expand All @@ -15,18 +35,75 @@ class AttendanceRecords(db.Model, BaseMixin):
attendance_sheet_id = db.Column(
db.Integer, db.ForeignKey("attendance_sheets.id"), nullable=False
)
supervision = db.Column(supervision_enum, nullable=False)
date = db.Column(db.String, nullable=False)

visit_date = db.Column(db.String, nullable=False)
visit_day = db.Column(db.String, nullable=False)
visit_supervision = db.Column(supervision_enum, nullable=False)
start_time = db.Column(db.String, nullable=False)
end_time = db.Column(db.String, nullable=False)
location = db.Column(db.String, nullable=False)
attendance = db.Column(attendance_enum, nullable=False)
attending_family = db.Column(attending_family_enum, nullable=False)

visiting_members = db.relationship(
"VisitingMember", backref="associated_record", cascade="all, delete"
)
transportation = db.relationship(
"Transportation", backref="associated_record", cascade="all, delete"
)

staff_transport_time_min = db.Column(db.Integer, nullable=True)
driver_transport_time_min = db.Column(db.Integer, nullable=True)
foster_parent_transport_time_min = db.Column(db.Integer, nullable=True)

notes = db.Column(db.String, nullable=True)
child_family_support_worker_id = db.Column(
db.Integer, db.ForeignKey("users.id"), nullable=True
)
comments = db.Column(db.String, nullable=True)

user = db.relationship("User")


class VisitingMember(db.Model):
__tablename__ = "visiting_members"

id = db.Column(db.Integer, primary_key=True, nullable=False)
attendance_record_id = db.Column(
db.Integer, db.ForeignKey("attendance_records.id"), nullable=False
)

visitor_relationship = db.Column(attending_family_enum, nullable=False)
description = db.Column(db.String, nullable=False)
visiting_member_name = db.Column(db.String, nullable=False)
visit_attendance = db.Column(attendance_enum, nullable=False)
reason_for_absence = db.Column(db.String, nullable=True)


class Transportation(db.Model):
__tablename__ = "transportation"

id = db.Column(db.Integer, primary_key=True, nullable=False)
attendance_record_id = db.Column(
db.Integer, db.ForeignKey("attendance_records.id"), nullable=False
)

guardian = db.Column(db.String, nullable=False)
name = db.Column(db.String, nullable=False)
duration = db.Column(db.Integer, nullable=False)

# meta = MetaData()
# visitingMembers = Table('visiting_members', meta,
# Column('id', Integer, primary_key=True, nullable=False),
# Column('attendance_record_id', Integer, ForeignKey("attendance_records.id"), nullable=False),
# Column('visitor_relationship', attending_family_enum, nullable=False),
# Column('description', String, nullable=False),
# Column('visiting_member_name', String, nullable=False),
# Column('visit_attendance', attendance_enum, nullable=False),
# Column('reason_for_absence', String, nullable=True)
# )

# transportation = Table('transportation', meta,
# Column('id', Integer, primary_key=True, nullable=False),
# Column('attendance_record_id', Integer, ForeignKey("attendance_records.id"), nullable=False),
# Column('guardian', String, nullable=False),
# Column('name', String, nullable=False),
# Column('duration', Integer, nullable=False)
# )
137 changes: 109 additions & 28 deletions backend/python/app/resources/attendance_records_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,65 @@ class Attendance(Enum):


class Attending_family(Enum):
# add more types
MOM = "MOM"
DAD = "DAD"
FOSTER_CAREGIVER = "FOSTER_CAREGIVER"
KINSHIP_CAREGIVER = "KINSHIP_CAREGIVER"
BIOLOGICAL_FAMILY = "BIOLOGICAL_FAMILY"
ADOPTIVE_PARENT = "ADOPTIVE_PARENT"
FOSTER_PARENT = "FOSTER_PARENT"
BIOLOGICAL_PARENT = "BIOLOGICAL_PARENT"
STEP_PARENT = "STEP_PARENT"
MATERNAL_GRANDPARENT = "MATERNAL_GRANDPARENT"
PATERNAL_GRANDPARENT = "PATERNAL_GRANDPARENT"
SIBLING = "SIBLING"
STEP_SIBLING = "STEP_SIBLING"
HALF_SIBLING = "HALF_SIBLING"
UNCLE_AUNT = "UNCLE/AUNT"
OTHER_RELATIVE = "OTHER_RELATIVE"
OTHER = "OTHER"


class AttendanceRecordsDTO:
def __init__(self, **kwargs):
self.id = kwargs.get("id")
self.attendance_sheet_id = kwargs.get("attendance_sheet_id")
self.supervision = kwargs.get("supervision")
self.date = kwargs.get("date")
self.visit_date = kwargs.get("visit_date")
self.visit_day = kwargs.get("visit_day")
self.visit_supervision = kwargs.get("visit_supervision")
self.start_time = kwargs.get("start_time")
self.end_time = kwargs.get("end_time")
self.location = kwargs.get("location")
self.attendance = kwargs.get("attendance")
self.attending_family = kwargs.get("attending_family")
self.visiting_members = kwargs.get("visiting_members")
self.transportation = kwargs.get("transportation")
self.staff_transport_time_min = kwargs.get("staff_transport_time_min")
self.driver_transport_time_min = kwargs.get("driver_transport_time_min")
self.foster_parent_transport_time_min = kwargs.get(
"foster_parent_transport_time_min"
)
self.notes = kwargs.get("notes")
self.child_family_support_worker_id = kwargs.get(
"child_family_support_worker_id"
)
self.comments = kwargs.get("comments")
self.user = kwargs.get("user")


class VisitingMemberDTO:
def __init__(self, **kwargs):
self.id = kwargs.get("id")
self.attendance_record_id = kwargs.get("attendance_record_id")
self.visitor_relationship = kwargs.get("visitor_relationship")
self.description = kwargs.get("description")
self.visiting_member_name = kwargs.get("visiting_member_name")
self.visit_attendance = kwargs.get("visit_attendance")
self.reason_for_absence = kwargs.get("reason_for_absence")


class TransportationDTO:
def __init__(self, **kwargs):
self.id = kwargs.get("id")
self.attendance_record_id = kwargs.get("attendance_record_id")
self.guardian = kwargs.get("guardian")
self.name = kwargs.get("name")
self.duration = kwargs.get("duration")


class CreateAttendanceRecordsDTO(AttendanceRecordsDTO):
Expand All @@ -51,16 +85,20 @@ def validate(self):
if not self.attendance_sheet_id or type(self.attendance_sheet_id) is not int:
error_list.append("attendance_sheet_id is not an integer")

if type(self.supervision) is str:
if not isinstance(self.supervision, Supervision):
if type(self.visit_date) is not str:
# add additional datetime validation
error_list.append("date must be a string")

if type(self.visit_day) is not str:
# add additional datetime validation
error_list.append("day must be a string")

if type(self.visit_supervision) is str:
if not isinstance(self.visit_supervision, Supervision):
error_list.append("must be a valid supervision")
else:
error_list.append("supervision must be a string")

if type(self.date) is not str:
# add additional datetime validation
error_list.append("date must be a string")

if type(self.start_time) is not str:
# add additional datetime validation
error_list.append("start_time must be a string")
Expand All @@ -72,18 +110,6 @@ def validate(self):
if type(self.location) is not str:
error_list.append("location must be a string")

if type(self.attendance) is str:
if not isinstance(self.attendance, Attendance):
error_list.append("must be a valid attendance")
else:
error_list.append("attendance must be a string")

if type(self.attending_family) is str:
if not isinstance(self.attending_family, Attending_family):
error_list.append("must be a valid attending_family")
else:
error_list.append("attending_family must be a string")

if type(self.staff_transport_time_min) is int:
if self.staff_transport_time_min < 0:
error_list.append("staff_transport_time_min must be non-negative")
Expand All @@ -104,8 +130,63 @@ def validate(self):
else:
error_list.append("foster_parent_transport_time_min must be an integer")

if type(self.notes) is not str:
error_list.append("notes must be a string")

if type(self.child_family_support_worker_id) is not int:
error_list.append("child_family_support_worker_id must be an integer")

if type(self.comments) is not str:
error_list.append("comments must be a string")

class CreateVisitingMemberDTO(VisitingMemberDTO):
def __init__(self, **kwargs):
super().__init__(**kwargs)

def validate(self):
error_list = []

if not self.attendance_record_id or type(self.attendance_record_id) is not int:
error_list.append("attendance_record_id is not an integer")

if type(self.visitor_relationship) is str:
if not isinstance(self.visitor_relationship, Attending_family):
error_list.append("must be a valid attending_family")
else:
error_list.append("attending_family must be a string")

if type(self.description) is not str:
error_list.append("description must be a string")

if type(self.visiting_member_name) is not str:
error_list.append("visiting_member_name must be a string")

if type(self.visit_attendance) is str:
if not isinstance(self.visit_attendance, Attendance):
error_list.append("must be a valid attendance")
else:
error_list.append("attendance must be a string")

if type(self.reason_for_absence) is not str:
error_list.append("reason_for_absence must be a string")


class CreateTransportationDTO(TransportationDTO):
def __init__(self, **kwargs):
super().__init__(**kwargs)

def validate(self):
error_list = []

if not self.attendance_record_id or type(self.attendance_record_id) is not int:
error_list.append("attendance_record_id is not an integer")

if type(self.guardian) is not str:
error_list.append("guardian must be a string")

if type(self.name) is not str:
error_list.append("name must be a string")

if type(self.duration) is int:
if self.duration < 0:
error_list.append("duration must be non-negative")
else:
error_list.append("duration must be an integer")
Loading
Loading