diff --git a/mergesync/build.gradle b/mergesync/build.gradle deleted file mode 100644 index 7be9197de..000000000 --- a/mergesync/build.gradle +++ /dev/null @@ -1,10 +0,0 @@ -import org.labkey.gradle.util.BuildUtils; - -plugins { - id 'org.labkey.build.module' -} - -dependencies { - BuildUtils.addLabKeyDependency(project: project, config: "implementation", depProjectPath: ":server:modules:ehrModules:ehr", depProjectConfig: "apiJarFile") - BuildUtils.addLabKeyDependency(project: project, config: "implementation", depProjectPath: ":server:modules:LabDevKitModules:LDK", depProjectConfig: "apiJarFile") -} diff --git a/mergesync/module.properties b/mergesync/module.properties deleted file mode 100644 index a6d6304b2..000000000 --- a/mergesync/module.properties +++ /dev/null @@ -1,3 +0,0 @@ -ModuleClass: org.labkey.mergesync.MergeSyncModule -ManageVersion: false -SupportedDatabases: mssql, pgsql diff --git a/mergesync/resources/module.xml b/mergesync/resources/module.xml deleted file mode 100644 index 0c59021b4..000000000 --- a/mergesync/resources/module.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - true - The is the URL of the merge website - - ADMIN - - - - diff --git a/mergesync/resources/queries/mergesync/merge_results/.qview.xml b/mergesync/resources/queries/mergesync/merge_results/.qview.xml deleted file mode 100644 index 717fe81fa..000000000 --- a/mergesync/resources/queries/mergesync/merge_results/.qview.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/mergesync/resources/queries/mergesync/merge_runs.query.xml b/mergesync/resources/queries/mergesync/merge_runs.query.xml deleted file mode 100644 index 1ab4b3e26..000000000 --- a/mergesync/resources/queries/mergesync/merge_runs.query.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - ldk.context - mergesync/mergeButtons.js - - MergeSync.buttons.resyncSelected(dataRegionName); - - -
-
-
-
diff --git a/mergesync/resources/queries/mergesync/merge_runs/.qview.xml b/mergesync/resources/queries/mergesync/merge_runs/.qview.xml deleted file mode 100644 index 717fe81fa..000000000 --- a/mergesync/resources/queries/mergesync/merge_runs/.qview.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/mergesync/resources/queries/mergesync/orderssynced.query.xml b/mergesync/resources/queries/mergesync/orderssynced.query.xml deleted file mode 100644 index 79c6a7b17..000000000 --- a/mergesync/resources/queries/mergesync/orderssynced.query.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - study - clinpathRuns - objectid - - - - - ehr - tasks - taskid - - - - - ehr - requests - requestid - - - -
-
-
-
diff --git a/mergesync/resources/queries/mergesync/orderssynced/.qview.xml b/mergesync/resources/queries/mergesync/orderssynced/.qview.xml deleted file mode 100644 index f4f1570e5..000000000 --- a/mergesync/resources/queries/mergesync/orderssynced/.qview.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.00-0.01.sql b/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.00-0.01.sql deleted file mode 100644 index f01fc2be2..000000000 --- a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.00-0.01.sql +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - --- Create schema, tables, indexes, and constraints used for MergeSync module here --- All SQL VIEW definitions should be created in mergesync-create.sql and dropped in mergesync-drop.sql -CREATE SCHEMA mergesync; - -CREATE TABLE mergesync.testnamemapping ( - rowid serial, - servicename varchar(100), - mergetestname varchar(100) -); - -CREATE TABLE mergesync.orderssynced ( - rowid serial, - objectid varchar(100), - merge_accession varchar(100), - container entityid, - created timestamp, - createdby int, - resultsreceived boolean -); - -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Albumin', 'ALB'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Amylase', 'AMYL'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Anaerobic Culture', 'ANCULT'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Antibiotic Sensitivity', 'SENSI'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('BAL Fluid Analysis with Cytology', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('BASIC Chemistry Panel in-house', 'BASIC'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Bile Acids Post-prarandial', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Bile Acids Pre-prarandial', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('C-Reactive Protein', 'CRP'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('CBC only, no differential', 'CBC'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('CBC with automated differential', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('CBC with manual differential', 'DIFF'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Chemistry panel with high density lipoprotein send out', 'CMPHDL'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Clotting panel', 'CLOTPL'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Comprehensive Chemistry panel in-house', 'COMP'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Comprehensive Chemistry Panel Send Out', 'CMP'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Compromised SPF Surveillance', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('CSF analysis (WBC count & differential)', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('CSF Glucose', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('CSF Total Protein', 'CSF'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Cytology Send out', 'CYTO'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Dermatophyte test medium culture', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('ESPF Surveillance - Monthly', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('ESPF Surveillance - Quarterly', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Exam for Yeast', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Fecal culture', 'F_CULT'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Fecal parasite exam', 'F_PARA'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Filovirus', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Fungus Culture', 'FUNGAL'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('General culture', 'G-CULT'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Glycosolated hemoglobin (HGBA1C)', 'HGBA1C'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Gram Stain', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('HDL', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Herpes B', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Herpes B Post-Exposure Baseline Serology', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Herpes B Post-Exposure Baseline Virology', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Herpes B Post-Exposure Follow-Up Serology', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Herpes B Status Confirmation', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('High-density lipoprotein & Low-density lipoprotein (HDL & LDL)', 'HDLLDL'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Intuitive Basic Array', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Intuitive Expanded Array', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Japanese Macaque Surveillance', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('LDL', 'LDL'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Lipase', 'Lipase'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Lipid panel in-house: Cholesterol, Triglyceride, HDL, LDL', 'LIPID'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Malaria Screen', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Miscellaneous in-house', 'MISIN'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Miscellaneous send out', 'MISOUT'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Occult Blood', 'OCCBLD'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Other Clinpath', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Other SPF Surveillance', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL ABSCN-5', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL ABSCN-8', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL PCR', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL SIV WB', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL SRV1 WB', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL SRV2 WB', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL SRV5 WB', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL STLV WB', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Phenobarbital', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Primagam for TB', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Protein Electrophoresis-Total Protein', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('RBC Morphology', 'MORPH'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Reticulocyte count', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Specific Gravity', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('SPF Surveillance - Annual', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('SRV', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('SRV Virus Isolation', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Terminal Serum Surveillance', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Thyroid Panel', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Urinalysis', 'URINE'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Vitamin D (1,25 Dihydroxy)', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Vitamin D (250H)', 'VITD'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('WBC differential', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Yersinia culture', 'YERSNA'); diff --git a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.01-0.02.sql b/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.01-0.02.sql deleted file mode 100644 index 376894fc3..000000000 --- a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.01-0.02.sql +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -ALTER TABLE mergesync.orderssynced DROP COLUMN merge_accession; -ALTER TABLE mergesync.orderssynced ADD order_accession integer; -ALTER TABLE mergesync.orderssynced ADD test_accession integer; -ALTER TABLE mergesync.orderssynced ADD taskid entityid; \ No newline at end of file diff --git a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.02-0.03.sql b/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.02-0.03.sql deleted file mode 100644 index 547b406d9..000000000 --- a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.02-0.03.sql +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -ALTER TABLE mergesync.orderssynced DROP COLUMN rowid; -ALTER TABLE mergesync.orderssynced ADD runid entityid; -ALTER TABLE mergesync.orderssynced ADD merge_datecreated timestamp; -ALTER TABLE mergesync.orderssynced ADD merge_dateposted timestamp; -ALTER TABLE mergesync.orderssynced ALTER COLUMN objectid SET not null; - -ALTER TABLE mergesync.orderssynced ADD CONSTRAINT PK_orderssynced PRIMARY KEY (objectid); \ No newline at end of file diff --git a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.03-0.04.sql b/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.03-0.04.sql deleted file mode 100644 index b85a2328c..000000000 --- a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.03-0.04.sql +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -ALTER TABLE mergesync.orderssynced ADD requestid entityid; \ No newline at end of file diff --git a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.04-0.05.sql b/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.04-0.05.sql deleted file mode 100644 index e8e7c5d4f..000000000 --- a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.04-0.05.sql +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -CREATE TABLE mergesync.mergetolkmapping ( - mergetestname varchar(100), - servicename varchar(100), - automaticresults bool default false, - - CONSTRAINT PK_mergetolkmapping PRIMARY KEY (mergetestname) -); - -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('ALB', 'Albumin', true); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('AMYL', 'Amylase', true); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('ANCULT', 'Anaerobic Culture', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('BASIC', 'BASIC Chemistry Panel in-house', true); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CBC', 'CBC with automated differential', true); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CBCMIN', 'CBC only, no differential', true); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CLOTPL', 'Clotting panel', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CMP', 'Comprehensive Chemistry Panel Send Out', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CMPHDL', 'Chemistry panel with high density lipoprotein send out', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('COMP', 'Comprehensive Chemistry panel in-house', true); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CRP', 'C-Reactive Protein', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CSFCC', 'CSF analysis (WBC count & differential)', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CSFPRO', 'CSF Total Protein', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CSFTP', 'Cerebral Spinal Fluid Total Protein – Send out', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CSFWBC', 'Cerebral Spinal Fluid white blood count with differential', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CYTO', 'BAL Fluid Analysis with Cytology', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('DIFF', 'CBC with manual differential', false); ---INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('DIFF', 'WBC differential', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('DTMFUN', 'Dermatophyte test medium culture', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('F_CULT', 'Fecal culture', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('F_PARA', 'Fecal parasite exam', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('FUNGAL', 'Fungus Culture', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('GCULT1', 'General culture', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('GCULT2', 'General culture', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('GCULT3', 'General culture', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('HDLLDL', 'High-density lipoprotein & Low-density lipoprotein (HDL & LDL)', true); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('HGBA1C', 'Glycosolated hemoglobin (HGBA1C)', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('LDL', 'LDL', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('LIPID', 'Lipid panel in-house: Cholesterol, Triglyceride, HDL, LDL', true); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('MALA', 'Malaria Screen', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('MIS IN', 'Miscellaneous in-house', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('MISOUT', 'Bile Acids Post-prarandial', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('OCCBLD', 'Occult Blood', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('RETIC', 'Reticulocyte count', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('SENS2', 'Antibiotic Sensitivity', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('SENS3', 'Antibiotic Sensitivity', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('SENSI', 'Antibiotic Sensitivity', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('URINE', 'Urinalysis', false); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('YERSNA', 'Yersinia culture', false); diff --git a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.05-0.06.sql b/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.05-0.06.sql deleted file mode 100644 index 45ac40c63..000000000 --- a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.05-0.06.sql +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -TRUNCATE TABLE mergesync.testnamemapping; -ALTER TABLE mergesync.testnamemapping DROP COLUMN rowid; -ALTER TABLE mergesync.testnamemapping ALTER COLUMN servicename SET NOT NULL; -ALTER TABLE mergesync.testnamemapping ADD CONSTRAINT PK_testnamemapping PRIMARY KEY (servicename); -ALTER TABLE mergesync.testnamemapping ADD automaticresults bool default false; - -DROP TABLE mergesync.mergetolkmapping; - -CREATE TABLE mergesync.mergetolkmapping ( - mergetestname varchar(100) NOT NULL, - servicename varchar(100), - - CONSTRAINT PK_mergetolkmapping PRIMARY KEY (mergetestname) -); - --- @SkipOnEmptySchemasBegin -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Albumin', 'ALB', true); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Amylase', 'AMYL', true); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Anaerobic Culture', 'ANCULT', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('BASIC Chemistry Panel in-house', 'BASIC', true); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('CBC with automated differential', 'CBC', true); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Clotting panel', 'CLOTPL', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Comprehensive Chemistry Panel Send Out', 'CMP', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Chemistry panel with high density lipoprotein send out', 'CMPHDL', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Comprehensive Chemistry panel in-house', 'COMP', true); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('C-Reactive Protein', 'CRP', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('CSF analysis (WBC count & differential)', 'CSFCC', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('CSF Total Protein', 'CSFPRO', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Cerebral Spinal Fluid Total Protein – Send out', 'CSFTP', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Cerebral Spinal Fluid white blood count with differential', 'CSFWBC', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('BAL Fluid Analysis with Cytology', 'CYTO', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Cytology Send out', 'CYTO', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('CBC with manual differential', 'DIFF', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('WBC differential', 'DIFF', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Dermatophyte test medium culture', 'DTMFUN', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Fecal culture', 'F_CULT', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Fecal parasite exam', 'F_PARA', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Fungus Culture', 'FUNGAL', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('General culture', 'GCULT1', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('High-density lipoprotein & Low-density lipoprotein (HDL & LDL)', 'HDLLDL', true); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Glycosolated hemoglobin (HGBA1C)', 'HGBA1C', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('LDL', 'LDL', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Lipid panel in-house: Cholesterol, Triglyceride, HDL, LDL', 'LIPID', true); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Malaria Screen', 'MALA', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Miscellaneous in-house', 'MIS IN', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Bile Acids Post-prarandial', 'MISOUT', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Bile Acids Pre-prarandial', 'MISOUT', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Calcium, ionized', 'MISOUT', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Calcium, total', 'MISOUT', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('CSF Glucose', 'MISOUT', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Lipase', 'MISOUT', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Miscellaneous send out', 'MISOUT', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Phenobarbital', 'MISOUT', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Protein Electrophoresis-Total Protein', 'MISOUT', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Thyroid Panel', 'MISOUT', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Vitamin D (1,25 Dihydroxy)', 'MISOUT', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Vitamin D (250H)', 'MISOUT', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('RBC Morphology', 'MORPH', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Occult Blood', 'OCCBLD', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Reticulocyte count', 'RETIC', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Antibiotic Sensitivity', 'SENSI', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Urinalysis', 'URINE', false); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Yersinia culture', 'YERSNA', false); - -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('ALB', 'Albumin'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('AMYL', 'Amylase'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('ANCULT', 'Anaerobic Culture'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('BASIC', 'BASIC Chemistry Panel in-house'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CBC', 'CBC with automated differential'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CLOTPL', 'Clotting panel'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CMP', 'Comprehensive Chemistry Panel Send Out'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CMPHDL', 'Chemistry panel with high density lipoprotein send out'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('COMP', 'Comprehensive Chemistry panel in-house'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CRP', 'C-Reactive Protein'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CSFCC', 'CSF analysis (WBC count & differential)'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CSFPRO', 'CSF Total Protein'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CSFTP', 'Cerebral Spinal Fluid Total Protein – Send out'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CSFWBC', 'Cerebral Spinal Fluid white blood count with differential'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CYTO', 'BAL Fluid Analysis with Cytology'); ---INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CYTO', 'Cytology Send out'); ---INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('DIFF', 'CBC with manual differential'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('DIFF', 'WBC differential'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('DTMFUN', 'Dermatophyte test medium culture'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('F_CULT', 'Fecal culture'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('F_PARA', 'Fecal parasite exam'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('FUNGAL', 'Fungus Culture'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('GCULT1', 'General culture'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('GCULT2', 'General culture'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('GCULT3', 'General culture'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('HDLLDL', 'High-density lipoprotein & Low-density lipoprotein (HDL & LDL)'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('HGBA1C', 'Glycosolated hemoglobin (HGBA1C)'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('LDL', 'LDL'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('LIPID', 'Lipid panel in-house: Cholesterol, Triglyceride, HDL, LDL'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('MALA', 'Malaria Screen'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('MIS IN', 'Miscellaneous in-house'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('MISOUT', 'Miscellaneous send out'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('MORPH', 'RBC Morphology'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('OCCBLD', 'Occult Blood'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('RETIC', 'Reticulocyte count'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('SENS2', 'Antibiotic Sensitivity'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('SENS3', 'Antibiotic Sensitivity'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('SENSI', 'Antibiotic Sensitivity'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('URINE', 'Urinalysis'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('YERSNA', 'Yersinia culture'); --- @SkipOnEmptySchemasEnd diff --git a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.06-0.07.sql b/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.06-0.07.sql deleted file mode 100644 index 1907176d3..000000000 --- a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.06-0.07.sql +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -UPDATE mergesync.testnamemapping SET automaticresults = true WHERE servicename = 'WBC differential'; -UPDATE mergesync.testnamemapping SET automaticresults = true WHERE servicename = 'RBC Morphology'; -UPDATE mergesync.testnamemapping SET automaticresults = true WHERE servicename = 'Reticulocyte count'; \ No newline at end of file diff --git a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.07-0.08.sql b/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.07-0.08.sql deleted file mode 100644 index c02ce88ce..000000000 --- a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.07-0.08.sql +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -DELETE FROM mergesync.testnamemapping WHERE servicename = 'CBC with manual differential'; \ No newline at end of file diff --git a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.08-0.09.sql b/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.08-0.09.sql deleted file mode 100644 index 4e8593ca9..000000000 --- a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.08-0.09.sql +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - --- @SkipOnEmptySchemasBegin -DELETE FROM mergesync.mergetolkmapping WHERE mergetestname = 'SENSI2'; -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('SENSI2', 'Antibiotic Sensitivity'); - -DELETE FROM mergesync.mergetolkmapping WHERE mergetestname = 'SENSI3'; -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('SENSI3', 'Antibiotic Sensitivity'); --- @SkipOnEmptySchemasEnd diff --git a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.09-0.10.sql b/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.09-0.10.sql deleted file mode 100644 index 68ee7cea9..000000000 --- a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.09-0.10.sql +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -ALTER TABLE mergesync.mergetolkmapping ADD deletedate TIMESTAMP; diff --git a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.10-0.11.sql b/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.10-0.11.sql deleted file mode 100644 index ed58c4cc2..000000000 --- a/mergesync/resources/schemas/dbscripts/postgresql/mergesync-0.10-0.11.sql +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -ALTER TABLE mergesync.mergetolkmapping DROP COLUMN deletedate; -ALTER TABLE mergesync.orderssynced ADD deletedate TIMESTAMP; diff --git a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.00-0.01.sql b/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.00-0.01.sql deleted file mode 100644 index 5b0814dbb..000000000 --- a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.00-0.01.sql +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - --- Create schema, tables, indexes, and constraints used for MergeSync module here --- All SQL VIEW definitions should be created in mergesync-create.sql and dropped in mergesync-drop.sql -CREATE SCHEMA mergesync; -GO - -CREATE TABLE mergesync.testnamemapping ( - rowid int identity(1,1), - servicename varchar(100), - mergetestname varchar(100) -); - -CREATE TABLE mergesync.orderssynced ( - rowid int identity(1,1), - objectid varchar(100), - merge_accession varchar(100), - container entityid, - created DATETIME, - createdby int, - resultsreceived bit -); - -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Albumin', 'ALB'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Amylase', 'AMYL'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Anaerobic Culture', 'ANCULT'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Antibiotic Sensitivity', 'SENSI'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('BAL Fluid Analysis with Cytology', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('BASIC Chemistry Panel in-house', 'BASIC'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Bile Acids Post-prarandial', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Bile Acids Pre-prarandial', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('C-Reactive Protein', 'CRP'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('CBC only, no differential', 'CBC'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('CBC with automated differential', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('CBC with manual differential', 'DIFF'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Chemistry panel with high density lipoprotein send out', 'CMPHDL'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Clotting panel', 'CLOTPL'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Comprehensive Chemistry panel in-house', 'COMP'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Comprehensive Chemistry Panel Send Out', 'CMP'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Compromised SPF Surveillance', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('CSF analysis (WBC count & differential)', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('CSF Glucose', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('CSF Total Protein', 'CSF'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Cytology Send out', 'CYTO'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Dermatophyte test medium culture', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('ESPF Surveillance - Monthly', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('ESPF Surveillance - Quarterly', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Exam for Yeast', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Fecal culture', 'F_CULT'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Fecal parasite exam', 'F_PARA'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Filovirus', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Fungus Culture', 'FUNGAL'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('General culture', 'G-CULT'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Glycosolated hemoglobin (HGBA1C)', 'HGBA1C'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Gram Stain', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('HDL', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Herpes B', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Herpes B Post-Exposure Baseline Serology', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Herpes B Post-Exposure Baseline Virology', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Herpes B Post-Exposure Follow-Up Serology', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Herpes B Status Confirmation', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('High-density lipoprotein & Low-density lipoprotein (HDL & LDL)', 'HDLLDL'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Intuitive Basic Array', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Intuitive Expanded Array', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Japanese Macaque Surveillance', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('LDL', 'LDL'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Lipase', 'Lipase'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Lipid panel in-house: Cholesterol, Triglyceride, HDL, LDL', 'LIPID'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Malaria Screen', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Miscellaneous in-house', 'MISIN'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Miscellaneous send out', 'MISOUT'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Occult Blood', 'OCCBLD'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Other Clinpath', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Other SPF Surveillance', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL ABSCN-5', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL ABSCN-8', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL PCR', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL SIV WB', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL SRV1 WB', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL SRV2 WB', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL SRV5 WB', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('PDL STLV WB', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Phenobarbital', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Primagam for TB', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Protein Electrophoresis-Total Protein', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('RBC Morphology', 'MORPH'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Reticulocyte count', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Specific Gravity', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('SPF Surveillance - Annual', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('SRV', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('SRV Virus Isolation', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Terminal Serum Surveillance', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Thyroid Panel', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Urinalysis', 'URINE'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Vitamin D (1,25 Dihydroxy)', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Vitamin D (250H)', 'VITD'); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('WBC differential', null); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname) VALUES ('Yersinia culture', 'YERSNA'); diff --git a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.01-0.02.sql b/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.01-0.02.sql deleted file mode 100644 index 178373298..000000000 --- a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.01-0.02.sql +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -ALTER TABLE mergesync.orderssynced DROP COLUMN merge_accession; -GO -ALTER TABLE mergesync.orderssynced ADD order_accession integer; -ALTER TABLE mergesync.orderssynced ADD test_accession integer; -ALTER TABLE mergesync.orderssynced ADD taskid entityid; \ No newline at end of file diff --git a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.02-0.03.sql b/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.02-0.03.sql deleted file mode 100644 index d68cddb8c..000000000 --- a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.02-0.03.sql +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -ALTER TABLE mergesync.orderssynced DROP COLUMN rowid; -ALTER TABLE mergesync.orderssynced ADD runid entityid; -ALTER TABLE mergesync.orderssynced ADD merge_datecreated DATETIME; -ALTER TABLE mergesync.orderssynced ADD merge_dateposted DATETIME; -ALTER TABLE mergesync.orderssynced ALTER COLUMN objectid entityid not null; -GO -ALTER TABLE mergesync.orderssynced ADD CONSTRAINT PK_orderssynced PRIMARY KEY (objectid); \ No newline at end of file diff --git a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.03-0.04.sql b/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.03-0.04.sql deleted file mode 100644 index b85a2328c..000000000 --- a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.03-0.04.sql +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -ALTER TABLE mergesync.orderssynced ADD requestid entityid; \ No newline at end of file diff --git a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.04-0.05.sql b/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.04-0.05.sql deleted file mode 100644 index e38a84398..000000000 --- a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.04-0.05.sql +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -CREATE TABLE mergesync.mergetolkmapping ( - mergetestname varchar(100), - servicename varchar(100), - automaticresults bit default 0, - - CONSTRAINT PK_mergetolkmapping PRIMARY KEY (mergetestname) -); - - -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('ALB', 'Albumin', 1); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('AMYL', 'Amylase', 1); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('ANCULT', 'Anaerobic Culture', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('BASIC', 'BASIC Chemistry Panel in-house', 1); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CBC', 'CBC with automated differential', 1); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CBCMIN', 'CBC only, no differential', 1); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CLOTPL', 'Clotting panel', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CMP', 'Comprehensive Chemistry Panel Send Out', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CMPHDL', 'Chemistry panel with high density lipoprotein send out', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('COMP', 'Comprehensive Chemistry panel in-house', 1); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CRP', 'C-Reactive Protein', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CSFCC', 'CSF analysis (WBC count & differential)', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CSFPRO', 'CSF Total Protein', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CSFTP', 'Cerebral Spinal Fluid Total Protein – Send out', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CSFWBC', 'Cerebral Spinal Fluid white blood count with differential', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('CYTO', 'BAL Fluid Analysis with Cytology', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('DIFF', 'CBC with manual differential', 0); ---INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('DIFF', 'WBC differential', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('DTMFUN', 'Dermatophyte test medium culture', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('F_CULT', 'Fecal culture', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('F_PARA', 'Fecal parasite exam', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('FUNGAL', 'Fungus Culture', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('GCULT1', 'General culture', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('GCULT2', 'General culture', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('GCULT3', 'General culture', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('HDLLDL', 'High-density lipoprotein & Low-density lipoprotein (HDL & LDL)', 1); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('HGBA1C', 'Glycosolated hemoglobin (HGBA1C)', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('LDL', 'LDL', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('LIPID', 'Lipid panel in-house: Cholesterol, Triglyceride, HDL, LDL', 1); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('MALA', 'Malaria Screen', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('MIS IN', 'Miscellaneous in-house', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('MISOUT', 'Bile Acids Post-prarandial', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('OCCBLD', 'Occult Blood', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('RETIC', 'Reticulocyte count', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('SENS2', 'Antibiotic Sensitivity', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('SENS3', 'Antibiotic Sensitivity', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('SENSI', 'Antibiotic Sensitivity', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('URINE', 'Urinalysis', 0); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename, automaticresults) VALUES ('YERSNA', 'Yersinia culture', 0); diff --git a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.05-0.06.sql b/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.05-0.06.sql deleted file mode 100644 index 9e1c8176c..000000000 --- a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.05-0.06.sql +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -TRUNCATE TABLE mergesync.testnamemapping; -ALTER TABLE mergesync.testnamemapping DROP COLUMN rowid; -ALTER TABLE mergesync.testnamemapping ALTER COLUMN servicename varchar(100) NOT NULL; -GO -ALTER TABLE mergesync.testnamemapping ADD CONSTRAINT PK_testnamemapping PRIMARY KEY (servicename); -GO -ALTER TABLE mergesync.testnamemapping ADD automaticresults bit default 0; -GO - -DROP TABLE mergesync.mergetolkmapping; -GO -CREATE TABLE mergesync.mergetolkmapping ( - mergetestname varchar(100) NOT NULL, - servicename varchar(100), - - CONSTRAINT PK_mergetolkmapping PRIMARY KEY (mergetestname) -); - -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Albumin', 'ALB', 1); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Amylase', 'AMYL', 1); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Anaerobic Culture', 'ANCULT', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('BASIC Chemistry Panel in-house', 'BASIC', 1); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('CBC with automated differential', 'CBC', 1); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Clotting panel', 'CLOTPL', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Comprehensive Chemistry Panel Send Out', 'CMP', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Chemistry panel with high density lipoprotein send out', 'CMPHDL', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Comprehensive Chemistry panel in-house', 'COMP', 1); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('C-Reactive Protein', 'CRP', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('CSF analysis (WBC count & differential)', 'CSFCC', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('CSF Total Protein', 'CSFPRO', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Cerebral Spinal Fluid Total Protein – Send out', 'CSFTP', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Cerebral Spinal Fluid white blood count with differential', 'CSFWBC', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('BAL Fluid Analysis with Cytology', 'CYTO', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Cytology Send out', 'CYTO', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('CBC with manual differential', 'DIFF', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('WBC differential', 'DIFF', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Dermatophyte test medium culture', 'DTMFUN', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Fecal culture', 'F_CULT', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Fecal parasite exam', 'F_PARA', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Fungus Culture', 'FUNGAL', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('General culture', 'GCULT1', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('High-density lipoprotein & Low-density lipoprotein (HDL & LDL)', 'HDLLDL', 1); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Glycosolated hemoglobin (HGBA1C)', 'HGBA1C', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('LDL', 'LDL', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Lipid panel in-house: Cholesterol, Triglyceride, HDL, LDL', 'LIPID', 1); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Malaria Screen', 'MALA', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Miscellaneous in-house', 'MIS IN', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Bile Acids Post-prarandial', 'MISOUT', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Bile Acids Pre-prarandial', 'MISOUT', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Calcium, ionized', 'MISOUT', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Calcium, total', 'MISOUT', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('CSF Glucose', 'MISOUT', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Lipase', 'MISOUT', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Miscellaneous send out', 'MISOUT', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Phenobarbital', 'MISOUT', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Protein Electrophoresis-Total Protein', 'MISOUT', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Thyroid Panel', 'MISOUT', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Vitamin D (1,25 Dihydroxy)', 'MISOUT', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Vitamin D (250H)', 'MISOUT', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('RBC Morphology', 'MORPH', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Occult Blood', 'OCCBLD', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Reticulocyte count', 'RETIC', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Antibiotic Sensitivity', 'SENSI', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Urinalysis', 'URINE', 0); -INSERT INTO mergesync.testnamemapping (servicename, mergetestname, automaticresults) VALUES ('Yersinia culture', 'YERSNA', 0); - -TRUNCATE TABLE mergesync.mergetolkmapping; -TRUNCATE TABLE mergesync.mergetolkmapping; -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('ALB', 'Albumin'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('AMYL', 'Amylase'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('ANCULT', 'Anaerobic Culture'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('BASIC', 'BASIC Chemistry Panel in-house'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CBC', 'CBC with automated differential'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CLOTPL', 'Clotting panel'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CMP', 'Comprehensive Chemistry Panel Send Out'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CMPHDL', 'Chemistry panel with high density lipoprotein send out'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('COMP', 'Comprehensive Chemistry panel in-house'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CRP', 'C-Reactive Protein'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CSFCC', 'CSF analysis (WBC count & differential)'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CSFPRO', 'CSF Total Protein'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CSFTP', 'Cerebral Spinal Fluid Total Protein – Send out'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CSFWBC', 'Cerebral Spinal Fluid white blood count with differential'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CYTO', 'BAL Fluid Analysis with Cytology'); ---INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('CYTO', 'Cytology Send out'); ---INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('DIFF', 'CBC with manual differential'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('DIFF', 'WBC differential'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('DTMFUN', 'Dermatophyte test medium culture'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('F_CULT', 'Fecal culture'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('F_PARA', 'Fecal parasite exam'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('FUNGAL', 'Fungus Culture'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('GCULT1', 'General culture'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('GCULT2', 'General culture'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('GCULT3', 'General culture'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('HDLLDL', 'High-density lipoprotein & Low-density lipoprotein (HDL & LDL)'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('HGBA1C', 'Glycosolated hemoglobin (HGBA1C)'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('LDL', 'LDL'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('LIPID', 'Lipid panel in-house: Cholesterol, Triglyceride, HDL, LDL'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('MALA', 'Malaria Screen'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('MIS IN', 'Miscellaneous in-house'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('MISOUT', 'Miscellaneous send out'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('MORPH', 'RBC Morphology'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('OCCBLD', 'Occult Blood'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('RETIC', 'Reticulocyte count'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('SENS2', 'Antibiotic Sensitivity'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('SENS3', 'Antibiotic Sensitivity'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('SENSI', 'Antibiotic Sensitivity'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('URINE', 'Urinalysis'); -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('YERSNA', 'Yersinia culture'); diff --git a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.06-0.07.sql b/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.06-0.07.sql deleted file mode 100644 index 9817c8a4d..000000000 --- a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.06-0.07.sql +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -UPDATE mergesync.testnamemapping SET automaticresults = 1 WHERE servicename = 'WBC differential'; -UPDATE mergesync.testnamemapping SET automaticresults = 1 WHERE servicename = 'RBC Morphology'; -UPDATE mergesync.testnamemapping SET automaticresults = 1 WHERE servicename = 'Reticulocyte count'; diff --git a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.07-0.08.sql b/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.07-0.08.sql deleted file mode 100644 index c02ce88ce..000000000 --- a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.07-0.08.sql +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -DELETE FROM mergesync.testnamemapping WHERE servicename = 'CBC with manual differential'; \ No newline at end of file diff --git a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.08-0.09.sql b/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.08-0.09.sql deleted file mode 100644 index 228cfa7a0..000000000 --- a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.08-0.09.sql +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -DELETE FROM mergesync.mergetolkmapping WHERE mergetestname = 'SENSI2'; -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('SENSI2', 'Antibiotic Sensitivity'); - -DELETE FROM mergesync.mergetolkmapping WHERE mergetestname = 'SENSI3'; -INSERT INTO mergesync.mergetolkmapping (mergetestname, servicename) VALUES ('SENSI3', 'Antibiotic Sensitivity'); \ No newline at end of file diff --git a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.09-0.10.sql b/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.09-0.10.sql deleted file mode 100644 index aa82e80f0..000000000 --- a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.09-0.10.sql +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -ALTER TABLE mergesync.mergetolkmapping ADD deletedate DATETIME; diff --git a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.10-0.11.sql b/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.10-0.11.sql deleted file mode 100644 index 8f1e07ad9..000000000 --- a/mergesync/resources/schemas/dbscripts/sqlserver/mergesync-0.10-0.11.sql +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2011 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -ALTER TABLE mergesync.mergetolkmapping DROP COLUMN deletedate; -ALTER TABLE mergesync.orderssynced ADD deletedate DATETIME; diff --git a/mergesync/resources/schemas/mergesync.xml b/mergesync/resources/schemas/mergesync.xml deleted file mode 100644 index 117971909..000000000 --- a/mergesync/resources/schemas/mergesync.xml +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - LabKey to Merge Service/Panel Name Mapping - - - Service Name - true - - - Merge Test Name - - - Expect Results From Merge? - - -
- - - Merge to LabKey Service/Panel Name Mapping - - - Merge Test Name - - - Service Name - - -
- - - Orders Synced To/From Merge - - - Clinpath Runs Record - - - Request Id - - - Task Id - - - Key - - - Merge Order Accession # - - - Merge Test Accession # - - - Merge Date Created - - - Merge Date Posted - - - Date Deleted In LabKey - - - Folder - - - - - - - - - Results Received? - - -
-
\ No newline at end of file diff --git a/mergesync/resources/scripts/mergesync/mergesync.js b/mergesync/resources/scripts/mergesync/mergesync.js deleted file mode 100644 index 1b7fe4d1a..000000000 --- a/mergesync/resources/scripts/mergesync/mergesync.js +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2012 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0 - */ -var console = require("console"); -var LABKEY = require("labkey"); - -exports.init = function(EHR){ - EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.COMPLETE, 'study', 'clinpathruns', function(event, errors, helper){ - var rows = helper.getRows(); - if (helper.getEvent() == 'insert' && rows.length && !helper.isValidateOnly()){ - var toSync = []; - for (var i=0;i - -Ext4.onReady(function (){ - - if (LABKEY.Security.currentUser.isAdmin){ - var webpart = <%=webpartContext%>; - - Ext4.define('ETLPanel', { - extend: 'Ext.form.Panel', - initComponent: function(){ - Ext4.apply(this, { - border: false, - items: [{ - html: 'Loading...' - }], - buttons: [{ - text: 'Submit', - handler: this.onSubmit - },{ - text: 'Pull From Merge Now', - itemId: 'runEtlBtn', - disabled: true, - handler: function(btn){ - LABKEY.Ajax.request({ - url: LABKEY.ActionURL.buildURL('mergeSync', 'pullFromMerge', null), - method : 'POST', - scope: this, - failure: LDK.Utils.getErrorCallback({ - showAlertOnError: true - }) - }); - Ext4.Msg.alert('Request Sent', 'A request has been sent to pull data from merge'); - } - }] - }); - - this.loadData(); - this.callParent(); - }, - - loadData: function(){ - LABKEY.Ajax.request({ - url: LABKEY.ActionURL.buildURL('mergeSync', 'getEtlDetails', null), - method : 'GET', - scope: this, - failure: LDK.Utils.getErrorCallback(), - success: this.onLoad - }); - }, - - onLoad: function(results){ - var json = LDK.Utils.decodeHttpResponseJson(results); - var labelWidth = 180; - var width = 550; - - var toAdd = []; - toAdd.push({ - xtype: 'checkbox', - fieldLabel: 'Pull Enabled', - labelWidth: labelWidth, - width: width, - itemId: 'pullEnabled', - checked: json.pullEnabled - }); - - toAdd.push({ - xtype: 'checkbox', - fieldLabel: 'Push Enabled', - labelWidth: labelWidth, - width: width, - itemId: 'pushEnabled', - checked: json.pushEnabled - }); - - toAdd.push({ - xtype: 'checkbox', - fieldLabel: 'Sync Animals and Projects', - labelWidth: labelWidth, - width: width, - itemId: 'syncAnimalsAndProjects', - checked: json.syncAnimalsAndProjects - }); - - toAdd.push({ - xtype: 'datefield', - fieldLabel: 'Min Date', - labelWidth: labelWidth, - width: width, - itemId: 'lastRun', - //format: 'Y-m-d h:i', - value: LDK.ConvertUtils.parseDate(json.lastRun) - }); - - toAdd.push({ - xtype: 'displayfield', - fieldLabel: 'Next Run', - labelWidth: labelWidth, - width: width, - value: json.nextRun - }); - - if (json.pullEnabled) - this.down('#runEtlBtn').setDisabled(false); - - Ext4.each(json.configKeys, function(key){ - toAdd.push({ - xtype: 'textfield', - labelWidth: labelWidth, - width: width, - itemId: key, - fieldLabel: key, - value: json.config[key] - }); - }, this); - - this.removeAll(); - this.add({ - title: 'ETL Settings', - xtype: 'form', - itemId: 'etlSettings', - bodyStyle: 'padding: 5px;', - items: toAdd - }); - }, - - onSubmit: function(btn){ - var form = btn.up('form'); - var settings = form.down('#etlSettings'); - var fields = settings.getForm().getFields(); - - var json = {}; - - fields.each(function(field){ - if (field.itemId) - json[field.itemId] = field.getValue(); - }, this); - - Ext4.Msg.wait('Saving...'); - LABKEY.Ajax.request({ - url: LABKEY.ActionURL.buildURL('mergeSync', 'setEtlDetails', null), - method : 'POST', - params: json, - scope: this, - failure: LDK.Utils.getErrorCallback(), - success: function(response){ - Ext4.Msg.hide(); - Ext4.Msg.alert('Success', 'Save Successful', function(){ - window.location.reload(); - }); - } - }); - } - }); - - Ext4.create('ETLPanel', {}).render('etl_div'); - } -}); - - - - -This page allows configuration of the Merge Sync. Below are explanations for the config properties: -

- - -

- Click here to view more detailed documentation on the Merge Sync process -

-
\ No newline at end of file diff --git a/mergesync/resources/views/begin.view.xml b/mergesync/resources/views/begin.view.xml deleted file mode 100644 index 60651d881..000000000 --- a/mergesync/resources/views/begin.view.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/mergesync/resources/views/instructions.html b/mergesync/resources/views/instructions.html deleted file mode 100644 index 256da47a4..000000000 --- a/mergesync/resources/views/instructions.html +++ /dev/null @@ -1,63 +0,0 @@ - diff --git a/mergesync/resources/views/instructions.view.xml b/mergesync/resources/views/instructions.view.xml deleted file mode 100644 index 8b9f5cc95..000000000 --- a/mergesync/resources/views/instructions.view.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/mergesync/resources/web/mergesync/mergeButtons.js b/mergesync/resources/web/mergesync/mergeButtons.js deleted file mode 100644 index f4e437638..000000000 --- a/mergesync/resources/web/mergesync/mergeButtons.js +++ /dev/null @@ -1,26 +0,0 @@ -Ext4.ns('MergeSync.buttons'); - -MergeSync.buttons = new function(){ - return { - resyncSelected: function(dataRegionName){ - var dataRegion = LABKEY.DataRegions[dataRegionName]; - var checked = dataRegion.getChecked(); - if (!checked || !checked.length){ - alert('No records selected'); - return; - } - - Ext4.Msg.wait('Loading...'); - LABKEY.Ajax.request({ - url: LABKEY.ActionURL.buildURL('mergesync', 'resyncRuns', null, {pks: checked}), - method: 'POST', - scope: this, - failure: LDK.Utils.getErrorCallback(), - success: function(){ - Ext4.Msg.hide(); - Ext4.Msg.alert('Success', 'Runs have been resynced'); - } - }); - } - } -}; \ No newline at end of file diff --git a/mergesync/src/org/labkey/mergesync/MergeSyncController.java b/mergesync/src/org/labkey/mergesync/MergeSyncController.java deleted file mode 100644 index 1709076bf..000000000 --- a/mergesync/src/org/labkey/mergesync/MergeSyncController.java +++ /dev/null @@ -1,350 +0,0 @@ -/* - * Copyright (c) 2013 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.labkey.mergesync; - -import org.apache.commons.beanutils.ConversionException; -import org.labkey.api.action.ApiResponse; -import org.labkey.api.action.ApiSimpleResponse; -import org.labkey.api.action.MutatingApiAction; -import org.labkey.api.action.ReadOnlyApiAction; -import org.labkey.api.action.SpringActionController; -import org.labkey.api.data.ContainerManager; -import org.labkey.api.data.ConvertHelper; -import org.labkey.api.data.PropertyManager; -import org.labkey.api.data.PropertyManager.WritablePropertyMap; -import org.labkey.api.security.RequiresPermission; -import org.labkey.api.security.ValidEmail; -import org.labkey.api.security.permissions.AdminPermission; -import org.labkey.api.util.JobRunner; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; - -import java.sql.SQLException; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -public class MergeSyncController extends SpringActionController -{ - private static final DefaultActionResolver _actionResolver = new DefaultActionResolver(MergeSyncController.class); - public static final String NAME = "mergesync"; - - public MergeSyncController() - { - setActionResolver(_actionResolver); - } - - @RequiresPermission(AdminPermission.class) - public static class SetEtlDetailsAction extends MutatingApiAction - { - @Override - public ApiResponse execute(EtlAdminForm form, BindException errors) - { - Map resultProperties = new HashMap<>(); - - WritablePropertyMap configMap = PropertyManager.getWritableProperties(MergeSyncManager.CONFIG_PROPERTY_DOMAIN, true); - - configMap.put(MergeSyncManager.DATA_SOURCE_PROP_NAME, form.getDataSourceName()); - configMap.put(MergeSyncManager.SCHEMA_PROP_NAME, form.getSchemaName()); - configMap.put(MergeSyncManager.MERGE_USER_PROP_NAME, form.getMergeUserName()); - if (form.getLastRun() != null) - { - try - { - Date lastRun = ConvertHelper.convert(form.getLastRun(), Date.class); - - configMap.put(MergeSyncManager.LAST_RUN_PROP_NAME, ((Long)lastRun.getTime()).toString()); - } - catch (ConversionException e) - { - errors.reject(ERROR_MSG, e.getMessage()); - return null; - } - } - configMap.put(MergeSyncManager.SYNC_INTERVAL_PROP_NAME, form.getSyncInterval() == null ? null : form.getSyncInterval().toString()); - - if (form.getLabkeyUser() != null) - { - try - { - new ValidEmail(form.getLabkeyUser()); - } - catch (ValidEmail.InvalidEmailException e) - { - errors.reject(ERROR_MSG, "Invalid email: " + e.getMessage()); - return null; - } - - configMap.put(MergeSyncManager.LABKEY_USER_PROP_NAME, form.getLabkeyUser()); - } - - if (form.getLabkeyContainer() != null) - { - if (ContainerManager.getForPath(form.getLabkeyContainer()) == null) - { - errors.reject(ERROR_MSG, "Invalid container: " + form.getLabkeyContainer()); - return null; - } - - configMap.put(MergeSyncManager.LABKEY_CONTAINER_PROP_NAME, form.getLabkeyContainer()); - } - - if (form.getPullEnabled() != null) - configMap.put(MergeSyncManager.PULL_ENABLED_PROP_NAME, form.getPullEnabled().toString()); - - if (form.getPushEnabled() != null) - configMap.put(MergeSyncManager.PUSH_ENABLED_PROP_NAME, form.getPushEnabled().toString()); - - if (form.getSyncAnimalsAndProjects() != null) - configMap.put(MergeSyncManager.SYNC_ANIMALS_PROP_NAME, form.getSyncAnimalsAndProjects().toString()); - - configMap.save(); - - //if config was changed and the ETL is current scheduled to run, we need to restart it - MergeSyncManager.get().onSettingsChange(); - - resultProperties.put("success", true); - - return new ApiSimpleResponse(resultProperties); - } - } - - public static class EtlAdminForm - { - private Boolean _pullEnabled; - private Boolean _pushEnabled; - private Boolean _syncAnimalsAndProjects; - private String _dataSourceName; - private String _schemaName; - private String _labkeyUser; - private String _lastRun; - private String _labkeyContainer; - private Integer _syncInterval; - private String _mergeUserName; - - public String getDataSourceName() - { - return _dataSourceName; - } - - public void setDataSourceName(String dataSourceName) - { - _dataSourceName = dataSourceName; - } - - public String getSchemaName() - { - return _schemaName; - } - - public void setSchemaName(String schemaName) - { - _schemaName = schemaName; - } - - public Boolean getPullEnabled() - { - return _pullEnabled; - } - - public void setPullEnabled(Boolean pullEnabled) - { - _pullEnabled = pullEnabled; - } - - public Boolean getPushEnabled() - { - return _pushEnabled; - } - - public void setPushEnabled(Boolean pushEnabled) - { - _pushEnabled = pushEnabled; - } - - public Boolean getSyncAnimalsAndProjects() - { - return _syncAnimalsAndProjects; - } - - public void setSyncAnimalsAndProjects(Boolean syncAnimalsAndProjects) - { - _syncAnimalsAndProjects = syncAnimalsAndProjects; - } - - public String getLabkeyUser() - { - return _labkeyUser; - } - - public void setLabkeyUser(String labkeyUser) - { - _labkeyUser = labkeyUser; - } - - public String getLabkeyContainer() - { - return _labkeyContainer; - } - - public void setLabkeyContainer(String labkeyContainer) - { - _labkeyContainer = labkeyContainer; - } - - public Integer getSyncInterval() - { - return _syncInterval; - } - - public void setSyncInterval(Integer syncInterval) - { - _syncInterval = syncInterval; - } - - public String getLastRun() - { - return _lastRun; - } - - public void setLastRun(String lastRun) - { - _lastRun = lastRun; - } - - public String getMergeUserName() - { - return _mergeUserName; - } - - public void setMergeUserName(String mergeUserName) - { - _mergeUserName = mergeUserName; - } - } - - @RequiresPermission(AdminPermission.class) - public static class GetEtlDetailsAction extends ReadOnlyApiAction - { - @Override - public ApiResponse execute(Object form, BindException errors) - { - Map resultProperties = new HashMap<>(); - resultProperties.put("pullEnabled", MergeSyncManager.get().isPullEnabled()); - resultProperties.put("pushEnabled", MergeSyncManager.get().isPushEnabled()); - resultProperties.put("lastRun", MergeSyncManager.get().getLastRun()); - resultProperties.put("nextRun", MergeSyncManager.get().getNextRun()); - resultProperties.put("syncAnimalsAndProjects", MergeSyncManager.get().doSyncAnimalsAndProjects()); - - String[] etlConfigKeys = {MergeSyncManager.DATA_SOURCE_PROP_NAME, MergeSyncManager.SCHEMA_PROP_NAME, MergeSyncManager.LABKEY_CONTAINER_PROP_NAME, MergeSyncManager.LABKEY_USER_PROP_NAME, MergeSyncManager.SYNC_INTERVAL_PROP_NAME, MergeSyncManager.MERGE_USER_PROP_NAME}; - - resultProperties.put("configKeys", etlConfigKeys); - resultProperties.put("config", PropertyManager.getProperties(MergeSyncManager.CONFIG_PROPERTY_DOMAIN)); - - return new ApiSimpleResponse(resultProperties); - } - } - - @RequiresPermission(AdminPermission.class) - public static class PullFromMergeAction extends MutatingApiAction - { - @Override - public ApiResponse execute(Object form, BindException errors) - { - try - { - JobRunner.getDefault().execute(() -> new MergeSyncRunner().pullResultsFromMerge()); - } - catch (Exception e) - { - errors.reject(ERROR_MSG, e.getMessage()); - return null; - } - - return new ApiSimpleResponse("success", true); - } - - @Override - public void validateForm(Object form, Errors errors) - { - try - { - MergeSyncManager.get().validateSettings(); - } - catch (Exception e) - { - errors.reject(ERROR_MSG, e.getMessage()); - } - } - } - - @RequiresPermission(AdminPermission.class) - public static class ResyncRunsAction extends MutatingApiAction - { - @Override - public ApiResponse execute(ResyncRunsForm form, BindException errors) - { - if (form.getPks() == null || form.getPks().length == 0) - { - errors.reject(ERROR_MSG, "Must supply a list of PKs to sync"); - return null; - } - - MergeSyncRunner runner = new MergeSyncRunner(); - try - { - for (String pk : form.getPks()) - { - String[] tokens = pk.split("<>"); - if (tokens.length != 2 || tokens[0] == null || tokens[1] == null) - { - errors.reject(ERROR_MSG, "Invalid PK: " + pk); - return null; - } - else - { - Integer accession = Integer.parseInt(tokens[0]); - Integer testId = Integer.parseInt(tokens[1]); - runner.syncSingleRun(getContainer(), getUser(), accession, testId); - } - } - } - catch (SQLException | RuntimeException e) - { - errors.reject(ERROR_MSG, e.getMessage()); - return null; - } - - return new ApiSimpleResponse("success", true); - } - } - - public static class ResyncRunsForm - { - private String[] _pks; - - public String[] getPks() - { - return _pks; - } - - public void setPks(String[] pks) - { - _pks = pks; - } - } -} \ No newline at end of file diff --git a/mergesync/src/org/labkey/mergesync/MergeSyncManager.java b/mergesync/src/org/labkey/mergesync/MergeSyncManager.java deleted file mode 100644 index 7c2ddfdec..000000000 --- a/mergesync/src/org/labkey/mergesync/MergeSyncManager.java +++ /dev/null @@ -1,393 +0,0 @@ -/* - * Copyright (c) 2013 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.labkey.mergesync; - -import org.apache.commons.lang3.time.DateUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.labkey.api.data.Container; -import org.labkey.api.data.ContainerManager; -import org.labkey.api.data.DbSchema; -import org.labkey.api.data.DbSchemaType; -import org.labkey.api.data.DbScope; -import org.labkey.api.data.PropertyManager; -import org.labkey.api.data.PropertyManager.WritablePropertyMap; -import org.labkey.api.security.User; -import org.labkey.api.security.UserManager; -import org.labkey.api.security.ValidEmail; -import org.labkey.api.util.JobRunner; -import org.quartz.JobBuilder; -import org.quartz.JobDetail; -import org.quartz.SimpleScheduleBuilder; -import org.quartz.Trigger; -import org.quartz.TriggerBuilder; -import org.quartz.impl.StdSchedulerFactory; - -import java.util.Calendar; -import java.util.Date; - -public class MergeSyncManager -{ - private static final MergeSyncManager _instance = new MergeSyncManager(); - private JobDetail _job = null; - private Trigger _trigger = null; - - public static final String TABLE_TESTNAMEMAPPING = "testnamemapping"; - public static final String TABLE_MERGE_TO_LK_MAPPING = "mergetolkmapping"; - public static final String TABLE_ORDERSSYNCED = "orderssynced"; - - public static final String TABLE_MERGE_ORDERS = "orders"; - public static final String TABLE_MERGE_RESULTS = "results"; - public static final String TABLE_MERGE_TEST = "tests"; - public static final String TABLE_MERGE_TESTINFO = "testinfo"; - public static final String TABLE_MERGE_CONTAINERS = "containers"; - public static final String TABLE_MERGE_VISITS = "visits"; - public static final String TABLE_MERGE_COPY_TO = "copyto"; - public static final String TABLE_MERGE_VISIT_INS = "vis_ins"; - public static final String TABLE_MERGE_INSURANCE = "insurance"; - public static final String TABLE_MERGE_PERSONNEL = "prsnl"; - public static final String TABLE_MERGE_PATIENTS = "patients"; - - private MergeSyncManager() - { - - } - - public static MergeSyncManager get() - { - return _instance; - } - - private static final Logger _log = LogManager.getLogger(MergeSyncManager.class); - private Integer _syncInterval; - - public static final String DATA_SOURCE_PROP_NAME = "dataSourceName"; - public static final String SCHEMA_PROP_NAME = "schemaName"; - - public static final String LABKEY_USER_PROP_NAME = "labkeyUser"; - public static final String LABKEY_CONTAINER_PROP_NAME = "labkeyContainer"; - public static final String SYNC_INTERVAL_PROP_NAME = "syncInterval"; - - public static final String PULL_ENABLED_PROP_NAME = "pullEnabled"; - public static final String PUSH_ENABLED_PROP_NAME = "pushEnabled"; - public static final String SYNC_ANIMALS_PROP_NAME = "syncAnimalsAndProjects"; - public static final String LAST_RUN_PROP_NAME = "lastRun"; - public static final String MERGE_USER_PROP_NAME = "mergeUserName"; - - public static final String CONFIG_PROPERTY_DOMAIN = "org.labkey.mergesync.etl.config"; - - public synchronized void schedule() - { - if (!isEnabled()) - return; - - try - { - validateSettings(); - _syncInterval = getSyncInterval(); - - if (_syncInterval <= 0) - { - _log.error("Merge sync has an invalid frequency, will not schedule: " + _syncInterval); - return; - } - - if (_job == null) - { - _job = JobBuilder.newJob(MergeSyncRunner.class) - .withIdentity(MergeSyncRunner.class.getCanonicalName(), MergeSyncRunner.class.getCanonicalName()) - .usingJobData("mergeSync", MergeSyncRunner.class.getName()) - .build(); - } - - _trigger = TriggerBuilder.newTrigger() - .withIdentity(MergeSyncRunner.class.getCanonicalName(), MergeSyncRunner.class.getCanonicalName()) - .withSchedule(SimpleScheduleBuilder.repeatMinutelyForever(_syncInterval)) - .forJob(_job) - .build(); - - StdSchedulerFactory.getDefaultScheduler().scheduleJob(_job, _trigger); - - _log.info("Merge sync scheduled to run every " + getSyncInterval() + " minutes"); - } - catch (IllegalArgumentException e) - { - _log.error("Merge sync is enabled, but the saved setting are invalid. Sync will not start.", e); - return; - } - catch (Exception e) - { - _log.error("Error scheduling Merge sync", e); - } - } - - public synchronized void unschedule() - { - if (_job != null) - { - try - { - StdSchedulerFactory.getDefaultScheduler().deleteJob(_job.getKey()); - _trigger = null; - _log.info("Merge sync unscheduled"); - } - catch (Exception e) - { - _log.error("Error unscheduling Merge sync", e); - } - } - } - - public void onSettingsChange() - { - if (!isEnabled()) - { - if (_job != null) - unschedule(); - } - else - { - try - { - validateSettings(); - - if (_job == null) - { - schedule(); - } - else - { - if (!_syncInterval.equals(getSyncInterval())) - { - _log.info("Rescheduling Merge Sync due to change in settings"); - unschedule(); - schedule(); - } - - //this indicates it is already scheduled with the correct frequency - } - } - catch (Exception e) - { - //ignore - } - } - } - - public Date getNextRun() - { - if (_trigger == null) - return null; - - return _trigger.getFireTimeAfter(new Date()); - } - - public Date getLastRun() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(LAST_RUN_PROP_NAME); - if (prop == null) - return null; - - Long value = Long.parseLong(prop); - if (value == null) - { - return null; - } - - return new Date(value); - } - - public void setLastRun(Date date) - { - WritablePropertyMap pm = PropertyManager.getWritableProperties(CONFIG_PROPERTY_DOMAIN, true); - date = DateUtils.truncate(date, Calendar.MINUTE); //always round to nearest minute - pm.put(LAST_RUN_PROP_NAME, String.valueOf(date.getTime())); - pm.save(); - } - - public void init() - { - if (isEnabled() && _trigger == null) - { - _log.info("scheduling Merge sync"); - JobRunner.getDefault().execute(new Runnable(){ - @Override - public void run() - { - schedule(); - } - }, 60000); - } - } - - public String getDataSourceName() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(DATA_SOURCE_PROP_NAME); - if (prop == null) - return null; - - return prop; - } - - public String getSchemaName() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(SCHEMA_PROP_NAME); - if (prop == null) - return null; - - return prop; - } - - public User getLabKeyUser() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(LABKEY_USER_PROP_NAME); - if (prop == null) - return null; - - try - { - ValidEmail email = new ValidEmail(prop); - return UserManager.getUser(email); - } - catch (ValidEmail.InvalidEmailException e) - { - _log.error("Invalid email saved for Merge Sync: " + e.getMessage()); - } - - return null; - } - - public Container getLabKeyContainer() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(LABKEY_CONTAINER_PROP_NAME); - if (prop == null) - return null; - - return ContainerManager.getForPath(prop); - } - - public int getSyncInterval() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(SYNC_INTERVAL_PROP_NAME); - if (prop == null) - return -1; - - Integer value = Integer.parseInt(prop); - if (value == null) - { - return -1; - } - - return value; - } - - public boolean isPullEnabled() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(PULL_ENABLED_PROP_NAME); - if (prop == null) - return false; - - Boolean value = Boolean.parseBoolean(prop); - if (value == null) - { - return false; - } - - return value; - } - - public boolean doSyncAnimalsAndProjects() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(SYNC_ANIMALS_PROP_NAME); - if (prop == null) - return false; - - Boolean value = Boolean.parseBoolean(prop); - if (value == null) - { - return false; - } - - return value; - } - - public boolean isPushEnabled() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(PUSH_ENABLED_PROP_NAME); - if (prop == null) - return false; - - Boolean value = Boolean.parseBoolean(prop); - if (value == null) - { - return false; - } - - return value; - } - - public String getMergeUserName() - { - return PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(MERGE_USER_PROP_NAME); - } - - private boolean isEnabled() - { - return isPullEnabled() || isPullEnabled(); - } - - public void validateSettings() throws IllegalArgumentException - { - if (isEnabled()) - { - if (getDataSourceName() == null) - throw new IllegalArgumentException("Must provide a data source name"); - - DbScope scope = DbScope.getDbScope(getDataSourceName()); - if (scope == null) - throw new IllegalArgumentException("Unknown data source: " + getDataSourceName()); - - DbSchema schema = scope.getSchema(getSchemaName(), DbSchemaType.Bare); - if (schema == null) - throw new IllegalArgumentException("Unknown schema: " + getSchemaName()); - } - - if (isPullEnabled()) - { - if (getLabKeyUser() == null) - throw new IllegalArgumentException("Unknown or invalid LabKey User"); - - if (PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(LABKEY_CONTAINER_PROP_NAME) == null) - throw new IllegalArgumentException("No LabKey container set"); - } - - if (isPushEnabled() || doSyncAnimalsAndProjects()) - { - if (getMergeUserName() == null) - throw new IllegalArgumentException("Must provide the name of the merge user to use for sync"); - } - } - - public DbSchema getMergeSchema() - { - DbScope scope = DbScope.getDbScope(MergeSyncManager.get().getDataSourceName()); - if (scope == null) - return null; - - return scope.getSchema(MergeSyncManager.get().getSchemaName(), DbSchemaType.Bare); - } -} \ No newline at end of file diff --git a/mergesync/src/org/labkey/mergesync/MergeSyncModule.java b/mergesync/src/org/labkey/mergesync/MergeSyncModule.java deleted file mode 100644 index 0b73faf24..000000000 --- a/mergesync/src/org/labkey/mergesync/MergeSyncModule.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2013 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.labkey.mergesync; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.labkey.api.data.Container; -import org.labkey.api.data.ContainerManager; -import org.labkey.api.ehr.EHRService; -import org.labkey.api.ldk.ExtendedSimpleModule; -import org.labkey.api.module.ModuleContext; -import org.labkey.api.query.DetailsURL; -import org.labkey.api.resource.Resource; -import org.labkey.api.security.permissions.AdminPermission; -import org.labkey.api.settings.AdminConsole; -import org.labkey.api.view.WebPartFactory; - -import java.util.Collection; -import java.util.Collections; -import java.util.Set; - -public class MergeSyncModule extends ExtendedSimpleModule -{ - public static final String NAME = "MergeSync"; - - @Override - public String getName() - { - return NAME; - } - - @Override - public @Nullable Double getSchemaVersion() - { - return 0.11; - } - - @Override - public boolean hasScripts() - { - return true; - } - - @NotNull - @Override - protected Collection createWebPartFactories() - { - return Collections.emptyList(); - } - - @Override - protected void init() - { - addController(MergeSyncController.NAME, MergeSyncController.class); - } - - @Override - protected void doStartupAfterSpringConfig(ModuleContext moduleContext) - { - Resource r = getModuleResource("/scripts/mergesync/mergesync.js"); - assert r != null; - EHRService.get().registerTriggerScript(this, r); - DetailsURL details = DetailsURL.fromString("/mergeSync-begin.view", ContainerManager.getSharedContainer()); - AdminConsole.addLink(AdminConsole.SettingsLinkType.Management, "merge sync admin", details.getActionURL(), AdminPermission.class); - - MergeSyncManager.get().init(); - - EHRService.get().registerTableCustomizer(this, MergeSyncTableCustomizer.class); - } - - @NotNull - @Override - public Collection getSummary(Container c) - { - return Collections.emptyList(); - } - - @Override - @NotNull - public Set getSchemaNames() - { - return Collections.singleton(MergeSyncSchema.NAME); - } - - @Override - protected void registerSchemas() - { - MergeSyncUserSchema.register(this); - } -} \ No newline at end of file diff --git a/mergesync/src/org/labkey/mergesync/MergeSyncRunner.java b/mergesync/src/org/labkey/mergesync/MergeSyncRunner.java deleted file mode 100644 index 4946d44c2..000000000 --- a/mergesync/src/org/labkey/mergesync/MergeSyncRunner.java +++ /dev/null @@ -1,1282 +0,0 @@ -package org.labkey.mergesync; - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateUtils; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.jetbrains.annotations.Nullable; -import org.labkey.api.cache.CacheManager; -import org.labkey.api.collections.CaseInsensitiveHashMap; -import org.labkey.api.data.ColumnInfo; -import org.labkey.api.data.CompareType; -import org.labkey.api.data.Container; -import org.labkey.api.data.ConvertHelper; -import org.labkey.api.data.DbSchema; -import org.labkey.api.data.DbSchemaType; -import org.labkey.api.data.DbScope; -import org.labkey.api.data.Results; -import org.labkey.api.data.ResultsImpl; -import org.labkey.api.data.SQLFragment; -import org.labkey.api.data.Selector; -import org.labkey.api.data.SimpleFilter; -import org.labkey.api.data.Sort; -import org.labkey.api.data.SqlExecutor; -import org.labkey.api.data.Table; -import org.labkey.api.data.TableInfo; -import org.labkey.api.data.TableSelector; -import org.labkey.api.ehr.EHRService; -import org.labkey.api.query.BatchValidationException; -import org.labkey.api.query.DuplicateKeyException; -import org.labkey.api.query.FieldKey; -import org.labkey.api.query.InvalidKeyException; -import org.labkey.api.query.QueryService; -import org.labkey.api.query.QueryUpdateServiceException; -import org.labkey.api.security.User; -import org.labkey.api.study.Dataset; -import org.labkey.api.study.StudyService; -import org.labkey.api.util.GUID; -import org.labkey.api.util.PageFlowUtil; -import org.labkey.api.view.ActionURL; -import org.labkey.api.view.ViewContext; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * User: bimber - * Date: 10/10/13 - * Time: 12:26 PM - */ -public class MergeSyncRunner implements Job -{ - private static final Logger _log = LogManager.getLogger(MergeSyncRunner.class); - protected final static SimpleDateFormat _dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd kk:mm"); - protected final static SimpleDateFormat _dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - private final Set EXCLUDED_RESULTS = PageFlowUtil.set("received", "recieved", ".", "SENT TO RHEIN CONSULTING LAB"); - - private final Map _cachedResultTables = new HashMap<>(); - private final Map _cachedProjectNames = new HashMap<>(); - private final Map _cachedTasks = new HashMap<>(); - private final Map> _cachedRuns = new HashMap<>(); - private final Map _cachedMethods = new HashMap<>(); - private final Map _cachedTissues = new HashMap<>(); - - public MergeSyncRunner() - { - - } - - /** - * pulls data from Merge back to EHR - */ - @Override - public void execute(JobExecutionContext context) throws JobExecutionException - { - if (!MergeSyncManager.get().isPullEnabled()) - return; - - pullResultsFromMerge(); - } - - /** - * When a request is sent to merge, a record is added to mergesync.orderssynced - * This inspects any records in this table and checks whether merge has results available for that run - */ - public void pullResultsFromMerge() - { - Date lastRun = MergeSyncManager.get().getLastRun(); - _log.info("Pulling results from merge verified since: " + (lastRun == null ? "never run before" : _dateTimeFormat.format(lastRun))); - - if (lastRun == null) - { - lastRun = new Date(); - } - - TableInfo mergeOrders = MergeSyncManager.get().getMergeSchema().getTable(MergeSyncManager.TABLE_MERGE_ORDERS); - if (mergeOrders == null) - { - _log.warn("Unable to find merge orders table, aborting"); - return; - } - - User u = MergeSyncManager.get().getLabKeyUser(); - Container c = MergeSyncManager.get().getLabKeyContainer(); - if (u == null || c == null) - { - _log.error("Unknown user or container, cannot pull results from merge"); - return; - } - - DbSchema mergeSchema = MergeSyncManager.get().getMergeSchema(); - if (mergeSchema == null) - { - _log.error("Unable to find merge schema, aborting"); - return; - } - - TableInfo resultTable = MergeSyncUserSchema.getMergeDataTable(mergeSchema, null); - if (resultTable == null) - { - _log.error("Unable to create merge results table"); - return; - } - - try (ViewContext.StackResetter ignored = ViewContext.pushMockViewContext(u, c, new ActionURL("onprc_ehr", "fake.view", c))) - { - QueryService.get().setEnvironment(QueryService.Environment.USER, u); - - Date syncStart = new Date(); - pullResults(u, c, mergeSchema, lastRun); - - MergeSyncManager.get().setLastRun(syncStart); - - validateRuns(c, u, mergeSchema, 30, syncStart); - - if (MergeSyncManager.get().doSyncAnimalsAndProjects()) - { - syncAnimalsToMerge(c, u, mergeSchema); - syncProjectsToMerge(c, u, mergeSchema); - } - } - finally - { - QueryService.get().clearEnvironment(); - } - } - - private void pullResults(final User u, final Container c, DbSchema mergeSchema, Date minDate) - { - TableInfo clinpathRuns = QueryService.get().getUserSchema(u, c, "study").getTable("clinpathRuns"); - if (clinpathRuns == null) - { - _log.error("Unable to find study.clinpathRuns, aborting"); - return; - } - - TableInfo runsTable = MergeSyncUserSchema.getMergeRunsTable(mergeSchema, null); - final TableInfo mergeResultTable = MergeSyncUserSchema.getMergeDataTable(mergeSchema, null); - - //sync on date/time in order to avoid additional work - SimpleFilter runFilter = new SimpleFilter(FieldKey.fromString("dateVerified"), minDate, CompareType.GTE); - runFilter.addCondition(FieldKey.fromString("status"), "V"); - - //Modified: 4-11-2016 R.Blasa allow both numeric and non-numeric ids - //runFilter.addCondition(FieldKey.fromString("numericLastName"), true, CompareType.EQUAL); - - TableSelector runTs = new TableSelector(runsTable, runFilter, null); - long count = runTs.getRowCount(); - if (count > 0) - { - _log.info("found " + count + " new merge runs to sync"); - processRuns(c, u, runTs, mergeResultTable); - _log.info("finished pulling results from merge"); - } - else - { - _log.info("no merge runs found, nothing to do"); - } - } - - private TableInfo getClinpathRuns(Container c, User u) - { - TableInfo clinpathRuns = QueryService.get().getUserSchema(u, c, "study").getTable("clinpathRuns"); - if (clinpathRuns == null) - { - _log.error("Unable to find study.clinpathRuns, aborting"); - return null; - } - - return clinpathRuns; - } - - private void processRuns(final Container c, final User u, TableSelector runTs, final TableInfo mergeResultTable) - { - runTs.forEach(new Selector.ForEachBlock<>() - { - @Override - public void exec(ResultSet runRs) throws SQLException - { - processSingleRun(c, u, mergeResultTable, runRs, false); - } - }); - } - - private void validateRuns(final Container c, final User u, DbSchema mergeSchema, int offset, final Date syncStart) - { - TableInfo runsTable = MergeSyncUserSchema.getMergeRunsTable(mergeSchema, null); - - Calendar minDate = Calendar.getInstance(); - minDate.setTime(new Date()); - minDate.add(Calendar.DATE, -1 * offset); - - SimpleFilter runFilter = new SimpleFilter(FieldKey.fromString("dateVerified"), minDate, CompareType.GTE); - runFilter.addCondition(FieldKey.fromString("dateVerified"), null, CompareType.NONBLANK); - runFilter.addCondition(FieldKey.fromString("status"), "V"); - - //Removed 4-12-2016 R.Blasa allow both nuemric and non-numeric ids - // runFilter.addCondition(FieldKey.fromString("numericLastName"), true, CompareType.EQUAL); - - final TableSelector runTs = new TableSelector(runsTable, runFilter, null); - if (runTs.exists()) - { - _log.info("verifying previous " + offset + " days of merge runs are present"); - runTs.forEach(new Selector.ForEachBlock<>() - { - @Override - public void exec(ResultSet mergeRunRs) throws SQLException - { - Integer accession = mergeRunRs.getInt("accession"); - Integer panelId = mergeRunRs.getInt("panelid"); - - Map existingRequest = getExistingRequest(c, u, accession, panelId, false); - if (existingRequest == null || existingRequest.get("runLsid") == null) //proxy for whether this record existing in clinpath runs - { - if (existingRequest == null || existingRequest.get("objectid") == null) //proxy for whether a record existing in orders synced. this might - { - //NOTE: if the dateVerified is greater than the sync start, it was most likely verified during this sync operation and we'll pick it up during the next sync anyway - String msg = "merge run missing: " + accession + " / " + panelId + ". No record of previous sync. Date verified: " + _dateTimeFormat.format(mergeRunRs.getDate("dateVerified")); - if (mergeRunRs.getDate("dateVerified").getTime() <= syncStart.getTime()) - { - _log.error(msg); - } - else - { - _log.warn(msg); - } - //processSingleRun(c, u, mergeResultTable, mergeRunRs, false); - } - else if (existingRequest.get("deletedate") != null) - { - //run was deleted from LabKey, ignore - } - else if (existingRequest.get("runLsid") == null) - { - _log.error("merge run missing: " + accession + " / " + panelId + ". Record of previous sync, but no clinpathRun record. Date verified: " + _dateTimeFormat.format(mergeRunRs.getDate("dateVerified"))); - //processSingleRun(c, u, mergeResultTable, mergeRunRs, false); - } - } - } - }); - } - } - - public void syncSingleRun(final Container c, final User u, final Integer mergeAccession, final Integer mergeTestId) throws SQLException - { - DbSchema mergeSchema = MergeSyncManager.get().getMergeSchema(); - if (mergeSchema == null) - return; - - _log.info("attempting to resync single run: " + mergeAccession + " / " + mergeTestId); - - TableInfo runsTable = MergeSyncUserSchema.getMergeRunsTable(mergeSchema, null); - final TableInfo mergeResultTable = MergeSyncUserSchema.getMergeDataTable(mergeSchema, null); - - SimpleFilter runFilter = new SimpleFilter(FieldKey.fromString("accession"), mergeAccession, CompareType.EQUAL); - runFilter.addCondition(FieldKey.fromString("panelid"), mergeTestId); - runFilter.addCondition(FieldKey.fromString("status"), "V"); - - //Modified: 4-11-2016 R.Blasa allow both numeric and non-numeric ids - // runFilter.addCondition(FieldKey.fromString("numericLastName"), true, CompareType.EQUAL); - - - - - TableSelector runTs = new TableSelector(runsTable, runFilter, null); - runTs.forEach(new Selector.ForEachBlock<>() - { - @Override - public void exec(ResultSet runRs) throws SQLException - { - //delete results if we expect automatic results - String mergeService = runRs.getString("servicename_abbr"); - String labkeyServiceName = resolveServiceName(c, u, mergeService, null); - if (shouldSyncResults(labkeyServiceName)) - { - deleteExistingResults(c, u, mergeAccession, mergeTestId); - } - else - { - _log.info("this service type does not have automatic results, so we will not delete any existing results"); - } - - try - { - Map existingRequest = getExistingRequest(c, u, mergeAccession, mergeTestId, false); - if (existingRequest != null) - { - TableSelector runsTs = new TableSelector(getClinpathRuns(c, u), PageFlowUtil.set("lsid", "Id", "project", "date"), new SimpleFilter(FieldKey.fromString("objectid"), existingRequest.get("runid")), null); - Map runRow = runsTs.getMap(); - if (runRow != null) - { - runRow = new CaseInsensitiveHashMap<>(runRow); - - boolean changed = false; - if (!runRow.get("Id").equals(runRs.getString("animalId"))) - { - runRow.put("Id", runRs.getString("Id")); - changed = true; - } - - if (!DateUtils.isSameInstant((Date) runRow.get("date"), runRs.getDate("date"))) - { - runRow.put("date", runRs.getDate("date")); - changed = true; - } - - Integer project = resolveProject(c, u, runRs.getString("projectName")); - if (project != null && !project.equals(runRow.get("project"))) - { - runRow.put("project", project); - changed = true; - } - - if (changed) - { - Map keys = new CaseInsensitiveHashMap<>(); - keys.put("lsid", runRow.get("lsid")); - getClinpathRuns(c, u).getUpdateService().updateRows(u, c, Collections.singletonList(runRow), Collections.singletonList(keys), null, getExtraContext()); - } - } - } - - processSingleRun(c, u, mergeResultTable, runRs, true); - } - catch (InvalidKeyException | BatchValidationException | QueryUpdateServiceException e) - { - throw new RuntimeException(e.getMessage(), e); - } - } - }); - } - - public void deleteExistingResults(final Container c, final User u, Integer mergeAccession, Integer mergeTestId) throws SQLException - { - Map request = getExistingRequest(c, u, mergeAccession, mergeTestId, false); - if (request == null) - { - return; - } - - String runId = (String)request.get("runid"); - if (runId == null) - { - return; - } - - TableSelector ts = new TableSelector(getClinpathRuns(c, u), Collections.singleton("servicerequested"), new SimpleFilter(FieldKey.fromString("objectid"), runId), null); - String servicename = ts.getObject(String.class); - if (servicename == null) - { - return; - } - - try - { - TableInfo resultTable = resolveServiceResultTable(c, u, servicename); - if (resultTable == null) - { - _log.error("Unable to find result table matching: " + servicename); - return; - } - - List lsids = new TableSelector(resultTable, Collections.singleton("lsid"), new SimpleFilter(FieldKey.fromString("runid"), runId), null).getArrayList(String.class); - if (lsids != null && !lsids.isEmpty()) - { - List> toDelete = new ArrayList<>(); - for (String lsid : lsids) - { - Map row = new CaseInsensitiveHashMap<>(); - row.put("lsid", lsid); - - toDelete.add(row); - } - - List deleted = resultTable.getUpdateService().deleteRows(u, c, toDelete, null, getExtraContext()); - _log.info("pre-deleted " + deleted.size() + " rows from table: " + resultTable.getName()); - } - else - { - _log.info("no existing results found, nothing to delete"); - } - } - catch (InvalidKeyException | BatchValidationException | QueryUpdateServiceException e) - { - throw new RuntimeException(e.getMessage(), e); - } - } - - private void processSingleRun(final Container c, final User u, TableInfo mergeResultTable, ResultSet mergeRunRs, final boolean forceSyncResults) throws SQLException - { - Integer accession = mergeRunRs.getInt("accession"); - Integer panelId = mergeRunRs.getInt("panelid"); - - SimpleFilter resultFilter = new SimpleFilter(FieldKey.fromString("accession"), accession); - resultFilter.addCondition(FieldKey.fromString("panelid"), panelId); - resultFilter.addCondition(FieldKey.fromString("isFinal"), "Y"); - resultFilter.addCondition(FieldKey.fromString("status"), "V"); - resultFilter.addCondition(FieldKey.fromString("text_result"), EXCLUDED_RESULTS, CompareType.NOT_IN); - - final Map>> resultsToCreate = new HashMap<>(); - final Map resultDatasets = new HashMap<>(); - - TableInfo tableOrdersSynced = MergeSyncSchema.getInstance().getSchema().getTable(MergeSyncManager.TABLE_ORDERSSYNCED); - Map existingRequest = getExistingRequest(c, u, accession, panelId, true); - final String existingRunId = existingRequest == null ? null : (String)existingRequest.get("runid"); - _log.info("processing order: " + accession); - _log.info("existingRunId: " + existingRunId); - - Set completedTasks = new HashSet<>(); - TableSelector resultsTs = new TableSelector(mergeResultTable, resultFilter, null); - resultsTs.forEach(new Selector.ForEachBlock<>() - { - @Override - public void exec(ResultSet rs) throws SQLException - { - Map resultRow = processResultSet(c, u, rs, existingRunId); - if (resultRow == null) - { - return; //this could occur if the result is simply a placeholder like 'RECEIVED' - } - - TableInfo dataset = getResultDataset(c, u, rs.getString("servicename_abbr"), existingRunId); - if (dataset == null) - { - return; //count on getResultDataset() for error reporting - } - - resultDatasets.put(dataset.getName(), dataset); - - List> list = resultsToCreate.get(dataset.getName()); - if (list == null) - list = new ArrayList<>(); - - list.add(resultRow); - - resultsToCreate.put(dataset.getName(), list); - } - }); - - DbScope scope = DbScope.getLabKeyScope(); - try (DbScope.Transaction transaction = scope.ensureTransaction()) - { - String taskId = null; - String runId = null; - String runLsid = null; - String runTaskId = null; - String orderObjectId = null; - if (existingRequest != null) - { - taskId = (String)existingRequest.get("taskid"); - runId = (String)existingRequest.get("runid"); - runLsid = (String)existingRequest.get("runLsid"); - orderObjectId = (String)existingRequest.get("objectid"); - runTaskId = (String)existingRequest.get("taskid"); - Boolean resultsReceived = (Boolean)existingRequest.get("resultsreceived"); - - if (resultsReceived && !forceSyncResults) - { - _log.info("This order already has results imported, skipping: " + accession + "/" + panelId); - return; - } - } - - String mergeService = mergeRunRs.getString("servicename_abbr"); - String labkeyServiceName = resolveServiceName(c, u, mergeService, runId); - boolean expectResults = shouldSyncResults(labkeyServiceName); - - //NOTE: only put this into a task if we expect to sync results. otherwise leave it in the queue and manual entry - if (taskId == null && expectResults) - { - taskId = createTask(c, u, mergeRunRs.getString("animalId"), mergeRunRs.getDate("date")); - } - - if (runId == null) - { - Map map = createRun(c, u, mergeRunRs, taskId, (expectResults && resultsToCreate.isEmpty())); - runId = map == null ? null : (String)map.get("runid"); - } - - if (runLsid == null && runId != null) - { - runLsid = getRunLsid(c, u, accession, panelId, runId); - runTaskId = getRunTaskId(c, u, accession, panelId, runId); - } - - String requestId = null; - if (orderObjectId == null) - { - orderObjectId = createOrderRecord(c, u, taskId, runId, accession, panelId, mergeRunRs.getDate("date")); - } - else - { - requestId = getRequestForOrder(c, u, orderObjectId); - } - - if (expectResults) - { - if (resultsToCreate.isEmpty()) - { - _log.error("Merge request for " + mergeService + " was expected to have results, but does not. Accession: " + accession + ", panelId: " + panelId); - } - - for (String datasetName : resultsToCreate.keySet()) - { - List> rows = resultsToCreate.get(datasetName); - for (Map row : rows) - { - row.put("taskid", taskId); - row.put("runid", runId); - row.put("requestid", requestId); - } - - TableInfo ds = resultDatasets.get(datasetName); - - _log.info("creating " + datasetName + " results: " + resultsToCreate.get(datasetName).size()); - - BatchValidationException errors = new BatchValidationException(); - ds.getUpdateService().insertRows(u, c, resultsToCreate.get(datasetName), errors, null, getExtraContext()); - } - - //if successful, we need to mark the run as completed - _log.info("marking clinpath run as complete: " + runId); - Map toUpdate = new CaseInsensitiveHashMap<>(); - toUpdate.put("lsid", runLsid); - toUpdate.put("QCStateLabel", EHRService.QCSTATES.Completed.getLabel()); - - Map toUpdateKeys = new CaseInsensitiveHashMap<>(); - toUpdateKeys.put("lsid", runLsid); - - getClinpathRuns(c, u).getUpdateService().updateRows(u, c, Collections.singletonList(toUpdate), Collections.singletonList(toUpdateKeys), null, getExtraContext()); - completedTasks.add(taskId); - } - else - { - if (!resultsToCreate.isEmpty()) - { - _log.error("Merge request for " + mergeService + " was not expected to have results, but does. Accession: " + accession + ", panelId: " + panelId); - for (String tableName : resultsToCreate.keySet()) - { - _log.error(tableName + ": " + resultsToCreate.get(tableName).size()); - } - } - else - { - //note: use whether this record is part of a task as a proxy for whether someone has worked with it or not - if (runTaskId == null) - { - Map toUpdate = new CaseInsensitiveHashMap<>(); - toUpdate.put("lsid", runLsid); - toUpdate.put("QCStateLabel", EHRService.QCSTATES.RequestSampleDelivered.getLabel()); - - Map toUpdateKeys = new CaseInsensitiveHashMap<>(); - toUpdateKeys.put("lsid", runLsid); - - _log.info("marking clinpath run as delivered: " + runId); - getClinpathRuns(c, u).getUpdateService().updateRows(u, c, Collections.singletonList(toUpdate), Collections.singletonList(toUpdateKeys), null, getExtraContext()); - } - else - { - _log.info("run is already part of a task, will not set qcstate"); - } - } - } - - for (String t : completedTasks) - { - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("taskid"), t); - filter.addCondition(FieldKey.fromString("qcstate"), EHRService.QCSTATES.Completed.getQCState(c).getRowId(), CompareType.NEQ_OR_NULL); - TableSelector ts = new TableSelector(getClinpathRuns(c, u), filter, null); - if (!ts.exists()) - { - _log.info("task has no non-completed runs, marking complete: " + t); - TableInfo taskTable = DbSchema.get("ehr").getTable("tasks"); - Map toUpdate = new CaseInsensitiveHashMap<>(); - toUpdate.put("taskid", t); - toUpdate.put("qcstate", EHRService.QCSTATES.Completed.getQCState(c).getRowId()); - Table.update(u, taskTable, toUpdate, t); - } - else - { - _log.info("task still has non-completed runs, will not mark complete: " + t); - } - } - - //update the LK table to indicate results are received - Map toUpdate = new CaseInsensitiveHashMap<>(); - toUpdate.put("resultsreceived", true); - toUpdate.put("objectid", orderObjectId); - toUpdate.put("taskid", taskId); - toUpdate.put("requestid", requestId); - Table.update(u, tableOrdersSynced, toUpdate, orderObjectId); - - transaction.commit(); - } - catch (BatchValidationException | DuplicateKeyException | InvalidKeyException | QueryUpdateServiceException e) - { - _log.error(e.getMessage(), e); - throw new RuntimeException(e.getMessage(), e); - } - } - - private boolean shouldSyncResults(String labkeyServiceName) - { - if (labkeyServiceName ==null) - return false; - - String cacheKey = this.getClass().getName() + "||" + "||resultsExpectedMap"; - if (CacheManager.getSharedCache().get(cacheKey) == null) - { - TableInfo ti = MergeSyncSchema.getInstance().getSchema().getTable(MergeSyncManager.TABLE_TESTNAMEMAPPING); - TableSelector ts = new TableSelector(ti); - Map ret = new HashMap<>(); - for (Map row : ts.getMapArray()) - { - ret.put((String)row.get("servicename"), (Boolean)row.get("automaticresults")); - } - - CacheManager.getSharedCache().put(cacheKey, ret); - } - - Map map = (Map)CacheManager.getSharedCache().get(cacheKey); - - return map.get(labkeyServiceName) != null ? map.get(labkeyServiceName) : false; - } - - private String createTask(Container c, User u, String animalId, Date date) throws SQLException - { - String key = animalId + " " + _dateFormat.format(date); - if (_cachedTasks.containsKey(key)) - { - return _cachedTasks.get(key); - } - - String taskId = new GUID().toString().toUpperCase(); - Map taskRecord = new CaseInsensitiveHashMap<>(); - taskRecord.put("taskid", taskId); - taskRecord.put("title", key); - taskRecord.put("category", "Task"); - taskRecord.put("formType", "Labwork"); - taskRecord.put("assignedto", u.getUserId()); - taskRecord.put("container", c.getId()); - taskRecord.put("created", new Date()); - taskRecord.put("createdby", u.getUserId()); - taskRecord.put("modified", new Date()); - taskRecord.put("modifiedby", u.getUserId()); - taskRecord.put("QCStateLabel", EHRService.QCSTATES.Completed.getLabel()); - - TableInfo taskTable = DbSchema.get("ehr").getTable("tasks"); - - _log.info("Creating task for merge sync: " + key); - Table.insert(u, taskTable, taskRecord); - - _cachedTasks.put(key, taskId); - - return taskId; - } - - private Map getExistingRequest(Container c, User u, Integer accession, Integer panelId, boolean validateRunId) - { - TableInfo tableOrdersSynced = MergeSyncSchema.getInstance().getSchema().getTable(MergeSyncManager.TABLE_ORDERSSYNCED); - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("order_accession"), accession); - filter.addCondition(FieldKey.fromString("container"), c.getId()); - - // this is designed to handle legacy data and newer data. the legacy data has only been tracked by accession. - // data synced via LK are tracked using accession and panelId - filter.addClause(new SimpleFilter.OrClause( - new CompareType.CompareClause(FieldKey.fromString("test_accession"), CompareType.EQUAL, panelId), - new CompareType.CompareClause(FieldKey.fromString("test_accession"), CompareType.ISBLANK, null) - )); - - TableSelector ts = new TableSelector(tableOrdersSynced, PageFlowUtil.set("objectid", "resultsreceived", "runid", "taskid", "deletedate"), filter, new Sort("-created")); - List ret = ts.getArrayList(Map.class); - if (ret.isEmpty()) - return null; - - Map map = new CaseInsensitiveHashMap(ret.get(0)); - - //make sure this runId actually exists - String runId = (String)map.get("runid"); - if (runId != null) - { - TableInfo ti = getClinpathRuns(c, u); - TableSelector ts2 = new TableSelector(ti, PageFlowUtil.set("lsid", "qcstate", "taskid"), new SimpleFilter(FieldKey.fromString("objectid"), runId), null); - Map row = ts2.getObject(Map.class); - if (row != null) - { - map.put("runLsid", row.get("lsid")); - map.put("qcstate", row.get("qcstate")); - map.put("taskid", row.get("taskid")); - - //NOTE: only return the map if this run is really found - return map; - } - else if (!validateRunId) - { - return map; - } - else - { - _log.error("There is a record of a synced merge request (" + accession + "), but the runId was not found: " + runId + ". the request will be recreated."); - } - } - - return validateRunId ? null : map; - } - - private Map processResultSet(Container c, User u, ResultSet rs, @Nullable String runId) throws SQLException - { - String animalId = rs.getString("animalId"); - Date date = convertGMTToLocal(rs.getTimestamp("date")); - // _log.info("Show Lab Record date: " + date); //Removed 3-24-2016 Blasa - - String projectName = rs.getString("projectName"); - //Date datecollected = convertGMTToLocal(rs.getDate("datecollected")); - String servicename_abbr = rs.getString("servicename_abbr"); - String testid_abbr = rs.getString("testid_abbr"); - - String text_result = rs.getString("text_result"); - Double numeric_result = rs.getDouble("numeric_result"); - numeric_result = rs.wasNull() ? null : numeric_result; - - String remark = rs.getString("remark"); - if (rs.getString("runRemark") != null) - { - if (remark == null) - remark = rs.getString("runRemark"); - else - remark = remark + "\n" + rs.getString("runRemark"); - } - Integer project = resolveProject(c, u, projectName); - - String servicename = resolveServiceName(c, u, servicename_abbr, null); - if (servicename == null) - { - _log.error("Unable to resolve merge servicename: " + servicename_abbr); - return null; - } - - Map resultRow = new CaseInsensitiveHashMap<>(); - resultRow.put("Id", animalId); - resultRow.put("date", date); - resultRow.put("project", project); - resultRow.put("testid", testid_abbr); - resultRow.put("remark", remark); - resultRow.put("units", resolveUnits(c, u, null, testid_abbr)); - - //NOTE: when a result is flagged as an error, merge seems to store 0 in the numeric result, while keeping the original value as the text result - //i dont like this behavior, but if there is a remark (a proxy for having an error), the numeric result is 0, and text result is numeric, then defer to the latter - if (!StringUtils.isEmpty(remark) && (numeric_result == null || numeric_result == 0.0) && !StringUtils.isEmpty(text_result) && text_result.matches("[-+]?\\d*\\.?\\d+")) - { - _log.info("deferring to text result instead of numeric result: " + text_result); - numeric_result = ConvertHelper.convert(text_result, Double.class); - } - - resultRow.put("result", numeric_result); - if (numeric_result == null) - { - resultRow.put("qualresult", text_result); - } - - return resultRow; - } - - private TableInfo getResultDataset(Container c, User u, String serviceName, @Nullable String runId) throws SQLException - { - String servicename = resolveServiceName(c, u, serviceName, runId); - if (servicename == null) - { - return null; - } - - TableInfo resultTable = resolveServiceResultTable(c, u, servicename); - if (resultTable == null) - { - _log.error("Unable to find result table matching: " + servicename); - return null; - } - - return resultTable; - } - - private Date convertGMTToLocal(Date d) - { - if (d == null) - return null; - - //NOTE: this is handled at the UserSchema level now - return d; - } - - private String getRunLsid(Container c, User u, Integer accessionId, Integer panelId, String runId) throws SQLException - { - String key = accessionId + "||" + panelId; - if (_cachedRuns.containsKey(key)) - { - return (String)_cachedRuns.get(key).get("lsid"); - } - - Map map = cacheRun(c, u, key, runId); - - return (String)map.get("lsid"); - } - - private String getRunTaskId(Container c, User u, Integer accessionId, Integer panelId, String runId) throws SQLException - { - String key = accessionId + "||" + panelId; - if (_cachedRuns.containsKey(key)) - { - return (String)_cachedRuns.get(key).get("taskid"); - } - - Map map = cacheRun(c, u, key, runId); - - return (String)map.get("taskid"); - } - - private Map cacheRun(Container c, User u, String key, String runId) - { - TableInfo ti = getClinpathRuns(c, u); - TableSelector ts = new TableSelector(ti, PageFlowUtil.set("lsid", "qcstate", "taskid"), new SimpleFilter(FieldKey.fromString("objectid"), runId), null); - Map found = ts.getObject(Map.class); - Map map = new CaseInsensitiveHashMap<>(); - if (found != null) - { - map.put("lsid", found.get("lsid")); - map.put("runid", runId); - map.put("qcstate", found.get("qcstate")); - map.put("taskid", found.get("taskid")); - } - - _cachedRuns.put(key, map); - - return map; - } - - private Map createRun(Container c, User u, ResultSet mergeRunRs, String taskId, boolean hasResults) throws SQLException - { - Integer accessionId = mergeRunRs.getInt("accession"); - int panelId = mergeRunRs.getInt(("panelid")); - - String key = accessionId + "||" + panelId; - if (_cachedRuns.containsKey(key)) - { - return _cachedRuns.get(key); - } - - String animalId = mergeRunRs.getString("animalId"); - Date date = convertGMTToLocal(mergeRunRs.getTimestamp("date")); - // _log.info("Show clinPath Record date: " + date); //Removed 3-24-2016 Blasa - - Integer project = resolveProject(c, u, mergeRunRs.getString("projectName")); - String servicename = resolveServiceName(c, u, mergeRunRs.getString("servicename_abbr"), null); - - String runId = new GUID().toString().toUpperCase(); - Map runRow = new CaseInsensitiveHashMap<>(); - runRow.put("Id", animalId); - runRow.put("date", date); - runRow.put("project", project); - runRow.put("objectid", runId); - runRow.put("taskid", taskId); - runRow.put("servicerequested", servicename); - - String tissue = resolveTissueForService(servicename, u, c); - if (tissue != null) - runRow.put("tissue", tissue); - - String method = resolveMethodForService(servicename, u, c); - if (method != null) - runRow.put("method", method); - - EHRService.QCSTATES qc = hasResults ? EHRService.QCSTATES.Completed : EHRService.QCSTATES.RequestSampleDelivered; - - runRow.put("QCStateLabel", qc.getLabel()); - - TableInfo clinpathRuns = getClinpathRuns(c, u); - try - { - _log.info("creating clinpath run for merge data: " + key); - BatchValidationException errors = new BatchValidationException(); - List> createdRunRows = clinpathRuns.getUpdateService().insertRows(u, c, Arrays.asList(runRow), errors, null, getExtraContext()); - if (errors.hasErrors()) - { - throw errors; - } - - if (createdRunRows == null) - { - throw new RuntimeException("Unable to create clinpath run record for: " + key); - } - - if (!createdRunRows.isEmpty()) - { - Map map = new CaseInsensitiveHashMap<>(); - map.put("runid", runId); - map.put("lsid", createdRunRows.get(0).get("lsid")); - map.put("taskid", createdRunRows.get(0).get("taskid")); - map.put("qcstate", qc.getQCState(c).getRowId()); - - _cachedRuns.put(key, map); - } - - return _cachedRuns.get(key); - } - catch (BatchValidationException | DuplicateKeyException | QueryUpdateServiceException | SQLException e) - { - _log.error(e.getMessage(), e); - throw new RuntimeException(e.getMessage(), e); - } - } - - public Map getExtraContext() - { - Map map = new HashMap<>(); - map.put("quickValidation", true); - map.put("generatedByServer", true); - - return map; - } - - private String getRequestForOrder(Container c, User u, String objectId) - { - TableInfo ti = MergeSyncSchema.getInstance().getSchema().getTable(MergeSyncManager.TABLE_ORDERSSYNCED); - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("objectid"), objectId); - TableSelector ts = new TableSelector(ti, Collections.singleton("requestid"), filter, null); - List ret = ts.getArrayList(String.class); - - return ret.isEmpty() ? null : ret.get(0); - } - - private String createOrderRecord(Container c, User u, String taskId, String runId, Integer accession, Integer panelId, Date date) throws SQLException - { - String objectId = new GUID().toString().toUpperCase(); - Map toInsert = new CaseInsensitiveHashMap<>(); - toInsert.put("resultsreceived", false); - toInsert.put("taskid", taskId); - toInsert.put("runid", runId); - toInsert.put("order_accession", accession); - toInsert.put("test_accession", panelId); - toInsert.put("merge_datecreated", date); - toInsert.put("merge_dateposted", new Date()); - toInsert.put("objectid", objectId); - toInsert.put("container", c.getId()); - toInsert.put("created", new Date()); - toInsert.put("createdby", u.getUserId()); - toInsert.put("modified", new Date()); - toInsert.put("modifiedby", u.getUserId()); - - _log.info("creating order record for merge data: " + accession + "/" + panelId); - Table.insert(u, MergeSyncSchema.getInstance().getSchema().getTable(MergeSyncManager.TABLE_ORDERSSYNCED), toInsert); - - return objectId; - } - - private String resolveServiceName(Container c, User u, String mergeServiceName, @Nullable String runId) - { - if (runId != null) - { - TableInfo clinpathRuns = getClinpathRuns(c, u); - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("objectId"), runId); - TableSelector ts = new TableSelector(clinpathRuns, Collections.singleton("servicerequested"), filter, null); - List ret = ts.getArrayList(String.class); - if (ret != null && !ret.isEmpty()) - { - return ret.get(0); - } - } - - String cacheKey = this.getClass().getName() + "||" + c.getId() + "||testNameMap"; - Map map = (Map)CacheManager.getSharedCache().get(cacheKey); - if (map == null) - { - TableInfo ti = MergeSyncSchema.getInstance().getSchema().getTable(MergeSyncManager.TABLE_MERGE_TO_LK_MAPPING); - TableSelector ts = new TableSelector(ti); - map = new HashMap<>(); - for (Map row : ts.getMapArray()) - { - map.put((String)row.get("mergetestname"), (String)row.get("servicename")); - } - - CacheManager.getSharedCache().put(cacheKey, map); - } - - return map.get(mergeServiceName) == null ? mergeServiceName : map.get(mergeServiceName); - } - - private String resolveTissueForService(String servicename, User u, Container c) - { - if (_cachedTissues.containsKey(servicename)) - { - return _cachedTissues.get(servicename); - } - - TableInfo ti = QueryService.get().getUserSchema(u, c, "ehr_lookups").getTable("labwork_services"); - TableSelector ts = new TableSelector(ti, PageFlowUtil.set("tissue"), new SimpleFilter(FieldKey.fromString("servicename"), servicename), null); - _cachedTissues.put(servicename, ts.getObject(String.class)); - - return _cachedTissues.get(servicename); - } - - private String resolveMethodForService(String servicename, User u, Container c) - { - if (_cachedMethods.containsKey(servicename)) - { - return _cachedMethods.get(servicename); - } - - TableInfo ti = QueryService.get().getUserSchema(u, c, "ehr_lookups").getTable("labwork_services"); - TableSelector ts = new TableSelector(ti, PageFlowUtil.set("method"), new SimpleFilter(FieldKey.fromString("servicename"), servicename), null); - _cachedMethods.put(servicename, ts.getObject(String.class)); - - return _cachedMethods.get(servicename); - } - - private String resolveUnits(Container c, User u, String category, String testid) - { - String cacheKey = this.getClass().getName() + "||" + c.getId() + "||testUnitMap"; - Map> ret = (Map)CacheManager.getSharedCache().get(cacheKey); - if (ret == null) - { - TableInfo ti = QueryService.get().getUserSchema(u, c, "ehr_lookups").getTable("lab_tests"); - TableSelector ts = new TableSelector(ti); - final Map> results = new HashMap<>(); - ts.forEach(new Selector.ForEachBlock<>() - { - @Override - public void exec(ResultSet rs) throws SQLException - { - String key = rs.getString("type") + "||" + rs.getString("testid"); - Map map = new HashMap<>(); - map.put("category", rs.getString("type")); - map.put("testid", rs.getString("testid")); - map.put("units", rs.getString("units")); - - results.put(key, map); - } - }); - - ret = results; - CacheManager.getSharedCache().put(cacheKey, ret); - } - - String key = category + "||" + testid; - Map map = ret.get(key); - - return map == null ? null : (String)map.get("units"); - } - - private TableInfo resolveServiceResultTable(Container c, User u, String servicename) - { - if (_cachedResultTables.containsKey(servicename)) - { - return _cachedResultTables.get(servicename); - } - - TableInfo ti = QueryService.get().getUserSchema(u, c, "ehr_lookups").getTable("labwork_services"); - Set fks = PageFlowUtil.set(FieldKey.fromString("dataset/category")); - final Map cols = QueryService.get().getColumns(ti, fks); - TableSelector ts = new TableSelector(ti, cols.values(), new SimpleFilter(FieldKey.fromString("servicename"), servicename), null); - List datasetNames = ts.getArrayList(String.class); - String datasetName = datasetNames == null || datasetNames.isEmpty() ? null : datasetNames.get(0); - if (datasetName == null) - { - _cachedResultTables.put(servicename, null); - return null; - } - - TableInfo ret = null; - int datasetId = StudyService.get().getDatasetIdByName(c, datasetName); - if (datasetId > -1) - { - Dataset ds = StudyService.get().getDataset(c, datasetId); - ret = QueryService.get().getUserSchema(u, c, "study").getTable(ds.getName()); - } - - _cachedResultTables.put(servicename, ret); - return ret; - } - - private void syncAnimalsToMerge(Container c, User u, DbSchema mergeSchema) - { - try - { - int datasetId = StudyService.get().getDatasetIdByName(c, "demographics"); - if (datasetId > -1) - { - Dataset ds = StudyService.get().getDataset(c, datasetId); - String realTableName = ds.getDomain().getStorageTableName(); - TableInfo realTable = DbSchema.get("studydataset", DbSchemaType.Provisioned).getTable(realTableName); - - TableInfo patients = mergeSchema.getTable(MergeSyncManager.TABLE_MERGE_PATIENTS); - - - //first find IDs we need to add. even though the 2 DBs are on the same server instance for us, dont make that assumption and compare lists in java - List livingAnimals = new TableSelector(realTable, PageFlowUtil.set("participantid"), new SimpleFilter(FieldKey.fromString("calculated_status"), "Alive"), null).getArrayList(String.class); - int start = 0; - int batchSize = 500; - while (start < livingAnimals.size()) - { - List sublist = livingAnimals.subList(start, Math.min(livingAnimals.size(), start + batchSize)); - start = start + batchSize; - - List idsPresent = new TableSelector(patients, PageFlowUtil.set("PT_LNAME"), new SimpleFilter(FieldKey.fromString("PT_LNAME"), sublist, CompareType.IN), null).getArrayList(String.class); - sublist.removeAll(idsPresent); - if (!sublist.isEmpty()) - { - _log.info("creating " + sublist.size() + " animals in merge"); - for (String id : sublist) - { - RequestSyncHelper.createPatient(mergeSchema, c, u, id); - } - } - } - - //then find any IDs we need to mark as dead in merge - List deadAnimals = new TableSelector(realTable, PageFlowUtil.set("participantid"), new SimpleFilter(FieldKey.fromString("calculated_status"), "Dead", CompareType.EQUAL), null).getArrayList(String.class); - start = 0; - while (start < deadAnimals.size()) - { - List sublist = deadAnimals.subList(start, Math.min(deadAnimals.size(), start + batchSize)); - start = start + batchSize; - - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("PT_LNAME"), sublist, CompareType.IN); - filter.addCondition(FieldKey.fromString("PT_FNAME"), "Deceased", CompareType.DOES_NOT_CONTAIN); - List idsToChange = new TableSelector(patients, PageFlowUtil.set("PT_NUM"), filter, null).getArrayList(String.class); - if (!idsToChange.isEmpty()) - { - _log.info("marking " + idsToChange.size() + " animals as deceased in merge"); - for (String ptNum : idsToChange) - { - SQLFragment sql = new SQLFragment("UPDATE dbo.patients SET pt_fname = left(rtrim(pt_fname), 5) + ' ' + '*Deceased*' WHERE PT_NUM = ?", ptNum); - new SqlExecutor(mergeSchema).execute(sql); - } - } - } - - //then shipped - List shippedAnimals = new TableSelector(realTable, PageFlowUtil.set("participantid"), new SimpleFilter(FieldKey.fromString("calculated_status"), "Shipped", CompareType.EQUAL), null).getArrayList(String.class); - start = 0; - while (start < shippedAnimals.size()) - { - List sublist = shippedAnimals.subList(start, Math.min(shippedAnimals.size(), start + batchSize)); - start = start + batchSize; - - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("PT_LNAME"), sublist, CompareType.IN); - filter.addCondition(FieldKey.fromString("PT_FNAME"), "Sold", CompareType.DOES_NOT_CONTAIN); - List idsToChange = new TableSelector(patients, PageFlowUtil.set("PT_NUM"), filter, null).getArrayList(String.class); - if (!idsToChange.isEmpty()) - { - _log.info("marking " + idsToChange.size() + " animals as shipped in merge"); - for (String ptNum : idsToChange) - { - SQLFragment sql = new SQLFragment("UPDATE dbo.patients SET pt_fname = left(rtrim(pt_fname), 5) + ' ' + '*Sold*' WHERE PT_NUM = ?", ptNum); - new SqlExecutor(mergeSchema).execute(sql); - } - } - } - } - } - catch (Exception e) - { - _log.error(e.getMessage(), e); - } - } - - private void syncProjectsToMerge(final Container c, final User u, final DbSchema mergeSchema) - { - TableInfo projects = QueryService.get().getUserSchema(u, c, "ehr").getTable("project"); - TableInfo insurance = mergeSchema.getTable("insurance"); - - //first create any project missing in merge - List activeProjects = new TableSelector(projects, PageFlowUtil.set("displayName"), new SimpleFilter(FieldKey.fromString("enddateCoalesced"), new Date(), CompareType.DATE_GTE), null).getArrayList(String.class); - int start = 0; - int batchSize = 500; - while (start < activeProjects.size()) - { - List sublist = activeProjects.subList(start, Math.min(activeProjects.size(), start + batchSize)); - start = start + batchSize; - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("INS_NAME"), sublist, CompareType.IN); - filter.addCondition(FieldKey.fromString("INS_TYPE"), "I"); //this will return only those active in merge - - List projectsPresent = new TableSelector(insurance, PageFlowUtil.set("INS_NAME"), filter, null).getArrayList(String.class); - sublist.removeAll(projectsPresent); - if (!sublist.isEmpty()) - { - _log.info("creating " + sublist.size() + " projects in merge"); - Set fks = PageFlowUtil.set(FieldKey.fromString("displayName"), FieldKey.fromString("investigatorId/lastName"), FieldKey.fromString("investigatorId/firstName"), FieldKey.fromString("enddate")); - final Map cols = QueryService.get().getColumns(projects, fks); - - TableSelector projectTs = new TableSelector(projects, cols.values(), new SimpleFilter(FieldKey.fromString("displayName"), sublist, CompareType.IN), null); - projectTs.forEach(new Selector.ForEachBlock<>() - { - @Override - public void exec(ResultSet object) throws SQLException - { - Results rs = new ResultsImpl(object, cols); - String projectName = rs.getString(FieldKey.fromString("displayName")); - String lastName = rs.getString(FieldKey.fromString("investigatorId/lastName")); - Date enddate = rs.getDate(FieldKey.fromString("enddate")); - - RequestSyncHelper.createInsurance(mergeSchema, c, u, projectName, lastName, enddate); - } - }); - } - } - - //then find expired projects and update if needed - List expiredProjectNames = new TableSelector(projects, PageFlowUtil.set("displayName"), new SimpleFilter(FieldKey.fromString("enddateCoalesced"), new Date(), CompareType.DATE_LT), null).getArrayList(String.class); - start = 0; - while (start < expiredProjectNames.size()) - { - List sublist = expiredProjectNames.subList(start, Math.min(expiredProjectNames.size(), start + batchSize)); - start = start + batchSize; - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("INS_NAME"), sublist, CompareType.IN); - filter.addCondition(FieldKey.fromString("INS_TYPE"), "C", CompareType.NEQ_OR_NULL); - List insuranceToUpdate = new TableSelector(insurance, PageFlowUtil.set("INS_INDEX"), filter, null).getArrayList(Integer.class); - if (!insuranceToUpdate.isEmpty()) - { - _log.info("marking " + insuranceToUpdate.size() + " projects inactive in merge"); - for (Integer index : insuranceToUpdate) - { - SQLFragment sql = new SQLFragment("UPDATE dbo.insurance SET INS_TYPE = 'C', INS_ADDR1 = (INS_ADDR1 + ' ' + '(Expired)') WHERE INS_INDEX = ?", index); - new SqlExecutor(mergeSchema).execute(sql); - } - } - } - } - - private Integer resolveProject(Container c, User u, String projectName) - { - if (_cachedProjectNames.containsKey(projectName)) - { - return _cachedProjectNames.get(projectName); - } - - if ("CLINIC".equals(projectName) || "PATHOLOGY".equals(projectName) || "SURGERY".equals(projectName)) - { - projectName = EHRService.get().getEHRDefaultClinicalProjectName(c); - } - - TableInfo ti = QueryService.get().getUserSchema(u, c, "ehr").getTable("project"); - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("displayName"), projectName); - TableSelector ts = new TableSelector(ti, Collections.singleton("project"), filter, null); - List results = ts.getArrayList(Integer.class); - Integer ret = results.isEmpty() ? null : results.get(0); - _cachedProjectNames.put(projectName, ret); - - return ret; - } -} diff --git a/mergesync/src/org/labkey/mergesync/MergeSyncSchema.java b/mergesync/src/org/labkey/mergesync/MergeSyncSchema.java deleted file mode 100644 index 57bf12a20..000000000 --- a/mergesync/src/org/labkey/mergesync/MergeSyncSchema.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2013 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.labkey.mergesync; - -import org.labkey.api.data.DbSchema; -import org.labkey.api.data.dialect.SqlDialect; - -public class MergeSyncSchema -{ - public static final String NAME = "mergesync"; - private static final MergeSyncSchema _instance = new MergeSyncSchema(); - - public static MergeSyncSchema getInstance() - { - return _instance; - } - - private MergeSyncSchema() - { - - } - - public DbSchema getSchema() - { - return DbSchema.get(NAME); - } - - public SqlDialect getSqlDialect() - { - return getSchema().getSqlDialect(); - } -} diff --git a/mergesync/src/org/labkey/mergesync/MergeSyncTableCustomizer.java b/mergesync/src/org/labkey/mergesync/MergeSyncTableCustomizer.java deleted file mode 100644 index acd74586b..000000000 --- a/mergesync/src/org/labkey/mergesync/MergeSyncTableCustomizer.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.labkey.mergesync; - -import org.labkey.api.data.AbstractTableInfo; -import org.labkey.api.data.TableInfo; -import org.labkey.api.data.WrappedColumn; -import org.labkey.api.ldk.table.AbstractTableCustomizer; -import org.labkey.api.module.ModuleLoader; -import org.labkey.api.query.LookupForeignKey; -import org.labkey.api.query.UserSchema; - -/** - - */ -public class MergeSyncTableCustomizer extends AbstractTableCustomizer -{ - public MergeSyncTableCustomizer() - { - - } - - @Override - public void customize(TableInfo ti) - { - if (ti instanceof AbstractTableInfo && (matches(ti, "study", "Clinpath Runs") || matches(ti, "study", "clinpathRuns"))) - { - customizeClinpathRuns((AbstractTableInfo)ti); - } - } - - private void customizeClinpathRuns(AbstractTableInfo ti) - { - if (ti.getUserSchema().getContainer().getActiveModules().contains(ModuleLoader.getInstance().getModule(MergeSyncModule.NAME))) - { - String name = "mergeSyncInfo"; - if (ti.getColumn(name) == null && ti.getColumn("servicerequested") != null) - { - final UserSchema us = getUserSchema(ti, MergeSyncSchema.NAME); - WrappedColumn ci = new WrappedColumn(ti.getColumn("servicerequested"), name); - LookupForeignKey fk = new LookupForeignKey() - { - @Override - public TableInfo getLookupTableInfo() - { - return us.getTable(MergeSyncManager.TABLE_TESTNAMEMAPPING); - } - }; - - ci.setFk(fk); - ci.setUserEditable(false); - ci.setIsUnselectable(true); - ci.setLabel("Merge Sync Info"); - ti.addColumn(ci); - } - } - } -} diff --git a/mergesync/src/org/labkey/mergesync/MergeSyncUserSchema.java b/mergesync/src/org/labkey/mergesync/MergeSyncUserSchema.java deleted file mode 100644 index bd43394f5..000000000 --- a/mergesync/src/org/labkey/mergesync/MergeSyncUserSchema.java +++ /dev/null @@ -1,359 +0,0 @@ -package org.labkey.mergesync; - -import org.jetbrains.annotations.NotNull; -import org.labkey.api.collections.CaseInsensitiveTreeSet; -import org.labkey.api.data.Container; -import org.labkey.api.data.ContainerFilter; -import org.labkey.api.data.DbSchema; -import org.labkey.api.data.JdbcType; -import org.labkey.api.data.SQLFragment; -import org.labkey.api.data.TableInfo; -import org.labkey.api.data.VirtualTable; -import org.labkey.api.module.Module; -import org.labkey.api.query.DefaultSchema; -import org.labkey.api.query.ExprColumn; -import org.labkey.api.query.QuerySchema; -import org.labkey.api.query.SimpleUserSchema; -import org.labkey.api.security.User; - -import java.util.Collections; -import java.util.Set; - -/** - - */ -public class MergeSyncUserSchema extends SimpleUserSchema -{ - public static final String TABLE_MERGE_RESULTS = "merge_results"; - public static final String TABLE_MERGE_RUNS = "merge_runs"; - - private MergeSyncUserSchema(User user, Container container, DbSchema schema) - { - super(MergeSyncSchema.NAME, null, user, container, schema); - } - - public static void register(final Module m) - { - final DbSchema dbSchema = DbSchema.get(MergeSyncSchema.NAME); - - DefaultSchema.registerProvider(MergeSyncSchema.NAME, new DefaultSchema.SchemaProvider(m) - { - @Override - public QuerySchema createSchema(final DefaultSchema schema, Module module) - { - return new MergeSyncUserSchema(schema.getUser(), schema.getContainer(), dbSchema); - } - }); - } - - @Override - public Set getTableNames() - { - Set ret = new CaseInsensitiveTreeSet(); - ret.addAll(super.getTableNames()); - ret.add(TABLE_MERGE_RESULTS); - ret.add(TABLE_MERGE_RUNS); - - return Collections.unmodifiableSet(ret); - } - - @Override - public Set getVisibleTableNames() - { - return getTableNames(); - } - - @Override - public TableInfo createTable(String name, ContainerFilter cf) - { - if (TABLE_MERGE_RESULTS.equalsIgnoreCase(name)) - { - DbSchema schema = MergeSyncManager.get().getMergeSchema(); - if (schema != null) - return getMergeDataTable(schema, cf); - } - else if (TABLE_MERGE_RUNS.equalsIgnoreCase(name)) - { - DbSchema schema = MergeSyncManager.get().getMergeSchema(); - if (schema != null) - return getMergeRunsTable(schema, cf); - } - - return super.createTable(name, cf); - } - - public static TableInfo getMergeDataTable(DbSchema schema, ContainerFilter cf) - { - return new VirtualTable(schema, TABLE_MERGE_RESULTS, null, cf) - { - { - setTitle("Merge Raw Result Data"); - setupColumns(); - } - - @NotNull - @Override - public SQLFragment getFromSQL() - { - SQLFragment ret = new SQLFragment(); - ret.append("select\n"); - ret.append("r.RE_FINAL as isFinal,\n"); - ret.append("t.TS_Stat as status,\n"); - - //is this needed? it doesnt seem to connect back to a user name. USERS has very generic names - //if there a differnet field holding user name? - //--o.O_DOCTOR as orderedby, - - ret.append("o.O_ACCNUM as accession,\n"); - ret.append("t.TS_INDEX as panelId,\n"); - ret.append("p.Pt_Lname as animalId,\n"); - ret.append("IsNumeric(p.Pt_Lname) as numericLastName,\n"); - //ret.append(MergeSyncUserSchema.getDateConversionSql("r.RE_DATE", "r.RE_TZ") + " as date,\n"); - // ret.append(MergeSyncUserSchema.getDateConversionSql("t.TS_VDT", "t.TS_VTZ") + " as dateVerified,\n"); - ret.append("i.INS_NAME as project,\n"); - ret.append(MergeSyncUserSchema.getDateConversionSql("o.O_COLLDT", "o.O_CLTZ") + " as dateCollected,\n"); - ret.append(MergeSyncUserSchema.getDateConversionSql("o.O_DATE", "o.O_DTZ") + " as dateOrdered,\n"); - - //Added new column 3-24-2016 R. Blasa - ret.append(MergeSyncUserSchema.getDateConversionSql("t.TS_VDT", "t.TS_VTZ") + " as date,\n"); - ret.append(MergeSyncUserSchema.getDateConversionSql("t.TS_VDT", "t.TS_VTZ") + " as dateVerified,\n"); - - //ret.append(MergeSyncUserSchema.getDateConversionSql("r.RE_DATE", "r.RE_TZ") + " as runDate,\n"); - - //Added new column 3-24-2016 R. Blasa - ret.append(MergeSyncUserSchema.getDateConversionSql("t.TS_VDT", "t.TS_VTZ") + " as runDate,\n"); - - ret.append("ti.T_ABBR as servicename_abbr,\n"); - ret.append("ti.T_NAME as servicename,\n"); - ret.append("pr.PR_LOGIN as doctorLogin,\n"); - ret.append("pr.PR_LNAME as doctorLastName,\n"); - ret.append("pr.PR_FNAME as doctorFirstName,\n"); - ret.append("tech.PR_LOGIN as techLogin,\n"); - ret.append("tech.PR_LNAME as techLastName,\n"); - ret.append("tech.PR_FNAME as techFirstName,\n"); - - ret.append("rs.RT_ABBR as testId_abbr,\n"); - ret.append("rs.RT_RDSCR as testId,\n"); - ret.append("r.re_data as text_result,\n"); - ret.append("r.RE_FLVAL as numeric_result,\n"); - ret.append("r.re_Text as remark,\n"); - ret.append("cm.RSC_COMMENT as runRemark,\n"); - ret.append("(SELECT max(r.re_data) as expr\n"); - ret.append("FROM results r \n"); - ret.append("LEFT JOIN RSLTTYP rs ON (rs.RT_RIDX = r.RE_RIDX)\n"); - ret.append("WHERE r.RE_ACCNR = o.O_ACCNUM\n"); - ret.append("AND r.RE_TIDX = t.TS_INDEX\n"); - ret.append("AND rs.RT_ABBR = 'COM 1:'\n"); - ret.append("AND r.re_data IS NOT NULL\n"); - ret.append("AND r.re_data != ''\n"); - ret.append(") as runComment\n"); - - //one row per batch of orders - ret.append("FROM Orders o\n"); - - //many panels could be ordered at a time - //TODO: what about failures and repeats? - ret.append("LEFT JOIN tests t ON (t.TS_ACCNR = o.O_ACCNUM)\n"); - - //contains reference info about that panel - ret.append("LEFT JOIN TESTINFO ti ON (ti.T_TSTNUM = t.TS_TNUM)\n"); - - //there will usually be many results per panel - ret.append("LEFT JOIN results r ON (\n"); - ret.append("r.RE_ACCNR = o.O_ACCNUM\n"); - ret.append("AND r.RE_TIDX = t.TS_INDEX\n"); - //ret.append("--AND o.O_ptnum = r.re_ptnum\n"); - ret.append(")\n"); - - //translate test name - ret.append("LEFT JOIN RSLTTYP rs ON (rs.RT_RIDX = r.RE_RIDX)\n"); - - //append result comment. is this guaranteed 1:1 with results?? - ret.append("left join RESULT_COMMENTS cm on (\n"); - ret.append("cm.RSC_ACCNR = r.RE_ACCNR\n"); - ret.append("and cm.RSC_RIDX = r.RE_RIDX\n"); - ret.append("and cm.RSC_COMMENT != '>^'\n"); //this might mean something - ret.append("and cm.RSC_COMMENT != '<^'\n"); //this might mean something - ret.append(")\n"); - - //there should only be 1 patient per order - ret.append("LEFT JOIN patients p ON (\n"); - ret.append("o.O_PTNUM = p.PT_NUM\n"); - - ret.append(")\n"); - - ret.append("LEFT JOIN PRSNL pr ON (o.O_DOCTOR = pr.pr_num)\n"); - ret.append("LEFT JOIN PRSNL tech ON (o.O_EPRSN = tech.pr_num)\n"); - - //there should only be 1 visit per order - ret.append("LEFT JOIN VISITS v ON (o.O_VID = v.V_ID)\n"); - - //join to visit/insurance - ret.append("LEFT JOIN Vis_Ins vi ON (vi.VINS_VID = v.V_ID)\n"); - - //join to insurance for project - ret.append("left join INSURANCE i ON (i.INS_INDEX = vi.VINS_INS1)\n"); - ret.append("WHERE rs.RT_ABBR != 'COM 1:'\n"); - return ret; - } - - protected void setupColumns() - { - addColumn(new ExprColumn(this, "accession", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".accession"), JdbcType.INTEGER)); - addColumn(new ExprColumn(this, "panelId", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".panelId"), JdbcType.INTEGER)); - addColumn(new ExprColumn(this, "animalId", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".animalId"), JdbcType.VARCHAR)); - var verifyDateCol = addColumn(new ExprColumn(this, "dateVerified", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".dateVerified"), JdbcType.TIMESTAMP)); - verifyDateCol.setFormat("yyyy-MM-dd HH:mm"); - - var dateCol = addColumn(new ExprColumn(this, "date", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".date"), JdbcType.TIMESTAMP)); - dateCol.setFormat("yyyy-MM-dd HH:mm"); - - addColumn(new ExprColumn(this, "projectName", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".project"), JdbcType.VARCHAR)); - var dateCollectedCol = addColumn(new ExprColumn(this, "dateCollected", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".dateCollected"), JdbcType.TIMESTAMP)); - dateCollectedCol.setFormat("yyyy-MM-dd HH:mm"); - - var dateOrderedCol = addColumn(new ExprColumn(this, "dateOrdered", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".dateCollected"), JdbcType.TIMESTAMP)); - dateOrderedCol.setFormat("yyyy-MM-dd HH:mm"); - - addColumn(new ExprColumn(this, "runDate", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".runDate"), JdbcType.TIMESTAMP)); - addColumn(new ExprColumn(this, "servicename_abbr", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".servicename_abbr"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "doctorLogin", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".doctorLogin"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "doctorLastName", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".doctorLastName"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "doctorFirstName", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".doctorFirstName"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "techLogin", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".techLogin"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "techLastName", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".techLastName"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "techFirstName", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".techFirstName"), JdbcType.VARCHAR)); - - addColumn(new ExprColumn(this, "testId_abbr", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".testId_abbr"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "testId", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".testId"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "text_result", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".text_result"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "numeric_result", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".numeric_result"), JdbcType.DOUBLE)); - addColumn(new ExprColumn(this, "remark", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".remark"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "runRemark", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".runRemark"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "runComment", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".runComment"), JdbcType.VARCHAR)); - - addColumn(new ExprColumn(this, "isFinal", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".isFinal"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "status", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".status"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "numericLastName", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".numericLastName"), JdbcType.BOOLEAN)); - } - }; - } - - public static TableInfo getMergeRunsTable(DbSchema schema, ContainerFilter cf) - { - return new VirtualTable(schema, TABLE_MERGE_RUNS, null, cf) - { - { - setTitle("Merge Run Data"); - setupColumns(); - } - - @NotNull - @Override - public SQLFragment getFromSQL() - { - SQLFragment ret = new SQLFragment(); - ret.append("select\n"); - ret.append(getSqlDialect().concatenate("CAST(o.O_ACCNUM as varchar)", "'<>'", "cast(t.TS_INDEX as varchar)")); - ret.append(" as pk,\n"); - - ret.append("t.TS_Stat as status,\n"); - - ret.append("o.O_ACCNUM as accession,\n"); - ret.append("t.TS_INDEX as panelId,\n"); - ret.append("p.Pt_Lname as animalId,\n"); - ret.append("IsNumeric(p.Pt_Lname) as numericLastName,\n"); - ret.append(MergeSyncUserSchema.getDateConversionSql("t.TS_VDT", "t.TS_VTZ") + " as date,\n"); - ret.append(MergeSyncUserSchema.getDateConversionSql("t.TS_VDT", "t.TS_VTZ") + " as dateVerified,\n"); - ret.append("i.INS_NAME as project,\n"); - ret.append(MergeSyncUserSchema.getDateConversionSql("o.O_COLLDT", "o.O_CLTZ") + " as dateCollected,\n"); - ret.append(MergeSyncUserSchema.getDateConversionSql("o.O_DATE", "o.O_DTZ") + " as dateOrdered,\n"); - ret.append("ti.T_ABBR as servicename_abbr,\n"); - ret.append("ti.T_NAME as servicename,\n"); - ret.append("pr.PR_LOGIN as doctorLogin,\n"); - ret.append("pr.PR_LNAME as doctorLastName,\n"); - ret.append("pr.PR_FNAME as doctorFirstName,\n"); - - ret.append("tech.PR_LOGIN as techLogin,\n"); - ret.append("tech.PR_LNAME as techLastName,\n"); - ret.append("tech.PR_FNAME as techFirstName,\n"); - ret.append("(SELECT max(r.re_data) as expr\n"); - ret.append("FROM results r \n"); - ret.append("LEFT JOIN RSLTTYP rs ON (rs.RT_RIDX = r.RE_RIDX)\n"); - ret.append("WHERE r.RE_ACCNR = o.O_ACCNUM\n"); - ret.append("AND r.RE_TIDX = t.TS_INDEX\n"); - ret.append("AND rs.RT_ABBR = 'COM 1:'\n"); - ret.append("AND r.re_data IS NOT NULL\n"); - ret.append("AND r.re_data != ''\n"); - ret.append(") as runRemark\n"); - - //one row per batch of orders - ret.append("FROM Orders o\n"); - - //many panels could be ordered at a time - ret.append("LEFT JOIN tests t ON (t.TS_ACCNR = o.O_ACCNUM)\n"); - - //contains reference info about that panel - ret.append("LEFT JOIN TESTINFO ti ON (ti.T_TSTNUM = t.TS_TNUM)\n"); - - //there should only be 1 patient per order - ret.append("LEFT JOIN patients p ON (\n"); - ret.append("o.O_PTNUM = p.PT_NUM\n"); - ret.append(")\n"); - - ret.append("LEFT JOIN PRSNL pr ON (o.O_DOCTOR = pr.pr_num)\n"); - ret.append("LEFT JOIN PRSNL tech ON (o.O_EPRSN = tech.pr_num)\n"); - - //there should only be 1 visit per order - ret.append("LEFT JOIN VISITS v ON (o.O_VID = v.V_ID)\n"); - - //join to visit/insurance - ret.append("LEFT JOIN Vis_Ins vi ON (vi.VINS_VID = v.V_ID)\n"); - - //join to insurance for project - ret.append("left join INSURANCE i ON (i.INS_INDEX = vi.VINS_INS1)\n"); - - return ret; - } - - protected void setupColumns() - { - addColumn(new ExprColumn(this, "accession", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".accession"), JdbcType.INTEGER)); - addColumn(new ExprColumn(this, "panelId", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".panelId"), JdbcType.INTEGER)); - addColumn(new ExprColumn(this, "animalId", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".animalId"), JdbcType.VARCHAR)); - var verifyDateCol = addColumn(new ExprColumn(this, "dateVerified", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".dateVerified"), JdbcType.TIMESTAMP)); - verifyDateCol.setFormat("yyyy-MM-dd HH:mm"); - - var dateCol = addColumn(new ExprColumn(this, "date", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".date"), JdbcType.TIMESTAMP)); - dateCol.setFormat("yyyy-MM-dd HH:mm"); - - addColumn(new ExprColumn(this, "projectName", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".project"), JdbcType.VARCHAR)); - var dateCollectedCol = addColumn(new ExprColumn(this, "dateCollected", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".dateCollected"), JdbcType.TIMESTAMP)); - dateCollectedCol.setFormat("yyyy-MM-dd HH:mm"); - - var dateOrderedCol = addColumn(new ExprColumn(this, "dateOrdered", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".dateCollected"), JdbcType.TIMESTAMP)); - dateOrderedCol.setFormat("yyyy-MM-dd HH:mm"); - - addColumn(new ExprColumn(this, "servicename_abbr", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".servicename_abbr"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "doctorLogin", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".doctorLogin"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "doctorLastName", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".doctorLastName"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "doctorFirstName", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".doctorFirstName"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "techLogin", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".techLogin"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "techLastName", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".techLastName"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "techFirstName", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".techFirstName"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "status", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".status"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "pk", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".pk"), JdbcType.VARCHAR)); - addColumn(new ExprColumn(this, "numericLastName", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".numericLastName"), JdbcType.BOOLEAN)); - addColumn(new ExprColumn(this, "runRemark", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".runRemark"), JdbcType.VARCHAR)); - - getMutableColumn("pk").setKeyField(true); - } - }; - } - - private static String getDateConversionSql(String colName, String tzColName) - { - //i dont know why merge doesnt store these offsets with the correct sign... - return "DATEADD(mi, (SELECT -1 * tz.TZ_OFFSET FROM TIMEZONES tz WHERE tz.ROWID = " + tzColName + "), " + colName + ")"; - } -} diff --git a/mergesync/src/org/labkey/mergesync/RequestSyncHelper.java b/mergesync/src/org/labkey/mergesync/RequestSyncHelper.java deleted file mode 100644 index 5c810d231..000000000 --- a/mergesync/src/org/labkey/mergesync/RequestSyncHelper.java +++ /dev/null @@ -1,732 +0,0 @@ -package org.labkey.mergesync; - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateUtils; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.labkey.api.collections.CaseInsensitiveHashMap; -import org.labkey.api.data.ColumnInfo; -import org.labkey.api.data.CompareType; -import org.labkey.api.data.Container; -import org.labkey.api.data.ContainerManager; -import org.labkey.api.data.DbSchema; -import org.labkey.api.data.DbScope; -import org.labkey.api.data.Results; -import org.labkey.api.data.SQLFragment; -import org.labkey.api.data.Selector; -import org.labkey.api.data.SimpleFilter; -import org.labkey.api.data.SqlExecutor; -import org.labkey.api.data.SqlSelector; -import org.labkey.api.data.Table; -import org.labkey.api.data.TableInfo; -import org.labkey.api.data.TableSelector; -import org.labkey.api.ehr.EHRDemographicsService; -import org.labkey.api.ehr.demographics.AnimalRecord; -import org.labkey.api.query.FieldKey; -import org.labkey.api.query.QueryService; -import org.labkey.api.security.User; -import org.labkey.api.security.UserManager; -import org.labkey.api.util.GUID; -import org.labkey.api.util.JobRunner; -import org.labkey.api.util.PageFlowUtil; -import org.labkey.api.util.Pair; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TimeZone; - -/** - * Syncs requests made in LK (ie. records from study.clinpathRuns) to merge. - * Primarily called through trigger scripts - */ -public class RequestSyncHelper -{ - private static final Logger _log = LogManager.getLogger(RequestSyncHelper.class); - protected final static SimpleDateFormat _dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - - private Container _container; - private User _user; - - public RequestSyncHelper(int userId, String containerId) - { - _user = UserManager.getUser(userId); - if (_user == null) - throw new RuntimeException("User does not exist: " + userId); - - _container = ContainerManager.getForId(containerId); - if (_container == null) - throw new RuntimeException("Container does not exist: " + containerId); - } - - public void asyncRequests(final Map[] rows) - { - if (!MergeSyncManager.get().isPushEnabled()) - { - _log.info("Merge push not enabled, skipping"); - return; - } - - JobRunner.getDefault().execute(new Runnable(){ - @Override - public void run() - { - doSyncRequest(Arrays.asList(rows)); - } - }); - } - - public void doSyncRequest(Collection rows) - { - if (!MergeSyncManager.get().isPushEnabled()) - { - _log.info("Merge push not enabled, skipping"); - return; - } - - MergeSyncManager.get().validateSettings(); - - DbSchema mergeSchema = MergeSyncManager.get().getMergeSchema(); - if (mergeSchema == null) - { - _log.error("Unable to find merge schema"); - return; - } - - Map>> recordsToSync = new HashMap<>(); - try - { - for (Map row : rows) - { - String animalId = (String)row.get("Id"); - Date date = (Date)row.get("date"); - String servicerequested = (String)row.get("servicerequested"); - String objectId = (String)row.get("objectid"); - String taskid = (String)row.get("taskid"); - String requestid = (String)row.get("requestid"); - String key = (taskid == null ? "" : taskid) + "<>" + (requestid == null ? "" : requestid) + "<>" + animalId + "<>" + _dateFormat.format(date); - - if (servicerequested == null || !shouldSyncService(servicerequested)) - { - _log.info("No mapping for service: " + servicerequested + ", skipping"); - return; - } - - _log.info("Syncing single request to merge for animal: " + animalId); - - if (hasBeenOrdered(_container, objectId)) - { - _log.error("Request has already been synced: " + objectId); - continue; - } - - List> list = recordsToSync.get(key); - if (list == null) - list = new ArrayList<>(); - - list.add(new CaseInsensitiveHashMap(row)); - - recordsToSync.put(key, list); - } - } - catch (SQLException e) - { - _log.error(e.getMessage(), e); - } - - if (recordsToSync.isEmpty()) - { - return; - } - - DbScope scope = mergeSchema.getScope(); - try (DbScope.Transaction transaction = scope.ensureTransaction()) - { - _log.info("Syncing requests to merge: " + recordsToSync.keySet().size()); - for (String key : recordsToSync.keySet()) - { - List> records = recordsToSync.get(key); - String[] tokens = key.split("<>"); - String taskId = StringUtils.trimToNull(tokens[0]); - String requestId = StringUtils.trimToNull(tokens[1]); - - //create 1 record per batch of tests - String patientId = createPatientIfNeeded(mergeSchema, _container, _user, (String)records.get(0).get("Id")); - Integer doctorId = getMergeUserId(mergeSchema, _user, "DOC"); - Integer techId = getMergeUserId(mergeSchema, _user, "TECH"); - if (doctorId == null) - { - _log.error("Unable to resolve merge user id for: " + _user.getEmail() + " with role: DOC"); - return; - } - - if (techId == null) - { - _log.error("Unable to resolve merge user id for: " + _user.getEmail() + " with role: TECH"); - return; - } - - Integer insuranceId = createInsuranceIfNeeded(mergeSchema, _container, _user, (Integer)records.get(0).get("project")); - String visitId = createVisit(mergeSchema, _user, patientId, doctorId, techId, insuranceId, (Date)records.get(0).get("date")); - createCopyTo(mergeSchema, _user, patientId, doctorId, techId, visitId); - int orderId = createOrder(mergeSchema, _user, patientId, doctorId, techId, visitId, (Date)records.get(0).get("date")); - - //then 1 row per service type (clinpath runs record) - int letterIdx = 0; - for (Map row : records) - { - Integer mergeTestId = resolveMergeTestId(mergeSchema, (String)row.get("servicerequested")); - if (mergeTestId == null) - { - _log.error("Unable to find merge test name matching: " + row.get("servicerequested")); - continue; - } - - //TODO: figure out what scheme to use to batch tests by container - char containerName = ALPHABET[letterIdx]; - letterIdx++; - if (letterIdx > 25) - { - _log.error("More than 26 containers were used for a merge import. Restarting at A"); - } - letterIdx = letterIdx % 26; - - int containerId = createContainer(mergeSchema, _user, orderId, mergeTestId, doctorId, techId, (Date)records.get(0).get("date"), containerName); - int testId = createTest(mergeSchema, _user, patientId, visitId, orderId, containerId, mergeTestId, (Date)row.get("date"), containerName); - - //insert record into orderssynced - TableInfo ordersSynced = MergeSyncSchema.getInstance().getSchema().getTable(MergeSyncManager.TABLE_ORDERSSYNCED); - CaseInsensitiveHashMap toInsert = new CaseInsensitiveHashMap(); - toInsert.put("objectid", new GUID().toString()); - toInsert.put("runid", row.get("objectid")); - toInsert.put("order_accession", orderId); - toInsert.put("test_accession", testId); - toInsert.put("container", _container.getId()); - toInsert.put("createdby", _user.getUserId()); - toInsert.put("merge_datecreated", new Date()); - toInsert.put("created", new Date()); - toInsert.put("taskid", taskId); - toInsert.put("requestid", requestId); - toInsert.put("resultsreceived", false); - Table.insert(_user, ordersSynced, toInsert); - } - - _log.info("created merge order: " + orderId + ", with " + records.size() + " tests"); - } - - transaction.commit(); - _log.info("Finished syncing requests to merge"); - } - catch (SQLException e) - { - _log.error(e.getMessage(), e); - } - } - - private boolean shouldSyncService(String servicename) - { - TableInfo testMapping = MergeSyncSchema.getInstance().getSchema().getTable(MergeSyncManager.TABLE_TESTNAMEMAPPING); - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("servicename"), servicename, CompareType.EQUAL); - filter.addCondition(FieldKey.fromString("mergetestname"), null, CompareType.NONBLANK); - TableSelector ts = new TableSelector(testMapping, filter, null); - - return ts.exists(); - } - - private Integer resolveMergeTestId(DbSchema mergeSchema, String servicename) - { - if (servicename == null) - return null; - - TableInfo testMapping = MergeSyncSchema.getInstance().getSchema().getTable(MergeSyncManager.TABLE_TESTNAMEMAPPING); - TableSelector ts = new TableSelector(testMapping, PageFlowUtil.set("mergetestname"), new SimpleFilter(FieldKey.fromString("servicename"), servicename, CompareType.EQUAL), null); - List ret = ts.getArrayList(String.class); - if (ret.isEmpty()) - return null; - - TableInfo mergeTestNames = mergeSchema.getTable(MergeSyncManager.TABLE_MERGE_TESTINFO); - TableSelector ts2 = new TableSelector(mergeTestNames, PageFlowUtil.set("T_TSTNUM"), new SimpleFilter(FieldKey.fromString("T_ABBR"), ret.get(0), CompareType.EQUAL), null); - List ret2 = ts2.getArrayList(Integer.class); - - return ret2.isEmpty() ? null : ret2.get(0); - } - - private Map getMergeTestInfo(DbSchema mergeSchema, int mergeTestId) - { - TableInfo mergeTestNames = mergeSchema.getTable(MergeSyncManager.TABLE_MERGE_TESTINFO); - TableSelector ts = new TableSelector(mergeTestNames, PageFlowUtil.set("T_PARTOF", "T_TYPE", "T_COLLTB"), new SimpleFilter(FieldKey.fromString("T_TSTNUM"), mergeTestId, CompareType.EQUAL), null); - Map ret = ts.getMap(); - - return ret; - } - - private boolean hasBeenOrdered(Container c, String objectid) throws SQLException - { - TableInfo ordersSynced = MergeSyncSchema.getInstance().getSchema().getTable(MergeSyncManager.TABLE_ORDERSSYNCED); - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("runid"), objectid, CompareType.EQUAL); - filter.addCondition(FieldKey.fromString("container"), c.getId(), CompareType.EQUAL); - TableSelector ts = new TableSelector(ordersSynced, filter, null); - - return ts.exists(); - } - - private String createPatientIfNeeded(DbSchema mergeSchema, Container c, User u, String animalId) throws SQLException - { - TableInfo ti = mergeSchema.getTable(MergeSyncManager.TABLE_MERGE_PATIENTS); - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("PT_LNAME"), animalId); - TableSelector ts = new TableSelector(ti, Collections.singleton("PT_NUM"), filter, null); - List existing = ts.getArrayList(String.class); - if (!existing.isEmpty()) - { - if (existing.size() > 1) - { - _log.error("More than 1 matching patient found: " + animalId); - } - - return existing.get(0); - } - - return createPatient(mergeSchema, c, u, animalId); - } - - public static String createPatient(DbSchema mergeSchema, Container c, User u, String animalId) throws SQLException - { - TableInfo ti = mergeSchema.getTable(MergeSyncManager.TABLE_MERGE_PATIENTS); - - Map toInsert = new CaseInsensitiveHashMap<>(); - toInsert.put("PT_LNAME", animalId); - toInsert.put("PT_NUM", animalId); - - //increment index? - - AnimalRecord ar = EHRDemographicsService.get().getAnimal(c, animalId); - if (ar != null) - { - toInsert.put("PT_SEX", ar.getGender() == null ? null : ar.getGender().toUpperCase()); - toInsert.put("PT_DOB", ar.getBirth()); - String species = ar.getSpecies(); - String speciesCode = null; - if (species != null) - { - speciesCode = getSpeciesCode(species); - toInsert.put("PT_RACE", speciesCode); - } - - String firstName = speciesCode == null ? "" : "(" + speciesCode + ")"; - if (!"Alive".equals(ar.getCalculatedStatus())) - { - firstName += " *" + (ar.getCalculatedStatus() == null ? "Unknown" : ar.getCalculatedStatus()) + "*"; - } - else - { - firstName += " -"; - } - - toInsert.put("PT_FNAME", firstName); - } - - Map inserted = Table.insert(u, ti, toInsert); - - return (String)inserted.get("PT_NUM"); - } - - public static String getSpeciesCode(String species) - { - if (species == null) - return null; - - //first translate project Id into the name - TableInfo speciesTable = DbSchema.get("ehr_lookups").getTable("species"); - TableSelector ts = new TableSelector(speciesTable, PageFlowUtil.set("cites_code"), new SimpleFilter(FieldKey.fromString("common"), species), null); - List ret = ts.getArrayList(String.class); - - return ret != null && !ret.isEmpty() ? ret.get(0) : null; - } - - private Integer createInsuranceIfNeeded(DbSchema mergeSchema, Container c, User u, Integer project) throws SQLException - { - if (project == null) - return null; - - //first translate project Id into the name - TableInfo projectTable = QueryService.get().getUserSchema(u, c, "ehr").getTable("project"); - if (projectTable == null) - { - _log.error("Unable to find ehr.project in container: " + _container.getPath()); - return null; - } - - Set fks = PageFlowUtil.set(FieldKey.fromString("displayName"), FieldKey.fromString("investigatorId/lastName"), FieldKey.fromString("investigatorId/firstName"), FieldKey.fromString("enddate")); - final Map cols = QueryService.get().getColumns(projectTable, fks); - - TableSelector projectTs = new TableSelector(projectTable, cols.values(), new SimpleFilter(FieldKey.fromString("project"), project), null); - if (!projectTs.exists()) - { - _log.error("Unable to find project with Id: " + project + " in container: " + _container.getPath()); - return null; - } - - try (Results rs = projectTs.getResults()) - { - rs.next(); - String projectName = rs.getString(FieldKey.fromString("displayName")); - String lastName = rs.getString(FieldKey.fromString("investigatorId/lastName")); - Date enddate = rs.getDate(FieldKey.fromString("enddate")); - - TableInfo ti = mergeSchema.getTable(MergeSyncManager.TABLE_MERGE_INSURANCE); - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("INS_NAME"), projectName); - TableSelector ts = new TableSelector(ti, Collections.singleton("INS_INDEX"), filter, null); - List existing = ts.getArrayList(Integer.class); - if (!existing.isEmpty()) - { - if (existing.size() > 1) - { - _log.error("More than insurance found matching project: " + project); - } - - return existing.get(0); - } - - return createInsurance(mergeSchema, c, u, projectName, lastName, enddate); - } - } - - public static Integer createInsurance(DbSchema mergeSchema, Container c, User u, String projectName, String lastName, Date enddate) throws SQLException - { - TableInfo ti = mergeSchema.getTable(MergeSyncManager.TABLE_MERGE_INSURANCE); - boolean isExpired = enddate == null ? false : DateUtils.truncate(enddate, Calendar.DATE).getTime() < DateUtils.truncate(new Date(), Calendar.DATE).getTime(); - - Map toInsert = new CaseInsensitiveHashMap<>(); - toInsert.put("INS_NAME", projectName + (isExpired ? " (Expired)" : "")); - toInsert.put("INS_ADDR1", lastName); - toInsert.put("INS_INDEX", getAndIncrementIndex("INS_INDEX", ti)); - toInsert.put("INS_PRINT_IP", "N"); - toInsert.put("INS_PRINT_OP", "N"); - toInsert.put("INS_TYPE", (isExpired ? "C" : "I")); - - Map inserted = Table.insert(u, ti, toInsert); - - return (Integer)inserted.get("INS_INDEX"); - } - - private static int getAndIncrementIndex(String colName, TableInfo ti) - { - SqlSelector ss = new SqlSelector(ti.getSchema(), new SQLFragment("SELECT COALESCE(NX_NUM, NX_MIN) as expr FROM Nextnum WHERE nx_Fldnm = ?", colName)); - List ret = ss.getArrayList(Integer.class); - if (ret.isEmpty()) - { - throw new RuntimeException("Unknown index: " + colName); - } - - Integer i = ret.get(0); - - //increment this index - SqlExecutor se = new SqlExecutor(ti.getSchema()); - se.execute(new SQLFragment("UPDATE Nextnum SET NX_NUM = (? + 1) WHERE nx_Fldnm = ?", i, colName)); - - return i; - } - - private Integer getMergeUserId(DbSchema mergeSchema, User u, String role) - { - TableInfo ti = mergeSchema.getTable(MergeSyncManager.TABLE_MERGE_PERSONNEL); - Integer mergeUserId = null; - - //make 3 attempts to find the user. first use login - String displayName = u.getEmail(); - if (displayName != null && displayName.contains("@")) - { - displayName = displayName.split("@")[0]; - } - - if (mergeUserId == null && displayName != null) - { - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("PR_LOGIN"), displayName, CompareType.EQUAL); - filter.addCondition(FieldKey.fromString("PR_CLASS"), role); - TableSelector ts = new TableSelector(ti, PageFlowUtil.set("PR_NUM"), filter, null); - List ret = ts.getArrayList(Integer.class); - if (ret != null && ret.size() == 1) - { - mergeUserId = ret.get(0); - } - } - - //by convention, doctor logins append an 'x' to the end of the login - if (mergeUserId == null && displayName != null && "DOC".equals(role)) - { - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("PR_LOGIN"), displayName + "x", CompareType.EQUAL); - filter.addCondition(FieldKey.fromString("PR_CLASS"), role); - TableSelector ts = new TableSelector(ti, PageFlowUtil.set("PR_NUM"), filter, null); - List ret = ts.getArrayList(Integer.class); - if (ret != null && ret.size() == 1) - { - mergeUserId = ret.get(0); - } - } - - //then first/lastname - if (mergeUserId == null && u.getLastName() != null && u.getFirstName() != null) - { - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("PR_FNAME"), u.getFirstName(), CompareType.EQUAL); - filter.addCondition(FieldKey.fromString("PR_FNAME"), u.getLastName()); - filter.addCondition(FieldKey.fromString("PR_CLASS"), role); - TableSelector ts = new TableSelector(ti, PageFlowUtil.set("PR_NUM"), filter, null); - List ret = ts.getArrayList(Integer.class); - if (ret != null && ret.size() == 1) - { - mergeUserId = ret.get(0); - } - } - - if (mergeUserId != null) - { - return mergeUserId; - } - - //finally default to a static username, defined in module properties - String mergeUserName = MergeSyncManager.get().getMergeUserName(); - if (mergeUserName == null) - { - _log.error("Merge user not configured, cannot push requests to merge"); - return null; - } - - //NOTE: if defaulting back to the default login, always use DOC role - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("PR_LOGIN"), mergeUserName, CompareType.EQUAL); - filter.addCondition(FieldKey.fromString("PR_CLASS"), "DOC"); - TableSelector ts = new TableSelector(ti, PageFlowUtil.set("PR_NUM"), filter, null); - List ret = ts.getArrayList(Integer.class); - - Integer i = ret == null || ret.isEmpty() ? null : ret.get(0); - if (i == null) - { - _log.error("Unable to find merge userId matching the login: " + mergeUserName + " with the role: DOC"); - } - - return i; - } - - private void createCopyTo(DbSchema mergeSchema, User u, String patientId, int doctorId, int techId, String visitId) throws SQLException - { - TableInfo ti = mergeSchema.getTable(MergeSyncManager.TABLE_MERGE_COPY_TO); - - Map toInsert = new CaseInsensitiveHashMap<>(); - toInsert.put("CO_PTNUM", patientId); - toInsert.put("CO_VID", visitId); - toInsert.put("CO_TYPE", "D"); - toInsert.put("CO_DOC", doctorId); - - Table.insert(u, ti, toInsert); - } - - private String createVisit(DbSchema mergeSchema, User u, String patientId, int doctorId, int techId, Integer insuranceId, Date date) throws SQLException - { - TableInfo ti = mergeSchema.getTable(MergeSyncManager.TABLE_MERGE_VISITS); - - Map toInsert = new CaseInsensitiveHashMap<>(); - toInsert.put("V_PTNUM", patientId); - toInsert.put("V_TYPE", "O"); - toInsert.put("V_IO", "o"); - toInsert.put("V_ADMDT", convertDate(date)); - toInsert.put("V_ADTZ", getTZ(date, mergeSchema)); - toInsert.put("V_WARD", "ONPRC"); - toInsert.put("V_EPRSN", techId); - toInsert.put("V_WORKCOMP", "N"); - - //find next value in the series - toInsert.put("V_ID", "V" + getAndIncrementIndex("V_ID", ti)); - - //v_disdt, v_ht, v_wt, v_icd1, v_icd2, v_icd3, v_icd4, v_billtype, v_client all null? - - - Map inserted = Table.insert(u, ti, toInsert); - String V_ID = (String)inserted.get("V_ID"); - - //also create V_INS record - TableInfo visInsTable = mergeSchema.getTable(MergeSyncManager.TABLE_MERGE_VISIT_INS); - Map insToInsert = new CaseInsensitiveHashMap<>(); - insToInsert.put("vins_vid", V_ID); - insToInsert.put("vins_ins1", insuranceId); - Table.insert(u, visInsTable, insToInsert); - - return V_ID; - } - - private Integer _timezone = null; - - private int getTZ(Date date, DbSchema mergeSchema) - { - if (_timezone == null) - { - TimeZone tz = Calendar.getInstance().getTimeZone(); - String abbr = tz.getDisplayName(tz.inDaylightTime(date), TimeZone.SHORT); - TableInfo ti = mergeSchema.getTable("TIMEZONES"); - TableSelector ts = new TableSelector(ti, Collections.singleton("rowid"), new SimpleFilter(FieldKey.fromString("TZ_ABBR"), abbr), null); - List ret = ts.getArrayList(Integer.class); - - if (ret.isEmpty()) - { - _log.error("Unable to find timezone matching: " + abbr); - throw new RuntimeException("Unable to find timezone matching: " + abbr); - } - - _timezone = ret.get(0); - } - - return _timezone; - } - - private Date convertDate(Date d) - { - Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); - TimeZone zone = Calendar.getInstance().getTimeZone(); - cal.setTimeInMillis(d.getTime() - zone.getOffset(d.getTime())); - - return cal.getTime(); - } - - private final char[] ALPHABET = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; - - private int createContainer(DbSchema mergeSchema, User u, int orderId, int mergeTestId, int doctorId, int techId, Date date, Character containerName) throws SQLException - { - TableInfo containerTable = mergeSchema.getTable(MergeSyncManager.TABLE_MERGE_CONTAINERS); - Map testInfo = getMergeTestInfo(mergeSchema, mergeTestId); - - Map toInsert = new CaseInsensitiveHashMap<>(); - toInsert.put("CNT_INDEX", getAndIncrementIndex("CNT_INDEX", containerTable)); - toInsert.put("CNT_ACCNR", orderId); - - toInsert.put("CNT_MAP", containerName.toString()); - toInsert.put("CNT_STATUS", "C"); - toInsert.put("CNT_DATE", convertDate(date)); - toInsert.put("CNT_DTZ", getTZ(date, mergeSchema)); - toInsert.put("CNT_TECH", techId); - toInsert.put("CNT_LOC", null); - toInsert.put("CNT_CURRLOC", "ONP"); - toInsert.put("CNT_DESTLOC", "ONP"); - toInsert.put("CNT_TUID", testInfo.get("T_COLLTB")); - toInsert.put("CNT_LABMIC", "L"); - toInsert.put("CNT_DRAWLOC", "ONPRC"); - toInsert.put("CNT_DRAWDATE", convertDate(date)); - toInsert.put("CNT_DRTZ", getTZ(date, mergeSchema)); - toInsert.put("CNT_TYPE", "P"); - - Map inserted = Table.insert(u, containerTable, toInsert); - return (Integer)inserted.get("CNT_INDEX"); - } - - private int createOrder(DbSchema mergeSchema, User u, String patientId, int doctorId, int techId, String visitId, Date date) throws SQLException - { - TableInfo ti = mergeSchema.getTable(MergeSyncManager.TABLE_MERGE_ORDERS); - - Map toInsert = new CaseInsensitiveHashMap<>(); - toInsert.put("O_PTNUM", patientId); - toInsert.put("O_VID", visitId); - toInsert.put("O_STATUS", "C"); - toInsert.put("O_DATE", convertDate(date)); - toInsert.put("O_DTZ", getTZ(date, mergeSchema)); - toInsert.put("O_COLLDT", convertDate(date)); - toInsert.put("O_CLTZ", getTZ(date, mergeSchema)); - toInsert.put("O_CDT", convertDate(date)); - toInsert.put("O_CTZ", getTZ(date, mergeSchema)); - toInsert.put("O_RCVDT", convertDate(date)); - toInsert.put("O_RCVTZ", getTZ(date, mergeSchema)); - toInsert.put("O_PRIO", 50); - toInsert.put("O_RPTD", "N"); - toInsert.put("O_DOCTOR", doctorId); - toInsert.put("O_EPRSN", techId); - toInsert.put("O_FASTING", "N"); - toInsert.put("O_LOC", "ONP"); - toInsert.put("O_WARD", "ONPRC"); - toInsert.put("O_ACCNUM", getAndIncrementIndex("O_ACCNUM", ti)); - - Map inserted = Table.insert(u, ti, toInsert); - - return (Integer)inserted.get("O_ACCNUM"); - } - - private Pair getWorklistInfo(DbSchema mergeSchema, Integer mergeTestId) - { - SQLFragment sql = new SQLFragment("SELECT w.WK_WIDX, ws.W_DEPT FROM TESTINFO t " + - "left join dbo.WKSTTSTS w on (w.WK_TESTN = t.T_TSTNUM) " + - "left join WORKSTAT ws ON (w.WK_WIDX = ws.W_INDEX)" + - "where t.T_TSTNUM = ?", mergeTestId); - - SqlSelector ss = new SqlSelector(mergeSchema, sql); - final Pair pair = Pair.of(null, null); - ss.forEach(new Selector.ForEachBlock<>() - { - @Override - public void exec(ResultSet rs) throws SQLException - { - pair.first = rs.getInt("WK_WIDX"); - pair.second = rs.getString("W_DEPT"); - } - }); - - return pair; - } - - private int createTest(DbSchema mergeSchema, User u, String patientId, String visitId, int accession, int containerId, int mergeTestId, Date date, Character containerName) throws SQLException - { - TableInfo ti = mergeSchema.getTable(MergeSyncManager.TABLE_MERGE_TEST); - Map testInfo = getMergeTestInfo(mergeSchema, mergeTestId); - Pair worklistInfo = getWorklistInfo(mergeSchema, mergeTestId); - - Map toInsert = new CaseInsensitiveHashMap<>(); - toInsert.put("TS_TNUM", mergeTestId); - toInsert.put("TS_PLTNR", mergeTestId); - toInsert.put("TS_MASTR", testInfo.get("T_PARTOF")); - toInsert.put("TS_PTNUM", patientId); - toInsert.put("TS_VID", visitId); - toInsert.put("TS_ACCNR", accession); - toInsert.put("TS_DEPT", worklistInfo.second); - toInsert.put("TS_WKIDX", worklistInfo.first); - toInsert.put("TS_MAP", containerName.toString()); - toInsert.put("TS_STAT", "C"); - toInsert.put("TS_PRIO", 50); - toInsert.put("TS_EDT", convertDate(date)); - toInsert.put("TS_ETZ", getTZ(date, mergeSchema)); - toInsert.put("TS_COLDT", convertDate(date)); - toInsert.put("TS_CLTZ", getTZ(date, mergeSchema)); - toInsert.put("TS_FILLR", null); - toInsert.put("TS_STECH", null); - toInsert.put("TS_VTECH", null); - toInsert.put("TS_RMTRPT", null); - toInsert.put("TS_REFLEX", null); - toInsert.put("TS_DBID", null); - toInsert.put("TS_SYSTEM", null); - toInsert.put("TS_DNLOAD", null); - toInsert.put("TS_ICD", null); - toInsert.put("TS_MODS", null); - toInsert.put("TS_BILLTYPE", null); - toInsert.put("TS_REFFLABNO", null); - toInsert.put("TS_CHGXMT", null); - toInsert.put("TS_INDEX", getAndIncrementIndex("TS_INDEX", ti)); - - Map inserted = Table.insert(u, ti, toInsert); - - return (Integer)inserted.get("TS_INDEX"); - } - - public void deleteSyncRecords(String objectid) - { - if (objectid == null) - return; - - SQLFragment sql = new SQLFragment("UPDATE " + MergeSyncSchema.NAME + "." + MergeSyncManager.TABLE_ORDERSSYNCED + " SET deletedate = ? WHERE runid = ?", new Date(), objectid); - SqlExecutor se = new SqlExecutor(MergeSyncSchema.getInstance().getSchema()); - long deleted = se.execute(sql); - _log.info("deleted " + deleted + " merge sync records following clinpath record delete"); - } -} diff --git a/ogasync/build.gradle b/ogasync/build.gradle deleted file mode 100644 index 48b434881..000000000 --- a/ogasync/build.gradle +++ /dev/null @@ -1,13 +0,0 @@ -import org.labkey.gradle.util.BuildUtils - -plugins { - id 'org.labkey.build.module' -} - -dependencies { - BuildUtils.addLabKeyDependency(project: project, config: "implementation", depProjectPath: ":server:modules:LabDevKitModules:LDK", depProjectConfig: "apiJarFile") - - BuildUtils.addLabKeyDependency(project: project, config: "modules", depProjectPath: ":server:modules:LabDevKitModules:LDK", depProjectConfig: "published", depExtension: "module") - BuildUtils.addLabKeyDependency(project: project, config: "modules", depProjectPath: ":server:modules:ehrModules:ehr", depProjectConfig: "published", depExtension: "module") - BuildUtils.addLabKeyDependency(project: project, config: "modules", depProjectPath: ":server:modules:onprcEHRModules:onprc_ehr", depProjectConfig: "published", depExtension: "module") -} diff --git a/ogasync/module.properties b/ogasync/module.properties deleted file mode 100644 index 6b5d55d87..000000000 --- a/ogasync/module.properties +++ /dev/null @@ -1,3 +0,0 @@ -ModuleClass: org.labkey.ogasync.OGASyncModule -SupportedDatabases: mssql -ManageVersion: false diff --git a/ogasync/resources/queries/oga/ZGMS_PRIM_ALL_V.query.xml b/ogasync/resources/queries/oga/ZGMS_PRIM_ALL_V.query.xml deleted file mode 100644 index 58b0d67d2..000000000 --- a/ogasync/resources/queries/oga/ZGMS_PRIM_ALL_V.query.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - OGA Data Feed - - - -
-
-
-
diff --git a/ogasync/resources/queries/oga/grantProjects.query.xml b/ogasync/resources/queries/oga/grantProjects.query.xml deleted file mode 100644 index 403229683..000000000 --- a/ogasync/resources/queries/oga/grantProjects.query.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - OGA Grant Projects - - - OGA Project Number - - - OGA Award Number - - - Agency Award Number - - - PI - - - PI Employee Number - true - - - Project Title - - - Active Alias - - - Project Status - - - Award Status - - -
-
-
-
diff --git a/ogasync/resources/queries/oga/grantProjects.sql b/ogasync/resources/queries/oga/grantProjects.sql deleted file mode 100644 index df4057cbf..000000000 --- a/ogasync/resources/queries/oga/grantProjects.sql +++ /dev/null @@ -1,4 +0,0 @@ -SELECT -v.* - -FROM oga.ZGMS_PRIM_ALL_V v \ No newline at end of file diff --git a/ogasync/resources/queries/oga/grantProjects/.qview.xml b/ogasync/resources/queries/oga/grantProjects/.qview.xml deleted file mode 100644 index 574d5989d..000000000 --- a/ogasync/resources/queries/oga/grantProjects/.qview.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/ogasync/resources/queries/oga/grantProjects/Active Projects.qview.xml b/ogasync/resources/queries/oga/grantProjects/Active Projects.qview.xml deleted file mode 100644 index 7a38d80ed..000000000 --- a/ogasync/resources/queries/oga/grantProjects/Active Projects.qview.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/ogasync/resources/queries/oga/grants.query.xml b/ogasync/resources/queries/oga/grants.query.xml deleted file mode 100644 index a3949b1f4..000000000 --- a/ogasync/resources/queries/oga/grants.query.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - Grants - - - OGA Award Number - - - Agency Award Number - - - PI - - - PI Employee Number - true - - - Project Title - - - Active Alias - - - Award Status - - -
-
-
-
diff --git a/ogasync/resources/queries/oga/grants.sql b/ogasync/resources/queries/oga/grants.sql deleted file mode 100644 index ec215a299..000000000 --- a/ogasync/resources/queries/oga/grants.sql +++ /dev/null @@ -1,18 +0,0 @@ -SELECT - v.OGA_AWARD_NUMBER, - - count(distinct PI_EMP_NUM) as total_PI_EMP_NUM, - max(PI_EMP_NUM) as PI_EMP_NUM, - - count(distinct PROJECT_TITLE) as total_PROJECT_TITLE, - max(PROJECT_TITLE) as PROJECT_TITLE, - - count(distinct AWARD_STATUS) as total_AWARD_STATUS, - max(AWARD_STATUS) as AWARD_STATUS, - - count(distinct PI_EMP_NUM) as total_PI_EMP_NUM, - max(PI_EMP_NUM) as PI_EMP_NUM, - - -FROM oga.ZGMS_PRIM_ALL_V v -group by OGA_AWARD_NUMBER \ No newline at end of file diff --git a/ogasync/resources/views/begin.html b/ogasync/resources/views/begin.html deleted file mode 100644 index 0d78a9832..000000000 --- a/ogasync/resources/views/begin.html +++ /dev/null @@ -1,171 +0,0 @@ - - - -This page allows configuration of the OGA ETL. There can only be one instance of the ETL active per site at any time. Below are explanations for the config properties: -

- -
    -
  • - labkeyUser: A valid LabKey user, which should have admin permission in the target folder -
  • -
  • - labkeyContainer: The containerPath where the data will be saved -
  • -
  • - dataSourceName: The name of the data source, which should be defined in application.properties -
  • -
  • - schemaName: The name of the source schema -
  • -
  • - ogaQueryName: The name of the source table for OGA aliases -
  • -
  • - allQueryName: The name of the source table for all aliases -
  • -
  • - hourOfDay: The hour (0-23) when the sync should run. It will run once per day. -
  • -
-
\ No newline at end of file diff --git a/ogasync/resources/views/begin.view.xml b/ogasync/resources/views/begin.view.xml deleted file mode 100644 index 3c89d0328..000000000 --- a/ogasync/resources/views/begin.view.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/ogasync/src/org/labkey/ogasync/OGASyncController.java b/ogasync/src/org/labkey/ogasync/OGASyncController.java deleted file mode 100644 index 0248ca936..000000000 --- a/ogasync/src/org/labkey/ogasync/OGASyncController.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2013 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.labkey.ogasync; - -import org.labkey.api.action.ApiResponse; -import org.labkey.api.action.ApiSimpleResponse; -import org.labkey.api.action.MutatingApiAction; -import org.labkey.api.action.ReadOnlyApiAction; -import org.labkey.api.action.SpringActionController; -import org.labkey.api.data.ContainerManager; -import org.labkey.api.data.PropertyManager; -import org.labkey.api.data.PropertyManager.WritablePropertyMap; -import org.labkey.api.security.RequiresPermission; -import org.labkey.api.security.ValidEmail; -import org.labkey.api.security.permissions.AdminPermission; -import org.labkey.api.util.JobRunner; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; - -import java.util.HashMap; -import java.util.Map; - -public class OGASyncController extends SpringActionController -{ - private static final DefaultActionResolver _actionResolver = new DefaultActionResolver(OGASyncController.class); - - public OGASyncController() - { - setActionResolver(_actionResolver); - } - - @RequiresPermission(AdminPermission.class) - public static class RunEtlAction extends MutatingApiAction - { - @Override - public ApiResponse execute(Object form, BindException errors) - { - try - { - JobRunner.getDefault().execute(() -> new OGASyncRunner().run()); - } - catch (Exception e) - { - errors.reject(ERROR_MSG, e.getMessage()); - return null; - } - - return new ApiSimpleResponse("success", true); - } - - @Override - public void validateForm(Object form, Errors errors) - { - try - { - OGASyncManager.get().validateSettings(); - } - catch (Exception e) - { - errors.reject(ERROR_MSG, e.getMessage()); - } - } - } - - @RequiresPermission(AdminPermission.class) - public static class SetEtlDetailsAction extends MutatingApiAction - { - @Override - public ApiResponse execute(EtlAdminForm form, BindException errors) - { - Map resultProperties = new HashMap<>(); - - WritablePropertyMap configMap = PropertyManager.getWritableProperties(OGASyncManager.CONFIG_PROPERTY_DOMAIN, true); - - if (form.getLabkeyUser() != null) - { - try - { - new ValidEmail(form.getLabkeyUser()); - } - catch (ValidEmail.InvalidEmailException e) - { - errors.reject(ERROR_MSG, "Invalid email: " + e.getMessage()); - return null; - } - - configMap.put(OGASyncManager.LABKEY_USER_PROP_NAME, form.getLabkeyUser()); - } - - if (form.getLabkeyContainer() != null) - { - if (ContainerManager.getForPath(form.getLabkeyContainer()) == null) - { - errors.reject(ERROR_MSG, "Invalid container: " + form.getLabkeyContainer()); - return null; - } - - configMap.put(OGASyncManager.LABKEY_CONTAINER_PROP_NAME, form.getLabkeyContainer()); - } - - configMap.put(OGASyncManager.DATA_SOURCE_PROP_NAME, form.getDataSourceName()); - configMap.put(OGASyncManager.SCHEMA_PROP_NAME, form.getSchemaName()); - configMap.put(OGASyncManager.OGA_QUERY_PROP_NAME, form.getOgaQueryName()); - configMap.put(OGASyncManager.ALL_QUERY_PROP_NAME, form.getAllQueryName()); - - if (form.getHourOfDay() != null) - { - if (form.getHourOfDay() > 23 || form.getHourOfDay() < -1) - { - errors.reject(ERROR_MSG, "Hour of day must be between 0-23"); - return null; - } - - configMap.put(OGASyncManager.HOUR_PROP_NAME, form.getHourOfDay().toString()); - } - - if (form.getEtlStatus() != null) - configMap.put(OGASyncManager.ENABLED_PROP_NAME, form.getEtlStatus().toString()); - - configMap.save(); - - //if config was changed and the ETL is current scheduled to run, we need to restart it - OGASyncManager.get().onSettingsChange(); - - resultProperties.put("success", true); - - return new ApiSimpleResponse(resultProperties); - } - } - - public static class EtlAdminForm - { - private Boolean _etlStatus; - private String _labkeyUser; - private String _labkeyContainer; - private Integer _hourOfDay; - private String _dataSourceName; - private String _schemaName; - private String _ogaQueryName; - private String _allQueryName; - - public Boolean getEtlStatus() - { - return _etlStatus; - } - - public void setEtlStatus(Boolean etlStatus) - { - _etlStatus = etlStatus; - } - - public String getLabkeyUser() - { - return _labkeyUser; - } - - public void setLabkeyUser(String labkeyUser) - { - _labkeyUser = labkeyUser; - } - - public String getLabkeyContainer() - { - return _labkeyContainer; - } - - public void setLabkeyContainer(String labkeyContainer) - { - _labkeyContainer = labkeyContainer; - } - - public Integer getHourOfDay() - { - return _hourOfDay; - } - - public void setHourOfDay(Integer hourOfDay) - { - _hourOfDay = hourOfDay; - } - - public String getDataSourceName() - { - return _dataSourceName; - } - - public void setDataSourceName(String dataSourceName) - { - _dataSourceName = dataSourceName; - } - - public String getSchemaName() - { - return _schemaName; - } - - public void setSchemaName(String schemaName) - { - _schemaName = schemaName; - } - - public String getOgaQueryName() - { - return _ogaQueryName; - } - - public void setOgaQueryName(String ogaQueryName) - { - _ogaQueryName = ogaQueryName; - } - - public String getAllQueryName() - { - return _allQueryName; - } - - public void setAllQueryName(String allQueryName) - { - _allQueryName = allQueryName; - } - } - - @RequiresPermission(AdminPermission.class) - public static class GetEtlDetailsAction extends ReadOnlyApiAction - { - @Override - public ApiResponse execute(Object form, BindException errors) - { - Map resultProperties = new HashMap<>(); - resultProperties.put("enabled", OGASyncManager.get().isEnabled()); - resultProperties.put("lastRun", OGASyncManager.get().getLastRun()); - resultProperties.put("nextRun", OGASyncManager.get().getNextRun()); - - String[] etlConfigKeys = {OGASyncManager.LABKEY_USER_PROP_NAME, OGASyncManager.LABKEY_CONTAINER_PROP_NAME, OGASyncManager.DATA_SOURCE_PROP_NAME, OGASyncManager.SCHEMA_PROP_NAME, OGASyncManager.OGA_QUERY_PROP_NAME, OGASyncManager.ALL_QUERY_PROP_NAME, OGASyncManager.HOUR_PROP_NAME}; - - resultProperties.put("configKeys", etlConfigKeys); - resultProperties.put("config", PropertyManager.getProperties(OGASyncManager.CONFIG_PROPERTY_DOMAIN)); - - return new ApiSimpleResponse(resultProperties); - } - } -} \ No newline at end of file diff --git a/ogasync/src/org/labkey/ogasync/OGASyncManager.java b/ogasync/src/org/labkey/ogasync/OGASyncManager.java deleted file mode 100644 index b4f9c36ea..000000000 --- a/ogasync/src/org/labkey/ogasync/OGASyncManager.java +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (c) 2013 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.labkey.ogasync; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.labkey.api.data.Container; -import org.labkey.api.data.ContainerManager; -import org.labkey.api.data.DbSchema; -import org.labkey.api.data.DbSchemaType; -import org.labkey.api.data.DbScope; -import org.labkey.api.data.PropertyManager; -import org.labkey.api.data.PropertyManager.WritablePropertyMap; -import org.labkey.api.data.TableInfo; -import org.labkey.api.security.User; -import org.labkey.api.security.UserManager; -import org.labkey.api.security.ValidEmail; -import org.labkey.api.util.JobRunner; -import org.quartz.CronScheduleBuilder; -import org.quartz.JobBuilder; -import org.quartz.JobDetail; -import org.quartz.Trigger; -import org.quartz.TriggerBuilder; -import org.quartz.impl.StdSchedulerFactory; - -import java.util.Date; - -public class OGASyncManager -{ - private static final OGASyncManager _instance = new OGASyncManager(); - - private OGASyncManager() - { - - } - - public static OGASyncManager get() - { - return _instance; - } - - private static final Logger _log = LogManager.getLogger(OGASyncManager.class); - public static final String LABKEY_USER_PROP_NAME = "labkeyUser"; - public static final String LABKEY_CONTAINER_PROP_NAME = "labkeyContainer"; - public static final String ENABLED_PROP_NAME = "etlStatus"; - public static final String HOUR_PROP_NAME = "hourOfDay"; - public static final String DATA_SOURCE_PROP_NAME = "dataSourceName"; - public static final String LAST_RUN_PROP_NAME = "lastRun"; - public static final String SCHEMA_PROP_NAME = "schemaName"; - public static final String OGA_QUERY_PROP_NAME = "ogaQueryName"; - public static final String ALL_QUERY_PROP_NAME = "allQueryName"; - - public static final String CONFIG_PROPERTY_DOMAIN = "org.labkey.ogasync.etl.config"; - - private JobDetail _job = null; - private Trigger _trigger = null; - private Integer _hourOfDay = null; - - public synchronized void schedule() - { - if (!isEnabled()) - return; - - try - { - validateSettings(); - _hourOfDay = getHourOfDay(); - - if (_hourOfDay <= 0) - { - _log.error("OGA sync has an invalid frequency, will not schedule: " + _hourOfDay); - return; - } - - if (_job == null) - { - _job = JobBuilder.newJob(OGASyncRunner.class) - .withIdentity(OGASyncRunner.class.getCanonicalName(), OGASyncRunner.class.getCanonicalName()) - .usingJobData("ogaSync", OGASyncRunner.class.getName()) - .build(); - } - - _trigger = TriggerBuilder.newTrigger() - .withIdentity(OGASyncRunner.class.getCanonicalName(), OGASyncRunner.class.getCanonicalName()) - .withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(_hourOfDay, 0)) - .forJob(_job) - .build(); - - StdSchedulerFactory.getDefaultScheduler().scheduleJob(_job, _trigger); - - _log.info("OGA sync scheduled to run at " + getHourOfDay() + ":00 each day"); - } - catch (IllegalArgumentException e) - { - _log.error("OGA sync is enabled, but the saved setting are invalid. Sync will not start.", e); - return; - } - catch (Exception e) - { - _log.error("Error scheduling OGA sync", e); - } - } - - public synchronized void unschedule() - { - if (_job != null) - { - try - { - StdSchedulerFactory.getDefaultScheduler().deleteJob(_job.getKey()); - _trigger = null; - _log.info("OGA sync unscheduled"); - } - catch (Exception e) - { - _log.error("Error unscheduling OGA sync", e); - } - } - } - - public void onSettingsChange() - { - if (!isEnabled()) - { - if (_job != null) - unschedule(); - } - else - { - try - { - validateSettings(); - - if (_job == null) - { - schedule(); - } - else - { - if (!_hourOfDay.equals(getHourOfDay())) - { - _log.info("Rescheduling OGA Sync due to change in settings"); - unschedule(); - schedule(); - } - - //this indicates it is already scheduled with the correct frequency - } - } - catch (Exception e) - { - //ignore - } - } - } - - public void init() - { - if (isEnabled() && _trigger == null) - { - _log.info("scheduling OGA sync"); - JobRunner.getDefault().execute(new Runnable(){ - @Override - public void run() - { - schedule(); - } - }, 10000); - } - } - - public Date getNextRun() - { - if (_trigger == null) - return null; - - return _trigger.getFireTimeAfter(new Date()); - } - - public int getHourOfDay() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(HOUR_PROP_NAME); - if (prop == null) - return -1; - - Integer value = Integer.parseInt(prop); - if (value == null) - { - return -1; - } - - return value; - } - - public Date getLastRun() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(LAST_RUN_PROP_NAME); - if (prop == null) - return null; - - Long value = Long.parseLong(prop); - if (value == null) - { - return null; - } - - return new Date(value); - } - - public String getDataSourceName() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(DATA_SOURCE_PROP_NAME); - if (prop == null) - return null; - - return prop; - } - - public String getSchemaName() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(SCHEMA_PROP_NAME); - if (prop == null) - return null; - - return prop; - } - - - public String getOgaQueryName() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(OGA_QUERY_PROP_NAME); - if (prop == null) - return null; - - return prop; - } - - public String getAllQueryName() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(ALL_QUERY_PROP_NAME); - if (prop == null) - return null; - - return prop; - } - - public boolean isEnabled() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(ENABLED_PROP_NAME); - if (prop == null) - return false; - - Boolean value = Boolean.parseBoolean(prop); - if (value == null) - { - return false; - } - - return value; - } - - public User getLabKeyUser() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(LABKEY_USER_PROP_NAME); - if (prop == null) - return null; - - try - { - ValidEmail email = new ValidEmail(prop); - return UserManager.getUser(email); - } - catch (ValidEmail.InvalidEmailException e) - { - _log.error("Invalid email saved for OGA Sync: " + e.getMessage()); - } - - return null; - } - - public Container getLabKeyContainer() - { - String prop = PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(LABKEY_CONTAINER_PROP_NAME); - if (prop == null) - return null; - - return ContainerManager.getForPath(prop); - } - - public void validateSettings() throws IllegalArgumentException - { - if (getLabKeyUser() == null) - throw new IllegalArgumentException("Unknown or invalid LabKey User"); - - if (PropertyManager.getProperties(CONFIG_PROPERTY_DOMAIN).get(LABKEY_CONTAINER_PROP_NAME) == null) - throw new IllegalArgumentException("No LabKey container set"); - - int hour = getHourOfDay(); - if (hour > 23) - throw new IllegalArgumentException("Hour of day cannot be more than 23"); - - if (isEnabled()) - { - if (hour < 0) - throw new IllegalArgumentException("Hour of day must be between 0-23"); - - if (getDataSourceName() == null) - throw new IllegalArgumentException("Must provide a data source name"); - - DbScope scope = DbScope.getDbScope(getDataSourceName()); - if (scope == null) - throw new IllegalArgumentException("Unknown data source: " + getDataSourceName()); - - if (getSchemaName() == null) - throw new IllegalArgumentException("Must provide a schemaName"); - - if (getOgaQueryName() == null) - throw new IllegalArgumentException("Must provide a queryName for OGA aliases"); - - if (getAllQueryName() == null) - throw new IllegalArgumentException("Must provide a queryName for all aliases"); - - DbSchema schema = scope.getSchema(getSchemaName(), DbSchemaType.Bare); - if (schema == null) - throw new IllegalArgumentException("Unknown schema: " + getSchemaName()); - - TableInfo ti = schema.getTable(getOgaQueryName()); - if (ti == null) - throw new IllegalArgumentException("Unknown table: " + getOgaQueryName()); - - TableInfo ti2 = schema.getTable(getAllQueryName()); - if (ti2 == null) - throw new IllegalArgumentException("Unknown table: " + getOgaQueryName()); - } - } - - public void setLastRun(Date date) - { - WritablePropertyMap pm = PropertyManager.getWritableProperties(CONFIG_PROPERTY_DOMAIN, true); - pm.put(LAST_RUN_PROP_NAME, String.valueOf(date.getTime())); - pm.save(); - } -} \ No newline at end of file diff --git a/ogasync/src/org/labkey/ogasync/OGASyncModule.java b/ogasync/src/org/labkey/ogasync/OGASyncModule.java deleted file mode 100644 index fb7c469e9..000000000 --- a/ogasync/src/org/labkey/ogasync/OGASyncModule.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2013 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.labkey.ogasync; - -import org.jetbrains.annotations.Nullable; -import org.labkey.api.data.ContainerManager; -import org.labkey.api.ldk.ExtendedSimpleModule; -import org.labkey.api.module.ModuleContext; -import org.labkey.api.query.DetailsURL; -import org.labkey.api.security.permissions.AdminPermission; -import org.labkey.api.settings.AdminConsole; - -public class OGASyncModule extends ExtendedSimpleModule -{ - @Override - public String getName() - { - return "OGASync"; - } - - @Override - public @Nullable Double getSchemaVersion() - { - return null; - } - - @Override - public boolean hasScripts() - { - return false; - } - - @Override - protected void init() - { - addController("ogasync", OGASyncController.class); - } - - @Override - public void doStartupAfterSpringConfig(ModuleContext moduleContext) - { - OGASyncManager.get().init(); - DetailsURL details = DetailsURL.fromString("/ogaSync-begin.view", ContainerManager.getSharedContainer()); - AdminConsole.addLink(AdminConsole.SettingsLinkType.Management, "oga sync admin", details.getActionURL(), AdminPermission.class); - } -} \ No newline at end of file diff --git a/ogasync/src/org/labkey/ogasync/OGASyncRunner.java b/ogasync/src/org/labkey/ogasync/OGASyncRunner.java deleted file mode 100644 index 9dc312afd..000000000 --- a/ogasync/src/org/labkey/ogasync/OGASyncRunner.java +++ /dev/null @@ -1,543 +0,0 @@ -package org.labkey.ogasync; - -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.jetbrains.annotations.Nullable; -import org.labkey.api.collections.CaseInsensitiveHashMap; -import org.labkey.api.data.CompareType; -import org.labkey.api.data.Container; -import org.labkey.api.data.DbSchema; -import org.labkey.api.data.DbSchemaType; -import org.labkey.api.data.DbScope; -import org.labkey.api.data.SQLFragment; -import org.labkey.api.data.Selector; -import org.labkey.api.data.SimpleFilter; -import org.labkey.api.data.SqlExecutor; -import org.labkey.api.data.SqlSelector; -import org.labkey.api.data.Table; -import org.labkey.api.data.TableInfo; -import org.labkey.api.data.TableSelector; -import org.labkey.api.exp.api.ExperimentService; -import org.labkey.api.query.FieldKey; -import org.labkey.api.query.QueryService; -import org.labkey.api.security.User; -import org.labkey.api.util.PageFlowUtil; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; - -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; - -/** - * User: bimber - * Date: 10/10/13 - * Time: 12:26 PM - */ -public class OGASyncRunner implements Job -{ - private static final Logger _log = LogManager.getLogger(OGASyncRunner.class); - private static final String INVESTIGATOR_EMPLOYYE_ID_NUMBER = "investigatorEmployeeNumber"; - private static final String FISCAL_AUTHORITY_EMPLOYEE_ID_NUMBER = "fiscalAuthorityNumber"; - private static final String ADFM_EMP_NUM = "ADFM_EMP_NUM"; - private static final String AWARD_STATUS = "awardStatus"; - private static final String PROJECT_STATUS = "projectStatus"; - - public OGASyncRunner() - { - - } - - @Override - public void execute(JobExecutionContext context) throws JobExecutionException - { - if (!OGASyncManager.get().isEnabled()) - return; - - run(); - } - - public void run() - { - _log.info("Starting OGA Sync"); - OGASyncManager.get().validateSettings(); - - User u = OGASyncManager.get().getLabKeyUser(); - Container c = OGASyncManager.get().getLabKeyContainer(); - if (c == null) - { - _log.error("Invalid LabKey container"); - return; - } - - TableInfo sourceTable = getOGAAliasesTable(); - if (sourceTable == null) - { - _log.error("Unable to find OGA aliases table"); - return; - } - - DbSchema targetSchema = DbSchema.get("onprc_billing"); - if (targetSchema == null) - { - _log.error("Unable to find schema: onprc_billing"); - return; - } - - try - { - doMergeInvestigators(u, c, sourceTable, targetSchema); - doMergeGrants(u, c, sourceTable, targetSchema); - doMergeGrantProjects(u, c, sourceTable, targetSchema); - doMergeOGAAccounts(u, c, sourceTable, targetSchema); - - doMergeOtherAccounts(u, c, sourceTable, targetSchema); - - updateStats(targetSchema); - } - catch (SQLException e) - { - _log.error(e.getMessage(), e); - } - - OGASyncManager.get().setLastRun(new Date()); - _log.info("Finished OGA Sync"); - } - - private TableInfo getOGAAliasesTable() - { - DbScope scope = DbScope.getDbScope(OGASyncManager.get().getDataSourceName()); - if (scope == null) - return null; - - DbSchema schema = scope.getSchema(OGASyncManager.get().getSchemaName(), DbSchemaType.Bare); - if (schema == null) - return null; - - TableInfo ti = schema.getTable(OGASyncManager.get().getOgaQueryName()); - if (ti == null) - return null; - - return ti; - } - - private TableInfo getAllAliasesTable() - { - DbScope scope = DbScope.getDbScope(OGASyncManager.get().getDataSourceName()); - if (scope == null) - return null; - - DbSchema schema = scope.getSchema(OGASyncManager.get().getSchemaName(), DbSchemaType.Bare); - if (schema == null) - return null; - - TableInfo ti = schema.getTable(OGASyncManager.get().getAllQueryName()); - if (ti == null) - return null; - - return ti; - } - - public void doMergeGrantProjects(User u, Container c, TableInfo sourceTable, DbSchema targetSchema) throws SQLException - { - TableInfo targetTable = targetSchema.getTable("grantProjects"); - Map fieldMap = new LinkedHashMap<>(); - fieldMap.put("projectNumber", "OGA_PROJECT_NUMBER"); - fieldMap.put("grantNumber", "OGA_AWARD_NUMBER"); - fieldMap.put("agencyAwardNumber", "AGENCY_AWARD_NUMBER"); - fieldMap.put(INVESTIGATOR_EMPLOYYE_ID_NUMBER, "PI_EMP_NUM"); - fieldMap.put(FISCAL_AUTHORITY_EMPLOYEE_ID_NUMBER, "PDFM_EMP_NUM"); - fieldMap.put("investigatorName", "PI_FULL_NAME"); - - fieldMap.put("projectTitle", "PROJECT_TITLE"); - fieldMap.put("projectDescription", "PROJECT_DESCRIPTION"); - fieldMap.put("organization", "ORG"); - - fieldMap.put("budgetStartDate", "CURRENT_BUDGET_START_DATE"); - fieldMap.put("budgetEndDate", "CURRENT_BUDGET_END_DATE"); - - fieldMap.put("protocolNumber", "IACUC_NUMBER"); - fieldMap.put(PROJECT_STATUS, "PROJECT_STATUS"); - fieldMap.put("applicationType", "APPLICATION_TYPE"); - fieldMap.put("activityType", "ACTIVITY_TYPE"); - fieldMap.put("ogaProjectId", "PROJECT_ID"); - - TableSelector ts = new TableSelector(sourceTable, new LinkedHashSet<>(fieldMap.values())); - doMerge(u, c, targetTable, ts, "projectNumber", fieldMap, null, null, null, null); - } - - public void updateStats(DbSchema targetSchema) throws SQLException - { - TableInfo aliases = DbSchema.get("onprc_billing").getTable("aliases"); - SQLFragment analyze = targetSchema.getSqlDialect().getAnalyzeCommandForTable(aliases.getSelectName()); - new SqlExecutor(aliases.getSchema()).execute(analyze); - } - - public void doMergeOtherAccounts(User u, Container c, TableInfo sourceTable, DbSchema targetSchema) throws SQLException - { - TableInfo allAliases = getAllAliasesTable(); - - TableInfo targetTable = targetSchema.getTable("aliases"); - Map fieldMap = new LinkedHashMap<>(); - - fieldMap.put("alias", "ALIAS_NAME"); - fieldMap.put("aliasEnabled", "ENABLED_FLAG"); - - //fieldMap.put(FISCAL_AUTHORITY_EMPLOYEE_ID_NUMBER, "PDFM_EMP_NUM"); - fieldMap.put("category", null); - - fieldMap.put("budgetStartDate", "START_DATE_ACTIVE"); - fieldMap.put("budgetEndDate", "END_DATE_ACTIVE"); - - //find existing aliases - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("category"), "Other", CompareType.NEQ_OR_NULL); - filter.addCondition(FieldKey.fromString("container"), c.getId()); - TableSelector existingTs = new TableSelector(targetTable, PageFlowUtil.set("alias"), filter, null); - Collection existingKeys = existingTs.getCollection(String.class); - - //find existing FAs - SimpleFilter filter2 = new SimpleFilter(FieldKey.fromString("category"), "Other", CompareType.EQUAL); - filter2.addCondition(FieldKey.fromString("container"), c.getId()); - filter2.addCondition(new SimpleFilter.OrClause(new CompareType.CompareClause(FieldKey.fromString("fiscalAuthority"), CompareType.NONBLANK, null), new CompareType.CompareClause(FieldKey.fromString("investigatorid"), CompareType.NONBLANK, null))); - TableSelector existingTs2 = new TableSelector(targetTable, PageFlowUtil.set("alias", "fiscalAuthority", "investigatorid"), filter2, null); - final Map faMap = new HashMap<>(); - final Map investigatorMap = new HashMap<>(); - existingTs2.forEach(new Selector.ForEachBlock<>() - { - @Override - public void exec(ResultSet rs) throws SQLException - { - if (rs.getObject("fiscalAuthority") != null && rs.getInt("fiscalAuthority") != 0) - faMap.put(rs.getString("alias"), rs.getInt("fiscalAuthority")); - - if (rs.getObject("investigatorid") != null && rs.getInt("investigatorid") != 0) - investigatorMap.put(rs.getString("alias"), rs.getInt("investigatorid")); - } - }); - - TableSelector ts = new TableSelector(allAliases, new LinkedHashSet<>(fieldMap.values())); - doMerge(u, c, targetTable, ts, "alias", fieldMap, "Other", existingKeys, faMap, investigatorMap); - } - - public void doMergeOGAAccounts(User u, Container c, TableInfo sourceTable, DbSchema targetSchema) throws SQLException - { - TableInfo targetTable = targetSchema.getTable("aliases"); - Map fieldMap = new LinkedHashMap<>(); - - fieldMap.put("alias", "ALIAS"); - fieldMap.put("aliasEnabled", "ALIAS_ENABLED_FLAG"); - - fieldMap.put("projectNumber", "OGA_PROJECT_NUMBER"); - fieldMap.put("grantNumber", "OGA_AWARD_NUMBER"); - fieldMap.put("agencyAwardNumber", "AGENCY_AWARD_NUMBER"); - fieldMap.put(INVESTIGATOR_EMPLOYYE_ID_NUMBER, "PI_EMP_NUM"); - fieldMap.put(FISCAL_AUTHORITY_EMPLOYEE_ID_NUMBER, "PDFM_EMP_NUM"); - fieldMap.put(ADFM_EMP_NUM, "ADFM_EMP_NUM"); - fieldMap.put("fiscalAuthorityName", "PDFM_FULL_NAME"); - fieldMap.put("investigatorName", "PI_FULL_NAME"); - fieldMap.put("category", null); //special case handling below - fieldMap.put("aliasType", "OGA_AWARD_TYPE"); - - fieldMap.put("budgetStartDate", "CURRENT_BUDGET_START_DATE"); - fieldMap.put("budgetEndDate", "CURRENT_BUDGET_END_DATE"); - - fieldMap.put("faRate", "BURDEN_RATE"); - fieldMap.put("faSchedule", "BURDEN_SCHEDULE"); - - //new - fieldMap.put("projectTitle", "PROJECT_TITLE"); - fieldMap.put("projectDescription", "PROJECT_DESCRIPTION"); - fieldMap.put(PROJECT_STATUS, "PROJECT_STATUS"); - - - TableSelector ts = new TableSelector(sourceTable, new LinkedHashSet<>(fieldMap.values())); - doMerge(u, c, targetTable, ts, "alias", fieldMap, "OGA", null, null, null); - } - - public void doMergeGrants(User u, Container c, TableInfo sourceTable, DbSchema targetSchema) throws SQLException - { - TableInfo targetTable = targetSchema.getTable("grants"); - Map fieldMap = new LinkedHashMap<>(); - - fieldMap.put("grantNumber", "OGA_AWARD_NUMBER"); - //fieldMap.put("fundingAgency", ""); - //fieldMap.put("grantType", ""); - //fieldMap.put("", "AWARD_NUMBER"); - fieldMap.put("agencyAwardNumber", "AGENCY_AWARD_NUMBER"); - //fieldMap.put(INVESTIGATOR_EMPLOYYE_ID_NUMBER, "PI_EMP_NUM"); - fieldMap.put(FISCAL_AUTHORITY_EMPLOYEE_ID_NUMBER, ADFM_EMP_NUM); - //fieldMap.put("investigatorName", "PI_FULL_NAME"); - fieldMap.put("title", "PROJECT_TITLE"); - fieldMap.put(AWARD_STATUS, "AWARD_STATUS"); - fieldMap.put("projectDescription", "PROJECT_DESCRIPTION"); - fieldMap.put("applicationType", "APPLICATION_TYPE"); - fieldMap.put("activityType", "ACTIVITY_TYPE"); - fieldMap.put("budgetStartDate", "CURRENT_BUDGET_START_DATE"); - fieldMap.put("budgetEndDate", "CURRENT_BUDGET_END_DATE"); - fieldMap.put("awardSuffix", "AWARD_SUFFIX"); - fieldMap.put("organization", "ORG"); - fieldMap.put("protocolNum", "IACUC_NUMBER"); - fieldMap.put("ogaAwardId", "AWARD_ID"); - - StringBuilder sql = new StringBuilder(); - sql.append("SELECT\n"); - - String delim = ""; - for (String fieldName : fieldMap.values()) - { - sql.append(delim); - delim = ",\n"; - if (fieldName.equalsIgnoreCase("OGA_AWARD_NUMBER")) - { - sql.append(fieldName); - } - else - { - sql.append("max(").append(fieldName).append(") AS ").append(fieldName); - } - } - - sql.append("\nFROM " + sourceTable.getSelectName()).append("\n"); - sql.append("GROUP BY OGA_AWARD_NUMBER"); - - SqlSelector ss = new SqlSelector(sourceTable.getSchema(), new SQLFragment(sql.toString())); - doMerge(u, c, targetTable, ss, "grantNumber", fieldMap, null, null, null, null); - } - - public void doMergeInvestigators(User u, Container c, TableInfo sourceTable, DbSchema targetSchema) - { - - - } - - /** - * This is not particularly efficient, but it runs in the background once per day, - * and total rows should not be that large - */ - public void doMerge(final User u, final Container c, final TableInfo targetTable, Selector selector, final String selectionKey, final Map fieldMap, final String category, final Collection existingAliases, @Nullable final Map faMap, @Nullable final Map investigatorMap) throws SQLException - { - _log.info("starting to merge table: " + targetTable.getName()); - - try (DbScope.Transaction transaction = ExperimentService.get().ensureTransaction()) - { - _log.info("truncating table"); - SqlExecutor ex = new SqlExecutor(targetTable.getSchema().getScope()); - ex.execute(new SQLFragment("DELETE FROM " + targetTable.getSelectName() + " WHERE container = ?" + (category != null ? " AND (category IS NULL OR category = '" + category + "')" : ""), c.getId())); - - final Map totals = new HashMap<>(); - totals.put("insert", 0); - totals.put("update", 0); - totals.put("total", 0); - final Date start = new Date(); - - selector.forEach(new Selector.ForEachBlock<>() - { - @Override - public void exec(ResultSet rs) throws SQLException - { - totals.put("total", totals.get("total") + 1); - if (totals.get("total") % 500 == 0) - { - _log.info("processed " + totals.get("total") + " rows in " + (((new Date()).getTime() - start.getTime()) / 1000) + " seconds"); - start.setTime(new Date().getTime()); - } - - Set columnNames = getColumnNames(rs); - - //first build the row - Map row = new CaseInsensitiveHashMap<>(); - row.put("container", c.getId()); - - for (String key : fieldMap.keySet()) - { - if (fieldMap.get(key) != null && !columnNames.contains(fieldMap.get(key))) - { - _log.error("Unknown column: " + fieldMap.get(key)); - } - else - { - if (key.equals(INVESTIGATOR_EMPLOYYE_ID_NUMBER)) - { - row.put("investigatorId", resolveInvestigatorId(c, u, rs.getString(fieldMap.get(key)))); - } - else if (targetTable.getName().equalsIgnoreCase("aliases") && "category".equals(key)) - { - row.put("category", category); - } - else if (key.equals(ADFM_EMP_NUM)) - { - continue; - } - else if (key.equals("faRate")) - { - row.put(key, rs.getDouble(fieldMap.get(key))); - } - else if (key.equals(FISCAL_AUTHORITY_EMPLOYEE_ID_NUMBER)) - { - String id = rs.getString(fieldMap.get(key)); - if (id == null && fieldMap.containsKey(ADFM_EMP_NUM)) - { - id = rs.getString(ADFM_EMP_NUM); - } - - row.put("fiscalAuthority", resolveFinancialAnalystId(c, u, id)); - } - else if (key.equals(AWARD_STATUS) || key.equals(PROJECT_STATUS)) - { - String val = (String) rs.getObject(fieldMap.get(key)); - if ("1000".equals(val)) - { - val = "At Risk"; - } - else if ("1002".equals(val)) - { - val = "On Hold"; - } - else if ("1003".equals(val)) - { - val = "Preliminary"; - } - else if ("1004".equals(val)) - { - val = "Uncloseable"; - } - else if ("1005".equals(val)) - { - val = "Destroyed"; - } - else if ("1006".equals(val)) - { - val = "Partial Setup"; - } - else if ("1007".equals(val)) - { - val = "Preaward"; - } - else if ("1008".equals(val)) - { - val = "No Cost Ext"; - } - else if ("1009".equals(val)) - { - val = "Archived"; - } - else if ("1010".equals(val)) - { - val = "IM Purged"; - } - else if ("1011".equals(val)) - { - val = "Capitalized"; - } - else if ("1012".equals(val)) - { - val = "Technical Issues"; - } - - row.put(key, val); - } - else - { - row.put(key, rs.getObject(fieldMap.get(key))); - } - } - } - - assert targetTable.getPkColumns().size() == 1 : "Incorrect number of PK columns for table: " + targetTable.getName(); - - if (existingAliases != null && existingAliases.contains(rs.getString(fieldMap.get("alias")))) - { - //TODO: consider update - } - else - { - if (faMap != null && faMap.containsKey(row.get("alias"))) - { - row.put("fiscalAuthority", faMap.get(row.get("alias"))); - } - - if (investigatorMap != null && investigatorMap.containsKey(row.get("alias"))) - { - row.put("investigatorid", investigatorMap.get(row.get("alias"))); - } - - row.put("modifiedby", u.getUserId()); - row.put("modified", new Date()); - - row.put("createdby", u.getUserId()); - row.put("created", new Date()); - Table.insert(u, targetTable, row); - - totals.put("insert", totals.get("insert") + 1); - } - } - }); - - transaction.commit(); - _log.info("finished merging table: " + targetTable.getName() + ". total inserts: " + totals.get("insert") + ". total updates: " + totals.get("update")); - } - } - - private Set getColumnNames(ResultSet rs) throws SQLException - { - Set columnNames = new HashSet<>(); - - ResultSetMetaData rsMetaData = rs.getMetaData(); - int numberOfColumns = rsMetaData.getColumnCount(); - - for (int i = 1; i < numberOfColumns + 1; i++) { - columnNames.add(rsMetaData.getColumnName(i)); - } - - return columnNames; - } - - private Map _investigatorMap = null; - - private Integer resolveInvestigatorId(Container c, User u, String employeeId) - { - if (_investigatorMap == null) - { - TableInfo ti = QueryService.get().getUserSchema(u, c, "onprc_ehr").getTable("investigators"); - TableSelector ts = new TableSelector(ti, PageFlowUtil.set("rowid", "employeeid")); - _investigatorMap = new HashMap<>(); - Collection> rows = ts.getMapCollection(); - for (Map row : rows) - { - if (row.containsKey("employeeid") && row.get("employeeid") != null) - _investigatorMap.put((String)row.get("employeeid"), (Integer)row.get("rowid")); - } - } - - return _investigatorMap.get(employeeId); - } - - private Map _financialAnalystMap = null; - - private Integer resolveFinancialAnalystId(Container c, User u, String employeeId) - { - if (_financialAnalystMap == null) - { - TableInfo ti = QueryService.get().getUserSchema(u, c, "onprc_billing").getTable("fiscalAuthorities"); - TableSelector ts = new TableSelector(ti, PageFlowUtil.set("rowid", "employeeid")); - _financialAnalystMap = new HashMap<>(); - Collection> rows = ts.getMapCollection(); - for (Map row : rows) - { - if (row.containsKey("employeeid") && row.get("employeeid") != null) - _financialAnalystMap.put((String)row.get("employeeid"), (Integer)row.get("rowid")); - } - } - - return _financialAnalystMap.get(employeeId); - } -} diff --git a/onprc_ehr/resources/queries/study/clinpathRuns/Requests.qview.xml b/onprc_ehr/resources/queries/study/clinpathRuns/Requests.qview.xml index 022367044..e8b0c0146 100644 --- a/onprc_ehr/resources/queries/study/clinpathRuns/Requests.qview.xml +++ b/onprc_ehr/resources/queries/study/clinpathRuns/Requests.qview.xml @@ -17,11 +17,6 @@ - - - - - diff --git a/onprc_ehr/resources/web/onprc_ehr/panel/EnterDataPanel.js b/onprc_ehr/resources/web/onprc_ehr/panel/EnterDataPanel.js index 07d179695..b3ad78b86 100644 --- a/onprc_ehr/resources/web/onprc_ehr/panel/EnterDataPanel.js +++ b/onprc_ehr/resources/web/onprc_ehr/panel/EnterDataPanel.js @@ -492,14 +492,9 @@ Ext4.define('onprc_ehr.panel.EnterDataPanel', { width: 200 },{ xtype: 'ldk-linkbutton', - text: 'Requests With Manual Results', + text: 'Requests', linkCls: 'labkey-text-link', - href: LABKEY.ActionURL.buildURL('query', 'executeQuery', null, {schemaName: 'study', 'query.queryName': 'Clinpath Runs', 'query.viewName': 'Requests', 'query.QCState/Label~startswith': 'Request:', 'query.servicerequested/chargetype~eq': 'Clinpath', 'query.mergeSyncInfo/automaticresults~eq': false}) - },{ - xtype: 'ldk-linkbutton', - text: 'Requests With Automatic Results', - linkCls: 'labkey-text-link', - href: LABKEY.ActionURL.buildURL('query', 'executeQuery', null, {schemaName: 'study', 'query.queryName': 'Clinpath Runs', 'query.viewName': 'Requests', 'query.QCState/Label~startswith': 'Request:', 'query.servicerequested/chargetype~eq': 'Clinpath', 'query.mergeSyncInfo/automaticresults~eq': true}) + href: LABKEY.ActionURL.buildURL('query', 'executeQuery', null, {schemaName: 'study', 'query.queryName': 'Clinpath Runs', 'query.viewName': 'Requests', 'query.QCState/Label~startswith': 'Request:', 'query.servicerequested/chargetype~eq': 'Clinpath'}) }] },{ layout: 'hbox', diff --git a/onprc_ehr/resources/web/onprc_ehr/panel/LabworkRequestInstructionsPanel.js b/onprc_ehr/resources/web/onprc_ehr/panel/LabworkRequestInstructionsPanel.js deleted file mode 100644 index e0d8fb19b..000000000 --- a/onprc_ehr/resources/web/onprc_ehr/panel/LabworkRequestInstructionsPanel.js +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2013-2014 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0 - */ -Ext4.define('ONPRC_EHR.panel.RequestInstructionsPanel', { - extend: 'Ext.panel.Panel', - alias: 'widget.onprc-labworkrequestinstructionspanel', - - initComponent: function(){ - var mergeURL = LABKEY.getModuleProperty('MergeSync', 'MergeURL'); - var items; - if (mergeURL){ - items = [{ - html: 'This form allows you to request Labwork, similar to requesting in Merge. After requesting Clinpath services through this form, this request will be created in Merge. You can print print labels through Merge.

' + - 'Click here to open Merge

' + - 'Click here for instructions on Merge label printing', - style: 'padding: 5px;' - }] - } - else { - items = [{ - html: 'The Merge URL has not been configured for this site', - style: 'padding: 5px;' - }] - } - - Ext4.apply(this, { - defaults: { - border: false - }, - items: items - }); - - this.callParent(arguments); - } -}); \ No newline at end of file diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/dataentry/LabworkRequestFormType.java b/onprc_ehr/src/org/labkey/onprc_ehr/dataentry/LabworkRequestFormType.java index 6f44fb36d..9127f1a57 100644 --- a/onprc_ehr/src/org/labkey/onprc_ehr/dataentry/LabworkRequestFormType.java +++ b/onprc_ehr/src/org/labkey/onprc_ehr/dataentry/LabworkRequestFormType.java @@ -39,10 +39,6 @@ public LabworkRequestFormType(DataEntryFormContext ctx, Module owner) { super(ctx, owner, NAME, LABEL, "Requests", Arrays.asList( new RequestFormSection(), - - //Modified: 1-14-2019 R. Blasa No longer need Merge web link -// new LabworkRequestInstructionsFormSection(), - new AnimalDetailsFormSection(), new ClinpathRunsFormSection(true) )); @@ -55,7 +51,6 @@ public LabworkRequestFormType(DataEntryFormContext ctx, Module owner) //Added 2-8-2016 Blasa addClientDependency(ClientDependency.supplierFromPath("onprc_ehr/model/sources/labworkPanel.js")); - addClientDependency(ClientDependency.supplierFromModuleName("MergeSync")); addClientDependency(ClientDependency.supplierFromPath("onprc_ehr/panel/LabworkRequestDataEntryPanel.js")); setJavascriptClass("ONPRC_EHR.panel.LabworkRequestDataEntryPanel"); } diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/dataentry/LabworkRequestInstructionsFormSection.java b/onprc_ehr/src/org/labkey/onprc_ehr/dataentry/LabworkRequestInstructionsFormSection.java deleted file mode 100644 index b896826b8..000000000 --- a/onprc_ehr/src/org/labkey/onprc_ehr/dataentry/LabworkRequestInstructionsFormSection.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2014 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.labkey.onprc_ehr.dataentry; - -import org.labkey.api.ehr.dataentry.AbstractFormSection; -import org.labkey.api.ehr.dataentry.DataEntryFormContext; -import org.labkey.api.ehr.dataentry.FormElement; -import org.labkey.api.view.template.ClientDependency; - -import java.util.Collections; -import java.util.List; - -/** - * User: bimber - * Date: 6/9/13 - * Time: 4:15 PM - */ -public class LabworkRequestInstructionsFormSection extends AbstractFormSection -{ - public LabworkRequestInstructionsFormSection() - { - super("LabworkRequestInstructions", "Instructions", "onprc-labworkrequestinstructionspanel"); - - addClientDependency(ClientDependency.supplierFromPath("onprc_ehr/panel/LabworkRequestInstructionsPanel.js")); - } - - @Override - protected List getFormElements(DataEntryFormContext ctx) - { - return Collections.emptyList(); - } -}