示例#1
0
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)
示例#2
0
def generate_triage():
    """
    Pull data from the triage_arr and randomly assign them to patients as if they were new inbound triage cases
    """    
    
    careteams = CareTeam.objects.all()    
    
    for careteam in careteams:
        max_encounters = random_inject.randint(1,2)
        random_inject.shuffle(triage_arr)
        print "Adding %d new triage events to patient %s" % (max_encounters, careteam.patient.user.title())
        for enc in range(0,max_encounters):    
            inject_case_data(careteam, triage_arr[enc])