blatta wrote on Thursday, January 02, 2014:
I think the original poster was simply asking how to automate the insertion of pharmacy information in the practice section. My technique follows, although I use it on a Mac so it probably would work on a Linux system but might require some minor modification for Windows. In the example there is a CSV text file on the desktop named “pharmacies.txt”. You can pattern your insertion data after the attached file then run the code. It will automatically insert the pharmacy data, address, phone and fax numbers and then update the sequences.id number.
Code:
– /* Create temporary OpenEMR table for importing pharmacies */
CREATE TABLE openemr.t_pharm_import (
id smallint,
name varchar(76),
address1 varchar(76),
address2 varchar(76),
city varchar(36),
state varchar(2),
zip varchar(10),
areacode varchar(3),
prefix varchar(3),
number varchar(4),
faxareacode varchar(3),
faxprefix varchar(3),
faxnumber varchar(4),
transmit_method smallint default 1,
email varchar(36),
primary key (id)
);
– /* needs UNIX-style new-lines at end of each line and no smart-quotes (as written - this can be modified) */
LOAD DATA LOCAL INFILE ‘~/desktop/pharmacies.txt’
INTO TABLE openemr.t_pharm_import
FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY “’”
LINES TERMINATED BY ‘\n’
IGNORE 1 LINES;
SET @i = (SELECT id FROM openemr.sequences);
– /* import basic pharmacy data /
INSERT INTO openemr.pharmacies(id, name, transmit_method, email)
SELECT @i+((id4)-3), name, transmit_method, email
FROM openemr.t_pharm_import
ORDER BY openemr.t_pharm_import.id;
SELECT * FROM openemr.pharmacies;
– /* import addresses /
INSERT INTO openemr.addresses(id, line1, line2, city, state, zip, plus_four, country, foreign_id)
SELECT @i+((id4)-2), address1, address2, city, state, zip, NULL, ‘USA’, @i+((id*4)-3)
FROM openemr.t_pharm_import
ORDER BY openemr.t_pharm_import.id;
SELECT * FROM openemr.addresses;
– /* import phone numbers /
INSERT INTO openemr.phone_numbers(id, country_code, area_code, prefix, number, type, foreign_id)
SELECT @i+((id4)-1), ‘+1’, areacode, prefix, number, 2, @i+((id*4)-3)
FROM openemr.t_pharm_import
ORDER BY openemr.t_pharm_import.id;
SELECT * FROM openemr.phone_numbers;
– /* import fax numbers /
INSERT INTO openemr.phone_numbers(id, country_code, area_code, prefix, number, type, foreign_id)
SELECT @i+(id4), ‘+1’, faxareacode, faxprefix, faxnumber, 5, @i+((id*4)-3)
FROM openemr.t_pharm_import
ORDER BY openemr.t_pharm_import.id;
SELECT * FROM openemr.phone_numbers;
– /* reset sequences.id to proper value (contingent upon number of pharmacies added /
Set @i = 4(select max(id) from openemr.t_pharm_import);
UPDATE openemr.sequences SET id = id + @i;
DROP TABLE openemr.t_pharm_import;