For an Xray file system patients have folders and folders have studies.
That is:
patients folders studies
id id id
name patient_id folder_id
… label type
… …
The list of studies with their associated folder and patient might look
like this:
name folder_label study_type
Brown,Sam brsa1 CXR
Jones,Gary jg99999 CXR
Jones,Gary joga15 CT
Smith,Rob smro4 CXR
Smith,Rob smro4 CT
I want to present my user with a list of all studies of type ‘CXR’
sorted by the patient name and folder label.
Rails seems to want us to do this:
In the models:
Link patients, folders and studies thru has_many and belongs_to
relationships.
In the controllers provide arrays of records with:
@studies= Study.find(:all, :condition => “type = ‘CXR’” )
In the list view do:
<% for study in @studies -%>
This seems to require a new query to the db for each row AND I don’t see
any reasonable way to sort the list by name and label. Sorting would
have to get into the pagination code. Ugly!
An SQL query to do this in one step would look like:
SELECT p.name, f.label, s.type
FROM patients p, folders f, studies s
WHERE f.id = s.folder_id
AND p.id = f.patient_id
AND s.type = ‘CXR’
ORDER BY p.name, f.label
Is there a way to put this into a model so that the controller and view
code might simply deal with:
@explicated_studies = ExplicatedStudy.find(:all, :condition => “type in
(‘CXR’, ‘CT’)” )
and:
…
acts_as_list appears to allow accessing the linked tables thru the
patients table. However, if I want a list of all studies that cuts
across all folders and patients and want to sort the list by fields in
folders and patients, acts_as_list doesn’t seem to provide any help.