Esempio n. 1
0
def handle_data_entity(context, phenotype: PhenotypeModel, define_name, final):
    print('data entity')
    pe = PhenotypeEntity(define_name, 'define', final=final)
    call = get_method_call(context.getChild(0))
    # hasSepsis = PhenotypeEntity('hasSepsis', 'define',
    #                             library='ClarityNLP',
    #                             funct='ProviderAssertion',
    #                             named_arguments={
    #                                 "termsets": ['Sepsis'],
    #                                 "documentsets": [
    #                                     'ProviderNotes',
    #                                     "Radiology"
    #                                 ]
    #                             })
    pe["funct"] = call["funct"]
    pe["library"] = call["library"]
    named_args = call["named_arguments"]
    args = call["arguments"]
    if named_args:
        pe["named_arguments"] = named_args
    if args and len(args) > 0:
        pe["arguments"] = args
    if not phenotype.data_entities:
        phenotype.data_entities = list()

    phenotype.data_entities.append(pe)
Esempio n. 2
0
def handle_tuple(context, phenotype: PhenotypeModel, define_name, final):
    log('tuple')

    obj = get_obj_context(context.getChild(0).getChild(1), to_string=True)
    num_children = len(context.children)
    op_raw_text = ''
    tuple_name = '{}_Step1'.format(define_name)
    if num_children == 2:
        operation = parse_operation(context.getChild(1), tuple_name, final)
        if operation:
            if not phenotype.operations:
                phenotype.operations = list()
            phenotype.operations.append(operation)
            op_raw_text = operation.get('raw_text')

    else:
        operation = None

    raw_text = '''
        Tuple {}
        {}
    '''

    if not operation:
        where = ''
    else:
        where = 'where {}'.format(op_raw_text)
    tuple_str = json.dumps(obj, indent=4)
    pe = PhenotypeEntity(tuple_name, 'define', final=final, tuple_=True, tuple_object=obj, tuple_predicate=operation,
                         raw_text=raw_text.format(tuple_str, where), tuple_raw_text='Tuple {}'.format(tuple_str))

    if not phenotype.tuples:
        phenotype.tuples = list()

    phenotype.tuples.append(pe)