INSERT INTO `hilis4`.`parent_organisations` (`parent_code`, `description`, `referral_type_id`) 
	VALUES ('MSDMDH', 'MATER DEI MALTA', '4');
SELECT @org_id := id FROM parent_organisations WHERE parent_code = 'MSDMDH';
INSERT INTO `hilis4`.`referral_sources` (`display_name`, `organisation_code`, `parent_organisation_id`, `referral_type_id`) 
	VALUES ('Mater Dei Hospital, Malta', 'MSDMDH', @org_id, 4);
INSERT INTO `hilis4`.`referrers` (`name`, `national_code`, `referral_type_id`) VALUES ('Betts, A', 'X0000001', 1);
SELECT @ref_id := id FROM referrers WHERE national_code = 'X0000001';
INSERT INTO `hilis4`.`referrer_department` (`referrer_id`, `parent_organisation_id`, `hospital_department_code`) 
	VALUES (@ref_id, @org_id, 824);
SELECT @refdept_id := id FROM referrer_department WHERE parent_organisation_id = @org_id;
UPDATE requests r SET r.referrer_department_id = @refdept_id, r.updated_at = r.updated_at 
	WHERE r.id IN (
	/* from scripts/mater-dei/find_and_replace.pl */
		226843,
		226844,
		233796,
		233798,
		233926,
		233927,
		241679,
		244104,
		244105,
		244106,
		255765,
		252987,
		256891,
		263982,
		265699,
		266724,
		268029,
		296265,
		296588,
		303125,
		298335,
		301020,
		304544,
		305086,
		309994,
		311903,
		311904,
		316508,
		317200,
		317201,
		317202,
		319894,
		327058,
		328143,
		229654 /* manual addition - hand-written form */
	);
SELECT @src_id := id FROM referral_sources WHERE organisation_code = 'MSDMDH';
UPDATE patient_case SET referral_source_id = @src_id, time = time WHERE id IN (
	SELECT patient_case_id FROM requests WHERE referrer_department_id = @refdept_id );

SELECT @user_id := id FROM users WHERE username = 'hmds-lth';
INSERT INTO request_history(request_id, action, user_id) VALUES
		(226843, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(226844, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(233796, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(233798, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(233926, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(233927, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(241679, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(244104, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(244105, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(244106, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(255765, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(252987, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(256891, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(263982, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(265699, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(266724, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(268029, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(296265, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(296588, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(303125, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(298335, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(301020, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(304544, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(305086, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(309994, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(311903, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(311904, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(316508, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(317200, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(317201, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(317202, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(319894, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(327058, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(328143, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id),
		(229654, 'amended referral source [Unknown -> Mater Dei Hospital]', @user_id);
	
