Пример #1
0
def generate_diagnosis_codes():
    """Generate a sorted grouping of diagnosis codes
    """
    lastMonthDateTime = datetime.today() - timedelta(days=30)
    thekey = settings['the.key']
    log = Base.metadata.tables['log']
    s = select([func.aes_decrypt(log.c.data, thekey).label('data')]).\
        where(and_(
            log.c.entity_type == 'planOfCare',
            log.c.action.like('Export%'),
            log.c.log_date >= lastMonthDateTime)).\
        group_by(log.c.log_entity_id, log.c.entity_type)
    result = DBSession.execute(s)

    countmap = {}
    for row in result:
        xml = row['data']
        code = poc.parse_primary_code(xml)
        if not code:
            continue
        count = countmap.get(code) or 0
        countmap[code] = count + 1

    codedescmap = {}
    decipheredcodes = {}
    for code, count in countmap.items():
        desc = codedescmap.get(code)
        if desc is None:
            desc = lookup_name_for_code(code)
            if desc is None:
                continue
            codedescmap[code] = desc 
        decipheredcodes[desc] = count

    l = sorted(decipheredcodes.items(), key=lambda t : t[1])
    l.reverse()
    l = [{'desc':x[0],'count':x[1]} for x in l]

    fd = open(settings['reports.dir'] + '/diagnosis_codes.json', 'w')
    fd.write(str(json.dumps(l)))
Пример #2
0
def generate_diagnosis_codes():
    """Generate a sorted grouping of diagnosis codes
    """
    lastMonthDateTime = datetime.today() - timedelta(days=30)
    thekey = settings['the.key']
    log = Base.metadata.tables['log']
    s = select([func.aes_decrypt(log.c.data, thekey).label('data')]).\
        where(and_(
            log.c.entity_type == 'planOfCare',
            log.c.action.like('Export%'),
            log.c.log_date >= lastMonthDateTime)).\
        group_by(log.c.log_entity_id, log.c.entity_type)
    result = DBSession.execute(s)

    diagdata = []
    for row in result:
        xml = row['data']
        r = poc.parse_all_codes(xml)
        if not r:
            continue
        diagdata.append(r)

    fd = open(settings['reports.dir'] + '/diagnosis_data.json', 'w')
    fd.write(str(json.dumps(diagdata)))