/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; DELIMITER ;; /*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE*/;; /*!50003 DROP PROCEDURE IF EXISTS `sp_ega_encounter_date` */;; /*!50003 SET SESSION SQL_MODE=""*/;; /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`localhost`*/ /*!50003 PROCEDURE `sp_ega_encounter_date`() BEGIN DECLARE v_done INT DEFAULT 0; DECLARE this_id BIGINT(20) default NULL; DECLARE this_encounter_date date; DECLARE this_current_lmp_date date; DECLARE this_current_ega_days int(11); DECLARE this_current_ega_days_encounter_id int(11); DECLARE this_current_flow int(11); DECLARE this_datevisit date; DECLARE this_lmp date; DECLARE this_edd date; DECLARE this_dateDiff int(11); DECLARE this_dateDiffDays int(11); DECLARE this_dateDiffWeeks int(11); DECLARE this_dateDiffRemainder int(11); DECLARE this_ega VARCHAR(20); DECLARE egaCursor CURSOR FOR SELECT id, encounter_date FROM zeports.hiv_report; DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = 1; OPEN egaCursor; egaLoop:LOOP FETCH egaCursor INTO this_id, this_encounter_date; call sp_pregnancy_dating(this_id, this_datevisit, this_lmp, this_edd, this_current_ega_days); SET this_dateDiffDays = DATEDIFF(this_encounter_date,this_datevisit); SET this_dateDiffWeeks = TRUNCATE((this_current_ega_days + this_dateDiffDays)/7,0); SET this_dateDiffRemainder = (this_current_ega_days + this_dateDiffDays) % 7; SET this_ega = CONCAT(this_dateDiffWeeks,' ',this_dateDiffRemainder,'/7'); UPDATE zeports.hiv_report set ega_weeks = this_ega WHERE id = this_id AND encounter_date = this_encounter_date; IF v_done=1 THEN LEAVE egaLoop; END IF; END LOOP egaLoop; CLOSE egaCursor; SET v_done=0; END */;;