Skip to content

Commit

Permalink
fix: set exercises in Therapy Session from Therapy Type on validate
Browse files Browse the repository at this point in the history
  • Loading branch information
akashkrishna619 authored and akurungadam committed Mar 16, 2023
1 parent 89cb4de commit c509042
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion healthcare/healthcare/doctype/therapy_plan/therapy_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ def make_therapy_session(therapy_plan, patient, therapy_type, company, appointme
therapy_session.therapy_type = therapy_type.name
therapy_session.duration = therapy_type.default_duration
therapy_session.rate = therapy_type.rate
therapy_session.exercises = therapy_type.exercises
if not therapy_session.exercises and therapy_type.exercises:
for exercise in therapy_type.exercises:
therapy_session.append(
"exercises",
(frappe.copy_doc(exercise)).as_dict(),
)
therapy_session.appointment = appointment

if frappe.flags.in_test:
Expand Down
11 changes: 11 additions & 0 deletions healthcare/healthcare/doctype/therapy_session/therapy_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

class TherapySession(Document):
def validate(self):
self.set_exercises_from_therapy_type()
self.validate_duplicate()
self.set_total_counts()

Expand Down Expand Up @@ -110,6 +111,16 @@ def set_total_counts(self):
self.db_set("total_counts_targeted", target_total)
self.db_set("total_counts_completed", counts_completed)

def set_exercises_from_therapy_type(self):
if self.therapy_type and not self.exercises:
therapy_type_doc = frappe.get_cached_doc("Therapy Type", self.therapy_type)
if therapy_type_doc.exercises:
for exercise in therapy_type_doc.exercises:
self.append(
"exercises",
(frappe.copy_doc(exercise)).as_dict(),
)


@frappe.whitelist()
def create_therapy_session(source_name, target_doc=None):
Expand Down

0 comments on commit c509042

Please sign in to comment.