Treatment notes section adjustment on injury create and edit forms
This commit is contained in:
parent
fd43de7443
commit
2d052d630b
3 changed files with 39 additions and 91 deletions
|
|
@ -126,7 +126,7 @@ class PatientInjuryPortal(CustomerPortal, AccessControlMixin):
|
||||||
'patient_id': patient.id,
|
'patient_id': patient.id,
|
||||||
'diagnosis': post.get('diagnosis', ''),
|
'diagnosis': post.get('diagnosis', ''),
|
||||||
'external_notes': post.get('external_notes', ''),
|
'external_notes': post.get('external_notes', ''),
|
||||||
'stage': 'active' if is_treatment_prof else 'unverified',
|
'stage': 'active',
|
||||||
}
|
}
|
||||||
|
|
||||||
# Handle injury date and injury_date_na checkbox
|
# Handle injury date and injury_date_na checkbox
|
||||||
|
|
@ -194,66 +194,31 @@ class PatientInjuryPortal(CustomerPortal, AccessControlMixin):
|
||||||
# Always try to assign team therapists regardless of who created the injury
|
# Always try to assign team therapists regardless of who created the injury
|
||||||
# Only when a single team context is determinable
|
# Only when a single team context is determinable
|
||||||
if team_id:
|
if team_id:
|
||||||
# Use the resolved team_id (single team) for assignment
|
|
||||||
selected_team_id = int(team_id)
|
selected_team_id = int(team_id)
|
||||||
|
# Find therapists (head and regular) specifically for this team
|
||||||
# Find therapists specifically for this team
|
|
||||||
team_staff = request.env['sports.team.staff'].sudo().search([
|
team_staff = request.env['sports.team.staff'].sudo().search([
|
||||||
('team_id', '=', selected_team_id), # Only from selected team
|
('team_id', '=', selected_team_id),
|
||||||
('role', 'in', ['head_therapist', 'therapist'])
|
('role', 'in', ['head_therapist', 'therapist'])
|
||||||
])
|
])
|
||||||
|
|
||||||
# Log debug info
|
# Collect user IDs from team staff (prefer direct user_ids relation, fallback to partner mapping)
|
||||||
# Process team staff to find therapists
|
team_tp_user_ids = set()
|
||||||
for staff in team_staff:
|
for staff in team_staff:
|
||||||
if not staff.user_ids:
|
if staff.user_ids:
|
||||||
# Try to find a user directly associated with this partner
|
for u in staff.user_ids:
|
||||||
|
team_tp_user_ids.add(u.id)
|
||||||
|
else:
|
||||||
users = request.env['res.users'].sudo().search([('partner_id', '=', staff.partner_id.id)])
|
users = request.env['res.users'].sudo().search([('partner_id', '=', staff.partner_id.id)])
|
||||||
|
for u in users:
|
||||||
# Filter by role
|
team_tp_user_ids.add(u.id)
|
||||||
head_therapists = team_staff.filtered(lambda s: s.role == 'head_therapist')
|
|
||||||
therapists = team_staff.filtered(lambda s: s.role == 'therapist')
|
if not team_tp_user_ids:
|
||||||
|
|
||||||
# Separate head therapists from regular therapists
|
|
||||||
|
|
||||||
# First try to assign head therapist, then any therapist from the selected team
|
|
||||||
treatment_pros_assigned = False
|
|
||||||
|
|
||||||
# Try to assign head therapist first
|
|
||||||
if head_therapists:
|
|
||||||
# Find users associated directly with the head therapist partner
|
|
||||||
head_therapist = head_therapists[0]
|
|
||||||
users = request.env['res.users'].search([('partner_id', '=', head_therapist.partner_id.id)])
|
|
||||||
|
|
||||||
if users:
|
|
||||||
# Assign head therapist to injury
|
|
||||||
injury.write({
|
|
||||||
'treatment_professional_ids': [(4, users[0].id)]
|
|
||||||
})
|
|
||||||
treatment_pros_assigned = True
|
|
||||||
else:
|
|
||||||
# No user account found for head therapist
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Try to assign regular therapist if no head therapist was assigned
|
|
||||||
if not treatment_pros_assigned and therapists:
|
|
||||||
# Find users associated directly with the therapist partner
|
|
||||||
therapist = therapists[0]
|
|
||||||
users = request.env['res.users'].sudo().search([('partner_id', '=', therapist.partner_id.id)])
|
|
||||||
|
|
||||||
if users:
|
|
||||||
# Assign therapist to injury
|
|
||||||
injury.write({
|
|
||||||
'treatment_professional_ids': [(4, users[0].id)]
|
|
||||||
})
|
|
||||||
treatment_pros_assigned = True
|
|
||||||
else:
|
|
||||||
# No user account found for therapist
|
|
||||||
pass
|
|
||||||
|
|
||||||
# If no therapist was assigned, log a warning
|
|
||||||
if not treatment_pros_assigned:
|
|
||||||
_logger.warning("No valid therapists found to assign to the injury for team %s", selected_team_id)
|
_logger.warning("No valid therapists found to assign to the injury for team %s", selected_team_id)
|
||||||
|
|
||||||
|
# Merge any team therapists with any already set/selected ones
|
||||||
|
merged_ids = set(treatment_prof_ids) | team_tp_user_ids if 'treatment_prof_ids' in locals() else team_tp_user_ids
|
||||||
|
if merged_ids:
|
||||||
|
injury.write({'treatment_professional_ids': [(6, 0, list(merged_ids))]})
|
||||||
else:
|
else:
|
||||||
_logger.info(
|
_logger.info(
|
||||||
"Skipping team-based therapist auto-assignment: patient %s has %s teams",
|
"Skipping team-based therapist auto-assignment: patient %s has %s teams",
|
||||||
|
|
|
||||||
|
|
@ -190,24 +190,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Add Treatment Note Section (only for treatment professionals) -->
|
|
||||||
<div t-if="is_treatment_prof" class="card mb-4">
|
|
||||||
<div class="card-header bg-info text-white">
|
|
||||||
<h4 class="mb-0">Add Treatment Note</h4>
|
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-12">
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="treatment_note">Treatment Note</label>
|
|
||||||
<textarea name="treatment_note" id="treatment_note" class="form-control" rows="4"
|
|
||||||
placeholder="Enter treatment note (will be saved with the current date)"></textarea>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- External Notes Section -->
|
<!-- External Notes Section -->
|
||||||
<div class="card mb-4">
|
<div class="card mb-4">
|
||||||
<div class="card-header bg-secondary text-white">
|
<div class="card-header bg-secondary text-white">
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Basic injury information -->
|
<!-- Basic injury information -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
|
|
@ -183,25 +184,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Add Treatment Note Section (only for treatment professionals) -->
|
|
||||||
<div t-if="is_treatment_prof" class="card mb-4">
|
|
||||||
<div class="card-header bg-info text-white">
|
|
||||||
<h4 class="mb-0">Add Treatment Note</h4>
|
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-12">
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="treatment_note">Treatment Note</label>
|
|
||||||
<textarea name="treatment_note" id="treatment_note" class="form-control" rows="4"
|
|
||||||
placeholder="Enter treatment note (will be saved with the current date)"></textarea>
|
|
||||||
<small class="text-muted">Optional: Add an initial treatment note if treatment was provided during injury assessment</small>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- External Notes Section -->
|
<!-- External Notes Section -->
|
||||||
<div class="card mb-4">
|
<div class="card mb-4">
|
||||||
<div class="card-header bg-secondary text-white">
|
<div class="card-header bg-secondary text-white">
|
||||||
|
|
@ -221,6 +203,25 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Add Treatment Note Section (only for treatment professionals) -->
|
||||||
|
<div t-if="is_treatment_prof" class="card mb-4">
|
||||||
|
<div class="card-header bg-info text-white">
|
||||||
|
<h4 class="mb-0">Add Treatment Note</h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="treatment_note">Treatment Note</label>
|
||||||
|
<textarea name="treatment_note" id="treatment_note" class="form-control" rows="4"
|
||||||
|
placeholder="Enter treatment note (will be saved with the current date)"></textarea>
|
||||||
|
<small class="text-muted">Optional: Add an initial treatment note if treatment was provided during injury assessment</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Action buttons -->
|
<!-- Action buttons -->
|
||||||
<div class="row mt-4">
|
<div class="row mt-4">
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue