예제 #1
0
def process(allPaths, lineFile, classFile, id):
    obj = {
        "info": [],
        "events": [],
        "h_bars": [],
        "v_bars": ["auto"],
        "v_spans": [],
        "classes": {}
    }
    util.add_files(obj, lineFile, classFile)

    addInfo(obj, "pid", "Patient", id)
    if len(allPaths) == 0:
        print('warning: no path given', file=sys.stderr)
    statusMap = {}
    for (path, isfile) in allPaths:
        if isfile:
            processFile(path, id, obj, statusMap)
        else:
            util.process_id_directory(
                path, id,
                lambda file, id: processFile(file, id, obj, statusMap))
    curInStart = None
    curInEnd = None
    curStatus = STATUS_UNKNOWN
    for k in sorted(statusMap):
        status = statusMap[k]
        if status == curStatus:
            if curInStart is None:
                curInStart = k
            curInEnd = k
        else:
            if curInStart is not None:
                if curStatus == STATUS_IN:
                    obj["v_spans"].append({
                        "from": curInStart,
                        "to": util.nextDay(curInEnd),
                        "class": "in_hospital"
                    })
                elif curStatus == STATUS_PROF:
                    obj["v_spans"].append({
                        "from": curInStart,
                        "to": util.nextDay(curInEnd),
                        "class": "professional"
                    })
                curInStart = None
            curStatus = status
    min_time = float('inf')
    max_time = float('-inf')
    for e in obj["events"]:
        time = e["time"]
        if time < min_time:
            min_time = time
        if time > max_time:
            max_time = time
    obj["start"] = min_time
    obj["end"] = max_time
    addInfo(obj, "event_count", "Events", len(obj["events"]))
    return obj
예제 #2
0
def process(allPaths, lineFile, classFile, id):
    obj = {
        "info": [],
        "events": [],
        "h_bars": [],
        "v_bars": [ "auto" ],
        "v_spans": [],
        "classes": {}
    }
    util.add_files(obj, lineFile, classFile)

    addInfo(obj, "pid", "Patient", id)
    if len(allPaths) == 0:
        print('warning: no path given', file=sys.stderr)
    statusMap = {}
    for (path, isfile) in allPaths:
        if isfile:
            processFile(path, id, obj, statusMap)
        else:
            util.process_id_directory(path, id, lambda file, id: processFile(file, id, obj, statusMap))
    curInStart = None
    curInEnd = None
    curStatus = STATUS_UNKNOWN
    for k in sorted(statusMap):
        status = statusMap[k]
        if status == curStatus:
            if curInStart is None:
                curInStart = k
            curInEnd = k
        else:
            if curInStart is not None:
                if curStatus == STATUS_IN:
                    obj["v_spans"].append({
                        "from": curInStart,
                        "to": util.nextDay(curInEnd),
                        "class": "in_hospital"
                    })
                elif curStatus == STATUS_PROF:
                    obj["v_spans"].append({
                        "from": curInStart,
                        "to": util.nextDay(curInEnd),
                        "class": "professional"
                    })
                curInStart = None
            curStatus = status
    min_time = float('inf')
    max_time = float('-inf')
    for e in obj["events"]:
        time = e["time"]
        if time < min_time:
            min_time = time
        if time > max_time:
            max_time = time
    obj["start"] = min_time
    obj["end"] = max_time
    addInfo(obj, "event_count", "Events", len(obj["events"]))
    return obj
예제 #3
0
 def time():
     if peek("<") or peek(">"):
         c = cmp()
         d = date()
         return {
             "<": Range(None, d),
             "<=": Range(None, util.nextDay(d)),
             ">": Range(util.nextDay(d), None),
             ">=": Range(d, None)
         }[c]
     start = date()
     if peek("-"):
         char("-")
         end = date()
         return Range(start, util.nextDay(end))
     return Range(start, util.nextDay(start))
예제 #4
0
 def admissionDates(fromDate, toDate):
     if fromDate == '':
         if toDate == '':
             return
         fromDate = toDate
         toDate = ''
     curDate = util.toTime(fromDate)
     endDate = util.toTime(toDate) if toDate != '' else curDate
     while curDate <= endDate:
         handleStatusEvent(curDate, STATUS_IN)
         curDate = util.nextDay(curDate)
예제 #5
0
 def admissionDates(fromDate, toDate):
     if fromDate == '':
         if toDate == '':
             return
         fromDate = toDate
         toDate = ''
     curDate = util.toTime(fromDate)
     endDate = util.toTime(toDate) if toDate != '' else curDate
     while curDate <= endDate:
         handleStatusEvent(curDate, STATUS_IN)
         curDate = util.nextDay(curDate)
