Exemplo n.º 1
0
def test_create_model():
    model = Model('test')
    case = Node({"handle": "case"})
    #  set_trace()
    case.props['days_to_enrollment'] = Property(
        {"handle": 'days_to_enrollment'})
    model.add_node(case)
    assert isinstance(model.nodes['case'], Node)
    assert model.props[('case', 'days_to_enrollment')]
    model.add_node({"handle": "sample"})
    assert model.nodes["sample"]
    assert isinstance(model.nodes["sample"], Node)
    assert model.nodes["sample"].model == 'test'
    case_id = Property({"handle": "case_id", "value_domain": "string"})
    model.add_prop(case, case_id)
    assert model.props[("case", "case_id")]
    assert model.props[("case", "case_id")].value_domain == 'string'
    assert 'case_id' in model.nodes['case'].props
    sample = model.nodes["sample"]
    of_case = Edge({"handle": "of_case", "src": sample, "dst": case})
    of_case.props['operator'] = Property({
        "handle": "operator",
        "value_domain": "boolean"
    })
    model.add_edge(of_case)
    assert model.edges[('of_case', 'sample', 'case')]
    assert model.contains(of_case.props['operator'])
    assert of_case.props['operator'].model == 'test'
    assert model.props[('of_case', 'sample', 'case', 'operator')]
    assert model.props[('of_case', 'sample', 'case',
                        'operator')].value_domain == 'boolean'
    dx = Property({"handle": "diagnosis", "value_domain": "value_set"})
    tm = Term({"value": "CRS"})
    model.add_prop(case, dx)
    model.add_terms(dx, tm, 'rockin_pneumonia', 'fungusamongus')
    assert {x.value
            for x in dx.terms.values()
            } == {'CRS', 'rockin_pneumonia', 'fungusamongus'}
Exemplo n.º 2
0
def test_put_model(bento_neo4j):
  (b,h)=bento_neo4j
  the_mdb = MDB(uri=b)
  assert the_mdb
  ObjectMap.clear_cache()
  m = Model(handle='ICDC',mdb=the_mdb)
  m.dget()
  prop = m.props[('sample','sample_type')]
  sample = m.nodes['sample']
  edge = m.edges[('on_visit','sample', 'visit')]
  term = Term({"value":"electric_boogaloo"})
  m.add_terms(prop, term)
  node = m.nodes['lab_exam']
  m.dput()
  with m.drv.session() as session:
    result = session.run('match (v:value_set)-->(t:term {value:"electric_boogaloo"}) return v,t')
    rec = result.single()
    assert rec['v'].id == prop.value_set.neoid
    assert rec['t'].id == term.neoid
    assert rec['t']['value'] == term.value
    result = session.run('match (n:node {handle:"lab_exam"}) return n')
    rec = result.single()
    assert rec['n'].id == node.neoid

  term = m.props[('demographic','sex')].terms['M']
  assert term.concept
  assert term.concept._id == "337c0e4f-506a-4f4e-95f6-07c3462b81ff"

  concept = term.concept
  assert term in concept.belongs.values()
  term.concept=None
  assert not term in concept.belongs.values()
  assert ('concept',concept) in term.removed_entities
  m.dput()
  with m.drv.session() as session:
    result = session.run('match (t:term) where id(t)=$id return t',{"id":term.neoid})
    assert result.single() # term there
    result = session.run('match (c:concept) where id(c)=$id return c',{"id":concept.neoid})
    assert result.single() # concept there
    result = session.run('match (t:term)-->(c:concept) where id(t)=$id return t',{"id":term.neoid})
    assert not result.single() # but link is gone
  
    concept._id="heydude"
    term.concept = concept
    prop.model = None
    assert not prop.model

  m.dput()

  with m.drv.session() as session:
    result = session.run('match (t:term)--(c:concept) where id(t)=$id return c',{"id":term.neoid})
    s = result.single()
    assert s
    assert s['c'].id == concept.neoid
    assert s['c']['id'] == "heydude"
    result = session.run('match (p:property) where id(p)=$id return p',{"id":prop.neoid})
    s = result.single()
    assert s
    assert s['p'].id == prop.neoid
    assert not 'model' in s['p']

  prop.model = 'ICDC'
  at_enrollment = m.edges[('at_enrollment','prior_surgery','enrollment')]
  prior_surgery = m.nodes['prior_surgery']
  with m.drv.session() as session:
    result = session.run('match (n:node)<-[:has_src]-(r:relationship {handle:"at_enrollment"})-[:has_dst]->(:node {handle:"enrollment"}) where id(n)=$id return r',{"id":prior_surgery.neoid})
    s = result.single()
    assert s

  m.rm_edge(at_enrollment)
  assert not at_enrollment.src
  assert not at_enrollment.dst
  assert not at_enrollment in m.edges_out(prior_surgery)
  m.dput()
  with m.drv.session() as session:
    result = session.run('match (n:node)<-[:has_src]-(r:relationship {handle:"at_enrollment"})-[:has_dst]->(:node {handle:"enrollment"}) where id(n)=$id return r',{"id":prior_surgery.neoid})
    s = result.single()
    assert not s
    result = session.run('match (e:relationship) where id(e)=$id return e',{"id":at_enrollment.neoid})
    s = result.single()
    assert s