#Location SQL

select * from location;
select * from location_tag;
select * from location_tag_map;
select * from bed_type;
select * from bed;
select * from bed_location_map;
select * from bed_patient_assignment_map;

insert into location_tag (name, description, creator, retired, date_created, uuid) values('Admission Location', 'General Ward Patients', 2, 0, NOW(), UUID());
SET @location_tag_id = (select location_tag_id from location_tag where name='Admission Location');

insert into bed_type values(1, 'deluxe', 'deluxe bed', 'DLX');
insert into bed_type values(2, 'luxury', 'luxury bed', 'LXY');
insert into bed_type values(3, 'normal', 'normal bed', 'NRM');

# First WARD

insert into location (name, description, creator, retired, date_created, uuid) values('General Ward', 'General Ward', 1, 0, NOW(), UUID());
SET @parent_location_id = (select location_id from location where name='General Ward');
insert into location (name, description, creator, retired, date_created, uuid, parent_location) values('Physical General Ward', '1st Floor of General Ward', 1, 0, NOW(), UUID(), @parent_location_id);
SET @location_id = (select location_id from location where name='Physical General Ward');

insert into location_tag_map values( @parent_location_id , @location_tag_id);
insert into location_tag_map values( @location_id , @location_tag_id);


insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(1, '304-a', 'AVAILABLE', 1, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(2, '304-b', 'AVAILABLE', 2, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(3, '304-c', 'AVAILABLE', 3, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(4, '304-d', 'AVAILABLE', 1, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(5, '305-a', 'AVAILABLE', 2, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(6, '305-b', 'AVAILABLE', 3, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(7, '305-c', 'AVAILABLE', 1, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(8, '305-d', 'AVAILABLE', 2, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(9, '306-a', 'AVAILABLE', 3, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(10, '306-b', 'AVAILABLE', 1, UUID(), 1, NOW(), false);

insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(1, @location_id, 1, 1, 1);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(2, @location_id, 1, 2, 2);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(3, @location_id, 1, 3, 3);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(4, @location_id, 1, 4, 4);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(5, @location_id, 2, 1, 5);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(6, @location_id, 2, 2, 6);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(7, @location_id, 2, 3, 7);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(8, @location_id, 2, 4, 8);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(9, @location_id, 3, 1, 9);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(10, @location_id, 3, 2, 10);


# Second Ward

insert into location (name, description, creator, retired, date_created, uuid) values('Labour Ward', 'General Ward', 1, 0, NOW(), UUID());
SET @parent_location_id = (select location_id from location where name='Labour Ward');
insert into location (name, description, creator, retired, date_created, uuid, parent_location) values('Physical Labour Ward', '1st Floor of General Ward', 1, 0, NOW(), UUID(), @parent_location_id);
SET @location_id = (select location_id from location where name='Physical Labour Ward');

SET @location_tag_id = (select location_tag_id from location_tag where name='Admission Location');

insert into location_tag_map values( @parent_location_id , @location_tag_id);
insert into location_tag_map values( @location_id , @location_tag_id);

insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(11, '314-a', 'AVAILABLE', 1, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(12, '314-b', 'AVAILABLE', 2, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(13, '314-c', 'AVAILABLE', 3, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(14, '314-d', 'AVAILABLE', 1, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(15, '315-a', 'AVAILABLE', 2, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(16, '315-b', 'AVAILABLE', 3, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(17, '315-c', 'AVAILABLE', 1, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(18, '315-d', 'AVAILABLE', 2, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(19, '316-a', 'AVAILABLE', 3, UUID(), 1, NOW(), false);
insert into bed (bed_id, bed_number, status, bed_type_id, uuid, creator, date_created, voided) values(20, '316-b', 'AVAILABLE', 1, UUID(), 1, NOW(), false);

insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(11, @location_id, 1, 1, 11);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(12, @location_id, 1, 2, 12);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(13, @location_id, 1, 3, 13);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(14, @location_id, 1, 4, 14);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(15, @location_id, 2, 1, 15);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(16, @location_id, 2, 2, 16);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(17, @location_id, 2, 3, 17);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(18, @location_id, 2, 4, 18);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(19, @location_id, 3, 1, 19);
insert into bed_location_map(bed_location_map_id, location_id, row_number, column_number, bed_id) values(20, @location_id, 3, 2, 20);
