/*DTP_HB_Hib1,2,3*/

delete FROM person_vaccine WHERE export_vaccine_code IN ('d21','d22','d23');

DELETE FROM wbc_vaccine WHERE export_vaccine_code IN ('d21','d22','d23');

delete FROM vaccine_combination

WHERE vaccine_code IN ('DTP-HB-Hib 1','DTP-HB-Hib 2','DTP-HB-Hib 3',@vaccine_code1,@vaccine_code2,@vaccine_code3);

delete FROM provis_vcctype WHERE CODE IN ('d21','d22','d23');

delete FROM provis_aptype WHERE CODE IN ('d21','d22','d23');

DELETE FROM baby_items WHERE export_code IN ('d21','d22','d23');

DELETE FROM person_vaccine_group_lot

WHERE vaccine_group IN('DTP-HB-Hib 1','DTP-HB-Hib 2','DTP-HB-Hib 3',@vaccine_code1,@vaccine_code2,@vaccine_code3);

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

SET @Hib2 = (select max(person_vaccine_id)+2 from person_vaccine) ;

SET @Hib3 = (select max(person_vaccine_id)+3 from person_vaccine) ;

set @vaccine_code1 = 'DTP-HB-Hib 1' ;

set @vaccine_code2 = 'DTP-HB-Hib 2' ;

set @vaccine_code3 = 'DTP-HB-Hib 3' ;

REPLACE INTO person_vaccine (person_vaccine_id, vaccine_name, vaccine_code, vaccine_group, export_vaccine_code, hos_guid, combine_vaccine, icode)

VALUES (@Hib1, 'ดีทีพีตับอักเสบบีฮิบ 1', @vaccine_code1, 'DTPHB', 'D21', NULL, NULL, NULL);

REPLACE INTO person_vaccine (person_vaccine_id, vaccine_name, vaccine_code, vaccine_group, export_vaccine_code, hos_guid, combine_vaccine, icode)

VALUES (@Hib2, 'ดีทีพีตับอักเสบบีฮิบ 2',@vaccine_code2, 'DTPHB', 'D22', NULL, NULL, NULL);

REPLACE INTO person_vaccine (person_vaccine_id, vaccine_name, vaccine_code, vaccine_group, export_vaccine_code, hos_guid, combine_vaccine, icode)

VALUES (@Hib3, 'ดีทีพีตับอักเสบบีฮิบ 3',@vaccine_code3, 'DTPHB', 'D23', NULL, NULL, NULL);

/*

SELECT * FROM person_vaccine

WHERE export_vaccine_code IN ('d21','d22','d23');*/

#----------------------wbc_vaccine

SET @hib_w1 =(select max(wbc_vaccine_id)+1 from wbc_vaccine);

SET @hib_w2 =(select max(wbc_vaccine_id)+2 from wbc_vaccine);

SET @hib_w3 =(select max(wbc_vaccine_id)+3 from wbc_vaccine);

INSERT 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 (@hib_w1, 'ดีทีพีตับอักเสบบีฮิบ 1',@vaccine_code1, 2, 4, 'D21','DTP_HBHib1', NULL, NULL, NULL, NULL, 'N');

INSERT 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 (@hib_w2, 'ดีทีพีตับอักเสบบีฮิบ 2',@vaccine_code2, 2, 4, 'D22','DTP_HBHib2', NULL, NULL, NULL, NULL, 'N');

INSERT 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 (@hib_w3, 'ดีทีพีตับอักเสบบีฮิบ 3',@vaccine_code3, 2, 4, 'D23','DTP_HBHib3', NULL, NULL, NULL, NULL, 'N');

#SELECT * FROM wbc_vaccine WHERE export_vaccine_code IN ('d21','d22','d23');

#----------------------vaccine_combination

SET @hib_c1 =(select max(vaccine_combination_id)+1 from vaccine_combination);

SET @hib_c2 =(select max(vaccine_combination_id)+2 from vaccine_combination);

SET @hib_c3 =(select max(vaccine_combination_id)+3 from vaccine_combination);

INSERT INTO vaccine_combination (vaccine_combination_id, vaccine_code, vaccine_combine_code, hos_guid)

VALUES (@hib_c1,@vaccine_code1, 'DTP-HB-Hib 1', NULL);

