I should probably add that this is the code frag that I'd like to add
Code:
CREATE OR REPLACE FUNCTION getCurrentDiagnosis(htcid integer) RETURNS SETOF integer AS $$
DECLARE
currentDiagnosis RECORD;
currentPatient RECORD;
BEGIN
FOR currentPatient IN SELECT subject.*
from subject, patientsitemember
where subject.id = patientsitemember.patient
and patientsitemember.htcsite = htcid LOOP
SELECT INTO currentDiagnosis diagnosis.* FROM diagnosis, patientstatus
where diagnosis.diagnosisid = patientstatus.patientstatusid
and patientstatus.patientid = currentPatient.id
order by diagnosis.diagnosisdate desc, diagnosis.diagnosisid desc
limit 1;
RETURN NEXT currentDiagnosis.bleedingdisorder;
END LOOP;
END;
$$ LANGUAGE plpgsql;