This section last updated: 2024-04-18 (8 months ago)
These are very rudimentary scripts for importing the LOINC codes into a various databases. These scripts are very basic and should not be used in a production environment. They are provided as a starting point to show one method that can be used to load the LOINC data.
It is highly recommended that you consult with your database administrator before attempting to run these scripts or load these data.
These scripts can be used to import the Loinc.csv, MapTo.csv, and SourceOrganization.csv files into your database.
Run the following to make the table structure needed to import the data.
DROP TABLE IF EXISTS SourceOrganization;
CREATE TABLE SourceOrganization (
id integer default null,
copyright_id varchar(255) not null,
name varchar(255) default null,
copyright text,
terms_of_use text,
url text default null,
primary key (copyright_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS Loinc;
CREATE TABLE Loinc (
loinc_num varchar(10) not null,
component varchar(255) default null,
property varchar(255) default null,
time_aspct varchar(255) default null,
`system` varchar(255) default null,
scale_typ varchar(255) default null,
method_typ varchar(255) default null,
class varchar(255) default null,
VersionLastChanged varchar(255) default null,
chng_type varchar(255) default null,
DefinitionDescription text,
status varchar(255) default null,
consumer_name varchar(255) default null,
classtype int(11) default null,
formula text,
exmpl_answers text,
survey_quest_text text,
survey_quest_src varchar(50) default null,
unitsrequired varchar(1) default null,
relatednames2 text,
shortname varchar(255) default null,
order_obs varchar(15) default null,
hl7_field_subfield_id varchar(50) default null,
external_copyright_notice text,
example_units varchar(255) default null,
long_common_name varchar(255) default null,
example_ucum_units varchar(255) default null,
status_reason varchar(9) default null,
status_text text,
change_reason_public text,
common_test_rank integer default null,
common_order_rank integer default null,
hl7_attachment_structure varchar(15) default null,
ExternalCopyrightLink varchar(255) default null,
PanelType varchar(50) default null,
AskAtOrderEntry varchar(255) default null,
AssociatedObservations varchar(255) default null,
VersionFirstReleased varchar(255) default null,
ValidHL7AttachmentRequest varchar(50) default null,
DisplayName varchar(255) default null,
primary key (loinc_num)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS MapTo;
CREATE TABLE MapTo (
loinc varchar(10) NOT NULL,
map_to varchar(10) NOT NULL,
comment text,
primary key (loinc, map_to)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Run the following to perform the import. The script assumes you are using the loinc schema to import the data, if not change the USE statement at the top to use the appropriate schema. Be sure to update the file paths to the correct location of the .csv files before running.
Refer to MySQL's documentation regarding the LOAD DATA statement. You may need to adjust the server's security settings or place the files in a privileged location (and omit LOCAL below) in order to the statement to work.
USE loinc;
LOAD DATA LOCAL INFILE '..\\Loinc.csv'
INTO TABLE Loinc
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(
loinc_num,
component,
property,
time_aspct,
`system`,
scale_typ,
method_typ,
class,
VersionLastChanged,
chng_type,
DefinitionDescription,
status,
consumer_name,
classtype,
formula,
exmpl_answers,
survey_quest_text,
survey_quest_src,
unitsrequired,
relatednames2,
shortname,
order_obs,
hl7_field_subfield_id,
external_copyright_notice,
example_units,
long_common_name,
example_ucum_units,
status_reason,
status_text,
change_reason_public,
common_test_rank,
common_order_rank,
hl7_attachment_structure,
ExternalCopyrightLink,
PanelType,
AskAtOrderEntry,
AssociatedObservations,
VersionFirstReleased,
ValidHL7AttachmentRequest,
DisplayName
)
;
LOAD DATA LOCAL INFILE '..\\MapTo.csv'
INTO TABLE MapTo FIELDS
TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(
loinc,
map_to,
comment
);
LOAD DATA LOCAL INFILE '..\\SourceOrganization.csv'
INTO TABLE SourceOrganization FIELDS
TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(
id,
copyright_id,
name,
copyright,
terms_of_use,
url
)
;
select count(*) from Loinc;
select count(*) from MapTo;
select count(*) from SourceOrganization;
Provided is an basic batch script you can use to automate the execution of the above queries. It is assumed that you are working in a Windows environment and have the MySQL software installed on your PC. Follow these steps to create and run the scripts:
Note: Perform these steps in the directory that contain the .csv files to be imported.
REM
REM
REM Please edit this script and provide values for the variables below.
REM
SET MYSQL_HOME=
SET USERNAME=
SET HOST_NAME=
SET DB_NAME=
ECHO Creating tables ...
%MYSQL_HOME%\bin\mysql -u %USERNAME% -h %HOST_NAME% -p %DB_NAME% < MySQLDDL.sql
ECHO Loading tables ...
%MYSQL_HOME%\bin\mysql -u %USERNAME% -h %HOST_NAME% -p %DB_NAME% < MySQLLoader.sql
echo
echo ----------------------------------------
echo Finished
echo ----------------------------------------
The scripts below require the Oracle SQL*Loader utility.
Run the following to make the table structure needed to import the data.
CREATE TABLE Loinc
(
LOINC_NUM VARCHAR2(10),
COMPONENT VARCHAR2(255),
PROPERTY VARCHAR2(255),
TIME_ASPCT VARCHAR2(255),
SYSTEM VARCHAR2(255),
SCALE_TYP VARCHAR2(255),
METHOD_TYP VARCHAR2(255),
CLASS VARCHAR2(255),
VersionLastChanged VARCHAR2(255),
CHNG_TYPE VARCHAR2(255),
DEFINITIONDESCRIPTION CLOB,
STATUS VARCHAR2(255),
CONSUMER_NAME VARCHAR2(255),
CLASSTYPE VARCHAR(2),
FORMULA CLOB,
EXMPL_ANSWERS CLOB,
SURVEY_QUEST_TEXT CLOB,
SURVEY_QUEST_SRC VARCHAR2(50),
UNITSREQUIRED VARCHAR2(1),
RELATEDNAMES2 CLOB,
SHORTNAME VARCHAR2(255),
ORDER_OBS VARCHAR2(15),
HL7_FIELD_SUBFIELD_ID VARCHAR2(50),
EXTERNAL_COPYRIGHT_NOTICE CLOB,
EXAMPLE_UNITS VARCHAR2(255),
LONG_COMMON_NAME VARCHAR2(255),
EXAMPLE_UCUM_UNITS VARCHAR2(255),
STATUS_REASON VARCHAR2(9),
STATUS_TEXT CLOB,
CHANGE_REASON_PUBLIC CLOB,
COMMON_TEST_RANK VARCHAR2(20),
COMMON_ORDER_RANK VARCHAR2(20),
HL7_ATTACHMENT_STRUCTURE VARCHAR2(15),
EXTERNAL_COPYRIGHT_LINK VARCHAR2(255),
PANELTYPE VARCHAR2(50),
ASKATORDERENTRY VARCHAR2(255),
ASSOCIATEDOBSERVATIONS VARCHAR2(255),
VersionFirstReleased VARCHAR2(255),
ValidHL7AttachmentRequest VARCHAR2(50),
DisplayName VARCHAR2(255)
);
CREATE TABLE MapTo
(
LOINC VARCHAR2(10),
MAP_TO VARCHAR2(10),
"COMMENT" CLOB
);
CREATE TABLE SourceOrganization
(
ID NUMBER,
COPYRIGHT_ID VARCHAR2(255),
NAME VARCHAR2(255),
COPYRIGHT CLOB,
TERMS_OF_USE CLOB,
URL VARCHAR2(4000)
);
EXIT;
Run the following commands to perform the import. Be sure to update the file paths to the correct location of the .csv files before running.
OPTIONS (errors=0, SKIP=1, SILENT=(FEEDBACK))
LOAD DATA
CHARACTERSET UTF8
INFILE '../Loinc.csv'
BADFILE 'Loinc.bad'
DISCARDFILE 'Loinc.dsc'
INTO TABLE Loinc
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
LOINC_NUM CHAR NULLIF (LOINC_NUM=BLANKS)
, COMPONENT CHAR NULLIF (COMPONENT=BLANKS)
, PROPERTY CHAR NULLIF (PROPERTY=BLANKS)
, TIME_ASPCT CHAR NULLIF (TIME_ASPCT=BLANKS)
, SYSTEM CHAR NULLIF (SYSTEM=BLANKS)
, SCALE_TYP CHAR NULLIF (SCALE_TYP=BLANKS)
, METHOD_TYP CHAR NULLIF (METHOD_TYP=BLANKS)
, CLASS CHAR NULLIF (CLASS=BLANKS)
, VersionLastChanged CHAR NULLIF (VersionLastChanged=BLANKS)
, CHNG_TYPE CHAR NULLIF (CHNG_TYPE=BLANKS)
, DEFINITIONDESCRIPTION CHAR(150000) NULLIF (DEFINITIONDESCRIPTION=BLANKS)
, STATUS CHAR NULLIF (STATUS=BLANKS)
, CONSUMER_NAME CHAR NULLIF (CONSUMER_NAME=BLANKS)
, CLASSTYPE CHAR NULLIF (CLASSTYPE=BLANKS)
, FORMULA CHAR(150000) NULLIF (FORMULA=BLANKS)
, EXMPL_ANSWERS CHAR(150000) NULLIF (EXMPL_ANSWERS=BLANKS)
, SURVEY_QUEST_TEXT CHAR(150000) NULLIF (SURVEY_QUEST_TEXT =BLANKS)
, SURVEY_QUEST_SRC CHAR NULLIF (SURVEY_QUEST_SRC=BLANKS)
, UNITSREQUIRED CHAR NULLIF (UNITSREQUIRED=BLANKS)
, RELATEDNAMES2 CHAR(150000) NULLIF (RELATEDNAMES2=BLANKS)
, SHORTNAME CHAR NULLIF (SHORTNAME=BLANKS)
, ORDER_OBS CHAR NULLIF (ORDER_OBS=BLANKS)
, HL7_FIELD_SUBFIELD_ID CHAR NULLIF (HL7_FIELD_SUBFIELD_ID=BLANKS)
, EXTERNAL_COPYRIGHT_NOTICE CHAR(150000) NULLIF (EXTERNAL_COPYRIGHT_NOTICE=BLANKS)
, EXAMPLE_UNITS CHAR NULLIF (EXAMPLE_UNITS=BLANKS)
, LONG_COMMON_NAME CHAR NULLIF (LONG_COMMON_NAME=BLANKS)
, EXAMPLE_UCUM_UNITS CHAR NULLIF (EXAMPLE_UCUM_UNITS=BLANKS)
, STATUS_REASON CHAR NULLIF (STATUS_REASON=BLANKS)
, STATUS_TEXT CHAR(150000) NULLIF (STATUS_TEXT=BLANKS)
, CHANGE_REASON_PUBLIC CHAR(150000) NULLIF (CHANGE_REASON_PUBLIC=BLANKS)
, COMMON_TEST_RANK CHAR NULLIF (COMMON_TEST_RANK=BLANKS)
, COMMON_ORDER_RANK CHAR NULLIF (COMMON_ORDER_RANK=BLANKS)
, HL7_ATTACHMENT_STRUCTURE CHAR NULLIF (HL7_ATTACHMENT_STRUCTURE=BLANKS)
, EXTERNAL_COPYRIGHT_LINK CHAR NULLIF (EXTERNAL_COPYRIGHT_LINK=BLANKS)
, PANELTYPE CHAR NULLIF (PANELTYPE=BLANKS)
, ASKATORDERENTRY CHAR NULLIF (ASKATORDERENTRY=BLANKS)
, ASSOCIATEDOBSERVATIONS CHAR NULLIF (ASSOCIATEDOBSERVATIONS=BLANKS)
, VersionFirstReleased CHAR NULLIF (VersionFirstReleased=BLANKS)
, ValidHL7AttachmentRequest CHAR NULLIF (ValidHL7AttachmentRequest=BLANKS)
, DisplayName CHAR NULLIF (DisplayName=BLANKS)
)
OPTIONS (errors=0, SKIP=1, SILENT=(FEEDBACK))
LOAD DATA
CHARACTERSET UTF8
INFILE '../MapTo.csv'
BADFILE 'MapTo.bad'
DISCARDFILE 'MapTo.dsc'
INTO TABLE MapTo
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
LOINC CHAR NULLIF (LOINC=BLANKS)
, MAP_TO CHAR NULLIF (MAP_TO=BLANKS)
, "COMMENT" CHAR(150000) NULLIF ("COMMENT"=BLANKS)
)
OPTIONS (errors=999, SKIP=1, SILENT=(FEEDBACK))
LOAD DATA
CHARACTERSET UTF8
INFILE '../SourceOrganization.csv'
BADFILE 'SourceOrganization.bad'
DISCARDFILE 'SourceOrganization.dsc'
INTO TABLE SourceOrganization
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
ID INTEGER EXTERNAL
, COPYRIGHT_ID CHAR NULLIF (COPYRIGHT_ID=BLANKS)
, NAME CHAR NULLIF (NAME=BLANKS)
, COPYRIGHT CHAR(150000) NULLIF (COPYRIGHT=BLANKS)
, TERMS_OF_USE CHAR(150000) NULLIF (TERMS_OF_USE=BLANKS)
, URL CHAR(150000) NULLIF (URL=BLANKS)
)
Provided is an basic batch script you can use to automate the execution of the above queries. It is assumed that you are working in a Windows environment and have the Oracle client software installed on your PC. Follow these steps to create and run the scripts:
Note: Perform these steps in the directory that contain the .csv files to be imported.
REM
REM
REM Please edit this script and provide values for the variables below.
REM
SET ORACLE_HOME=
SET USERNAME=
SET PASSWORD=
SET TNS_NAME=
ECHO Creating tables ...
%ORACLE_HOME%\bin\sqlplus %USERNAME%/%PASSWORD%@%TNS_NAME% @OracleDDL.SQL > OracleDDL.LOG
ECHO Loading tables ...
%ORACLE_HOME%\bin\sqlldr %USERNAME%/%PASSWORD%@%TNS_NAME% control="SourceOrganization.ctl"
%ORACLE_HOME%\bin\sqlldr %USERNAME%/%PASSWORD%@%TNS_NAME% control="MapTo.ctl"
%ORACLE_HOME%\bin\sqlldr %USERNAME%/%PASSWORD%@%TNS_NAME% control="Loinc.ctl"
ECHO Loading tables has completed.
Run the following to make the table structure needed to import the data.
DROP TABLE IF EXISTS sourceorganization;
CREATE TABLE sourceorganization (
id integer,
copyright_id varchar(255) not null,
name varchar(255),
copyright text,
terms_of_use text,
url text,
primary key (copyright_id)
);
DROP TABLE IF EXISTS loinc;
CREATE TABLE loinc (
loinc_num varchar(10) not null,
component varchar(255),
property varchar(255),
time_aspct varchar(255),
system varchar(255),
scale_typ varchar(255),
method_typ varchar(255),
class varchar(255),
VersionLastChanged varchar(255),
chng_type varchar(255),
DefinitionDescription text,
status varchar(255),
consumer_name varchar(255),
classtype integer,
formula text,
exmpl_answers text,
survey_quest_text text,
survey_quest_src varchar(50),
unitsrequired varchar(1),
relatednames2 text,
shortname varchar(255),
order_obs varchar(15),
hl7_field_subfield_id varchar(50),
external_copyright_notice text,
example_units varchar(255),
long_common_name varchar(255),
example_ucum_units varchar(255),
status_reason varchar(9),
status_text text,
change_reason_public text,
common_test_rank integer,
common_order_rank integer,
hl7_attachment_structure varchar(15),
ExternalCopyrightLink varchar(255),
PanelType varchar(50),
AskAtOrderEntry varchar(255),
AssociatedObservations varchar(255),
VersionFirstReleased varchar(255),
ValidHL7AttachmentRequest varchar(50),
DisplayName varchar(255),
primary key (loinc_num)
);
DROP TABLE IF EXISTS mapto;
CREATE TABLE mapto (
loinc varchar(10) NOT NULL,
map_to varchar(10) NOT NULL,
comment text,
primary key (loinc, map_to)
);
Run the following to perform the import. Be sure to update the file paths to the correct location of the .csv files before running.
\copy loinc (loinc_num, component, property, time_aspct, system, scale_typ, method_typ, class, VersionLastChanged, chng_type, DefinitionDescription, status, consumer_name, classtype, formula, exmpl_answers, survey_quest_text, survey_quest_src, unitsrequired, relatednames2, shortname, order_obs, hl7_field_subfield_id, external_copyright_notice, example_units, long_common_name, example_ucum_units, status_reason, status_text, change_reason_public, common_test_rank, common_order_rank, hl7_attachment_structure, ExternalCopyrightLink, PanelType, AskAtOrderEntry, AssociatedObservations, VersionFirstReleased, ValidHL7AttachmentRequest, DisplayName ) FROM '../Loinc.csv' CSV HEADER
\copy mapto (loinc, map_to, comment) FROM '../MapTo.csv' CSV HEADER
\copy sourceorganization (id, copyright_id, name, copyright, terms_of_use, url) FROM '../SourceOrganization.csv' CSV HEADER
select count(*) from loinc;
select count(*) from mapto;
select count(*) from sourceorganization;
LOINC is no longer published in a *.mdb (Microsoft Access) format. These instructions show you how to load the available CSV files into Access thereby creating your own Loinc.mdb file. Follow the following steps to import Loinc.csv, MapTo.csv, SourceOrganization.csv into Loinc.mdb.