Closed fedorov closed 6 years ago
Scans and Annotation objects are stored in different tables, and so to do this type of query, you need a join
clause. See here.
Also, to get counts from a query, you can just issue a count
on the query, e.g.:
print pl.query(pl.Annotation).join(pl.Scan)\
.filter(pl.Scan.patient_id == 'LIDC-IDRI-0011').count()
# 23
Alternatively, you can accomplish this same result by:
scan = pl.query(pl.Scan).filter(pl.Scan.patient_id == 'LIDC-IDRI-0011').first()
print len(scan.annotations)
# 23
Thank you! Sorry for the confusion.
No problem. FYI, pylidc
is implemented with sqlalchemy
, which is where the filter
, count
, join
, etc ... functions come from. sqlalchemy
has nice documentation if you want to dive deeper into more complex query capabilities.
I am confused about the behavior of the query below. Should it filter by patient ID, or not?