INSERT INTO vaccine_combination (vaccine_combination_id, vaccine_code, vaccine_combine_code, hos_guid)

VALUES (@hib_c2,@vaccine_code2, 'DTP-HB-Hib 2', NULL);

INSERT INTO vaccine_combination (vaccine_combination_id, vaccine_code, vaccine_combine_code, hos_guid)

VALUES (@hib_c3,@vaccine_code3, 'DTP-HB-Hib 3', NULL);

/*SELECT * FROM vaccine_combination

WHERE vaccine_code IN ('DTP-HB-Hib 1','DTP-HB-Hib 2','DTP-HB-Hib 3');*/

UPDATE serial AS s

SET s.serial_no = @hib_c3

WHERE NAME LIKE 'vaccine_combination_id%';

#----------------------provis_vcctype

INSERT INTO provis_vcctype (code, name, hos_guid)

VALUES ('D21',@vaccine_code1, NULL);

INSERT INTO provis_vcctype (code, name, hos_guid)

VALUES ('D22',@vaccine_code2, NULL);

INSERT INTO provis_vcctype (code, name, hos_guid)

VALUES ('D23',@vaccine_code3, NULL);

/*SELECT * FROM provis_vcctype

WHERE CODE IN ('d21','d22','d23');*/

#----------------------provis_aptype

INSERT INTO provis_aptype (code, name, hos_guid, hos_guid_ext)

VALUES ('D21',@vaccine_code1, NULL, NULL);

INSERT INTO provis_aptype (code, name, hos_guid, hos_guid_ext)

VALUES ('D22',@vaccine_code2, NULL, NULL);

INSERT INTO provis_aptype (code, name, hos_guid, hos_guid_ext)

VALUES ('D23',@vaccine_code3, NULL, NULL);

/*SELECT * FROM provis_aptype

WHERE CODE IN ('d21','d22','d23');*/

#----------------------baby_items

SET @baby_code = (SELECT MAX(baby_code)+1 FROM baby_items);

SET @baby_code2 = (SELECT MAX(baby_code)+2 FROM baby_items);

SET @baby_code3 = (SELECT MAX(baby_code)+3 FROM baby_items);

INSERT INTO baby_items (baby_code, baby_group, service_code, baby_name, vaccine_code, display_order, export_code, hos_guid)

VALUES (@baby_code, 2, NULL, 'ดีทีพีตับอักเสบบีฮิบ 1',@vaccine_code1, NULL, 'D21', NULL);

INSERT INTO baby_items (baby_code, baby_group, service_code, baby_name, vaccine_code, display_order, export_code, hos_guid)

VALUES (@baby_code2, 2, NULL, 'ดีทีพีตับอักเสบบีฮิบ 2',@vaccine_code2, NULL, 'D22', NULL);

INSERT INTO baby_items (baby_code, baby_group, service_code, baby_name, vaccine_code, display_order, export_code, hos_guid)

VALUES (@baby_code3, 2, NULL, 'ดีทีพีตับอักเสบบีฮิบ 3',@vaccine_code3, NULL, 'D23', NULL);

/*SELECT * FROM baby_items

WHERE export_code IN ('d21','d22','d23');*/

#-----------------------person_vaccine_group_lot

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

SET @Hibg2 = (select max(person_vaccine_group_lot_id)+2 from person_vaccine_group_lot) ;

SET @Hibg3 = (select max(person_vaccine_group_lot_id)+3 from person_vaccine_group_lot) ;

INSERT 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 (@Hibg1,@vaccine_code1, NULL, NULL, NULL, NULL, NULL, 'Y', NULL);

INSERT 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 (@Hibg2,@vaccine_code2, NULL, NULL, NULL, NULL, NULL, 'Y', NULL);

INSERT 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 (@Hibg3,@vaccine_code3, NULL, NULL, NULL, NULL, NULL, 'Y', NULL);

UPDATE serial

SET serial_no = @Hibg3

WHERE NAME LIKE 'person_vaccine_group_lot_id%';

SELECT *

FROM person_vaccine_group_lot AS g

WHERE g.vaccine_group IN(@vaccine_code1,@vaccine_code2,@vaccine_code3);

#-----------------------