RSS Git Download  Clone
Raw Blame History
[previous_cml_monitoring]
select date(r.created_at) as 'registered', rrs.results_summary as 'result'
from requests r
	join ( patient_case pc join patients p on pc.patient_id = p.id )
		on r.patient_case_id = pc.id
	join ( request_initial_screen ris join screens s on ris.screen_id = s.id )
		on ris.request_id = r.id
	join ( request_result_summaries rrs join lab_sections ls on rrs.lab_section_id = ls.id )
		on rrs.request_id = r.id
where s.description = 'Follow-up CML (PB)'
	and ls.section_name = 'Molecular'
	and p.nhs_number = ?
order by r.created_at desc
limit 5

[referral_sources]
select rs.id, rs.display_name, rs.organisation_code
from referral_sources rs
    join referral_types rt on rs.referral_type_id = rt.id
where rt.description = 'hospital'
    and rs.is_active = 'yes'
	and rs.display_name regexp ? /* sqlite can't do rlike, use 'regexp' */
order by rs.display_name
limit 5

[referrers]
select r.id, r.name, hd.display_name, po.description
from referrer_department rd
	join referrers r on rd.referrer_id = r.id
	join parent_organisations po on rd.parent_organisation_id = po.id
	join hospital_departments hd on rd.hospital_department_code = hd.id
	join referral_sources rs on rs.parent_organisation_id = po.id
where rd.is_active = 'yes'
	and r.name regexp ?
	/* and hd.display_name rlike 'haematology' */
	and rs.id = ?
order by r.name
limit 5