/* LIST MEDICINE RISK SEVERITIES AS COMMA SEPERATED LIST */
/* =============================================================================================================== */
DROP FUNCTION IF EXISTS LIST_MEDICINE_RISKS;
COMMIT;

DELIMITER //

CREATE FUNCTION `LIST_MEDICINE_RISKS`(`p_userId` VARCHAR(36), `p_start` DATETIME)
RETURNS VARCHAR(555)
BEGIN

	DECLARE vList VARCHAR(555) DEFAULT NULL;

  SELECT GROUP_CONCAT(`severity`)
  FROM `MedicineRisks`
  WHERE `userId` = p_userId
  AND `dependant` IS NULL
  AND DATEDIFF(`weekStart`, p_start) = 0
  INTO vList;
	
	RETURN vList;

END 
//
COMMIT //

DELIMITER ;
