def get_participantTags(self): tag_list = [] # TODO: Implement Participant Tags # For NLM study_type_service = StudyTypeService("NLM", user=self.user) if study_type_service.is_cohort_assigned(self.participant.cohort): tag_list.append("NLM") # TODO: Add more tags if necessary return tag_list
def nlm_base_hourly_task(parameters): # try to bring all hourly studies hourly_study_types = StudyType.objects.filter(frequency=StudyType.HOURLY).all() for an_hourly_study_type in hourly_study_types: # try to bring nlm study architecture log("hourly study type discovered: {}".format(an_hourly_study_type.name)) study_type_service = StudyTypeService.create_service(an_hourly_study_type) cohort_assignments = study_type_service.get_all_child_cohort_assignments() for a_cohort_assignment in cohort_assignments: log("cohort discovered: {}".format(a_cohort_assignment)) a_cohort = a_cohort_assignment.cohort participants = Participant.objects.filter(cohort=a_cohort, active=True).all() for a_participant in participants: log("participant discovered: {}".format(a_participant)) # generic_messages_service = GenericMessagesService.create_service(username=a_participant.user.username) # sent_message = generic_messages_service.send_message("test intervention", "Notification.GenericMessagesTest2", "Title from Tasks", "Body from Tasks: {}".format(parameters["minute"]), False) # log('Message sent using generic_messages: msg-{}, url- /notification/{}'.format("Sample Body: {}".format(parameters["minute"]), sent_message.data["messageId"])) study_type_service.handle_participant_hourly_task(a_participant.user)
def test_check_sequence_assignment_3(self): study_type_service = StudyTypeService(self.study_type_name, self.user) self.assertFalse(study_type_service.is_level_sequence_assigned(self.user)) sample_sequence = ["1"] * 5 sample_sequence_str = ",".join(sample_sequence) sample_csv = [sample_sequence_str] * 3 # sample_csv = ['"1","1","1","1","1"', # '"1","1","1","1","1"', # '"1","1","1","1","1"' # ] study_type_service.upload_level_csv("sample.csv", "sample_csv", sample_csv) study_type_service.assign_level_sequence(self.user, "sample_csv") self.assertTrue(study_type_service.is_level_sequence_assigned(self.user)) study_type_service.delete_level_csv("sample_csv")
def test_create_preloaded_level_sequence_file(self): study_type_service = StudyTypeService(self.study_type_name, self.user) sample_sequence = ["1"] * 5 sample_sequence_str = ",".join(sample_sequence) sample_csv = [sample_sequence_str] * 3 # print(sample_csv) study_type_service.upload_level_csv("sample.csv", "sample_csv", sample_csv) # dev_service = DevService(self.user) # print(dev_service.view_preloaded_seq()) study_type_service.delete_level_csv("sample_csv")
def test_is_decision_point_1(self): study_type_service = StudyTypeService(self.study_type_name, self.user) self.assertFalse(study_type_service.is_decision_needed(self.user, test_time=datetime(2021, 6, 3, 7, 59, 59))) self.assertTrue(study_type_service.is_decision_needed(self.user, test_time=datetime(2021, 6, 3, 8, 0, 0))) self.assertTrue(study_type_service.is_decision_needed(self.user, test_time=datetime(2021, 6, 3, 8, 1, 0))) self.assertTrue(study_type_service.is_decision_needed(self.user, test_time=datetime(2021, 6, 3, 8, 3, 0))) self.assertTrue(study_type_service.is_decision_needed(self.user, test_time=datetime(2021, 6, 3, 8, 10, 0))) self.assertFalse(study_type_service.is_decision_needed(self.user, test_time=datetime(2021, 6, 3, 8, 10, 1))) self.assertFalse(study_type_service.is_decision_needed(self.user, test_time=datetime(2021, 6, 3, 10, 59, 59))) self.assertTrue(study_type_service.is_decision_needed(self.user, test_time=datetime(2021, 6, 3, 11, 0, 0))) self.assertTrue(study_type_service.is_decision_needed(self.user, test_time=datetime(2021, 6, 3, 11, 1, 0))) self.assertTrue(study_type_service.is_decision_needed(self.user, test_time=datetime(2021, 6, 3, 11, 3, 0))) self.assertTrue(study_type_service.is_decision_needed(self.user, test_time=datetime(2021, 6, 3, 11, 10, 0))) self.assertFalse(study_type_service.is_decision_needed(self.user, test_time=datetime(2021, 6, 3, 11, 10, 1)))
def test_fetch_todays_level(self): study_type_service = StudyTypeService(self.study_type_name, self.user) self.assertFalse(study_type_service.is_level_sequence_assigned(self.user)) sample_sequence = [str(StudyTypeService.LEVEL1)] * 5 sample_sequence_str = ",".join(sample_sequence) sample_csv = [sample_sequence_str] * 3 # sample_csv = ['"1","1","1","1","1"', # '"1","1","1","1","1"', # '"1","1","1","1","1"' # ] study_type_service.upload_level_csv("sample.csv", "sample_csv", sample_csv) study_type_service.assign_level_sequence(self.user, "sample_csv") self.assertTrue(study_type_service.is_level_sequence_assigned(self.user)) self.assertEqual(StudyTypeService.LEVEL1, study_type_service.fetch_todays_level(self.user)) study_type_service.delete_level_csv("sample_csv")
def test_check_sequence_assignment_2(self): study_type_service = StudyTypeService(self.study_type_name, self.user) self.assertFalse(study_type_service.is_level_sequence_assigned(self.user))
def test_assign_level_sequence_2(self): study_type_service = StudyTypeService(self.study_type_name, self.user) self.assertRaises(PreloadedLevelSequenceFile.DoesNotExist, study_type_service.assign_level_sequence, self.user, "sample_seq")
def test_assign_level_sequence_1(self): study_type_service = StudyTypeService(self.study_type_name, self.user) self.assertRaises(AssertionError, study_type_service.assign_level_sequence, self.user, None)
def test_handle_conditionality(self): study_type_service = StudyTypeService(self.study_type_name, self.user) nlm_base_hourly_task({})
def test_use_conditionality_parameter_with_setting(self): study_type_service = StudyTypeService(self.study_type_name, self.user) name = "random with parameterized threshold" description = "random with parameterized threshold" module_path = "nlm.conditionality.parameterized_conditionality" try: study_type_service.remove_conditionality(module_path) except: pass new_conditionality = study_type_service.add_conditionality(name, description, module_path) conditionality_parameter_name = "nlm.test.test_conditionality.ramdom.threshold" try: study_type_service.remove_conditionality_parameter(new_conditionality, conditionality_parameter_name) except: pass study_type_service.set_conditionality_parameter(new_conditionality, conditionality_parameter_name, 0.2) conditionality_parameter_name2 = "nlm.test.test_conditionality.ramdom.test_str" try: study_type_service.remove_conditionality_parameter(new_conditionality, conditionality_parameter_name2) except: pass study_type_service.set_conditionality_parameter(new_conditionality, conditionality_parameter_name2, "test string") params = ProgramletParameters( "Test_Test", study_type_service, new_conditionality) study_type_service.call_conditionality(module_path, parameters=params) study_type_service.remove_conditionality_parameter(new_conditionality, conditionality_parameter_name) study_type_service.remove_conditionality_parameter(new_conditionality, conditionality_parameter_name2) study_type_service.remove_conditionality(module_path)