From b75db2914aef8a9b0e24ac986f7a9b0d1fe0d56a Mon Sep 17 00:00:00 2001 From: Edward Lu Date: Fri, 7 Apr 2023 17:54:53 -0400 Subject: [PATCH 1/5] Add toxicology report data --- .../scripts/02-create-raw-db.sql.sh | 1 + .../src/schema-typing/12-tox_reports.sql | 587 ++++++++++++++++++ 2 files changed, 588 insertions(+) create mode 100644 data-processor/src/schema-typing/12-tox_reports.sql diff --git a/data-processor/scripts/02-create-raw-db.sql.sh b/data-processor/scripts/02-create-raw-db.sql.sh index 64a0fff0..eb160b24 100755 --- a/data-processor/scripts/02-create-raw-db.sql.sh +++ b/data-processor/scripts/02-create-raw-db.sql.sh @@ -22,5 +22,6 @@ sqlite3 $DB << EOF .mode csv .import "${DATA_SOURCES}/Marion_OD_Dataset-6_20_2019.csv" od_deaths_raw .import "${DATA_SOURCES}/Marion_OD_Jail_Weekly--06252019.csv" od_incarcerations_weekly_raw +.import "${DATA_SOURCES}/2023_Tox_Reports.csv" tox_reports_raw .quit EOF diff --git a/data-processor/src/schema-typing/12-tox_reports.sql b/data-processor/src/schema-typing/12-tox_reports.sql new file mode 100644 index 00000000..7693a2b1 --- /dev/null +++ b/data-processor/src/schema-typing/12-tox_reports.sql @@ -0,0 +1,587 @@ +DROP TABLE IF EXISTS tox_reports; +DROP TABLE IF EXISTS tox_reports1; +DROP TABLE IF EXISTS tox_reports2; +DROP TABLE IF EXISTS tox_reports3; + +CREATE TABLE tox_reports1 AS SELECT + "ACCT_NUM", + "REQ_FC_NUM", + "_NAME_", + "Norfentanyl", + "Meprobamate", + "______No_Testing_Performed", + "BARBITURATES", + "SYNTHETIC_CANNABINOIDS", + "Caffeine", + "MUSCLE_RELAXANTS", + "GASTROINTESTINALS", + "VOLATILES", + "Hydroxyzine", + "Oxycodone", + "Methanol". + "ANTIDIABETICS", + "Cotinine", + "ANTIFUNGALS", + "NOVEL_PSYCHOACTIVES", + "Alprazolam", + "Phencyclidine__PCP_", + "Morphine", + "O_Desmethyltramadol", + "Acetaminophen", + "HALLUCINOGENS", + "Acetone", + "CANNABINOIDS", + "MISCELLANEOUS", + "SEDATIVE_HYPNOTICS", + "ANESTHETICS", + "ANTIHISTAMINES", + "Isopropanol", + "ANTIPSYCHOTICS", + "DESIGNER_OPIOIDS", + "Nicotine", + "AMPHETAMINES", + "ANTICONVULSANTS", + "ANTICHOLINERGICS", + "ANTIDEPRESSANTS", + "Amphetamine", + "BENZODIAZEPINES", + "OPIOID_ANALGESICS", + "STIMULANTS", + "Hydrocodone", + "Ethanol", + "Diphenhydramine", + "Methamphetamine", + "Hydromorphone", + "Oxazepam", + "a_OH_Alprazolam", + "ANALGESICS", + "Oxymorphone", + "UROLOGICALS", + "MDMA", + "_7_Aminoclonazepam", + "_6_Monoacetylmorphine", + "CARDIOVASCULARS", + "EDDP", + "Fentanyl", + "Methadone", + "Benzoylecgonine", + "Codeine", + "Norbuprenorphine", + "Nordiazepam", + "Gabapentin", + "Lorazepam", + "Buprenorphine", + "Tramadol", + "Temazepam", + "THC_COOH", + "Delta_9_THC", + "__SUBMITTING_COUNTY_", + "__CORONER_", + "Carboxyhemoglobin", + "Cancelled_Order_Code_", + "Cancellation_Reason_", + "__Date_of_Birth_", + "Sertraline", + "Paroxetine", + "Amlodipine", + "Desmethylsertraline", + "Diazepam", + "Dextromethorphan", + "Levetiracetam", + "Acetylfentanyl", + "_4_ANPP", + "Naloxone", + "Olanzapine", + "Flubromazolam", + "Midazolam", + "Salicylic_Acid", + "Metoprolol", + "Ibuprofen", + "Pseudoephedrine", + "Pregabalin", + "Fluorofentanyl", + "Acrylfentanyl", + "NOVEL_EMERGING_SUBSTANCES", + "Naproxen", + "__Volatile_Testing_Not_Perfo", + "Trazodone", + "Quinidine_Quinine", + "Xylazine", + "Propranolol", + "Aripiprazole", + "Citalopram", + "Flurazepam", + "Warfarin", + "meta_Chlorophenylpiperazine", + "Promethazine", + "Norfluoxetine", + "NITAZENE_ANALOG_PANEL", + "Protonitazene", + "Bupropion", + "Metonitazene", + "Buspirone__BuSpar__", + "Cyclobenzaprine", + "Lamotrigine", + "Fluoxetine", + "Dihydrocodeine", + "Phenylpropanolamine", + "Ephedrine", + "Metoclopramide", + "Theophylline", + "Donepezil", + "Creatinine", + "Potassium", + "Glucose", + "Sodium", + "Chloride", + "Urea_Nitrogen", + "Carfentanil", + "Mephedrone", + "Butyrylfentanyl", + "Flualprazolam", + "Eutylone", + "_25B_NBOMe", + "_25C_NBOMe", + "Dimethylone", + "Methcathinone", + "cis_3_Methylfentanyl", + "Etizolam", + "_5_MeO_DALT", + "Ethylone", + "Clonazolam", + "_2C_I", + "_2C_E", + "Methylone", + "_6_Beta_Naltrexol", + "Adinazolam", + "Ocfentanil", + "Butylone", + "Tetrahydrofuranfentanyl", + "MDMB_4en_PINACA_Metabolite", + "_5F_MDMB_PICA_Metabolite", + "_2C_B", + "Methoxetamine", + "MDPV", + "Cyclopropylfentanyl", + "Dibutylone", + "_25I_NBOMe", + "TFMPP", + "N_ethylpentylone", + "Methoxyacetylfentanyl", + "Alpha_PVP", + "_4F_MDMB_BICA_Metabolite", + "U47700", + "Naltrexone", + "Betahydroxythiofentanyl", + "Parafluorobutyrylfentanyl", + "Methedrone", + "Furanylfentanyl", + "Pentylone", + "Quetiapine", + "Amiodarone", + "Lidocaine", + "Promazine", + "Trihexyphenidyl", + "Desmethylclomipramine", + "Thioridazine", + "Propoxyphene", + "Norpropoxyphene", + "N_Acetylprocainamide", + "Ketoconazole", + "Gamma_Hydroxybutyrate__GHB_", + "Estazolam__ProSom__", + "Norketamine", + "Ketamine", + "INHALANTS_PANEL", + "_1_1_Difluoroethane", + "_1_1_1_2_Tetrafluoroethane", + "Topiramate", + "HALOCARBONS", + "HYDROCARBON_GASES", + "Nifedipine", + "_9_Hydroxyrisperidone", + "Desmethyldoxepin", + "Doxepin", + "FENTANYL_METABOLITE", + "Cocaine", + "Cocaethylene" +FROM tox_reports_raw; + + +CREATE TABLE tox_reports2 AS SELECT + "ACCT_NUM", + "Doxylamine", + "_6_Acetylmorphine", + "DESIGNER_OPIOIDS_PANEL", + "Etonitazene", + "Isotonitazene", + "Etodesnitazene", + "Metodesnitazene", + "Butonitazene", + "Flunitazene", + "Isotodesnitazene", + "N_Pyrrolidino_Etonitazene", + "Loperamide", + "Etomidate", + "Tapentadol", + "Haloperidol", + "Primidone", + "Ziprasidone__Geodon__", + "Furosemide", + "Phenacetin", + "Dicyclomine", + "Zopiclone", + "Clonazepam", + "Amitriptyline", + "Nortriptyline", + "Levamisole", + "O_Desmethylvenlafaxine", + "Demoxepam", + "ADB_4en_PINACA", + "_4_cyano_CUMYL_BINACA", + "ADB_BINACA", + "_4_fluoro_MDMB_BINACA", + "Prochlorperazine", + "Prochlorperazine__Quan", + "Clozapine", + "Norclozapine", + "Venlafaxine", + "Duloxetine", + "Chlorpromazine", + "Zolpidem", + "Atomoxetine__Strattera__", + "Orphenadrine", + "Mirtazapine", + "MDA", + "Phenytoin", + "Phentermine", + "Atenolol", + "Mitragynine", + "Methylphenidate", + "ETHYLENE_GLYCOL", + "Oxcarbazepine_Metabolite", + "Benzocaine", + "Memantine", + "_5F_ADB", + "FUB_AMB", + "MDMB_FUBINACA", + "MDMB_FUBINACA_Metabolite", + "FUB_144", + "_5F_MDMB_PICA", + "_5F_ADB_Metabolite", + "_4CN_CUMYL_BINACA", + "ADB_FUBINACA", + "_4F_MDMB_BINACA", + "Dextrorphan_Levorphanol", + "Chlorpheniramine", + "Clonidine", + "Tadalafil", + "Zonisamide", + "Tetrahydrozoline", + "Hydrochlorothiazide", + "Butalbital", + "Bupivacaine", + "Phenobarbital", + "Procainamide", + "Sildenafil", + "Strychnine", + "Brorphine", + "AP_237", + "N_Desmethylsildenafil", + "Chlordiazepoxide", + "Glipizide", + "Lacosamide", + "Bisoprolol", + "Furanyl_Fentanyl", + "U_47700", + "Diltiazem", + "Salicylates", + "Guaifenesin", + "IRON", + "CARBON_MONOXIDE", + "Risperidone", + "Phencyclidine", + "Carisoprodol", + "Buspirone", + "_10_Hydroxycarbazepine", + "Fluphenazine__Prolixin__", + "Diphenoxylate", + "METHADONE_METABOLITE", + "Desmethylloperamide", + "Atomoxetine", + "Benztropine", + "Medazepam", + "Maprotiline", + "Metoprolol__Lopressor__", + "Citalopram_Escitalopram", + "_5_fluoro_MDMB_PICA", + "Pentobarbital", + "Secobarbital", + "Amobarbital", + "Butabarbital", + "THC", + "Loperamide__Imodium__", + "Sotalol", + "Hydroxyzine__Vistaril__", + "Norsertraline", + "Ketamine__Ketalar__", + "___Investigator_", + "Pregabalin__Lyrica__", + "Chlorophenylpiperazine", + "MDA__MDMA_Metabolite_", + "Lysergic_Acid_Diethylamide", + "Quinine", + "FUB_AMB___AB_FUBINACA", + "_5_fluoro_ADB", + "Hydroxybupropion", + "Phenytoin__Dilantin__", + "Imipramine", + "Desipramine", + "Delorazepam", + "Diclazepam", + "Eszopiclone__Lunesta__", + "ANALYSIS_METHOD_", + "FINDINGS_", + "TRACE_SUBSTANCE_ANALYSIS", + "SPECIMEN_RECEIVED_", + "Phenylethylmalonamide__PEMA_", + "Ropivacaine", + "Labetalol", + "Diltiazem__Cardizem__", + "Methyl_Ethyl_Ketone", + "Methyl_Isobutyl_Ketone", + "KETONE_PANEL", + "Cyclohexanone", + "Methyl_n_Butyl_Ketone", + "Itraconazole", + "SELENIUM", + "LEAD", + "MERCURY", + "METALS___ACUTE_POISONING", + "THALLIUM", + "ARSENIC", + "BISMUTH", + "ANTIMONY", + "Nortramadol", + "Risperidone__Risperdal__", + "Difluoroethane", + "Verapamil", + "Suvorexant", + "Lidocaine__Xylocaine__", + "FLUNITRAZEPAM__Rohypnol_", + "Vecuronium__Norcuron_", + "Mivacurium_Hydrolysis_Produc", + "Tubocurarine", + "Normeperidine", + "Rucuronium__Zemuron_", + "Atricurium_Cisatricurium_Hyd", + "Succinylmonocholine__Metabol", + "Doxacurium__Nuromax_", + "Meperidine", + "NEUROMUSCULAR_BLOCKING_AGENT", + "Bretylium", + "Laudanosine", + "Doxacurium_Hydrolysis_Produc", + "Succinylcholine__Suxamethoni", + "Pancuronium__Pavulon_", + "COCAINE___METABOLITES", + "Yohimbine", + "PMA", + "Norpseudoephedrine", + "Tiletamine", + "Lysergic_Acid_Diethylamide_", + "Levorphanol__Levo_Dromoran__", + "OPIATES", + "Toluene", + "PALIPERIDONE", + "Salvinorin_B", + "Nordoxepin", + "Carbamazepine", + "Carbamazepine_Epoxide", + "Glyburide", + "Mesoridazine", + "Thioridazine__Mellaril__", + "Indomethacin", + "Etomidate__Amidate__", + "Flecainide", + "Zaleplon__Sonata__", + "Dextro_Levo_Methorphan", + "_3_Methoxy_PCP", + "Acetyl_Fentanyl", + "Valeryl_Fentanyl", + "Butyrl_Fentanyl_Isobutyryl_F" +FROM tox_reports_raw; + +CREATE TABLE tox_reports3 AS SELECT + "ACCT_NUM", + "ZOLPIDEM__Ambien_", + "Glyburide__DiaBeta__", + "Nalbuphine", + "Desmethyltrimipramine", + "Zaleplon", + "Fluvoxamine", + "Reserpine", + "Amoxapine", + "Disopyramide", + "U_49900", + "Carbamazepine_10_11_epoxide", + "Fluphenazine", + "ortho_Fluoro_Fentanyl", + "_1_Hydroxymidazolam", + "Alprenolol", + "Methaqualone", + "ADB_CHMINACA", + "Vardenafil", + "Bromazepam", + "Sufentanil", + "CUMYL_THPINACA", + "Alfentanil", + "Voriconazole", + "U_51754", + "Iloperidone", + "Clomipramine", + "TRAMADOL_METABOLITE", + "Zolpidem_4_Phenyl_COOH", + "Zolpidem__Ambien__", + "ZOLPIDEM_METABOLITE", + "Glimepiride", + "Methocarbamol", + "Phenazepam", + "Desalkylflurazepam", + "Pheniramine", + "p_Methylmethoxyacetyl_Fentan", + "Loxapine", + "m_Methylmethoxyacetyl_Fentan", + "Ziprasidone", + "Lithium", + "n_Propanol__n_Propyl_Alcohol", + "Volatiles__Hydrocarbons", + "Isopropanol__Isopropyl_Alcoh", + "Methyl_Isobutyl_Ketone__MIBK", + "Ethanol__Ethyl_Alcohol_", + "Acetaldehyde", + "Pentane", + "Methyl_Acrylate", + "Ethyl_Benzene", + "n_Hexane", + "Methanol__Methyl_Alcohol_", + "Diethyl_Ether", + "n_Heptane", + "Styrene__Vinylbenzene_", + "Xylenes__o_m_p_", + "Ethyl_Acetate", + "Methyl_Ethyl_Ketone__MEK_", + "Benzene", + "Methylpentanes__2__and_3__Is", + "n_Butanol__Butyl_Alcohol_", + "Methyl_Tertiary_Butyl_Ether", + "Flunitrazolam", + "Flubromazepam", + "Nitrazolam", + "Alpha_Hydroxyetizolam", + "Triprolidine", + "_3_Hydroxy_PCP", + "Brompheniramine", + "Mescaline", + "Pyrilamine", + "N_Ethyl_Pentylone", + "Psilocin", + "Atropine", + "Diphacinone", + "Chlorophacinone", + "Dicumarol", + "Bromadiolone", + "Brodifacoum", + "Difenacoum", + "Desmethyltramadol", + "Amiodarone__Cordarone__", + "Desethylamiodarone", + "Fentanyl__Vitreous", + "BARBITURATE_PANEL", + "SPECIAL_REQUEST", + "Methemoglobin", + "Betaxolol", + "Loratadine", + "Lacosamide__Vimpat__", + "Baclofen", + "Clenbuterol", + "Norethandrolone_Metabolite", + "Methandrostenolone", + "Clostebol", + "Oxymetholone_Metabolite", + "Turinabol", + "Clostebol_Metabolite", + "Testosterone", + "Norandrostenedione", + "Stanozolol_Metabolite", + "Epitestosterone", + "Norethindrone", + "Boldenone", + "Norethandrolone", + "Nandrolone", + "Probenecid", + "ANABOLIC_STEROIDS", + "Stanozolol", + "Methyltestosterone", + "Tetrahydrogestrinone", + "T_EpiT_Ratio", + "Methandrostenolone_Metabolit", + "Nandrolone_Metabolite", + "Oxandrolone", + "Fluoxymesterone", + "Methenolone", + "Trenbolone_Metabolite", + "Bolasterone", + "Drostanolone_Metabolite", + "CYANIDE", + "Oxybutynin", + "Hydroxychloroquine", + "Amlodipine__Norvasc__", + "Albuterol", + "Mexiletine", + "Chlorothiazide", + "Magnesium", + "Pentazocine", + "Trimipramine", + "Esmolol", + "Timolol", + "Cyclizine", + "Brompheniramine__Drixoral__", + "Metformin", + "Nitrous_Oxide", + "_5F_ADB_Butanoic_Acid_Metabol", + "Disposal_Date___1yr__", + "MDMB_FUBINACA_Butanoic_Acid", + "Valproic_Acid", + "Propofol", + "SPECIMEN_NUM", + "PLACE_HOLDER", + "FIRST_NAME", + "MIDDLE_NAME", + "LAST_NAME", + "GENDER", + "COLLECT_DATE", + "RECEIVED_DATE", + "LAST_REPORT_DATE", + "DATE_OF_DEATH", + "PERFORMING_LOCATION", + "PERFORMING_LOCATION_NAME", + "LOCATION_ADDRESS_1", + "LOCATION_ADDRESS_2", + "LOCATION_CITY", + "LOCATION_STATE", + "LOCATION_ZIP", + "LOCATION_PHONE", + "DOD", + "month", + "year", + "Quarter", + "SUNMITTING_COUNTYU", + "CORONER_U", + "County", + "Coroner" +FROM tox_reports_raw; + +CREATE INDEX tox_reports1_fk ON tox_reports1("ACCT_NUM"); +CREATE INDEX tox_reports2_fk ON tox_reports2("ACCT_NUM"); +CREATE INDEX tox_reports3_fk ON tox_reports3("ACCT_NUM"); From 3ac39eaee3104d60588e9ed896c6803322f3006e Mon Sep 17 00:00:00 2001 From: Edward Lu Date: Tue, 11 Apr 2023 20:04:47 -0400 Subject: [PATCH 2/5] Modify SQL --- .gitignore | 1 + .../src/schema-typing/12-tox_reports.sql | 71 ++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 46149641..9e436a9a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /raw-data container.sif website/debug.log +job.sh diff --git a/data-processor/src/schema-typing/12-tox_reports.sql b/data-processor/src/schema-typing/12-tox_reports.sql index 7693a2b1..1789715e 100644 --- a/data-processor/src/schema-typing/12-tox_reports.sql +++ b/data-processor/src/schema-typing/12-tox_reports.sql @@ -1,8 +1,75 @@ DROP TABLE IF EXISTS tox_reports; +DROP TABLE IF EXISTS tox_reports_selected; DROP TABLE IF EXISTS tox_reports1; DROP TABLE IF EXISTS tox_reports2; DROP TABLE IF EXISTS tox_reports3; +CREATE TABLE tox_reports_selected ( + "ACCT_NUM" CHARACTER(5) CHECK(length(ACCT_NUM) = 5), + "Fentanyl" BOOLEAN CHECK(Fentanyl IN (NULL, 0, 1)), + "BENZODIAZEPINES" BOOLEAN CHECK(BENZODIAZEPINES IN (NULL, 0, 1)), + "Methamphetamine" BOOLEAN CHECK(Methamphetamine IN (NULL, 0, 1)), + "SEDATIVE_HYPNOTICS" BOOLEAN CHECK(SEDATIVE_HYPNOTICS IN (NULL, 0, 1)), + "Hydromorphone" BOOLEAN CHECK(Hydromorphone IN (NULL, 0, 1)), + "Oxymorphone" BOOLEAN CHECK(Oxymorphone IN (NULL, 0, 1)), + "Oxycodone" BOOLEAN CHECK(Oxycodone IN (NULL, 0, 1)), + "ANTIDEPRESSANTS" BOOLEAN CHECK(ANTIDEPRESSANTS IN (NULL, 0, 1)), + "__Date_of_Birth_" DATE, + "GENDER" CHARACTER CHECK(GENDER IN(NULL, 'M', 'F')), + "DOD" DATE +); +INSERT INTO tox_reports_selected + SELECT + ACCT_NUM, + CASE Fentanyl + WHEN 'Negative' THEN 0 + WHEN 'POSITIVE' THEN 1 + ELSE NULL + END, + CASE BENZODIAZEPINES + WHEN 'Negative' THEN 0 + WHEN 'POSITIVE' THEN 1 + ELSE NULL + END, + CASE Methamphetamine + WHEN 'Negative' THEN 0 + WHEN 'POSITIVE' THEN 1 + ELSE NULL + END, + CASE SEDATIVE_HYPNOTICS + WHEN 'Negative' THEN 0 + WHEN 'POSITIVE' THEN 1 + ELSE NULL + END, + CASE Hydromorphone + WHEN 'Negative' THEN 0 + WHEN 'POSITIVE' THEN 1 + ELSE NULL + END, + CASE Oxymorphone + WHEN 'Negative' THEN 0 + WHEN 'POSITIVE' THEN 1 + ELSE NULL + END, + CASE Oxycodone + WHEN 'Negative' THEN 0 + WHEN 'POSITIVE' THEN 1 + ELSE NULL + END, + CASE ANTIDEPRESSANTS + WHEN 'Negative' THEN 0 + WHEN 'POSITIVE' THEN 1 + ELSE NULL + END, + CAST('__Date_of_Birth_' as DATE), + CAST('DOD' as DATE), + CASE GENDER + WHEN 'M' THEN 'M' + WHEN 'F' THEN 'F' + ELSE NULL + END +FROM tox_reports_raw; + CREATE TABLE tox_reports1 AS SELECT "ACCT_NUM", "REQ_FC_NUM", @@ -18,7 +85,7 @@ CREATE TABLE tox_reports1 AS SELECT "VOLATILES", "Hydroxyzine", "Oxycodone", - "Methanol". + "Methanol", "ANTIDIABETICS", "Cotinine", "ANTIFUNGALS", @@ -207,7 +274,6 @@ CREATE TABLE tox_reports1 AS SELECT "Cocaethylene" FROM tox_reports_raw; - CREATE TABLE tox_reports2 AS SELECT "ACCT_NUM", "Doxylamine", @@ -582,6 +648,7 @@ CREATE TABLE tox_reports3 AS SELECT "Coroner" FROM tox_reports_raw; +CREATE INDEX tox_reports_selected_fk ON tox_reports_selected("ACCT_NUM"); CREATE INDEX tox_reports1_fk ON tox_reports1("ACCT_NUM"); CREATE INDEX tox_reports2_fk ON tox_reports2("ACCT_NUM"); CREATE INDEX tox_reports3_fk ON tox_reports3("ACCT_NUM"); From ae6098c918181bc653b7a746878f2807dd36569e Mon Sep 17 00:00:00 2001 From: Edward Lu Date: Mon, 17 Apr 2023 16:57:30 -0400 Subject: [PATCH 3/5] Clean up SQL and add age --- data-processor/src/a2agc/schema.py | 3 +- .../src/schema-typing/12-tox_reports.sql | 641 +----------------- 2 files changed, 31 insertions(+), 613 deletions(-) diff --git a/data-processor/src/a2agc/schema.py b/data-processor/src/a2agc/schema.py index 7634fe28..50af3677 100644 --- a/data-processor/src/a2agc/schema.py +++ b/data-processor/src/a2agc/schema.py @@ -20,7 +20,8 @@ def load(xml: str) -> Schema: 'medications': 'PHYS_TIME', 'ems_incidents': 'PCRDateTime', 'incarcerations': 'BOOKING_DATE', - 'encounters': 'ADMIT_TIME' + 'encounters': 'ADMIT_TIME', + 'tox_reports': 'DOD' } # Node queries diff --git a/data-processor/src/schema-typing/12-tox_reports.sql b/data-processor/src/schema-typing/12-tox_reports.sql index 1789715e..801bdb6a 100644 --- a/data-processor/src/schema-typing/12-tox_reports.sql +++ b/data-processor/src/schema-typing/12-tox_reports.sql @@ -1,654 +1,71 @@ DROP TABLE IF EXISTS tox_reports; -DROP TABLE IF EXISTS tox_reports_selected; -DROP TABLE IF EXISTS tox_reports1; -DROP TABLE IF EXISTS tox_reports2; -DROP TABLE IF EXISTS tox_reports3; -CREATE TABLE tox_reports_selected ( - "ACCT_NUM" CHARACTER(5) CHECK(length(ACCT_NUM) = 5), - "Fentanyl" BOOLEAN CHECK(Fentanyl IN (NULL, 0, 1)), - "BENZODIAZEPINES" BOOLEAN CHECK(BENZODIAZEPINES IN (NULL, 0, 1)), - "Methamphetamine" BOOLEAN CHECK(Methamphetamine IN (NULL, 0, 1)), - "SEDATIVE_HYPNOTICS" BOOLEAN CHECK(SEDATIVE_HYPNOTICS IN (NULL, 0, 1)), - "Hydromorphone" BOOLEAN CHECK(Hydromorphone IN (NULL, 0, 1)), - "Oxymorphone" BOOLEAN CHECK(Oxymorphone IN (NULL, 0, 1)), - "Oxycodone" BOOLEAN CHECK(Oxycodone IN (NULL, 0, 1)), - "ANTIDEPRESSANTS" BOOLEAN CHECK(ANTIDEPRESSANTS IN (NULL, 0, 1)), - "__Date_of_Birth_" DATE, - "GENDER" CHARACTER CHECK(GENDER IN(NULL, 'M', 'F')), - "DOD" DATE +CREATE TABLE tox_reports ( + "ACCT_NUM" CHARACTER(5) CHECK(length(acct_num) = 5), + "FENTANYL" BOOLEAN CHECK(fentanyl IN (NULL, 0, 1)), + "BENZODIAZEPINES" BOOLEAN CHECK(benzodiazepines IN (NULL, 0, 1)), + "METHAMPHETAMINE" BOOLEAN CHECK(methamphetamine IN (NULL, 0, 1)), + "SEDATIVE_HYPNOTICS" BOOLEAN CHECK(sedative_hypnotics IN (NULL, 0, 1)), + "HYDROMORPHONE" BOOLEAN CHECK(hydromorphone IN (NULL, 0, 1)), + "OXYMORPHONE" BOOLEAN CHECK(oxymorphone IN (NULL, 0, 1)), + "OXYCODONE" BOOLEAN CHECK(oxycodone IN (NULL, 0, 1)), + "ANTIDEPRESSANTS" BOOLEAN CHECK(antidepressants IN (NULL, 0, 1)), + "DOD" DATE CHECK(length(dod) = 10), + "DOB" DATE CHECK(length(dob) = 10 OR dob IS NULL), + "AGE" INT CHECK(typeof(age) = 'integer' OR age IS NULL), + "GENDER" CHARACTER CHECK(gender IN (NULL, 'M', 'F')) ); -INSERT INTO tox_reports_selected +INSERT INTO tox_reports SELECT - ACCT_NUM, - CASE Fentanyl + acct_num, + CASE fentanyl WHEN 'Negative' THEN 0 WHEN 'POSITIVE' THEN 1 ELSE NULL END, - CASE BENZODIAZEPINES + CASE benzodiazepines WHEN 'Negative' THEN 0 WHEN 'POSITIVE' THEN 1 ELSE NULL END, - CASE Methamphetamine + CASE methamphetamine WHEN 'Negative' THEN 0 WHEN 'POSITIVE' THEN 1 ELSE NULL END, - CASE SEDATIVE_HYPNOTICS + CASE sedative_hypnotics WHEN 'Negative' THEN 0 WHEN 'POSITIVE' THEN 1 ELSE NULL END, - CASE Hydromorphone + CASE hydromorphone WHEN 'Negative' THEN 0 WHEN 'POSITIVE' THEN 1 ELSE NULL END, - CASE Oxymorphone + CASE oxymorphone WHEN 'Negative' THEN 0 WHEN 'POSITIVE' THEN 1 ELSE NULL END, - CASE Oxycodone + CASE oxycodone WHEN 'Negative' THEN 0 WHEN 'POSITIVE' THEN 1 ELSE NULL END, - CASE ANTIDEPRESSANTS + CASE antidepressants WHEN 'Negative' THEN 0 WHEN 'POSITIVE' THEN 1 ELSE NULL END, - CAST('__Date_of_Birth_' as DATE), - CAST('DOD' as DATE), - CASE GENDER + date(dod) as dod, + date(substr(__Date_of_Birth_, 7, 4) || '-' || substr(__Date_of_Birth_, 4, 2) || '-' || substr(__Date_of_Birth_, 1, 2)) AS dob, + CAST((JULIANDAY(date(dod)) - JULIANDAY(date(substr(__Date_of_Birth_, 7, 4) || '-' || substr(__Date_of_Birth_, 4, 2) || '-' || substr(__Date_of_Birth_, 1, 2))))/365 as INT) AS age, + CASE gender WHEN 'M' THEN 'M' WHEN 'F' THEN 'F' ELSE NULL END FROM tox_reports_raw; -CREATE TABLE tox_reports1 AS SELECT - "ACCT_NUM", - "REQ_FC_NUM", - "_NAME_", - "Norfentanyl", - "Meprobamate", - "______No_Testing_Performed", - "BARBITURATES", - "SYNTHETIC_CANNABINOIDS", - "Caffeine", - "MUSCLE_RELAXANTS", - "GASTROINTESTINALS", - "VOLATILES", - "Hydroxyzine", - "Oxycodone", - "Methanol", - "ANTIDIABETICS", - "Cotinine", - "ANTIFUNGALS", - "NOVEL_PSYCHOACTIVES", - "Alprazolam", - "Phencyclidine__PCP_", - "Morphine", - "O_Desmethyltramadol", - "Acetaminophen", - "HALLUCINOGENS", - "Acetone", - "CANNABINOIDS", - "MISCELLANEOUS", - "SEDATIVE_HYPNOTICS", - "ANESTHETICS", - "ANTIHISTAMINES", - "Isopropanol", - "ANTIPSYCHOTICS", - "DESIGNER_OPIOIDS", - "Nicotine", - "AMPHETAMINES", - "ANTICONVULSANTS", - "ANTICHOLINERGICS", - "ANTIDEPRESSANTS", - "Amphetamine", - "BENZODIAZEPINES", - "OPIOID_ANALGESICS", - "STIMULANTS", - "Hydrocodone", - "Ethanol", - "Diphenhydramine", - "Methamphetamine", - "Hydromorphone", - "Oxazepam", - "a_OH_Alprazolam", - "ANALGESICS", - "Oxymorphone", - "UROLOGICALS", - "MDMA", - "_7_Aminoclonazepam", - "_6_Monoacetylmorphine", - "CARDIOVASCULARS", - "EDDP", - "Fentanyl", - "Methadone", - "Benzoylecgonine", - "Codeine", - "Norbuprenorphine", - "Nordiazepam", - "Gabapentin", - "Lorazepam", - "Buprenorphine", - "Tramadol", - "Temazepam", - "THC_COOH", - "Delta_9_THC", - "__SUBMITTING_COUNTY_", - "__CORONER_", - "Carboxyhemoglobin", - "Cancelled_Order_Code_", - "Cancellation_Reason_", - "__Date_of_Birth_", - "Sertraline", - "Paroxetine", - "Amlodipine", - "Desmethylsertraline", - "Diazepam", - "Dextromethorphan", - "Levetiracetam", - "Acetylfentanyl", - "_4_ANPP", - "Naloxone", - "Olanzapine", - "Flubromazolam", - "Midazolam", - "Salicylic_Acid", - "Metoprolol", - "Ibuprofen", - "Pseudoephedrine", - "Pregabalin", - "Fluorofentanyl", - "Acrylfentanyl", - "NOVEL_EMERGING_SUBSTANCES", - "Naproxen", - "__Volatile_Testing_Not_Perfo", - "Trazodone", - "Quinidine_Quinine", - "Xylazine", - "Propranolol", - "Aripiprazole", - "Citalopram", - "Flurazepam", - "Warfarin", - "meta_Chlorophenylpiperazine", - "Promethazine", - "Norfluoxetine", - "NITAZENE_ANALOG_PANEL", - "Protonitazene", - "Bupropion", - "Metonitazene", - "Buspirone__BuSpar__", - "Cyclobenzaprine", - "Lamotrigine", - "Fluoxetine", - "Dihydrocodeine", - "Phenylpropanolamine", - "Ephedrine", - "Metoclopramide", - "Theophylline", - "Donepezil", - "Creatinine", - "Potassium", - "Glucose", - "Sodium", - "Chloride", - "Urea_Nitrogen", - "Carfentanil", - "Mephedrone", - "Butyrylfentanyl", - "Flualprazolam", - "Eutylone", - "_25B_NBOMe", - "_25C_NBOMe", - "Dimethylone", - "Methcathinone", - "cis_3_Methylfentanyl", - "Etizolam", - "_5_MeO_DALT", - "Ethylone", - "Clonazolam", - "_2C_I", - "_2C_E", - "Methylone", - "_6_Beta_Naltrexol", - "Adinazolam", - "Ocfentanil", - "Butylone", - "Tetrahydrofuranfentanyl", - "MDMB_4en_PINACA_Metabolite", - "_5F_MDMB_PICA_Metabolite", - "_2C_B", - "Methoxetamine", - "MDPV", - "Cyclopropylfentanyl", - "Dibutylone", - "_25I_NBOMe", - "TFMPP", - "N_ethylpentylone", - "Methoxyacetylfentanyl", - "Alpha_PVP", - "_4F_MDMB_BICA_Metabolite", - "U47700", - "Naltrexone", - "Betahydroxythiofentanyl", - "Parafluorobutyrylfentanyl", - "Methedrone", - "Furanylfentanyl", - "Pentylone", - "Quetiapine", - "Amiodarone", - "Lidocaine", - "Promazine", - "Trihexyphenidyl", - "Desmethylclomipramine", - "Thioridazine", - "Propoxyphene", - "Norpropoxyphene", - "N_Acetylprocainamide", - "Ketoconazole", - "Gamma_Hydroxybutyrate__GHB_", - "Estazolam__ProSom__", - "Norketamine", - "Ketamine", - "INHALANTS_PANEL", - "_1_1_Difluoroethane", - "_1_1_1_2_Tetrafluoroethane", - "Topiramate", - "HALOCARBONS", - "HYDROCARBON_GASES", - "Nifedipine", - "_9_Hydroxyrisperidone", - "Desmethyldoxepin", - "Doxepin", - "FENTANYL_METABOLITE", - "Cocaine", - "Cocaethylene" -FROM tox_reports_raw; - -CREATE TABLE tox_reports2 AS SELECT - "ACCT_NUM", - "Doxylamine", - "_6_Acetylmorphine", - "DESIGNER_OPIOIDS_PANEL", - "Etonitazene", - "Isotonitazene", - "Etodesnitazene", - "Metodesnitazene", - "Butonitazene", - "Flunitazene", - "Isotodesnitazene", - "N_Pyrrolidino_Etonitazene", - "Loperamide", - "Etomidate", - "Tapentadol", - "Haloperidol", - "Primidone", - "Ziprasidone__Geodon__", - "Furosemide", - "Phenacetin", - "Dicyclomine", - "Zopiclone", - "Clonazepam", - "Amitriptyline", - "Nortriptyline", - "Levamisole", - "O_Desmethylvenlafaxine", - "Demoxepam", - "ADB_4en_PINACA", - "_4_cyano_CUMYL_BINACA", - "ADB_BINACA", - "_4_fluoro_MDMB_BINACA", - "Prochlorperazine", - "Prochlorperazine__Quan", - "Clozapine", - "Norclozapine", - "Venlafaxine", - "Duloxetine", - "Chlorpromazine", - "Zolpidem", - "Atomoxetine__Strattera__", - "Orphenadrine", - "Mirtazapine", - "MDA", - "Phenytoin", - "Phentermine", - "Atenolol", - "Mitragynine", - "Methylphenidate", - "ETHYLENE_GLYCOL", - "Oxcarbazepine_Metabolite", - "Benzocaine", - "Memantine", - "_5F_ADB", - "FUB_AMB", - "MDMB_FUBINACA", - "MDMB_FUBINACA_Metabolite", - "FUB_144", - "_5F_MDMB_PICA", - "_5F_ADB_Metabolite", - "_4CN_CUMYL_BINACA", - "ADB_FUBINACA", - "_4F_MDMB_BINACA", - "Dextrorphan_Levorphanol", - "Chlorpheniramine", - "Clonidine", - "Tadalafil", - "Zonisamide", - "Tetrahydrozoline", - "Hydrochlorothiazide", - "Butalbital", - "Bupivacaine", - "Phenobarbital", - "Procainamide", - "Sildenafil", - "Strychnine", - "Brorphine", - "AP_237", - "N_Desmethylsildenafil", - "Chlordiazepoxide", - "Glipizide", - "Lacosamide", - "Bisoprolol", - "Furanyl_Fentanyl", - "U_47700", - "Diltiazem", - "Salicylates", - "Guaifenesin", - "IRON", - "CARBON_MONOXIDE", - "Risperidone", - "Phencyclidine", - "Carisoprodol", - "Buspirone", - "_10_Hydroxycarbazepine", - "Fluphenazine__Prolixin__", - "Diphenoxylate", - "METHADONE_METABOLITE", - "Desmethylloperamide", - "Atomoxetine", - "Benztropine", - "Medazepam", - "Maprotiline", - "Metoprolol__Lopressor__", - "Citalopram_Escitalopram", - "_5_fluoro_MDMB_PICA", - "Pentobarbital", - "Secobarbital", - "Amobarbital", - "Butabarbital", - "THC", - "Loperamide__Imodium__", - "Sotalol", - "Hydroxyzine__Vistaril__", - "Norsertraline", - "Ketamine__Ketalar__", - "___Investigator_", - "Pregabalin__Lyrica__", - "Chlorophenylpiperazine", - "MDA__MDMA_Metabolite_", - "Lysergic_Acid_Diethylamide", - "Quinine", - "FUB_AMB___AB_FUBINACA", - "_5_fluoro_ADB", - "Hydroxybupropion", - "Phenytoin__Dilantin__", - "Imipramine", - "Desipramine", - "Delorazepam", - "Diclazepam", - "Eszopiclone__Lunesta__", - "ANALYSIS_METHOD_", - "FINDINGS_", - "TRACE_SUBSTANCE_ANALYSIS", - "SPECIMEN_RECEIVED_", - "Phenylethylmalonamide__PEMA_", - "Ropivacaine", - "Labetalol", - "Diltiazem__Cardizem__", - "Methyl_Ethyl_Ketone", - "Methyl_Isobutyl_Ketone", - "KETONE_PANEL", - "Cyclohexanone", - "Methyl_n_Butyl_Ketone", - "Itraconazole", - "SELENIUM", - "LEAD", - "MERCURY", - "METALS___ACUTE_POISONING", - "THALLIUM", - "ARSENIC", - "BISMUTH", - "ANTIMONY", - "Nortramadol", - "Risperidone__Risperdal__", - "Difluoroethane", - "Verapamil", - "Suvorexant", - "Lidocaine__Xylocaine__", - "FLUNITRAZEPAM__Rohypnol_", - "Vecuronium__Norcuron_", - "Mivacurium_Hydrolysis_Produc", - "Tubocurarine", - "Normeperidine", - "Rucuronium__Zemuron_", - "Atricurium_Cisatricurium_Hyd", - "Succinylmonocholine__Metabol", - "Doxacurium__Nuromax_", - "Meperidine", - "NEUROMUSCULAR_BLOCKING_AGENT", - "Bretylium", - "Laudanosine", - "Doxacurium_Hydrolysis_Produc", - "Succinylcholine__Suxamethoni", - "Pancuronium__Pavulon_", - "COCAINE___METABOLITES", - "Yohimbine", - "PMA", - "Norpseudoephedrine", - "Tiletamine", - "Lysergic_Acid_Diethylamide_", - "Levorphanol__Levo_Dromoran__", - "OPIATES", - "Toluene", - "PALIPERIDONE", - "Salvinorin_B", - "Nordoxepin", - "Carbamazepine", - "Carbamazepine_Epoxide", - "Glyburide", - "Mesoridazine", - "Thioridazine__Mellaril__", - "Indomethacin", - "Etomidate__Amidate__", - "Flecainide", - "Zaleplon__Sonata__", - "Dextro_Levo_Methorphan", - "_3_Methoxy_PCP", - "Acetyl_Fentanyl", - "Valeryl_Fentanyl", - "Butyrl_Fentanyl_Isobutyryl_F" -FROM tox_reports_raw; - -CREATE TABLE tox_reports3 AS SELECT - "ACCT_NUM", - "ZOLPIDEM__Ambien_", - "Glyburide__DiaBeta__", - "Nalbuphine", - "Desmethyltrimipramine", - "Zaleplon", - "Fluvoxamine", - "Reserpine", - "Amoxapine", - "Disopyramide", - "U_49900", - "Carbamazepine_10_11_epoxide", - "Fluphenazine", - "ortho_Fluoro_Fentanyl", - "_1_Hydroxymidazolam", - "Alprenolol", - "Methaqualone", - "ADB_CHMINACA", - "Vardenafil", - "Bromazepam", - "Sufentanil", - "CUMYL_THPINACA", - "Alfentanil", - "Voriconazole", - "U_51754", - "Iloperidone", - "Clomipramine", - "TRAMADOL_METABOLITE", - "Zolpidem_4_Phenyl_COOH", - "Zolpidem__Ambien__", - "ZOLPIDEM_METABOLITE", - "Glimepiride", - "Methocarbamol", - "Phenazepam", - "Desalkylflurazepam", - "Pheniramine", - "p_Methylmethoxyacetyl_Fentan", - "Loxapine", - "m_Methylmethoxyacetyl_Fentan", - "Ziprasidone", - "Lithium", - "n_Propanol__n_Propyl_Alcohol", - "Volatiles__Hydrocarbons", - "Isopropanol__Isopropyl_Alcoh", - "Methyl_Isobutyl_Ketone__MIBK", - "Ethanol__Ethyl_Alcohol_", - "Acetaldehyde", - "Pentane", - "Methyl_Acrylate", - "Ethyl_Benzene", - "n_Hexane", - "Methanol__Methyl_Alcohol_", - "Diethyl_Ether", - "n_Heptane", - "Styrene__Vinylbenzene_", - "Xylenes__o_m_p_", - "Ethyl_Acetate", - "Methyl_Ethyl_Ketone__MEK_", - "Benzene", - "Methylpentanes__2__and_3__Is", - "n_Butanol__Butyl_Alcohol_", - "Methyl_Tertiary_Butyl_Ether", - "Flunitrazolam", - "Flubromazepam", - "Nitrazolam", - "Alpha_Hydroxyetizolam", - "Triprolidine", - "_3_Hydroxy_PCP", - "Brompheniramine", - "Mescaline", - "Pyrilamine", - "N_Ethyl_Pentylone", - "Psilocin", - "Atropine", - "Diphacinone", - "Chlorophacinone", - "Dicumarol", - "Bromadiolone", - "Brodifacoum", - "Difenacoum", - "Desmethyltramadol", - "Amiodarone__Cordarone__", - "Desethylamiodarone", - "Fentanyl__Vitreous", - "BARBITURATE_PANEL", - "SPECIAL_REQUEST", - "Methemoglobin", - "Betaxolol", - "Loratadine", - "Lacosamide__Vimpat__", - "Baclofen", - "Clenbuterol", - "Norethandrolone_Metabolite", - "Methandrostenolone", - "Clostebol", - "Oxymetholone_Metabolite", - "Turinabol", - "Clostebol_Metabolite", - "Testosterone", - "Norandrostenedione", - "Stanozolol_Metabolite", - "Epitestosterone", - "Norethindrone", - "Boldenone", - "Norethandrolone", - "Nandrolone", - "Probenecid", - "ANABOLIC_STEROIDS", - "Stanozolol", - "Methyltestosterone", - "Tetrahydrogestrinone", - "T_EpiT_Ratio", - "Methandrostenolone_Metabolit", - "Nandrolone_Metabolite", - "Oxandrolone", - "Fluoxymesterone", - "Methenolone", - "Trenbolone_Metabolite", - "Bolasterone", - "Drostanolone_Metabolite", - "CYANIDE", - "Oxybutynin", - "Hydroxychloroquine", - "Amlodipine__Norvasc__", - "Albuterol", - "Mexiletine", - "Chlorothiazide", - "Magnesium", - "Pentazocine", - "Trimipramine", - "Esmolol", - "Timolol", - "Cyclizine", - "Brompheniramine__Drixoral__", - "Metformin", - "Nitrous_Oxide", - "_5F_ADB_Butanoic_Acid_Metabol", - "Disposal_Date___1yr__", - "MDMB_FUBINACA_Butanoic_Acid", - "Valproic_Acid", - "Propofol", - "SPECIMEN_NUM", - "PLACE_HOLDER", - "FIRST_NAME", - "MIDDLE_NAME", - "LAST_NAME", - "GENDER", - "COLLECT_DATE", - "RECEIVED_DATE", - "LAST_REPORT_DATE", - "DATE_OF_DEATH", - "PERFORMING_LOCATION", - "PERFORMING_LOCATION_NAME", - "LOCATION_ADDRESS_1", - "LOCATION_ADDRESS_2", - "LOCATION_CITY", - "LOCATION_STATE", - "LOCATION_ZIP", - "LOCATION_PHONE", - "DOD", - "month", - "year", - "Quarter", - "SUNMITTING_COUNTYU", - "CORONER_U", - "County", - "Coroner" -FROM tox_reports_raw; - -CREATE INDEX tox_reports_selected_fk ON tox_reports_selected("ACCT_NUM"); -CREATE INDEX tox_reports1_fk ON tox_reports1("ACCT_NUM"); -CREATE INDEX tox_reports2_fk ON tox_reports2("ACCT_NUM"); -CREATE INDEX tox_reports3_fk ON tox_reports3("ACCT_NUM"); +CREATE INDEX tox_reports_fk ON tox_reports("ACCT_NUM"); From d43c2c95cdf48976c21f6b737f5efb432c69705b Mon Sep 17 00:00:00 2001 From: Edward Lu Date: Wed, 19 Apr 2023 05:01:22 -0400 Subject: [PATCH 4/5] Add all tox reports data to data distributions page --- .../src/schema-typing/12-tox_reports.sql | 584 ++++++++++++++++++ 1 file changed, 584 insertions(+) diff --git a/data-processor/src/schema-typing/12-tox_reports.sql b/data-processor/src/schema-typing/12-tox_reports.sql index 801bdb6a..41257fe1 100644 --- a/data-processor/src/schema-typing/12-tox_reports.sql +++ b/data-processor/src/schema-typing/12-tox_reports.sql @@ -1,4 +1,7 @@ DROP TABLE IF EXISTS tox_reports; +DROP TABLE IF EXISTS tox_reports1; +DROP TABLE IF EXISTS tox_reports2; +DROP TABLE IF EXISTS tox_reports3; CREATE TABLE tox_reports ( "ACCT_NUM" CHARACTER(5) CHECK(length(acct_num) = 5), @@ -68,4 +71,585 @@ INSERT INTO tox_reports END FROM tox_reports_raw; +CREATE TABLE tox_reports1 AS SELECT + "ACCT_NUM", + "REQ_FC_NUM", + "_NAME_", + "Norfentanyl", + "Meprobamate", + "______No_Testing_Performed", + "BARBITURATES", + "SYNTHETIC_CANNABINOIDS", + "Caffeine", + "MUSCLE_RELAXANTS", + "GASTROINTESTINALS", + "VOLATILES", + "Hydroxyzine", + "Oxycodone", + "Methanol", + "ANTIDIABETICS", + "Cotinine", + "ANTIFUNGALS", + "NOVEL_PSYCHOACTIVES", + "Alprazolam", + "Phencyclidine__PCP_", + "Morphine", + "O_Desmethyltramadol", + "Acetaminophen", + "HALLUCINOGENS", + "Acetone", + "CANNABINOIDS", + "MISCELLANEOUS", + "SEDATIVE_HYPNOTICS", + "ANESTHETICS", + "ANTIHISTAMINES", + "Isopropanol", + "ANTIPSYCHOTICS", + "DESIGNER_OPIOIDS", + "Nicotine", + "AMPHETAMINES", + "ANTICONVULSANTS", + "ANTICHOLINERGICS", + "ANTIDEPRESSANTS", + "Amphetamine", + "BENZODIAZEPINES", + "OPIOID_ANALGESICS", + "STIMULANTS", + "Hydrocodone", + "Ethanol", + "Diphenhydramine", + "Methamphetamine", + "Hydromorphone", + "Oxazepam", + "a_OH_Alprazolam", + "ANALGESICS", + "Oxymorphone", + "UROLOGICALS", + "MDMA", + "_7_Aminoclonazepam", + "_6_Monoacetylmorphine", + "CARDIOVASCULARS", + "EDDP", + "Fentanyl", + "Methadone", + "Benzoylecgonine", + "Codeine", + "Norbuprenorphine", + "Nordiazepam", + "Gabapentin", + "Lorazepam", + "Buprenorphine", + "Tramadol", + "Temazepam", + "THC_COOH", + "Delta_9_THC", + "__SUBMITTING_COUNTY_", + "__CORONER_", + "Carboxyhemoglobin", + "Cancelled_Order_Code_", + "Cancellation_Reason_", + "__Date_of_Birth_", + "Sertraline", + "Paroxetine", + "Amlodipine", + "Desmethylsertraline", + "Diazepam", + "Dextromethorphan", + "Levetiracetam", + "Acetylfentanyl", + "_4_ANPP", + "Naloxone", + "Olanzapine", + "Flubromazolam", + "Midazolam", + "Salicylic_Acid", + "Metoprolol", + "Ibuprofen", + "Pseudoephedrine", + "Pregabalin", + "Fluorofentanyl", + "Acrylfentanyl", + "NOVEL_EMERGING_SUBSTANCES", + "Naproxen", + "__Volatile_Testing_Not_Perfo", + "Trazodone", + "Quinidine_Quinine", + "Xylazine", + "Propranolol", + "Aripiprazole", + "Citalopram", + "Flurazepam", + "Warfarin", + "meta_Chlorophenylpiperazine", + "Promethazine", + "Norfluoxetine", + "NITAZENE_ANALOG_PANEL", + "Protonitazene", + "Bupropion", + "Metonitazene", + "Buspirone__BuSpar__", + "Cyclobenzaprine", + "Lamotrigine", + "Fluoxetine", + "Dihydrocodeine", + "Phenylpropanolamine", + "Ephedrine", + "Metoclopramide", + "Theophylline", + "Donepezil", + "Creatinine", + "Potassium", + "Glucose", + "Sodium", + "Chloride", + "Urea_Nitrogen", + "Carfentanil", + "Mephedrone", + "Butyrylfentanyl", + "Flualprazolam", + "Eutylone", + "_25B_NBOMe", + "_25C_NBOMe", + "Dimethylone", + "Methcathinone", + "cis_3_Methylfentanyl", + "Etizolam", + "_5_MeO_DALT", + "Ethylone", + "Clonazolam", + "_2C_I", + "_2C_E", + "Methylone", + "_6_Beta_Naltrexol", + "Adinazolam", + "Ocfentanil", + "Butylone", + "Tetrahydrofuranfentanyl", + "MDMB_4en_PINACA_Metabolite", + "_5F_MDMB_PICA_Metabolite", + "_2C_B", + "Methoxetamine", + "MDPV", + "Cyclopropylfentanyl", + "Dibutylone", + "_25I_NBOMe", + "TFMPP", + "N_ethylpentylone", + "Methoxyacetylfentanyl", + "Alpha_PVP", + "_4F_MDMB_BICA_Metabolite", + "U47700", + "Naltrexone", + "Betahydroxythiofentanyl", + "Parafluorobutyrylfentanyl", + "Methedrone", + "Furanylfentanyl", + "Pentylone", + "Quetiapine", + "Amiodarone", + "Lidocaine", + "Promazine", + "Trihexyphenidyl", + "Desmethylclomipramine", + "Thioridazine", + "Propoxyphene", + "Norpropoxyphene", + "N_Acetylprocainamide", + "Ketoconazole", + "Gamma_Hydroxybutyrate__GHB_", + "Estazolam__ProSom__", + "Norketamine", + "Ketamine", + "INHALANTS_PANEL", + "_1_1_Difluoroethane", + "_1_1_1_2_Tetrafluoroethane", + "Topiramate", + "HALOCARBONS", + "HYDROCARBON_GASES", + "Nifedipine", + "_9_Hydroxyrisperidone", + "Desmethyldoxepin", + "Doxepin", + "FENTANYL_METABOLITE", + "Cocaine", + "Cocaethylene" +FROM tox_reports_raw; + +CREATE TABLE tox_reports2 AS SELECT + "ACCT_NUM", + "Doxylamine", + "_6_Acetylmorphine", + "DESIGNER_OPIOIDS_PANEL", + "Etonitazene", + "Isotonitazene", + "Etodesnitazene", + "Metodesnitazene", + "Butonitazene", + "Flunitazene", + "Isotodesnitazene", + "N_Pyrrolidino_Etonitazene", + "Loperamide", + "Etomidate", + "Tapentadol", + "Haloperidol", + "Primidone", + "Ziprasidone__Geodon__", + "Furosemide", + "Phenacetin", + "Dicyclomine", + "Zopiclone", + "Clonazepam", + "Amitriptyline", + "Nortriptyline", + "Levamisole", + "O_Desmethylvenlafaxine", + "Demoxepam", + "ADB_4en_PINACA", + "_4_cyano_CUMYL_BINACA", + "ADB_BINACA", + "_4_fluoro_MDMB_BINACA", + "Prochlorperazine", + "Prochlorperazine__Quan", + "Clozapine", + "Norclozapine", + "Venlafaxine", + "Duloxetine", + "Chlorpromazine", + "Zolpidem", + "Atomoxetine__Strattera__", + "Orphenadrine", + "Mirtazapine", + "MDA", + "Phenytoin", + "Phentermine", + "Atenolol", + "Mitragynine", + "Methylphenidate", + "ETHYLENE_GLYCOL", + "Oxcarbazepine_Metabolite", + "Benzocaine", + "Memantine", + "_5F_ADB", + "FUB_AMB", + "MDMB_FUBINACA", + "MDMB_FUBINACA_Metabolite", + "FUB_144", + "_5F_MDMB_PICA", + "_5F_ADB_Metabolite", + "_4CN_CUMYL_BINACA", + "ADB_FUBINACA", + "_4F_MDMB_BINACA", + "Dextrorphan_Levorphanol", + "Chlorpheniramine", + "Clonidine", + "Tadalafil", + "Zonisamide", + "Tetrahydrozoline", + "Hydrochlorothiazide", + "Butalbital", + "Bupivacaine", + "Phenobarbital", + "Procainamide", + "Sildenafil", + "Strychnine", + "Brorphine", + "AP_237", + "N_Desmethylsildenafil", + "Chlordiazepoxide", + "Glipizide", + "Lacosamide", + "Bisoprolol", + "Furanyl_Fentanyl", + "U_47700", + "Diltiazem", + "Salicylates", + "Guaifenesin", + "IRON", + "CARBON_MONOXIDE", + "Risperidone", + "Phencyclidine", + "Carisoprodol", + "Buspirone", + "_10_Hydroxycarbazepine", + "Fluphenazine__Prolixin__", + "Diphenoxylate", + "METHADONE_METABOLITE", + "Desmethylloperamide", + "Atomoxetine", + "Benztropine", + "Medazepam", + "Maprotiline", + "Metoprolol__Lopressor__", + "Citalopram_Escitalopram", + "_5_fluoro_MDMB_PICA", + "Pentobarbital", + "Secobarbital", + "Amobarbital", + "Butabarbital", + "THC", + "Loperamide__Imodium__", + "Sotalol", + "Hydroxyzine__Vistaril__", + "Norsertraline", + "Ketamine__Ketalar__", + "___Investigator_", + "Pregabalin__Lyrica__", + "Chlorophenylpiperazine", + "MDA__MDMA_Metabolite_", + "Lysergic_Acid_Diethylamide", + "Quinine", + "FUB_AMB___AB_FUBINACA", + "_5_fluoro_ADB", + "Hydroxybupropion", + "Phenytoin__Dilantin__", + "Imipramine", + "Desipramine", + "Delorazepam", + "Diclazepam", + "Eszopiclone__Lunesta__", + "ANALYSIS_METHOD_", + "FINDINGS_", + "TRACE_SUBSTANCE_ANALYSIS", + "SPECIMEN_RECEIVED_", + "Phenylethylmalonamide__PEMA_", + "Ropivacaine", + "Labetalol", + "Diltiazem__Cardizem__", + "Methyl_Ethyl_Ketone", + "Methyl_Isobutyl_Ketone", + "KETONE_PANEL", + "Cyclohexanone", + "Methyl_n_Butyl_Ketone", + "Itraconazole", + "SELENIUM", + "LEAD", + "MERCURY", + "METALS___ACUTE_POISONING", + "THALLIUM", + "ARSENIC", + "BISMUTH", + "ANTIMONY", + "Nortramadol", + "Risperidone__Risperdal__", + "Difluoroethane", + "Verapamil", + "Suvorexant", + "Lidocaine__Xylocaine__", + "FLUNITRAZEPAM__Rohypnol_", + "Vecuronium__Norcuron_", + "Mivacurium_Hydrolysis_Produc", + "Tubocurarine", + "Normeperidine", + "Rucuronium__Zemuron_", + "Atricurium_Cisatricurium_Hyd", + "Succinylmonocholine__Metabol", + "Doxacurium__Nuromax_", + "Meperidine", + "NEUROMUSCULAR_BLOCKING_AGENT", + "Bretylium", + "Laudanosine", + "Doxacurium_Hydrolysis_Produc", + "Succinylcholine__Suxamethoni", + "Pancuronium__Pavulon_", + "COCAINE___METABOLITES", + "Yohimbine", + "PMA", + "Norpseudoephedrine", + "Tiletamine", + "Lysergic_Acid_Diethylamide_", + "Levorphanol__Levo_Dromoran__", + "OPIATES", + "Toluene", + "PALIPERIDONE", + "Salvinorin_B", + "Nordoxepin", + "Carbamazepine", + "Carbamazepine_Epoxide", + "Glyburide", + "Mesoridazine", + "Thioridazine__Mellaril__", + "Indomethacin", + "Etomidate__Amidate__", + "Flecainide", + "Zaleplon__Sonata__", + "Dextro_Levo_Methorphan", + "_3_Methoxy_PCP", + "Acetyl_Fentanyl", + "Valeryl_Fentanyl", + "Butyrl_Fentanyl_Isobutyryl_F" +FROM tox_reports_raw; + +CREATE TABLE tox_reports3 AS SELECT + "ACCT_NUM", + "ZOLPIDEM__Ambien_", + "Glyburide__DiaBeta__", + "Nalbuphine", + "Desmethyltrimipramine", + "Zaleplon", + "Fluvoxamine", + "Reserpine", + "Amoxapine", + "Disopyramide", + "U_49900", + "Carbamazepine_10_11_epoxide", + "Fluphenazine", + "ortho_Fluoro_Fentanyl", + "_1_Hydroxymidazolam", + "Alprenolol", + "Methaqualone", + "ADB_CHMINACA", + "Vardenafil", + "Bromazepam", + "Sufentanil", + "CUMYL_THPINACA", + "Alfentanil", + "Voriconazole", + "U_51754", + "Iloperidone", + "Clomipramine", + "TRAMADOL_METABOLITE", + "Zolpidem_4_Phenyl_COOH", + "Zolpidem__Ambien__", + "ZOLPIDEM_METABOLITE", + "Glimepiride", + "Methocarbamol", + "Phenazepam", + "Desalkylflurazepam", + "Pheniramine", + "p_Methylmethoxyacetyl_Fentan", + "Loxapine", + "m_Methylmethoxyacetyl_Fentan", + "Ziprasidone", + "Lithium", + "n_Propanol__n_Propyl_Alcohol", + "Volatiles__Hydrocarbons", + "Isopropanol__Isopropyl_Alcoh", + "Methyl_Isobutyl_Ketone__MIBK", + "Ethanol__Ethyl_Alcohol_", + "Acetaldehyde", + "Pentane", + "Methyl_Acrylate", + "Ethyl_Benzene", + "n_Hexane", + "Methanol__Methyl_Alcohol_", + "Diethyl_Ether", + "n_Heptane", + "Styrene__Vinylbenzene_", + "Xylenes__o_m_p_", + "Ethyl_Acetate", + "Methyl_Ethyl_Ketone__MEK_", + "Benzene", + "Methylpentanes__2__and_3__Is", + "n_Butanol__Butyl_Alcohol_", + "Methyl_Tertiary_Butyl_Ether", + "Flunitrazolam", + "Flubromazepam", + "Nitrazolam", + "Alpha_Hydroxyetizolam", + "Triprolidine", + "_3_Hydroxy_PCP", + "Brompheniramine", + "Mescaline", + "Pyrilamine", + "N_Ethyl_Pentylone", + "Psilocin", + "Atropine", + "Diphacinone", + "Chlorophacinone", + "Dicumarol", + "Bromadiolone", + "Brodifacoum", + "Difenacoum", + "Desmethyltramadol", + "Amiodarone__Cordarone__", + "Desethylamiodarone", + "Fentanyl__Vitreous", + "BARBITURATE_PANEL", + "SPECIAL_REQUEST", + "Methemoglobin", + "Betaxolol", + "Loratadine", + "Lacosamide__Vimpat__", + "Baclofen", + "Clenbuterol", + "Norethandrolone_Metabolite", + "Methandrostenolone", + "Clostebol", + "Oxymetholone_Metabolite", + "Turinabol", + "Clostebol_Metabolite", + "Testosterone", + "Norandrostenedione", + "Stanozolol_Metabolite", + "Epitestosterone", + "Norethindrone", + "Boldenone", + "Norethandrolone", + "Nandrolone", + "Probenecid", + "ANABOLIC_STEROIDS", + "Stanozolol", + "Methyltestosterone", + "Tetrahydrogestrinone", + "T_EpiT_Ratio", + "Methandrostenolone_Metabolit", + "Nandrolone_Metabolite", + "Oxandrolone", + "Fluoxymesterone", + "Methenolone", + "Trenbolone_Metabolite", + "Bolasterone", + "Drostanolone_Metabolite", + "CYANIDE", + "Oxybutynin", + "Hydroxychloroquine", + "Amlodipine__Norvasc__", + "Albuterol", + "Mexiletine", + "Chlorothiazide", + "Magnesium", + "Pentazocine", + "Trimipramine", + "Esmolol", + "Timolol", + "Cyclizine", + "Brompheniramine__Drixoral__", + "Metformin", + "Nitrous_Oxide", + "_5F_ADB_Butanoic_Acid_Metabol", + "Disposal_Date___1yr__", + "MDMB_FUBINACA_Butanoic_Acid", + "Valproic_Acid", + "Propofol", + "SPECIMEN_NUM", + "PLACE_HOLDER", + "FIRST_NAME", + "MIDDLE_NAME", + "LAST_NAME", + "GENDER", + "COLLECT_DATE", + "RECEIVED_DATE", + "LAST_REPORT_DATE", + "DATE_OF_DEATH", + "PERFORMING_LOCATION", + "PERFORMING_LOCATION_NAME", + "LOCATION_ADDRESS_1", + "LOCATION_ADDRESS_2", + "LOCATION_CITY", + "LOCATION_STATE", + "LOCATION_ZIP", + "LOCATION_PHONE", + "DOD", + "month", + "year", + "Quarter", + "SUNMITTING_COUNTYU", + "CORONER_U", + "County", + "Coroner" +FROM tox_reports_raw; + CREATE INDEX tox_reports_fk ON tox_reports("ACCT_NUM"); +CREATE INDEX tox_reports1_fk ON tox_reports1("ACCT_NUM"); +CREATE INDEX tox_reports2_fk ON tox_reports2("ACCT_NUM"); +CREATE INDEX tox_reports3_fk ON tox_reports3("ACCT_NUM"); From 4429584f43783ca8b8a9aa50e1f3d7540ffcade8 Mon Sep 17 00:00:00 2001 From: Edward Lu Date: Mon, 24 Apr 2023 20:23:51 -0400 Subject: [PATCH 5/5] filter data for entries with valid age data --- .../src/schema-typing/12-tox_reports.sql | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/data-processor/src/schema-typing/12-tox_reports.sql b/data-processor/src/schema-typing/12-tox_reports.sql index 41257fe1..87b26823 100644 --- a/data-processor/src/schema-typing/12-tox_reports.sql +++ b/data-processor/src/schema-typing/12-tox_reports.sql @@ -4,7 +4,7 @@ DROP TABLE IF EXISTS tox_reports2; DROP TABLE IF EXISTS tox_reports3; CREATE TABLE tox_reports ( - "ACCT_NUM" CHARACTER(5) CHECK(length(acct_num) = 5), + "SPECIMEN_NUM" CHARACTER(8) CHECK(length(specimen_num) = 8), "FENTANYL" BOOLEAN CHECK(fentanyl IN (NULL, 0, 1)), "BENZODIAZEPINES" BOOLEAN CHECK(benzodiazepines IN (NULL, 0, 1)), "METHAMPHETAMINE" BOOLEAN CHECK(methamphetamine IN (NULL, 0, 1)), @@ -13,14 +13,14 @@ CREATE TABLE tox_reports ( "OXYMORPHONE" BOOLEAN CHECK(oxymorphone IN (NULL, 0, 1)), "OXYCODONE" BOOLEAN CHECK(oxycodone IN (NULL, 0, 1)), "ANTIDEPRESSANTS" BOOLEAN CHECK(antidepressants IN (NULL, 0, 1)), - "DOD" DATE CHECK(length(dod) = 10), - "DOB" DATE CHECK(length(dob) = 10 OR dob IS NULL), - "AGE" INT CHECK(typeof(age) = 'integer' OR age IS NULL), - "GENDER" CHARACTER CHECK(gender IN (NULL, 'M', 'F')) + "GENDER" CHARACTER NOT NULL CHECK(gender IN ('N/A', 'M', 'F')), + "DOD" DATE CHECK(typeof(dod) = 'text' AND length(dod) = 10), + "DOB" DATE CHECK(typeof(dob) = 'text' AND length(dob) = 10), + "AGE" INT NOT NULL CHECK(typeof(age) = 'integer') ); INSERT INTO tox_reports SELECT - acct_num, + specimen_num, CASE fentanyl WHEN 'Negative' THEN 0 WHEN 'POSITIVE' THEN 1 @@ -61,18 +61,20 @@ INSERT INTO tox_reports WHEN 'POSITIVE' THEN 1 ELSE NULL END, - date(dod) as dod, - date(substr(__Date_of_Birth_, 7, 4) || '-' || substr(__Date_of_Birth_, 4, 2) || '-' || substr(__Date_of_Birth_, 1, 2)) AS dob, - CAST((JULIANDAY(date(dod)) - JULIANDAY(date(substr(__Date_of_Birth_, 7, 4) || '-' || substr(__Date_of_Birth_, 4, 2) || '-' || substr(__Date_of_Birth_, 1, 2))))/365 as INT) AS age, CASE gender WHEN 'M' THEN 'M' WHEN 'F' THEN 'F' + WHEN 'NOT' THEN 'N/A' ELSE NULL - END -FROM tox_reports_raw; + END, + date(dod) as dod, + date(substr(__Date_of_Birth_, 7, 4) || '-' || substr(__Date_of_Birth_, 4, 2) || '-' || substr(__Date_of_Birth_, 1, 2)) AS dob, + CAST((JULIANDAY(date(dod)) - JULIANDAY(date(substr(__Date_of_Birth_, 7, 4) || '-' || substr(__Date_of_Birth_, 4, 2) || '-' || substr(__Date_of_Birth_, 1, 2))))/365 as INT) AS age +FROM tox_reports_raw +WHERE age != ''; CREATE TABLE tox_reports1 AS SELECT - "ACCT_NUM", + "SPECIMEN_NUM", "REQ_FC_NUM", "_NAME_", "Norfentanyl", @@ -276,7 +278,7 @@ CREATE TABLE tox_reports1 AS SELECT FROM tox_reports_raw; CREATE TABLE tox_reports2 AS SELECT - "ACCT_NUM", + "SPECIMEN_NUM", "Doxylamine", "_6_Acetylmorphine", "DESIGNER_OPIOIDS_PANEL", @@ -480,7 +482,7 @@ CREATE TABLE tox_reports2 AS SELECT FROM tox_reports_raw; CREATE TABLE tox_reports3 AS SELECT - "ACCT_NUM", + "SPECIMEN_NUM", "ZOLPIDEM__Ambien_", "Glyburide__DiaBeta__", "Nalbuphine", @@ -649,7 +651,7 @@ CREATE TABLE tox_reports3 AS SELECT "Coroner" FROM tox_reports_raw; -CREATE INDEX tox_reports_fk ON tox_reports("ACCT_NUM"); -CREATE INDEX tox_reports1_fk ON tox_reports1("ACCT_NUM"); -CREATE INDEX tox_reports2_fk ON tox_reports2("ACCT_NUM"); -CREATE INDEX tox_reports3_fk ON tox_reports3("ACCT_NUM"); +CREATE INDEX tox_reports_fk ON tox_reports("SPECIMEN_NUM"); +CREATE INDEX tox_reports1_fk ON tox_reports1("SPECIMEN_NUM"); +CREATE INDEX tox_reports2_fk ON tox_reports2("SPECIMEN_NUM"); +CREATE INDEX tox_reports3_fk ON tox_reports3("SPECIMEN_NUM");