예제 #6
0
 def get_drugs(self, pid, obj, dict, new_dict_entries):
     query = """SELECT
         o.drug_exposure_id as id_row,
         o.drug_exposure_start_date as date_start,
         o.drug_exposure_end_date as date_end,
         o.drug_concept_id as m_id,
         o.drug_source_value as m_orig,
         c.domain_id as m_domain,
         c.concept_name as m_name,
         c.vocabulary_id as m_vocab,
         c.concept_code as m_num,
         p.total_paid as m_cost
        FROM
         {schema}.drug_exposure  o
        LEFT JOIN {schema}.concept c ON (
         c.concept_id = o.drug_concept_id
        )
        LEFT OUTER JOIN {schema}.drug_cost p ON (
         p.drug_exposure_id = o.drug_exposure_id
        )
        WHERE
         o.person_id = :pid
     """
     for row in self._exec(query, pid=pid):
         code = row['m_num']
         unmapped = False
         if code == 0:
             code = row['m_orig']
             unmapped = True
         id_row = 'm' + str(row['id_row'])
         d_id = row['m_id']
         name = row['m_name']
         vocab = row['m_vocab']
         group = "Drug" if row['m_domain'] is None else row['m_domain']
         desc = "{0} ({1} {2})".format(name, vocab, code)
         self.add_dict(dict, new_dict_entries, group, vocab, d_id, name,
                       desc, code, unmapped)
         date_start = self.to_time(row['date_start'])
         date_end = self.to_time(
             row['date_end']) if row['date_end'] else date_start
         date_cur = date_start
         cost = row['m_cost'] if 'm_cost' in row else None
         while date_cur <= date_end:
             event = self.create_event(group,
                                       str(vocab) + str(d_id), id_row)
             event['time'] = date_cur
             if cost:
                 event['cost'] = float(cost)
                 cost = None
             obj['events'].append(event)
             date_cur = util.nextDay(date_cur)
예제 #7
0
파일: omop.py 프로젝트: rkboyce/patient-viz
 def get_drugs(self, pid, obj, dict, new_dict_entries):
     query = """SELECT
         o.drug_exposure_id as id_row,
         o.drug_exposure_start_date as date_start,
         o.drug_exposure_end_date as date_end,
         o.drug_concept_id as m_id,
         o.drug_source_value as m_orig,
         c.domain_id as m_domain,
         c.concept_name as m_name,
         c.vocabulary_id as m_vocab,
         c.concept_code as m_num,
         p.total_paid as m_cost
        FROM
         {schema}.drug_exposure  o
        LEFT JOIN {schema}.concept c ON (
         c.concept_id = o.drug_concept_id
        )
        LEFT OUTER JOIN {schema}.drug_cost p ON (
         p.drug_exposure_id = o.drug_exposure_id
        )
        WHERE
         o.person_id = :pid
     """
     for row in self._exec(query, pid=pid):
         code = row['m_num']
         unmapped = False
         if code == 0:
             code = row['m_orig']
             unmapped = True
         id_row = 'm' + str(row['id_row'])
         d_id = row['m_id']
         name = row['m_name']
         vocab = row['m_vocab']
         group = "Drug" if row['m_domain'] is None else row['m_domain']
         desc = "{0} ({1} {2})".format(name, vocab, code)
         self.add_dict(dict, new_dict_entries, group, vocab, d_id, name, desc, code, unmapped)
         date_start = self.to_time(row['date_start'])
         date_end = self.to_time(row['date_end']) if row['date_end'] else date_start
         date_cur = date_start
         cost = row['m_cost'] if 'm_cost' in row else None
         while date_cur <= date_end:
             event = self.create_event(group, str(vocab) + str(d_id), id_row)
             event['time'] = date_cur
             if cost:
                 event['cost'] = float(cost)
                 cost = None
             obj['events'].append(event)
             date_cur = util.nextDay(date_cur)
