Each type (Problem, Goal, Objective, and Intervention) has two tables, a data table and a link table.Each link table includes the links to full path of the given node.Some examples (from the sample data given below):Goal2 with a GOALID of 438 is linked:- TestingLinking1 Library (LIBID 9)
- Problem5 (PROBID 88 ) which in turn is linked to TestingLinking1.
- TestingLinking2 Library (LIBID 10)
This is represented in with the following rows in the 'link' tables.Problem_Link_Table:ID FACILITY LIBID PROBID1.88.9 1 9 88
Goal_Link_Table:ID FACILITY LIBID PROBID GOALID1.438.9.0 1 9 0 4381.438.9.88 1 9 88 4381.438.10.0 1 10 0 438
Notes:- The app uses Facility to keep the Production, Development and Testing data separate (that is right the data for each is stored in the same tables and differentiated with this column) … so all queries must link on facility.
- The ID of each row is made up of the ID columns concatenated together. For the data tables they are delimitated with the bar (|) character. For link tables they are delimitated with the dot (.) character.
/****************** library *********************/CREATE TABLE #Library_Data (ID varchar(254), FACILITY Int, library_year varchar(50), LIBID Int, Library_Name varchar(50), entry_date Datetime, entry_time varchar(50), entry_by varchar(50), effective_date Datetime, expiration_date Datetime, library_origin varchar(50), Wiley_Library_ID varchar(50), active_code varchar(50), active_value varchar(50))INSERT INTO #Library_DataSELECT '1||9',1,'1840',9,'TestingLinking1', '2007-08-30 00:00:00.000', 'Laurie Cox', 'Laurie Cox', '2007-08-29 00:00:00.000', NULL, 'Test', NULL, 'N', 'No' UNION ALLSELECT '1||10',1,'1840',10,'TestingLinking2', '2007-08-30 00:00:00.000', 'Laurie Cox', 'Laurie Cox', '2007-08-30 00:00:00.000', NULL, 'Test', NULL, 'N', 'No' /****************** Problems *********************/CREATE TABLE #Problem_Data (ID varchar(254), FACILITY Int, PROBID Int, prob_Text ntext, Wiley_Problem_ID varchar(50), suggested_diagnosis ntext)INSERT INTO #Problem_Data SELECT '1||87',1,87,'abc', 'Problem1', NULL UNION ALLSELECT '1||88',1,88,'def', 'Problem5', NULL UNION ALLSELECT '1||89',1,89,'est', 'Problem6', NULL CREATE TABLE #Problem_Link_Data (ID varchar(50), FACILITY Int, LIBID Int, PROBID Int)INSERT INTO #Problem_Link_Data SELECT '1.87.9',1,9,87 UNION ALLSELECT '1.88.9',1,9,88 UNION ALLSELECT '1.87.10',1,10,87 UNION ALLSELECT '1.89.10',1,10,89 /****************** Goals *********************/CREATE TABLE #Goal_Data(ID varchar(254), FACILITY Int, GOALID Int, goal_text ntext, Wiley_Goal_ID varchar(50))INSERT INTO #goal_data SELECT '1||437',1,437,'abc', 'Goal1' UNION ALLSELECT '1||438',1,438,'axy', 'Goal2' UNION ALLSELECT '1||439',1,439,'xyz', 'Goal4'CREATE TABLE #Goal_Link_Data (ID varchar(50), FACILITY Int, LIBID Int, PROBID Int, GOALID Int)INSERT INTO #Goal_Link_Data SELECT '1.438.9.0',1,9,0,438 UNION ALLSELECT '1.439.9.0',1,9,0,439 UNION ALLSELECT '1.437.9.87',1,9,87,437 UNION ALLSELECT '1.438.9.88',1,9,88,438 UNION ALLSELECT '1.438.10.0',1,10,0,438 UNION ALLSELECT '1.437.10.89',1,10,89,437 /****************** Objectives *********************/CREATE TABLE #Objective_Data (ID varchar(254), FACILITY Int, OBJID Int, objective_text ntext, Wiley_Objective_ID varchar(50))INSERT INTO #Objective_Data SELECT '1||1269',1,1269,'adf', 'Objective1' UNION ALLSELECT '1||1270',1,1270,'xyz', 'Objective2' UNION ALLSELECT '1||1271',1,1271,'aml', 'Objective3' CREATE TABLE #Objective_Link_Data (ID varchar(50), FACILITY Int, LIBID Int, PROBID Int, GOALID Int, OBJID Int)INSERT INTO #Objective_Link_Data SELECT '1.1271.9.0.0',1,9,0,0,1271 UNION ALLSELECT '1.1270.9.0.438',1,9,0,438,1270 UNION ALLSELECT '1.1269.9.87.437',1,9,87,437,1269 UNION ALLSELECT '1.1270.10.89.437',1,10,89,437,1270 /****************** Interventions *********************/CREATE TABLE #Intervention_Data (ID varchar(254), FACILITY Int, INTID Int, intervention_text ntext, Wiley_Intervention_ID varchar(50))INSERT INTO #Intervention_Data SELECT '1||1',1,1,'text', 'Intervention 1' UNION ALLSELECT '1||2469',1,2469,'axd', 'Intervention2' UNION ALLSELECT '1||2470',1,2470,'ad', 'Intervention3' UNION ALLSELECT '1||2471',1,2471,'ghf', 'Intervention4' UNION ALLSELECT '1||2472',1,2472,'dfg', 'Intervention6' UNION ALLSELECT '1||1',1,1,'text', 'Intervention 1' UNION ALLSELECT '1||2469',1,2469,'axd', 'Intervention2' UNION ALLSELECT '1||2470',1,2470,'ad', 'Intervention3' UNION ALLSELECT '1||2471',1,2471,'ghf', 'Intervention4' UNION ALLSELECT '1||2472',1,2472,'dfg', 'Intervention6' CREATE TABLE #Intervention_Link_Data (ID varchar(50), FACILITY Int, LIBID Int, PROBID Int, GOALID Int, OBJID Int, INTID Int)INSERT INTO #Intervention_Link_Data SELECT '1.2470.9.0.0.1271',1,9,0,0,1271,2470 UNION ALLSELECT '1.2469.9.0.438.1270',1,9,0,438,1270,2469 UNION ALLSELECT '1.2471.9.0.439.0',1,9,0,439,0,2471 UNION ALLSELECT '1.1.9.87.437.1269',1,9,87,437,1269,1 UNION ALLSELECT '1.2470.9.88.0.0',1,9,88,0,0,2470 UNION ALLSELECT '1.1.9.88.438.0',1,9,88,438,0,1 UNION ALLSELECT '1.1.10.0.438.0',1,10,0,438,0,1 UNION ALLSELECT '1.2472.10.89.437.1270',1,10,89,437,1270,2472