/*

R21:โรต้า3-1 2 เดือนอายุไม่เกิน 15 สัปดาห์

*/

# person_vaccine

DELETE FROM person_vaccine WHERE export_vaccine_code ='R21';

SET @R21 = (select max(person_vaccine_id)+1 from person_vaccine) ;

INSERT IGNORE INTO person_vaccine ( person_vaccine_id , vaccine_name , vaccine_code , vaccine_group , export_vaccine_code , hos_guid , combine_vaccine , icode ) VALUES (@R21, 'R21: โรต้า 3-1 2 เดือน (อายุไม่เกิน 15 สัปดาห์)', 'RV3-1', 'RV', 'R21', NULL, 'N', NULL);

-- SELECT * FROM person_vaccine wHERE export_vaccine_code = 'R21';

# vaccine_combination

SET @c21 = ( SELECT MAX(vaccine_combination_id)+1 FROM vaccine_combination) ;

DELETE FROM vaccine_combination WHERE vaccine_code= 'RV3-1';

INSERT IGNORE INTO vaccine_combination (vaccine_combination_id, vaccine_code, vaccine_combine_code, hos_guid) VALUES (@c21, 'RV3-1', 'RV3-1', NULL);

UPDATE serial

SET serial_no = (SELECT MAX(vaccine_combination_id) FROM vaccine_combination)

WHERE serial.name = 'vaccine_combination_id';

-- select * FROM vaccine_combination WHERE vaccine_code= 'RV3-1';

# wbc_vaccine

DELETE FROM wbc_vaccine WHERE export_vaccine_code='R21';

SET @w21 = (

SELECT MAX(wbc_vaccine_id)+1

FROM wbc_vaccine) ;

INSERT IGNORE INTO wbc_vaccine (wbc_vaccine_id, wbc_vaccine_name, wbc_vaccine_code, age_min, age_max, export_vaccine_code, check_code, vaccine_in_use, hos_guid, icode, price, combine_vaccine) VALUES (@w21, 'R21: โรต้า 3-1 2 เดือน (อายุไม่เกิน 15 สัปดาห์)', 'RV3-1', 8, 15, 'R21', 'R21', NULL, NULL, NULL, NULL, 'N');

-- select * FROM wbc_vaccine WHERE export_vaccine_code='R21';

# provis_vcctype

DELETE FROM provis_vcctype WHERE code='R21';

INSERT IGNORE INTO provis_vcctype (code, name, hos_guid) VALUES ('R21', 'RV3-1', NULL);

-- SELECT * FROM provis_vcctype v WHERE v.code ='R21';

# provis_aptype

delete FROM provis_aptype where code = 'R21';

INSERT IGNORE INTO provis_aptype (code,name,hos_guid,hos_guid_ext) VALUES ('R21','RV3-1',NULL,NULL);

-- SELECT * FROM provis_aptype as v where v.code = 'R21';

# baby_items

delete FROM baby_items where export_code = 'R21';

set @b21 = (SELECT max(baby_code)+1 FROM baby_items);

INSERT IGNORE INTO baby_items (baby_code, baby_group, service_code, baby_name, vaccine_code, display_order, export_code, hos_guid) VALUES (@b21, 4, NULL, 'โรต้า 3-1 2 เดือน (อายุไม่เกิน 15 สัปดาห์)', 'RV3-1', NULL, 'R21', NULL);

-- SELECT * FROM baby_items where export_code = 'R21';

# person_vaccine_group_lot

delete FROM person_vaccine_group_lot where vaccine_group = 'RV3-1';

SET @G21 = (select max(person_vaccine_group_lot_id)+1 from person_vaccine_group_lot) ;

INSERT IGNORE INTO person_vaccine_group_lot (person_vaccine_group_lot_id, vaccine_group, vaccine_lot, receive_date, expire_date, receive_qty, left_qty, vaccine_lot_active, hos_guid) VALUES (@G21, 'RV3-1', NULL, NULL, NULL, NULL, NULL, 'Y', NULL);

UPDATE  serial

SET serial_no = (

select person_vaccine_group_lot_id

from person_vaccine_group_lot

where vaccine_group = 'RV3-1')

WHERE serial.name = 'person_vaccine_group_lot_id';

SELECT * FROM person_vaccine_group_lot o where o.vaccine_group = 'RV3-1';