예제 #8
0
 def get_diagnoses(self, pid, obj, dict, new_dict_entries):
     query = """SELECT
         o.condition_occurrence_id as id_row,
         o.condition_start_date as date_start,
         o.condition_end_date as date_end,
         o.condition_concept_id as d_id,
         o.condition_source_value as d_orig,
         c.domain_id as d_domain,
         c.concept_name as d_name,
         c.vocabulary_id as d_vocab,
         c.concept_code as d_num
        FROM
         {schema}.condition_occurrence  o
        LEFT JOIN {schema}.concept c ON (
         c.concept_id = o.condition_concept_id
        )
        WHERE
         o.person_id = :pid
     """
     for row in self._exec(query, pid=pid):
         code = row['d_num']
         unmapped = False
         if code == 0:
             code = row['d_orig']
             unmapped = True
         id_row = 'c' + str(row['id_row'])
         d_id = row['d_id']
         name = row['d_name']
         vocab = row['d_vocab']
         group = "Condition" if row['d_domain'] is None else row['d_domain']
         desc = "{0} ({1} {2})".format(name, vocab, code)
         self.add_dict(dict, new_dict_entries, group, vocab, d_id, name,
                       desc, code, unmapped)
         date_start = self.to_time(row['date_start'])
         date_end = self.to_time(
             row['date_end']) if row['date_end'] else date_start
         date_cur = date_start
         while date_cur <= date_end:
             event = self.create_event(group,
                                       str(vocab) + str(d_id), id_row)
             event['time'] = date_cur
             obj['events'].append(event)
             date_cur = util.nextDay(date_cur)
예제 #9
0
 def dates(fromDate, toDate):
     if fromDate == '':
         if toDate == '':
             return
         fromDate = toDate
         toDate = ''
     curDate = util.toTime(fromDate)
     endDate = util.toTime(toDate) if toDate != '' else curDate
     while curDate <= endDate:
         for event in handleEvent(row, claim_id):
             event['time'] = curDate
             handleKey(row, "claim_amount", MODE_OPTIONAL,
                       lambda amount: addCost(event, amount))
             obj['events'].append(event)
         handleStatusEvent(curDate, curStatus)
         handleKey(
             row, "location_flag", MODE_OPTIONAL,
             lambda flag: handleStatusEvent(
                 curDate, STATUS_FLAG_MAP.get(flag, STATUS_UNKNOWN)))
         curDate = util.nextDay(curDate)
예제 #10
0
 def dates(fromDate, toDate):
     if fromDate == '':
         if toDate == '':
             return
         fromDate = toDate
         toDate = ''
     curDate = util.toTime(fromDate)
     endDate = util.toTime(toDate) if toDate != '' else curDate
     while curDate <= endDate:
         for event in handleEvent(row, claim_id):
             event['time'] = curDate
             handleKey(row, "claim_amount", MODE_OPTIONAL, lambda amount:
                 addCost(event, amount)
             )
             obj['events'].append(event)
         handleStatusEvent(curDate, curStatus)
         handleKey(row, "location_flag", MODE_OPTIONAL, lambda flag:
             handleStatusEvent(curDate, STATUS_FLAG_MAP.get(flag, STATUS_UNKNOWN))
         )
         curDate = util.nextDay(curDate)
예제 #11
0
파일: omop.py 프로젝트: rkboyce/patient-viz
 def get_diagnoses(self, pid, obj, dict, new_dict_entries):
     query = """SELECT
         o.condition_occurrence_id as id_row,
         o.condition_start_date as date_start,
         o.condition_end_date as date_end,
         o.condition_concept_id as d_id,
         o.condition_source_value as d_orig,
         c.domain_id as d_domain,
         c.concept_name as d_name,
         c.vocabulary_id as d_vocab,
         c.concept_code as d_num
        FROM
         {schema}.condition_occurrence  o
        LEFT JOIN {schema}.concept c ON (
         c.concept_id = o.condition_concept_id
        )
        WHERE
         o.person_id = :pid
     """
     for row in self._exec(query, pid=pid):
         code = row['d_num']
         unmapped = False
         if code == 0:
             code = row['d_orig']
             unmapped = True
         id_row = 'c' + str(row['id_row'])
         d_id = row['d_id']
         name = row['d_name']
         vocab = row['d_vocab']
         group = "Condition" if row['d_domain'] is None else row['d_domain']
         desc = "{0} ({1} {2})".format(name, vocab, code)
         self.add_dict(dict, new_dict_entries, group, vocab, d_id, name, desc, code, unmapped)
         date_start = self.to_time(row['date_start'])
         date_end = self.to_time(row['date_end']) if row['date_end'] else date_start
         date_cur = date_start
         while date_cur <= date_end:
             event = self.create_event(group, str(vocab) + str(d_id), id_row)
             event['time'] = date_cur
             obj['events'].append(event)
             date_cur = util.nextDay(date_cur)