def create_case(user, all_users, case_no): newcase = Case() newcase.body = "Aliquam ultricies in. Nisl suspendisse ut curabitur nullam, libero magna, id velit quis vitae at. In massa gravida, luctus consequat quis integer, amet amet diam ornare nascetur libero ultrices, lorem urna et. Hac vestibulum, turpis sed sapien cumque. Morbi justo semper lorem gravida, interdum a ante mattis augue at semper, aliquam ridiculus, vulputate repellendus, mi sem in non. Vitae nunc egestas, consectetuer nibh est, ac vestibulum vitae augue ut mauris, ante tortor, velit gravida nisl pellentesque dolor." newcase.opened_by = user newcase.last_edit_by = user newcase.assigned_to = all_users[random.randint(0,len(all_users)-1)] newcase.assigned_date = datetime.utcnow() - timedelta(days=random.randint(0,720)) #newcase.category = Category.objects.all()[random.randint(0, Category.objects.all().count()-1)] newcase.category = Category.objects.all()[random.randint(0, 1)] #right now only support issue/question categories, so only the first two categories #newcase.status = Status.objects.all()[random.randint(0, Status.objects.all().count() -1)] #set the default opened case newcase.status = Status.objects.all().filter(category=newcase.category).filter(state_class=constants.CASE_STATE_OPEN)[0] newcase.priority = Priority.objects.all()[random.randint(0, Priority.objects.all().count() -1)] if newcase.category.slug == "Question": newcase.description = question_arr[random.randint(0,len(question_arr))-1] elif newcase.category.slug == "Issue": newcase.description = question_arr[random.randint(0,len(question_arr))-1] newcase.save() return newcase
def _testCreateCase(self): oldcasecount = Case.objects.all().count() oldevents = CaseEvent.objects.all().count() user = User.objects.get(username='******') newcase = Case() newcase.description = "this is a case made by the test case" newcase.opened_by = user newcase.assigned_date = datetime.utcnow() newcase.assigned_to = user newcase.category = Category.objects.all()[0] newcase.status = Status.objects.all()[0] newcase.priority = Priority.objects.all()[0] newcase.save() #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("event-open", events[0].activity.event_class)
def create_homemonitoring_alert(num_alerts, careteam): alerts = [ ("Patient weight has dropped over 10 lbs","Please contact patient immediately for dietary assessment", 1), ("Patient has been vomiting more than 48 hours after treatment","Please contact patient immediately - if non responsive, call for an ambulance",1), ("Patient has shortness of breath/chest pain","Contact patient immediately and recommend checking in to ED",1), ("Patient has pain in a new place","Call patient for pain assessment",4), ("Patient has severe nausea", "Contact patient immediately",3), ("Patient is experiencing hearing loss","Check for other neuro side effects",4), ("Patient has not submitted daily measurements","Contact patient and caregiver immediately",1), ("Patient daily measurements incomplete", "Advise patient to retest full results",4) ] random.shuffle(alerts) for n in range(0, num_alerts): newcase = Case() newcase.description = "%s" % alerts[n][0] newcase.body = alerts[n][1] print "\tNew Alert: %s" % alerts[n][0] newcase.category = Category.objects.get(category='HomeMonitoring') newcase.opened_by = User.objects.get(id=2) # the hard coded ashand system messages newcase.last_edit_by = User.objects.get(id=2) # the hard coded ashand system messages newcase.assigned_to = careteam.primary_provider.user newcase.status = Status.objects.all().filter(category=newcase.category).filter(state_class=constants.CASE_STATE_OPEN)[0] td = timedelta(hours=alerts[n][2]) newcase.next_action_date = datetime.utcnow() + td newcase.priority= Priority.objects.all()[0] newcase.save() careteam.add_case(newcase)
def inject_case_data(patient, event_arr): """ Pull data from the event_arr and assign it to a patient if they were new inbound triage cases """ print "Adding monitoring event to patient %s" % (patient) startdelta = timedelta(minutes=random_inject.randint(1,200)) #sometime in the past 3 main_info = event_arr[0:4] category_txt = main_info[0].strip() title = main_info[1].strip() body = main_info[2].strip() source = main_info[3].strip() if title.count("%s") == 1: title = title % patient if body.count("%s") == 1: body = body % patient\ newcase = Case() newcase.description = title newcase.body = body newcase.category = Category.objects.get(slug=category_txt) creator=None if source.lower() == 'provider': creator = careteam.primary_provider.user elif source.lower() == 'caregiver': creator = careteam.caregivers.all()[0] elif source.lower() == 'patient': creator = careteam.patient.user elif source.lower() == 'home monitor': creator = User.objects.get(username ='******') if creator == None: print "no creator, wtf" newcase.opened_by = creator newcase.opened_date = datetime.utcnow() - startdelta newcase.last_edit_by = creator newcase.last_edit_date = newcase.opened_date newcase.status = Status.objects.all().filter(category=newcase.category).filter(state_class=constants.CASE_STATE_OPEN)[0] newcase.assigned_to = careteam.primary_provider.user newcase.assigned_date = newcase.opened_date if source.lower() == 'home monitor': newcase.priority = Priority.objects.all()[0] else: newcase.priority = Priority.objects.all()[random_inject.randint(0, Priority.objects.all().count() -1)] newcase.save(unsafe=True) careteam.add_case(newcase)
def load_interaction(careteam, interaction_arr): """ works through the entire array to simulate the case lifecycle """ startdelta = timedelta(days=random.randint(1,7)) #sometime in the past week main_info = interaction_arr[0:4] category_txt = main_info[0].strip() title = main_info[1].strip() body = main_info[2].strip() source = main_info[3].strip() if title.count("%s") == 1: title = title % careteam.patient.user.first_name if body.count("%s") == 1: body = body % careteam.patient.user.first_name newcase = Case() newcase.description = title newcase.body = body newcase.category = Category.objects.get(slug=category_txt) creator=None if source.lower() == 'provider': creator = careteam.primary_provider.user elif source.lower() == 'caregiver': creator = careteam.caregivers.all()[0] elif source.lower() == 'patient': creator = careteam.patient.user elif source.lower() == 'home monitor': creator = User.objects.get(username ='******') if creator == None: print "no creator, wtf: " + str(interaction_arr) newcase.opened_by = creator newcase.opened_date = datetime.utcnow() - startdelta newcase.last_edit_by = creator newcase.last_edit_date = newcase.opened_date newcase.status = Status.objects.all().filter(category=newcase.category).filter(state_class=constants.CASE_STATE_OPEN)[0] newcase.assigned_to = careteam.providers.all()[random.randint(0,careteam.providers.all().count()-1)].user newcase.assigned_date = newcase.opened_date newcase.priority = Priority.objects.all()[random.randint(0, Priority.objects.all().count() -1)] newcase.save(unsafe=True) careteam.add_case(newcase) subarr = interaction_arr[4:] while len(subarr) >= 3: resp = subarr[0].strip() src = subarr[1].lower().strip() evt = subarr[2].lower().strip() if resp == '' and src == '' and evt == '': break responder=None if src.lower() == 'provider': responder = careteam.primary_provider.user elif src.lower() == 'caregiver': responder = careteam.caregivers.all()[0] elif src.lower() == 'patient': responder = careteam.patient.user if responder == None: print "wtf: " + str(subarr) evt = CaseEvent() evt.case = newcase if resp.count("%s") == 1: resp = resp % careteam.patient.user.first_name evt.notes = resp evt.activity = ActivityClass.objects.filter(category=newcase.category)\ .filter(event_class=constants.CASE_EVENT_COMMENT)[0] evt.created_by = responder startdelta = startdelta - timedelta(minutes=random.randint(4,480)) evt.created_date = datetime.utcnow() - startdelta evt.save(unsafe=True) if len(subarr[3:]) >= 3: subarr = subarr[3:] else: break