Skip to content

Instantly share code, notes, and snippets.

@delonnewman
Last active February 11, 2016 19:25
Show Gist options
  • Save delonnewman/5843780 to your computer and use it in GitHub Desktop.
Save delonnewman/5843780 to your computer and use it in GitHub Desktop.
#
# Creates a set 'Patients' from the ORM model 'Recruitment::Patient'
# (DataMapper, ActiveRecord, and plain Ruby Arrays are supported)
#
# When exported as a PDF it will have the title "Recruited Patients"
# and the subtitle "[DATE], [NUMBER OF CASES] Cases"
#
defset :Patients do
from Recruitment::Patient
has :fields => [ :PID, :DateOfDeath, :CompletionDate ],
:title => "Recruited Patients",
:subtitle => "%D, %C Cases",
:sections => []
end
#
# Creates a subset or section for Patients
# of all the patients with a non-nil 'DateOfDeath'
#
# When the Patients set its printed as a PDF all
# subsets or sections will be printed along with it.
#
defset :Deceased do
from Patients.DateOfDeath
has :title => "Deceased, %C Cases"
Patients.sections << us
end
#
# Create subsets for Patients for patients recruited
# for each year of the study.
#
Patients.map(&:StudyYear).uniq.sort.each do |y|
defset :"SY#{y}" do
from Patients.StudyYear(y)
has :title => "Study Year #{y}, %C Cases"
Patients.sections << us
end
end
# Export to a PDF called "patients-[DATE]-[COUNT OF CASES].pdf"
Patients.export.to("patients-%D-%C.pdf")
# Export to a CSV file called "patients-[DATE]-[COUNT OF CASES].csv"
Patients.export.to("patients-%D-%C.csv")
# Export just the Deceased
Deceased.export.to("deceased-%D-%C.pdf")
# Export patients recruited during the first year
SY01.export.to("patients-year-01-%D-%C.pdf")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment