def test_update_procedure_step(self): testAssign, testPatient, testProcedure = self.test_create_assignedProcedure( ) AssignedProcedures.update_procedure_step(2, testPatient, testProcedure) toCheck = AssignedProcedures.objects.get(patient=testPatient, procedure=testProcedure) self.assertEqual(toCheck.phaseNumber, 2)
def test_patient_today(self): from assigned_procedures.models import AssignedProcedures from procedures.models import Procedure tPatient = self.create_patient() tPatient.save() actualResult = tPatient.patient_status() self.assertEqual("Referred", actualResult) tProcedure = Procedure.objects.create(procedure_name="leeches") tProcedure.save() tProcedure2 = Procedure.objects.create(procedure_name="Bloodwork") tProcedure2.save() tProcedure3 = Procedure.objects.create(procedure_name="TAVR") tProcedure3.save() ap1 = AssignedProcedures.assign_procedure_to_patient( 1, tPatient, tProcedure) self.assertFalse(tPatient.has_incomplete_procedure_today()) ap1.scheduled = True ap1.save() ap2 = AssignedProcedures.assign_procedure_to_patient( 2, tPatient, tProcedure2) ap3 = AssignedProcedures.assign_procedure_to_patient( 3, tPatient, tProcedure3) expected_list = [tProcedure] final_procedures_list = tPatient.procedures_for_today() self.assertListEqual(expected_list, final_procedures_list) self.assertTrue(tPatient.has_incomplete_procedure_today())
def test_convert_days_to_date(self): solution = timezone.now() + timedelta(days=3) self.assertEqual( AssignedProcedures.convert_days_to_date(3).year, solution.year) self.assertEqual( AssignedProcedures.convert_days_to_date(3).month, solution.month) self.assertEqual( AssignedProcedures.convert_days_to_date(3).day, solution.day)
def patient_is_done(self): from assigned_procedures.models import AssignedProcedures if (not AssignedProcedures.get_all_active_procedures_for_patient(self) ) and (AssignedProcedures.get_all_procedures_completed_by_patient( self)): # This patient has been assigned procedures and has completed them all return True else: return False
def test_toggle_completed(self): testAssign, testPatient, testProcedure = self.test_create_assignedProcedure( ) result = AssignedProcedures.toggle_completed( searchPatient=testPatient, searchProcedure=testProcedure) self.assertTrue(result) result = AssignedProcedures.toggle_completed( searchPatient=testPatient, searchProcedure=testProcedure) self.assertFalse(result)
def test_get_first_incomplete_phase(self): testAssign, testPatient, testProcedure = self.test_create_assignedProcedure( ) testProcedure2 = Procedure.objects.create(procedure_name="Procedure 2") testProcedure3 = Procedure.objects.create(procedure_name="Procedure 3") assigned2 = AssignedProcedures.assign_procedure_to_patient( 2, testPatient, testProcedure2) assigned3 = AssignedProcedures.assign_procedure_to_patient( 3, testPatient, testProcedure3) first_incomplete_phase = AssignedProcedures.get_first_incomplete_phase( testPatient) self.assertEqual(first_incomplete_phase, 1) AssignedProcedures.set_complete(testPatient, testProcedure, 1) first_incomplete_phase = AssignedProcedures.get_first_incomplete_phase( testPatient) self.assertEqual(first_incomplete_phase, 2) AssignedProcedures.set_complete(testPatient, testProcedure2, 2) first_incomplete_phase = AssignedProcedures.get_first_incomplete_phase( testPatient) self.assertEqual(first_incomplete_phase, 3)
def test_add_roadmap_to_patient(self): tPatient = Patients.objects.create(first_name="Lyle", last_name="Magoo", bday=datetime(1996, 10, 24)) tPatient.save() tRoadmap, tProcedure, tProcedure2 = self.test_create_roadmap() AssignedProcedures.add_roadmap_to_patient(tRoadmap, tPatient) toCheck = AssignedProcedures.get_all_procedures(tPatient) solution = [(tProcedure, 1), (tProcedure2, 2)] self.assertEqual(toCheck, solution)
def test_calculate_behind_procedure_prec(self): tpatient, tprocedure, tassignedProc = self.test_create_test_inputs() self.assertEqual(Analytics.calculate_behind_procedure_prec(), 0) tprocedure2 = Procedure.objects.create(procedure_name="TAVR Old", est_days_to_complete=-2) AssignedProcedures.assign_procedure_to_patient(2, tpatient, tprocedure2) self.assertEqual(Analytics.calculate_behind_procedure_prec(), 50) self.assertEqual(Analytics.behind_procedure_perc, 50)
def test_remove_assigned_procedure(self): testAssign, testPatient, testProcedure = self.test_create_assignedProcedure( ) tProcedure = Procedure.objects.create(procedure_name="TAVR") AssignedProcedures.assign_procedure_to_patient(2, testPatient, tProcedure) AssignedProcedures.remove_assigned_procedure(testPatient, testProcedure, 1) toCheck = AssignedProcedures.get_all_procedures(testPatient) correct = [(tProcedure, 2)] self.assertEqual(toCheck, correct)
def test_get_all_active(self): # one linked procedure case testAssign, testPatient, testProcedure = self.test_create_assignedProcedure( ) # two linked procedures case tProcedure = Procedure.objects.create(procedure_name="bloodwork") assigned = AssignedProcedures.assign_procedure_to_patient( 2, testPatient, tProcedure) assigned.completed = True assigned.save() quiriedProcedure = AssignedProcedures.get_all_active_procedures() self.assertTrue(assigned not in quiriedProcedure)
def test_get_all_procedures(self): # one linked procedure case testAssign, testPatient, testProcedure = self.test_create_assignedProcedure( ) quiriedProcedure = AssignedProcedures.get_all_procedures(testPatient) self.assertEqual(quiriedProcedure[0], (testProcedure, 1)) # two linked procedures case tProcedure = Procedure.objects.create(procedure_name="bloodwork") AssignedProcedures.assign_procedure_to_patient(2, testPatient, tProcedure) quiriedProcedure = AssignedProcedures.get_all_procedures(testPatient) self.assertEqual(quiriedProcedure, [(testProcedure, 1), (tProcedure, 2)])
def test_set_incomplete(self): testAssign, testPatient, testProcedure = self.test_set_complete() self.assertTrue(testAssign.completed) AssignedProcedures.set_incomplete(testPatient, testProcedure, testAssign.phaseNumber) resultAssign = AssignedProcedures.objects.get( patient=testPatient, procedure=testProcedure, phaseNumber=testAssign.phaseNumber) self.assertFalse(resultAssign.completed)
def return_all_behind_procedures(): allLateProcedures = [] for incompleteProcedure in AssignedProcedures.get_all_active_procedures( ): incompleteProcedurePatient = incompleteProcedure.patient.all()[0] incompleteProcedureProc = incompleteProcedure.procedure.all()[0] assignedProcStatus = AssignedProcedures.check_goal_status( incompleteProcedurePatient, incompleteProcedureProc) if assignedProcStatus == "in progress (behind)": allLateProcedures.append(incompleteProcedure) return allLateProcedures
def test_flag_update(self): from assigned_procedures.models import AssignedProcedures from procedures.models import Procedure tProcedure = Procedure.objects.create(procedure_name="leeches") tProcedure.save() tProcedure2 = Procedure.objects.create(procedure_name="Bloodwork") tProcedure2.save() tProcedure3 = Procedure.objects.create(procedure_name="TAVR") tProcedure3.save() tPatient = self.create_patient() tPatient.save() AssignedProcedures.assign_procedure_to_patient(1, tPatient, tProcedure) AssignedProcedures.assign_procedure_to_patient(2, tPatient, tProcedure2) AssignedProcedures.assign_procedure_to_patient(3, tPatient, tProcedure3) self.assertEqual(tPatient.flag_update(), (None, False)) tProcedure = Procedure.objects.create(procedure_name="mmmhm popy") tProcedure.save() AssignedProcedures.assign_procedure_to_patient(4, tPatient, tProcedure, -10) self.assertEqual(tPatient.flag_update(), (tProcedure, True))
def test_get_all_completed_procedures_for_patient(self): testAssign, testPatient, testProcedure = self.test_create_assignedProcedure( ) actual_return = AssignedProcedures.get_all_procedures_completed_by_patient( testPatient) self.assertListEqual(actual_return, []) testAssign.completed = True testAssign.save() actual_return = AssignedProcedures.get_all_procedures_completed_by_patient( testPatient) self.assertListEqual(actual_return, [testAssign])
def flag_update(self): import assigned_procedures from assigned_procedures.models import AssignedProcedures assignedProcs = AssignedProcedures.get_all_procedures(self) for procedureToCheck in assignedProcs: result = AssignedProcedures.check_goal_status( self, procedureToCheck[0], 1) if result == "in progress (behind)": self.behind_flag = True self.save() return procedureToCheck[0], True self.behind_flag = False self.save() return None, False
def test_create_assignedProcedureReturnVisit(self): tPatient = Patients.objects.create(first_name="Kyle", last_name="Dorce", bday=datetime(1996, 10, 24)) tProcedure = Procedure.objects.create(procedure_name="leeches") tAssignment = AssignedProcedures.assign_procedure_to_patient( 1, tPatient, tProcedure, True) return tAssignment, tPatient, tProcedure
def test_check_goal_status(self): testAssign, testPatient, testProcedure = self.test_create_assignedProcedure( ) result = AssignedProcedures.check_goal_status(testPatient, testProcedure) self.assertEqual(result, "not scheduled") tAssignment = AssignedProcedures.assign_procedure_to_patient( step=2, patientToLink=testPatient, procedureToLink=testProcedure, proc_est=2, return_visit=True) resultz = AssignedProcedures.check_goal_status(testPatient, testProcedure, 2) self.assertEqual(resultz, "in progress (on time)") AssignedProcedures.toggle_completed(testPatient, testProcedure, 2) tAssignment = AssignedProcedures.assign_procedure_to_patient( step=3, patientToLink=testPatient, procedureToLink=testProcedure, proc_est=2, return_visit=True) resultz = AssignedProcedures.check_goal_status(testPatient, testProcedure, 2) self.assertEqual(resultz, "completed (on time)")
def patient_status(self): from assigned_procedures.models import AssignedProcedures # If the patient doesn't have any procedures assigned, then they've only been referred # If the patient has procedures, but the first_incomplete_phase is not the final phase, then they aren't ready for the final procedure(s) # Only procedures left for the patient are the final ones # Patient has procedures that are all completed first_incomplete_phase = AssignedProcedures.get_first_incomplete_phase( self) final_phase_for_patient = AssignedProcedures.get_final_phase_number( self) if not AssignedProcedures.objects.filter(patient=self): return "Referred" elif first_incomplete_phase < final_phase_for_patient: return "In-Progress" elif first_incomplete_phase == final_phase_for_patient: return "Ready" else: return "Done"
def test_return_all_behind_procedures(self): tpatient, tprocedure, tassignedProc = self.test_create_test_inputs() self.assertEqual(Analytics.return_all_behind_procedures(), []) tprocedure2 = Procedure.objects.create(procedure_name="TAVR Old", est_days_to_complete=-2) solution = AssignedProcedures.assign_procedure_to_patient(2, tpatient, tprocedure2) self.assertEqual(Analytics.return_all_behind_procedures(), [solution])
def test_patient_status(self): from assigned_procedures.models import AssignedProcedures from procedures.models import Procedure tPatient = self.create_patient() tPatient.save() actualResult = tPatient.patient_status() self.assertEqual("Referred", actualResult) tProcedure = Procedure.objects.create(procedure_name="leeches") tProcedure.save() tProcedure2 = Procedure.objects.create(procedure_name="Bloodwork") tProcedure2.save() tProcedure3 = Procedure.objects.create(procedure_name="TAVR") tProcedure3.save() ap1 = AssignedProcedures.assign_procedure_to_patient( 1, tPatient, tProcedure) ap2 = AssignedProcedures.assign_procedure_to_patient( 2, tPatient, tProcedure2) ap3 = AssignedProcedures.assign_procedure_to_patient( 3, tPatient, tProcedure3) actualResult = tPatient.patient_status() self.assertEqual("In-Progress", actualResult) ap1.completed = True ap1.save() ap2.completed = True ap2.save() actualResult = tPatient.patient_status() self.assertEqual("Ready", actualResult) ap3.completed = True ap3.save() actualResult = tPatient.patient_status() self.assertEqual("Done", actualResult)
def test_get_last_procedure_date(self): testAssign, testPatient, testProcedure = self.test_create_assignedProcedure( ) testAssign.completed = True testAssign.save() actual_return = AssignedProcedures.get_last_completed_date(testPatient) self.assertEqual(actual_return.date(), timezone.now().date())
def homepage(request): if request.method == 'GET': return render( request, 'homepage.html', { 'title': 'Home', 'patients': Patients.objects.all(), 'alert_patients': AssignedProcedures.update_and_return_all_patient_goal_flags() })
def patient_final_procedures(self): from assigned_procedures.models import AssignedProcedures final_phase_for_patient = AssignedProcedures.get_final_phase_number( self) final_procedure_list = [] final_procedures = AssignedProcedures.objects.filter( patient=self, phaseNumber=final_phase_for_patient) for single_procedure in final_procedures: final_procedure_list.append(single_procedure.procedure.all()[0]) return final_procedure_list
def calculate_behind_procedure_prec(): totalProc = 0 for indivAssignedProc in AssignedProcedures.get_all_active_procedures( ): totalProc += 1 behindProc = 0 for flaggedPatients in AssignedProcedures.update_and_return_all_patient_goal_flags( ): if flaggedPatients.behind_flag is True: behindProc += 1 if totalProc is 0: percentBehind = 0 else: percentBehind = (behindProc / totalProc) * 100 Analytics.behind_procedure_perc = percentBehind return round(percentBehind, 1)
def test_post_add_procedure_valid(self): add_request = self.factory.post('profile/procedures/add_procedure/?id=' + str(self.test_patient.id), { 'procedure': [self.test_object_one.id, self.test_object_two.id, self.test_object_three.id], 'phase': 1}) self.middleware.process_request(add_request) add_request.user = self.user response = add_procedure(add_request) self.assertEqual(response.status_code, 302) expected_list = [(self.test_object_one, 1), (self.test_object_two, 1), (self.test_object_three, 1)] self.assertListEqual(expected_list, AssignedProcedures.get_all_procedures(self.test_patient))
def get_patient_next_procedures(self): from assigned_procedures.models import AssignedProcedures first_incomplete_phase = AssignedProcedures.get_first_incomplete_phase( self) next_procedure_list = [] final_procedures = AssignedProcedures.objects.filter( patient=self, phaseNumber=first_incomplete_phase, completed=False) for incomplete_procedure in final_procedures: next_procedure_list.append(incomplete_procedure.procedure.all()[0]) return next_procedure_list
def test_get_average_completed(self): testAssign, testPatient, testProcedure = self.test_create_assignedProcedure( ) # test 1 procedure 0 time tProcedure = Procedure.objects.create(procedure_name="bloodwork") assigned = AssignedProcedures.assign_procedure_to_patient( 2, testPatient, tProcedure) spoof_time = assigned.created_at assigned.completed = True assigned.date_completed = spoof_time assigned.save() time = AssignedProcedures.average_completion_time(tProcedure.id) self.assertEqual(time, "0") # test 2 procedures 1 time assigned = AssignedProcedures.assign_procedure_to_patient( 3, testPatient, tProcedure) spoof_time = assigned.created_at assigned.completed = True assigned.date_completed = spoof_time + timedelta(days=2) assigned.save() time = AssignedProcedures.average_completion_time(tProcedure.id) self.assertEqual(time, "1")
def test_get_update_page(self): procedure = AssignedProcedures.assign_procedure_to_patient(1, self.test_patient, self.test_object_one) request = self.factory.get('/assigned/procedure/?id=' + str(procedure.id)) self.middleware.process_request(request) request.session.save() request.user = self.user setattr(request, 'session', 'session') messages = FallbackStorage(request) setattr(request, '_messages', messages) response = update(request) self.assertEqual(response.status_code, 200)
def test_post_add_roadmap_valid(self): post_request = self.factory.post('/patients/profile/procedures/add_roadmap/?id=' + str(self.test_patient.id), {'roadmap': [str(self.test_roadmap.id)]}) self.middleware.process_request(post_request) post_request.user = self.user response = add_roadmap(post_request) self.assertEqual(response.status_code, 302) expected_list = [(self.test_object_one, 1), (self.test_object_two, 1), (self.test_object_three, 1)] self.assertListEqual(expected_list, AssignedProcedures.get_all_procedures(self.test_patient)) return post_request