def testAdvancedPermissionsThreePatients(self): """ Create a multitude of patients where a provider has varying actor roles (provider, none, etc) """ patients = [] for i in range(3): patients.append(generator.get_or_create_patient()) role_options = ['caregiver', 'provider', None] user = self._createUser() for i in range(3): patient = patients[i] role = role_options[i] if role != None: actor = generator.generate_role(user, role) patient.add_actor(actor) for i in range(0,3): patient = patients[i] if i == 0: #caregiver self.assertEqual(Actor.permissions.get_roles(patient, user)[0].role_type.model_class(), Caregiver) elif i == 1: #provider: self.assertNotEqual(Actor.permissions.get_roles(patient, user)[0].role_type.model_class(), Caregiver) role_type = Actor.permissions.get_roles(patient, user)[0].role_type.model_class() if role_type == Doctor or role_type == TriageNurse: pass else: self.fail("Not a known role type") if i == 2: self.assertEqual(Actor.permissions.get_roles(patient, user).count(), 0)
def testCaseModifyDescriptionApi(self): desc= uuid.uuid1().hex self.testCreateCaseApi(description=desc) user1 = generator.get_or_create_user() actor1 = generator.generate_role(user1, 'provider') case = Case.objects.all().get(description=desc) case.description = CHANGED_DESCRIPTION case.last_edit_by = actor1 activity = constants.CASE_EVENT_EDIT case.save_comment="editing in testCaseModifyDescription" case.save(activity=activity) events = CaseEvent.objects.filter(case=case) #we just did an edit, so it should be 2 self.assertEqual(2, events.count()) #the top one due to the sort ordering should be the one we just did self.assertEqual(constants.CASE_EVENT_EDIT, events[0].activity) #quickly verify that the original description is still unchanged dbcase = Case.objects.all().get(description=CHANGED_DESCRIPTION) self.assertEqual(dbcase.id, case.id)
def testCreateCaseApi(self, description=INITIAL_DESCRIPTION): ########################### #get the basic counts user1 = generator.get_or_create_user() user2 = generator.get_or_create_user() role1 = generator.generate_role(user1, 'caregiver') role2 = generator.generate_role(user2, 'provider') oldcasecount = Case.objects.all().count() oldevents = CaseEvent.objects.all().count() # newcase = Case() # newcase.description = description # newcase.opened_by = role1 # newcase.last_edit_by = role1 # # newcase.assigned_date = datetime.utcnow() # newcase.assigned_to = role2 # newcase.category = Category.objects.all()[0] # newcase.status = Status.objects.all().filter(state_class=constants.CASE_STATE_OPEN)[0] # newcase.priority = Priority.objects.all()[0] # activity = ActivityClass.objects.filter(event_class=constants.CASE_EVENT_OPEN)[0] # newcase.save(activity=activity) newcase = Case.objects.new_case(constants.CATEGORY_CHOICES[0][0], role1, description, "mock body %s" % (uuid.uuid1().hex), constants.PRIORITY_MEDIUM, status=constants.CASE_STATE_OPEN, activity=constants.CASE_EVENT_OPEN ) #is the thing created? self.assertEqual(Case.objects.all().count(), oldcasecount + 1) self.assertEqual(CaseEvent.objects.all().count(), oldevents + 1) #verify that the case count created has created a new caseevent events = CaseEvent.objects.filter(case=newcase) self.assertEqual(1,events.count()) #verify that said case count is a new case event of type "open" self.assertEqual(constants.CASE_EVENT_OPEN, events[0].activity) return newcase
def testBusyProvider(self): """Create a single provider/user caring for many patients.""" num_patients = 20 my_patients = 5 user = generator.get_or_create_user() actor = generator.generate_role(user, 'provider') patients = [generator.get_or_create_patient() for i in range(num_patients)] for i in range(my_patients): patients[i].add_actor(actor)
def testCreateSingleCareTeamAPI(self): print "===========================\nCreating singular patient with careteam via API" pt = generator.get_or_create_patient() provrole = generator.generate_role(generator.get_or_create_user(), 'provider') pt.add_provider(provoler) provrole = generator.generate_role(generator.get_or_create_user(), 'provider') pt.add_provider(provoler) provrole = generator.generate_role(generator.get_or_create_user(), 'provider') pt.add_provider(provoler) cgrole = generator.generate_role(generator.get_or_create_user(), 'caregiver') pt.add_caregiver(cgoler) cgrole = generator.generate_role(generator.get_or_create_user(), 'caregiver') pt.add_caregiver(cgoler) #next, verify single careteam exists via the patient access API. cg_pull = pt.get_caregivers() prov_pull = pt.get_providers() self.assertEqual(2, cg_pull.count()) self.assertEqual(3, prov_pull.count())
def testCaseCreateChildCases(self): self.testCreateCaseApi() user1 = generator.get_or_create_user() role1 = generator.generate_role(user1, 'provider') case = Case.objects.all().get(description =INITIAL_DESCRIPTION) CHILD_CASES=10 for num in range(0,CHILD_CASES): desc = uuid.uuid1().hex newcase = self.testCreateCaseApi(description=desc) newcase.parent_case = case newcase.last_edit_by = role1 activity = constants.CASE_EVENT_EDIT newcase.save_comment="editing in testCaseCreateChildCases" newcase.save(activity=activity) self.assertEqual(case.child_cases.count(), CHILD_CASES)
def testAdvancedPermissionsOnePatient(self): """ Create a multitude of patients where a provider has varying roles (provider, none, etc) """ patient = generator.get_or_create_patient() role_possibilities = ['caregiver', 'provider', None] for r in role_possibilities: user = self._createUser() if r != None: role = generator.generate_role(user, r) pal = CareTeamMember(patient=patient, role=role, active=True) pal.save() if r == 'caregiver': self.assertEqual(Actor.permissions.get_roles(patient, user)[0].role_type.model_class(), Caregiver) elif r == 'provider': self.assertNotEqual(Actor.permissions.get_roles(patient, user)[0].role_type.model_class(), Caregiver) elif r == None: self.assertEqual(Actor.permissions.get_roles(patient, user).count(), 0)