Example #1
0
def get_schedule(chw_username, override_date = None):
    #print "doing schedule lookup for %s" % (chw_username)
    #if cached_schedules.has_key(chw_username):
        #return cached_schedules[chw_username]
    if override_date == None:
        nowdate = datetime.now()
    else:
        nowdate = override_date
    db = PactPatient.get_db()
    chw_schedules = db.view('pactcarehq/chw_dot_schedule_condensed', key=chw_username).all()
    day_intervaltree = {}

    for item in chw_schedules:
        single_sched = item['value']
        day_of_week = int(single_sched['day_of_week'])
        if day_intervaltree.has_key(day_of_week):
            daytree = day_intervaltree[day_of_week]
        else:
            #if there's no day of week indication for this, then it's just a null interval node.  to ensure that it's not checked, we make it REALLY old.
            daytree = IntervalNode(get_seconds(datetime.min), get_seconds(nowdate + timedelta(days=10)))

        if single_sched['ended_date'] == None:
            enddate = nowdate+timedelta(days=9)
        else:
            enddate = datetime.strptime(single_sched['ended_date'], "%Y-%m-%dT%H:%M:%SZ")
            #enddate = single_sched['ended_date']

        startdate = datetime.strptime(single_sched['active_date'], "%Y-%m-%dT%H:%M:%SZ")
        #startdate = single_sched['active_date']
        pact_id = single_sched['pact_id']
        
        daytree.insert(get_seconds(startdate), get_seconds(enddate), other=pact_id)
        day_intervaltree[day_of_week] = daytree

    #cached_schedules[chw_username] = CHWPatientSchedule(chw_username, day_intervaltree, chw_schedules)
    #return cached_schedules[chw_username]
    return CHWPatientSchedule(chw_username, day_intervaltree, chw_schedules)
Example #2
0
def run():
    #really hacky script to address null issues in couch for patient data.  a weird issue not able to pinpoint.
    #patients = PactPatient.view('patient/all').all()
    db = PactPatient.get_db()
    rawdocs = db.view('patient/all' ).all()
    for doc in rawdocs:
        #print doc
        try:
            ptdoc = doc['value']
            phone_hash = ptdoc['phones']
            for ph in phone_hash:
                print ph
                print ph.keys()
                ph['is_default'] = False
            pt = PactPatient.wrap(ptdoc)
            for phone in pt.phones:
                #print phone.is_default
                phone.save()
            pt.save()
        except Exception, e:

            print ptdoc
            print e
            print "fail!"