예제 #1
0
def enrichDict(file, mid):
    dict = loadOldDict(file)
    if mid == '-':
        patient = json.loads(sys.stdin.read())
    else:
        with open(mid, 'r') as pfile:
            patient = json.loads(pfile.read())
    extractEntries(dict, patient)
    with util.OutWrapper(file) as out:
        print(json.dumps(dict, indent=2, sort_keys=True), file=out)
예제 #2
0
        "v_spans": []
    }
    if lineFile is not None:
        with open(lineFile, 'r') as lf:
            for line in lf:
                processLine(obj, line)

    addInfo(obj, "pid", "Patient", id)
    if len(allPaths) == 0:
        print('warning: no path given', file=sys.stderr)
    for (path, isfile) in allPaths:
        if isfile:
            processFile(path, id, obj)
        else:
            processDirectory(path, id, obj)
    min_time = sys.maxint
    max_time = -sys.maxint - 1
    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"]))
    if output != '-' and not os.path.exists(os.path.dirname(output)):
        os.makedirs(os.path.dirname(output))
    with util.OutWrapper(output) as out:
        print(json.dumps(obj, indent=2), file=out)
예제 #3
0
if __name__ == '__main__':
    (settings, settingsFile, info, lookupMode, rest) = interpretArgs()
    dictionary.init(settings, settingsFile)
    if lookupMode:
        edict = {}

        def addEntry(e):
            spl = e.split('__', 1)
            if len(spl) != 2:
                print("shorthand format is '${group_id}__${type_id}': " + e,
                      file=sys.stderr)
                sys.exit(1)
            dictionary.createEntry(edict, spl[0].strip(), spl[1].strip())

        for e in rest:
            if e == "-":
                for eid in sys.stdin.read().split(" "):
                    if len(
                            eid
                    ) > 0 and eid != "id" and eid != "outcome" and eid != "test":
                        addEntry(eid)
            else:
                addEntry(e)

        ofile = info['output']
        with util.OutWrapper(ofile) as out:
            print(json.dumps(edict, indent=2, sort_keys=True), file=out)
    else:
        enrichDict(info['output'], info['mid'])
예제 #4
0
                usage()
            info['pid'] = args.pop(0)
        elif val == '--all':
            info['pid'] = '--all'
        elif val == '-c':
            if not args:
                print('-c requires argument', file=sys.stderr)
                usage()
            readConfig(settings, args.pop(0))
        elif val == '-o':
            if not args:
                print('-o requires argument', file=sys.stderr)
                usage()
            info['output'] = args.pop(0)
        else:
            print('illegal argument ' + val, file=sys.stderr)
            usage()
    if do_list:
        printList(settings)
        sys.exit(0)
    if info['pid'] == '':
        print('patient id required', file=sys.stderr)
        usage()
    return (settings, info)


if __name__ == '__main__':
    (settings, info) = interpretArgs()
    with util.OutWrapper(info['output']) as output:
        readShelve(info['pid'], settings, output)