-
Notifications
You must be signed in to change notification settings - Fork 0
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
Visitation Flow #247
Open
rodrigotiscareno
wants to merge
25
commits into
main
Choose a base branch
from
rt/visit-backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Visitation Flow #247
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
534cb89
routing
rodrigotiscareno d0d0d14
tweak
rodrigotiscareno d8a01e9
Link and Integrate PUT Case Submission Pt. 1 (#237)
JennyVong df593f7
checkpoint
rodrigotiscareno 1c259f8
checkpoint
rodrigotiscareno c75a85d
Add CreateVisitDTO class
helioshe4 25f7de8
database insertion work
rodrigotiscareno 2ba274f
Revert "Link and Integrate PUT Case Submission Pt. 1 (#237)"
rodrigotiscareno 30a3cac
ui tweaks
rodrigotiscareno be9d469
fixes for placeholders
rodrigotiscareno e036585
Merge branch 'main' into rt/visit-backend
7ebeb1f
Bug fixes on frontend about visitation data handling
d61cbcd
refresh validations to be less restrictive
rodrigotiscareno 53b4409
install cancel logic
rodrigotiscareno 6a9661e
fix visitation notes UI
rodrigotiscareno 323be11
fix child and family support worker ui and functionality
rodrigotiscareno 77ce02a
re-direct to home after submission
rodrigotiscareno 90c9b38
Merge branch 'main' into rt/visit-backend
04c946a
Fixed visit data collection (Transportaion and Attendance mainly)
173ecdd
Added POST and GET requests
vaaranan-y 215593a
fix buggy test
rodrigotiscareno d481cdd
visitation workflow tweaks
rodrigotiscareno 732aaf9
make duration ui integer-based
rodrigotiscareno 60ac3b1
fix enums for front-end
rodrigotiscareno 83d3662
support transport and visiting member backend functionality
rodrigotiscareno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
class VisitDTO(object): | ||
def __init__(self, **kwargs): | ||
self.user_id = kwargs.get("user_id") | ||
self.childInformation = kwargs.get("childInformation") | ||
self.visitTimestamp = kwargs.get("visitTimestamp") | ||
self.attendance = kwargs.get("attendance") | ||
self.transportation = kwargs.get("transportation") | ||
self.notes = kwargs.get("notes") | ||
self.childAndFamilySupportWorker = kwargs.get("childAndFamilySupportWorker") | ||
self.case_id = kwargs.get("case_id") | ||
self.child_details = kwargs.get("child_details") | ||
self.visit_details = kwargs.get("visit_details") | ||
self.attendance = kwargs.get("attendance_entries") | ||
self.transportation = kwargs.get("transportation_entries") | ||
self.notes = kwargs.get("visit_notes") | ||
|
||
|
||
class CreateVisitDTO(VisitDTO): | ||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
def validate(self): | ||
pass | ||
error_list = [] | ||
|
||
if not self.user_id or not isinstance(self.user_id, int): | ||
error_list.append("user_id is invalid") | ||
if not self.child_details: | ||
error_list.append("childInformation is invalid") | ||
if not self.attendance: | ||
error_list.append("attendance is invalid") | ||
|
||
return error_list |
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
89 changes: 87 additions & 2 deletions
89
backend/python/app/services/implementations/visit_service.py
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,10 +1,95 @@ | ||
from ...models import db | ||
from ..interfaces.visit_service import IVisitService | ||
from ...resources.visit_dto import VisitDTO | ||
from ...resources.attendance_sheet_dto import AttendanceSheetDTO | ||
from ...resources.attendance_records_dto import AttendanceRecordsDTO | ||
from ...models.attendance_sheets import AttendanceSheets | ||
from ...models.attendance_records import AttendanceRecords | ||
from ...models.attendance_records import VisitingMember | ||
from ...models.attendance_records import Transportation | ||
from ...models.transportation_method import TransportationMethod | ||
|
||
|
||
class VisitService(IVisitService): | ||
def __init__(self, logger): | ||
self.logger = logger | ||
|
||
def create_visit(): | ||
pass | ||
def create_visit(self, visit: VisitDTO): | ||
try: | ||
attendance_sheet = AttendanceSheets( | ||
family_name=visit.child_details["family_name"], | ||
csw=visit.child_details["child_service_worker"], | ||
cpw=visit.child_details["child_protection_worker"], | ||
fcc=visit.child_details["foster_care_coordinator"], | ||
) | ||
db.session.add(attendance_sheet) | ||
db.session.flush() | ||
|
||
attendance_record = AttendanceRecords( | ||
attendance_sheet_id=attendance_sheet.id, | ||
visit_date=visit.visit_details["visit_date"], | ||
visit_day=visit.visit_details["visit_day"], | ||
visit_supervision=visit.visit_details["visit_supervision"].upper(), | ||
start_time=visit.visit_details["start_time"], | ||
end_time=visit.visit_details["end_time"], | ||
location=visit.visit_details["location"], | ||
notes=visit.notes, | ||
) | ||
db.session.add(attendance_record) | ||
db.session.flush() | ||
|
||
for visiting_member in visit.attendance["entries"]: | ||
member = VisitingMember( | ||
attendance_record_id=attendance_record.id, | ||
visitor_relationship=visiting_member["visitor_relationship"], | ||
visiting_member_name=visiting_member["visiting_member_name"], | ||
description=visiting_member["description"], | ||
visit_attendance=visiting_member["visit_attendance"], | ||
reason_for_absence=visiting_member["absence_reason"], | ||
) | ||
db.session.add(member) | ||
|
||
for transport in visit.transportation["entries"]: | ||
transportation = Transportation( | ||
attendance_record_id=attendance_record.id, | ||
guardian=transport["guardian"], | ||
name=transport["name"], | ||
duration=transport["duration"], | ||
) | ||
db.session.add(transportation) | ||
|
||
# TODO: Add a reference key to transportation method for the visit | ||
# transportation_entry = visit.transportation["entries"][0] | ||
# transportation_method_name = transportation_entry["name"] | ||
# attendance_record.notes += ( | ||
# f" Transportation Method: {transportation_method_name}" | ||
# ) | ||
|
||
db.session.commit() | ||
|
||
return {"message": "Visit created successfully"} | ||
except Exception as error: | ||
db.session.rollback() | ||
self.logger.error(f"Error creating visit: {error}") | ||
raise error | ||
|
||
def get_visit_by_user_id(self, userID): | ||
try: | ||
attendance_sheets = AttendanceSheets.query.filter_by(id=userID) | ||
attendance_sheets_dto = [ | ||
AttendanceSheetDTO(**attendance_sheet.to_dict()) | ||
for attendance_sheet in attendance_sheets | ||
] | ||
|
||
attendance_records = AttendanceRecords.query.filter_by( | ||
attendance_sheet_id=userID | ||
) | ||
attendance_records_dto = [ | ||
AttendanceRecordsDTO(**attendance_record.to_dict()) | ||
for attendance_record in attendance_records | ||
] | ||
|
||
return attendance_sheets_dto + attendance_records_dto | ||
except Exception as error: | ||
self.logger.error(str(error)) | ||
raise error |
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import baseAPIClient from "./BaseAPIClient"; | ||
import AUTHENTICATED_USER_KEY from "../constants/AuthConstants"; | ||
import { getLocalStorageObjProperty } from "../utils/LocalStorageUtils"; | ||
import { Case } from "../types/CasesContextTypes"; | ||
|
||
interface Visit { | ||
user_id: number; | ||
case_id: number; | ||
childDetails: { | ||
familyName: string; | ||
children: string[]; | ||
childServiceWorker: string; | ||
childProtectionWorker: string; | ||
fosterCareCoordinator: string; | ||
}; | ||
visitDetails: { | ||
visitDate: string; | ||
visitDay: string; | ||
visitSupervision: string; | ||
startTime: string; | ||
endTime: string; | ||
location: string; | ||
}; | ||
attendanceEntries: { | ||
visitingMembers: string; | ||
visitorRelationship: string; | ||
description: string; | ||
visitingMemberName: string; | ||
visitAttendance: string; | ||
absenceReason: string; | ||
}[]; | ||
transportationEntries: { | ||
guardian: string; | ||
name: string; | ||
duration: string; | ||
notes: string; | ||
}[]; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any | ||
const post = async (formData: any): Promise<Case> => { | ||
const bearerToken = `Bearer ${getLocalStorageObjProperty( | ||
AUTHENTICATED_USER_KEY, | ||
"access_token", | ||
)}`; | ||
try { | ||
const { data } = await baseAPIClient.post("/visits", formData, { | ||
headers: { Authorization: bearerToken }, | ||
}); | ||
return data; | ||
} catch (error) { | ||
return error; | ||
} | ||
}; | ||
|
||
const put = async ({ | ||
changedData, | ||
intakeID, | ||
}: { | ||
changedData: Record<string, string>; | ||
intakeID: number; | ||
}): Promise<Case> => { | ||
const bearerToken = `Bearer ${getLocalStorageObjProperty( | ||
AUTHENTICATED_USER_KEY, | ||
"access_token", | ||
)}`; | ||
try { | ||
const { data } = await baseAPIClient.put( | ||
`/visit/${intakeID}`, | ||
changedData, | ||
{ | ||
headers: { Authorization: bearerToken }, | ||
}, | ||
); | ||
return data; | ||
} catch (error) { | ||
return error; | ||
} | ||
}; | ||
|
||
export default { post, put }; |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium