-
Notifications
You must be signed in to change notification settings - Fork 0
/
informationmodel.php
744 lines (733 loc) · 28.6 KB
/
informationmodel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
<?php
require_once 'inc/util.inc';
session_start();
$_SESSION['queryvariableerror'] = "";
$_SESSION['error'] = "";
$_SESSION['iderror'] = "";
if (isset($_COOKIE['user'])) {
$username = $_COOKIE['user'];
$password = $_COOKIE['pass'];
$db_link = mysql_connect($db, $db_user, $db_pass, TRUE, MYSQL_CLIENT_INTERACTIVE);
if (!$db_link)
error(mysql_error());
mysql_query("SET NAMES utf8", $db_link);
mysql_query("SET CHARACTER SET utf8", $db_link);
mysql_query("SET SESSION interactive_timeout=30", $db_link);
mysql_select_db($dbname);
$user = mysql_query("SELECT * FROM user WHERE firstname = '$username'");
if (!$user)
error(mysql_error());
while ($userinfo = mysql_fetch_array($user)) {
if ($password != $userinfo['password']) {
header("Location: login.php");
return;
} else {
$_SESSION['unlocked'] = $userinfo['unlocked'];
if (!(bool) $_SESSION['unlocked']) {
header("Location: unlock.php");
return;
}
if (isset($_POST['indicatorSelect'])) {
$_SESSION['indicatorid'] = $_POST['indicatorSelect'];
}
if (!isset($_SESSION['indicatorid'])) {
$_SESSION['indicatorid'] = 1;
}
$indicatorid = $_SESSION['indicatorid'];
$step = "informationmodel";
$userid = $userinfo['id'];
$commentresult = mysql_query(
"SELECT * FROM comment WHERE userid = '$userid' AND indicatorid = '$indicatorid' AND step = '$step'");
if (!$commentresult)
error(mysql_error());
$comment_num_rows = mysql_num_rows($commentresult);
while ($commentinfo = mysql_fetch_array($commentresult)) {
$comment = $commentinfo['comment'];
$commentold = $commentinfo['comment'];
}
mysql_free_result($commentresult);
if ($_POST['submitComment'] == "submit") {
$commentnew = $_POST['comment'];
$commentnewprep = PrepSQL($commentnew);
if ($commentnewprep != $commentcomment) {
if ($comment_num_rows == 0) {
$sql = "INSERT INTO comment (userid, indicatorid, step, comment, inserted) VALUES (
$userid, $indicatorid, '$step', '$commentnewprep', NOW())";
mysql_query($sql);
$comment = $commentnewprep;
} else if ($comment_num_rows > 0) {
if (strcmp($commentnew, $commentold) != 0) {
$sqlupdate = "UPDATE comment SET `comment` = '$commentnewprep', `updated` = NOW() WHERE `userid` = '$userid' AND `indicatorid` = '$indicatorid' AND `step` = '$step'";
mysql_query($sqlupdate);
$comment = $commentnewprep;
}
}
}
$commentresult = mysql_query(
"SELECT * FROM comment WHERE userid = '$userid' AND indicatorid = '$indicatorid' AND step = '$step'");
if (!$commentresult)
error(mysql_error());
while ($commentinfo = mysql_fetch_array($commentresult)) {
$comment = $commentinfo['comment'];
}
mysql_free_result($commentresult);
}
// automated generation of query variables
if ($_POST['generateAutomatically'] == "submit") {
$concepts = mysql_query(
"SELECT * FROM concept WHERE userid = '$userid' AND indicatorid = '$indicatorid' ORDER BY `id`");
if (!$concepts)
error(mysql_error());
while ($conceptrow = mysql_fetch_array($concepts)) {
$conceptid = $conceptrow['conceptid'];
$boundesult = mysql_query(
"SELECT * FROM `formalised_constraint` WHERE constrainttype = 'informationmodel' AND userid = '$userid' AND indicatorid = '$indicatorid' AND `conceptid` = '$conceptid'");
if (!$boundesult)
error(mysql_error());
$bound_num_rows = mysql_num_rows($boundesult);
$fsn = mysql_query(
"SELECT FULLYSPECIFIEDNAME FROM `$snomeddbname`.concepts WHERE CONCEPTID = '$conceptid' ");
if (!$fsn)
error(mysql_error());
$row = mysql_fetch_row($fsn);
mysql_free_result($fsn);
$aliasname = str_replace(' ', '_', $row[0]);
if ($bound_num_rows == 0) {
$isprocedure = mysql_query(
"SELECT COUNT(*) FROM `$snomeddbname`.`sct_transitiveclosure` WHERE `SubtypeId` = $conceptid AND `SupertypeId` = 71388002");
if (!$isprocedure)
error(mysql_error());
$procedurerow = mysql_fetch_row($isprocedure);
if (strcmp($procedurerow[0], "1") == 0)
$aliasfortable = "Procedure_undertaken";
if (strcmp($procedurerow[0], "1") == 0)
$sctid = "Procedure_snomedctconceptid";
$isfinding = mysql_query(
"SELECT COUNT(*) FROM `$snomeddbname`.`sct_transitiveclosure` WHERE `SubtypeId` = $conceptid AND `SupertypeId` = 404684003");
if (!$isfinding)
error(mysql_error());
$findingrow = mysql_fetch_row($isfinding);
if (strcmp($findingrow[0], "1") == 0)
$aliasfortable = "Diagnosis";
if (strcmp($findingrow[0], "1") == 0)
$sctid = "Diagnosis_snomedctconceptid";
if ((strcmp($procedurerow[0], "1") == 0) || (strcmp($findingrow[0], "1") == 0)) {
// save query variable if not already in there!!
$numquery = "SELECT * FROM `query_variable` WHERE `userid` = '$userid' AND `indicatorid` = '$indicatorid' AND `variable` = '$aliasname' AND `table` = '$aliasfortable'";
$result = mysql_query($numquery);
if (!$result)
error(mysql_error());
$num_rows = mysql_num_rows($result);
mysql_free_result($result);
if ($num_rows == 0) {
$sql = "INSERT INTO query_variable (`variableid`, `userid`, `indicatorid`, `variable`, `table`, `inserted`) VALUES (
NULL,
$userid,
$indicatorid,
'$aliasname',
'$aliasfortable', NOW())";
mysql_query($sql);
}
// save constraint
$sql = "' INTO formalised_constraint (`id`, `userid`, `indicatorid`, `constrainttype`, `indicatortext`, `table`, `attribute`, `conceptid`, `relation`, `date`, `table2`, `attribute2`, `number`, `isexclusion`, `numeratoronly`, `inserted`) VALUES (
NULL,
$userid,
$indicatorid,
'informationmodel',
NULL,
'$aliasname',
'$sctid',
'$conceptid', 'is', NULL, NULL, NULL, NULL, NULL, NULL, NOW())";
mysql_query($sql);
}
}
}
mysql_free_result($concepts);
}
if ($_POST['form'] == "variableexclusionconstraints") {
// update constraints
$allconstraints = mysql_query(
"SELECT * FROM query_variable WHERE indicatorid = '$indicatorid' AND userid = '$userid'");
if (!$allconstraints)
error(mysql_error());
while ($constraintinfo = mysql_fetch_array($allconstraints)) {
$id = $constraintinfo['variableid'];
$sqlupdate = "UPDATE query_variable SET isexclusion = '0' WHERE `variableid` = '$id'";
mysql_query($sqlupdate);
}
mysql_free_result($allconstraints);
$selconstraints = $_POST['constraints'];
if (!empty($selconstraints)) {
$N = count($selconstraints);
for ($i = 0; $i < $N; $i++) {
$sqlupdate = "UPDATE query_variable SET `isexclusion` = '1' WHERE `variableid` = '$selconstraints[$i]'";
mysql_query($sqlupdate);
}
}
}
if (isset($_POST['tableSelect']) || $_POST['submitQueryVariable'] == "submit") {
$queryvariable = $_POST['queryvariable'];
$table = $_POST['tableSelect'];
// all empty
if (empty($queryvariable) && empty($table)) {
$_SESSION['queryvariableerror'] = "Nothing saved: all fields empty";
} else if (empty($queryvariable) || empty($table)) {
$_SESSION['queryvariableerror'] = "Nothing saved: one or more empty fields";
} else {
$numquery = "SELECT * FROM `query_variable` WHERE `userid` = '$userid' AND `indicatorid` = '$indicatorid' AND `variable` = '$queryvariable' AND `table` = '$table'";
$result = mysql_query($numquery);
if (!$result)
error(mysql_error());
$num_rows = mysql_num_rows($result);
mysql_free_result($result);
if ($num_rows > 0) {
$_SESSION['queryvariableerror'] = "Nothing saved: same row already in database. ";
} else {
$prepvariable = PrepSQL($queryvariable);
$sql = "INSERT INTO query_variable (`variableid`, `userid`, `indicatorid`, `variable`, `table`, `inserted`) VALUES (
NULL,
$userid,
$indicatorid,
'$prepvariable',
'$table', NOW())";
mysql_query($sql);
$queryvariable = "";
$table = "";
}
}
}
if (isset($_POST['tableattributeSelect']) || isset($_POST['conceptidSelect'])) {
$selectedattribute = $_POST['tableattributeSelect'];
$selectedconceptid = $_POST['conceptidSelect'];
// all empty
if (empty($selectedattribute) && empty($selectedconceptid)) {
$_SESSION['error'] = "Nothing saved: all fields empty";
} else if (empty($selectedattribute) || empty($selectedconceptid)) {
$_SESSION['error'] = "Nothing saved: one or more empty fields";
} else {
$pos = strpos($selectedattribute, ".");
$table = substr($selectedattribute, 0, $pos);
$attribute = substr($selectedattribute, ($pos + 1), strlen($selectedattribute));
$numquery = "SELECT * FROM `formalised_constraint` WHERE `userid` = '$userid' AND `indicatorid` = '$indicatorid' AND `constrainttype` = 'informationmodel' AND `table` = '$table' AND `attribute` = '$attribute' AND `conceptid` = $selectedconceptid";
$result = mysql_query($numquery);
if (!$result)
error(mysql_error());
$num_rows = mysql_num_rows($result);
mysql_free_result($result);
if ($num_rows > 0) {
$_SESSION['error'] = "Nothing saved: same row already in database. ";
} else {
$sql = "INSERT INTO formalised_constraint (`id`, `userid`, `indicatorid`, `constrainttype`, `indicatortext`, `table`, `attribute`, `conceptid`, `relation`, `date`, `table2`, `attribute2`, `number`, `isexclusion`, `numeratoronly`, `inserted`) VALUES (
NULL,
$userid,
$indicatorid,
'informationmodel',
NULL,
'$table',
'$attribute',
'$selectedconceptid', 'is', NULL, NULL, NULL, NULL, NULL, NULL, NOW())";
mysql_query($sql);
$selectedattribute = "";
$selectedconceptid = "";
}
}
}
if (isset($_POST['tableidSelect']) || isset($_POST['tableidSelect2'])) {
$selectedid = $_POST['tableidSelect'];
$selectedid2 = $_POST['tableidSelect2'];
$pos = strpos($selectedid, ".");
$table = substr($selectedid, 0, $pos);
$attribute = substr($selectedid, ($pos + 1), strlen($selectedid));
$pos2 = strpos($selectedid2, ".");
$table2 = substr($selectedid2, 0, $pos2);
$attribute2 = substr($selectedid2, ($pos2 + 1), strlen($selectedid2));
// all empty
if (empty($selectedid) && empty($selectedid2)) {
$_SESSION['iderror'] = "Nothing saved: all fields empty";
} else if (empty($selectedid) || empty($selectedid2)) {
$_SESSION['iderror'] = "Nothing saved: one or more empty fields";
} else if (($attribute != $attribute2)
&& (!endsWith($attribute, "diagnosisid") && !endsWith($attribute2, "diagnosisid"))) {
$_SESSION['iderror'] = "Nothing saved: you can only join two tables by a common id";
} else if (($table == $table2) && ($attribute == $attribute2)) {
$_SESSION['iderror'] = "Nothing saved: it does not make sense to match the same table on the same id";
} else {
$numquery = "SELECT * FROM `formalised_constraint` WHERE `userid` = '$userid' AND `indicatorid` = '$indicatorid' AND `constrainttype` = 'idjoin' AND `table` = '$table' AND `attribute` = '$attribute' AND `table2` = '$table2' AND `attribute2` = '$attribute2'";
$result = mysql_query($numquery);
if (!$result)
error(mysql_error());
$num_rows = mysql_num_rows($result);
mysql_free_result($result);
if ($num_rows > 0) {
$_SESSION['iderror'] = "Nothing saved: same row already in database. ";
} else {
$sql = "INSERT INTO formalised_constraint (`id`, `userid`, `indicatorid`, `constrainttype`, `indicatortext`, `table`, `attribute`, `conceptid`, `relation`, `date`, `table2`, `attribute2`, `number`, `isexclusion`, `numeratoronly`, `inserted`) VALUES (
NULL,
$userid,
$indicatorid,
'idjoin',
NULL,
'$table',
'$attribute',
NULL, 'is', NULL, '$table2', '$attribute2', NULL, NULL, NULL, NOW())";
mysql_query($sql);
$selectedid = "";
$selectedid2 = "";
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>CLIF: Information Model</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet"></link>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
</head>
<body>
<?php include_once("inc/head.inc") ?>
<div style="height: 50px"></div>
<div class="container">
<h1>Define the information model</h1>
<p>
First, please have a look at the <a target="_blank"
href="schema/tables/Patient.html">database schema</a>. On this page
you need to define the information model. This consists of three
steps: first, in case you need to select several elements of the same
type / table Procedure_undertaken or Diagnosis, such as the procedures lymph node examination and colectomy,
you need to define query variables in order to be able to distinguish
them (<a href="<?php echo $_SERVER['PHP_SELF'] . '#queryvariables' ?>">substeps
1.</a>). Then, in <a
href="<?php echo $_SERVER['PHP_SELF'] . '#sctcodes' ?>">substeps 2</a>,
you bind previously defined SNOMED CT codes to the attribute snomedctconceptid of
tables and query variables defined before. Additionally, you might
need to define how the tables and query variables are related to each
other (<a
href="<?php echo $_SERVER['PHP_SELF'] . '#join' ?>">substeps 3</a>).
</p>
<?php include_once("inc/indicator.inc") ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<button type="submit" class="btn small primary"
name="generateAutomatically" value="submit">Run substeps 1. and 2
automatically</button>
</form>
<a name="queryvariables"></a>
<h2>1. Define query variables</h2>
If you need several elements of the type / database table Procedure_undertaken or Diagnosis (check the <a
target="_blank" href="schema/tables/Patient.html">database schema</a>), please define query variables
(i.e. alias names) in order to distinguish them.
<div class="workwell">
<form action="<?php echo $_SERVER['PHP_SELF'] . '#queryvariables' ?>"
method="post" name="QueryVariableForm">
<table class="table table-condensed">
<tr>
<th>Assign an intuitive name for a query variable</th>
<th>=</th>
<th>Choose database table</th>
<th>Exluded</th>
<th>Delete</th>
</tr>
<?php
$content = mysql_query(
"SELECT * FROM query_variable WHERE userid = '$userid' AND indicatorid = '$indicatorid'");
if (!$content)
error(mysql_error());
while ($row = mysql_fetch_array($content)) {
$id = $row['variableid'];
$variable = $row['variable'];
$querytable = $row['table'];
$isexclusion = $row['isexclusion'];
echo "<tr>";
echo "<td>" . $variable . "</td>";
echo "<td>=</td>";
echo "<td>" . $querytable . "</td>";
echo "<td><input type='checkbox' name='constraints[]' value='$id' onchange='this.form.submit();'";
if ((bool) $isexclusion) {
echo " checked = 'checked' ";
}
echo " /></td>";
echo "<td><a href='deletevariable.php?id=$id&step=query_variable'>x</a></td>";
echo "</tr>";
}
mysql_free_result($content);
?>
<input type="hidden" name="form" value="variableexclusionconstraints" />
</form>
<tr valign="top">
<td><input type="text" name="queryvariable" maxlength="100"
value="<?php echo $queryvariable; ?>" /></td>
<td>=</td>
<td><select name="tableSelect" onchange="this.form.submit();">
<option value="">please choose</option>
<?php
foreach ($patienttables as &$patienttable) {
$option = "$patienttable";
if ((strcmp($option, "firstpage") == 0) || (strcmp($option, "lab_test") == 0)
|| (strcmp($option, "examination") == 0) || (strcmp($option, "treatment") == 0)) {
echo "<option value='$option'";
if (strcmp($table, $option) == 0) {
echo "selected='selected'";
}
;
echo ">$option</option>";
}
}
?>
</select></td>
<td></td>
</tr>
</table>
<button type="submit" class="btn small primary"
name="submitQueryVariable" value="submit">save changes</button>
<span style="color: red"> <?php echo $_SESSION['queryvariableerror']; ?>
</span>
</form>
</div>
<div style="height: 30px"></div>
<a name="sctcodes"></a>
<h2>2. Bind the concepts to query variables / database tables</h2>
In this step, bind the concept ids that you entered in <a
href="concepts.php">the previous step</a> to the attribute conceptid of
query variables and tables. If you defined a query variable above, use
this instead of the table name (this also applies to all further
steps)!
<div class="workwell">
<form action="<?php echo $_SERVER['PHP_SELF'] . '#sctcodes' ?>"
method="post" name="informationModelForm">
<table class="table table-condensed">
<tr>
<th>queryvariable/table.conceptid</th>
<th>=</th>
<th>Value (concept defined previously)</th>
<th>Delete</th>
</tr>
<?php
$content = mysql_query(
"SELECT * FROM formalised_constraint WHERE userid = '$userid' AND indicatorid = '$indicatorid' AND constrainttype = 'informationmodel'");
if (!$content)
error(mysql_error());
while ($row = mysql_fetch_array($content)) {
$id = $row['id'];
$conceptid = $row['conceptid'];
$fsn = mysql_query(
"SELECT FULLYSPECIFIEDNAME FROM `$snomeddbname`.concepts WHERE CONCEPTID = '$conceptid' ");
if (!$content)
error(mysql_error());
$snorow = mysql_fetch_row($fsn);
mysql_free_result($fsn);
$conceptexists = mysql_query(
"SELECT * FROM concept WHERE conceptid = '$conceptid' AND userid = '$userid' AND indicatorid = '$indicatorid'");
if (!$conceptexists)
error(mysql_error());
$conceptexistsrow = mysql_fetch_row($conceptexists);
$concept_num_rows = mysql_num_rows($conceptexists);
mysql_free_result($conceptexists);
echo "<tr>";
echo "<td>" . $row['table'] . "." . $row['attribute'];
$found = false;
foreach ($patienttables as &$patienttable) {
if (strcmp($row['table'], $patienttable) == 0) {
$found = true;
}
}
$variablesql = "SELECT * FROM `query_variable` WHERE `userid` = '$userid' AND `indicatorid` = '$indicatorid'";
$tables = mysql_query($variablesql);
if (!$tables)
error(mysql_error());
while ($tablerow = mysql_fetch_array($tables)) {
if (strcmp($tablerow['variable'], $row['table']) == 0) {
$found = true;
}
}
mysql_free_result($tables);
if (!$found) {
echo "<br /><span style='color: red'>This query variable is undefined. Do you really want to use it? </span>";
}
echo "</td>";
echo "<td>=</td>";
echo "<td>" . $row['conceptid'] . " " . $snorow[0];
if ($concept_num_rows == 0) {
echo "<br /><span style='color: red'> This concept has been deleted. Are you sure that you want to use it? </span>";
}
echo "</td>";
echo "<td><a href='delete.php?id=$id&step=$step&anchor=sctcodes'>x</a></td>";
echo "</tr>\n";
}
mysql_free_result($content);
?>
<tr valign="top">
<td><select name="tableattributeSelect"
onchange="this.form.submit();">
<option value="">please choose</option>
<?php
$variablesql = "SELECT * FROM `query_variable` WHERE `userid` = '$userid' AND `indicatorid` = '$indicatorid' ORDER BY `variable`";
$variables = mysql_query($variablesql);
if (!$variables)
error(mysql_error());
mysql_select_db($patientsdbname);
while ($variablerow = mysql_fetch_array($variables)) {
$variableattributes = mysql_query("DESCRIBE `$variablerow[table]`");
if (!$variableattributes)
error(mysql_error());
while ($variableattributerow = mysql_fetch_array($variableattributes)) {
foreach ($codecolumns as &$codecolumn) {
if (endsWith($variableattributerow[0], $codecolumn)) {
$option = "$variablerow[variable].$variableattributerow[0]";
echo "<option value='$option'";
if (strcmp($selectedattribute, $option) == 0) {
echo "selected='selected'";
}
echo ">$option</option>";
}
}
}
mysql_free_result($variableattributes);
}
mysql_free_result($variables);
foreach ($patienttables as &$patienttable) {
$attributes = mysql_query("DESCRIBE `$patienttable`");
if (!$attributes)
error(mysql_error());
while ($attributerow = mysql_fetch_array($attributes)) {
foreach ($codecolumns as &$codecolumn) {
if (endsWith($attributerow[0], $codecolumn)) {
$option = "$patienttable.$attributerow[0]";
echo "<option value='$option'";
if (strcmp($selectedattribute, $option) == 0) {
echo "selected='selected'";
}
echo ">$option</option>";
}
}
}
}
mysql_free_result($attributes);
mysql_select_db($dbname);
?>
</select></td>
<td>=</td>
<td><select name="conceptidSelect" onchange="this.form.submit();">
<option value="">please choose</option>
<?php
$concepts = mysql_query(
"SELECT * FROM concept WHERE userid = '$userid' AND indicatorid = '$indicatorid' ORDER BY `id`");
if (!$concepts)
error(mysql_error());
while ($conceptrow = mysql_fetch_array($concepts)) {
$conceptid = $conceptrow['conceptid'];
//$fsn = mysql_query(
// "SELECT FULLYSPECIFIEDNAME FROM `$snomeddbname`.concepts WHERE CONCEPTID = '$conceptid' ");
// if (!$fsn)
// error(mysql_error());
// $row = mysql_fetch_row($fsn);
//mysql_free_result($fsn);
echo "<option value='$conceptid'";
if ($selectedconceptid == $conceptid)
echo ("selected='selected'");
echo ">$conceptid</option>";
}
mysql_free_result($concepts);
?>
</select></td>
<td></td>
</tr>
</table>
<span style="color: red"> <?php echo $_SESSION['error']; ?>
</span>
</form>
</div>
<div style="height: 30px"></div>
<a name="join"></a>
<h2>3. Relate bound elements to each other</h2>
The main goal of this step is to exploit the problem-oriented patient record, that is to relate procedures to the diagnoses due to which they have been carried out. Have a look at the <a target="_blank"
href="schema/tables/Patient.html">database schema</a> to see which
tables you can join.
<div class="workwell">
<form action="<?php echo $_SERVER['PHP_SELF'] . '#join' ?>"
method="post" name="IDsForm">
<table class="table table-condensed">
<tr>
<th>queryvariable/table.ID</th>
<th>=</th>
<th>queryvariable/table.ID 2</th>
<th>Delete</th>
</tr>
<?php
$content = mysql_query(
"SELECT * FROM formalised_constraint WHERE userid = '$userid' AND indicatorid = '$indicatorid' AND constrainttype = 'idjoin'");
if (!$content)
error(mysql_error());
while ($row = mysql_fetch_array($content)) {
$id = $row['id'];
echo "<tr>";
echo "<td>" . $row['table'] . "." . $row['attribute'];
$found = false;
foreach ($patienttables as &$patienttable) {
if (strcmp($row['table'], $patienttable) == 0) {
$found = true;
}
}
$variablesql = "SELECT * FROM `query_variable` WHERE `userid` = '$userid' AND `indicatorid` = '$indicatorid'";
$tables = mysql_query($variablesql);
if (!$tables)
error(mysql_error());
while ($tablerow = mysql_fetch_array($tables)) {
if (strcmp($tablerow['variable'], $row['table']) == 0) {
$found = true;
}
}
mysql_free_result($tables);
if (!$found) {
echo "<br /><span style='color: red'>This query variable is undefined. Do you really want to use it? </span>";
}
echo "</td>";
echo "<td>=</td>";
echo "<td>" . $row['table2'] . "." . $row['attribute2'];
$found = false;
foreach ($patienttables as &$patienttable) {
if (strcmp($row['table2'], $patienttable) == 0) {
$found = true;
}
}
$variablesql = "SELECT * FROM `query_variable` WHERE `userid` = '$userid' AND `indicatorid` = '$indicatorid'";
$tables = mysql_query($variablesql);
if (!$tables)
error(mysql_error());
while ($tablerow = mysql_fetch_array($tables)) {
if (strcmp($tablerow['variable'], $row['table2']) == 0) {
$found = true;
}
}
mysql_free_result($tables);
if (!$found) {
echo "<br /><span style='color: red'>This query variable is undefined. Do you really want to use it? </span>";
}
echo "</td>";
echo "<td><a href='delete.php?id=$id&step=$step&anchor=join'>x</a></td>";
echo "</tr>\n";
}
mysql_free_result($content);
?>
<tr valign="top">
<td><select name="tableidSelect" onchange="this.form.submit();">
<option value="">please choose</option>
<?php
$variablesql = "SELECT * FROM `query_variable` WHERE `userid` = '$userid' AND `indicatorid` = '$indicatorid' ORDER BY `variable`";
$variables = mysql_query($variablesql);
if (!$variables)
error(mysql_error());
mysql_select_db($patientsdbname);
while ($variablerow = mysql_fetch_array($variables)) {
$variableattributes = mysql_query("DESCRIBE `$variablerow[table]`");
if (!$variableattributes)
error(mysql_error());
while ($variableattributerow = mysql_fetch_array($variableattributes)) {
if ((endsWith($variableattributerow[0], "id"))
&& (!endsWith($variableattributerow[0], "snomedctconceptid"))
&& (strcmp($variableattributerow[0], "patientid") != 0)) {
$option = "$variablerow[variable].$variableattributerow[0]";
echo "<option value='$option'";
if (strcmp($selectedid, $option) == 0) {
echo "selected='selected'";
}
;
echo ">$option</option>";
}
}
mysql_free_result($variableattributes);
}
mysql_free_result($variables);
foreach ($patienttables as &$patienttable) {
$attributes = mysql_query("DESCRIBE `$patienttable`");
if (!$attributes)
error(mysql_error());
while ($attributerow = mysql_fetch_array($attributes)) {
if ((endsWith($attributerow[0], "id")) && (!endsWith($attributerow[0], "snomedctconceptid"))
&& (strcmp($attributerow[0], "patientid") != 0)) {
$option = "$patienttable.$attributerow[0]";
echo "<option value='$option'";
if (strcmp($selectedid, $option) == 0) {
echo "selected='selected'";
}
;
echo ">$option</option>";
}
}
}
mysql_select_db($dbname);
mysql_free_result($attributes);
?>
</select></td>
<td>=</td>
<td><select name="tableidSelect2" onchange="this.form.submit();">
<option value="">please choose</option>
<?php
$variablesql = "SELECT * FROM `query_variable` WHERE `userid` = '$userid' AND `indicatorid` = '$indicatorid' ORDER BY `variable`";
$variables = mysql_query($variablesql);
if (!$variables)
error(mysql_error());
mysql_select_db($patientsdbname);
while ($variablerow = mysql_fetch_array($variables)) {
$variableattributes = mysql_query("DESCRIBE `$variablerow[table]`");
if (!$variableattributes)
error(mysql_error());
while ($variableattributerow = mysql_fetch_array($variableattributes)) {
if ((endsWith($variableattributerow[0], "id"))
&& (!endsWith($variableattributerow[0], "snomedctconceptid"))
&& (strcmp($variableattributerow[0], "patientid") != 0)) {
$option = "$variablerow[variable].$variableattributerow[0]";
echo "<option value='$option'";
if (strcmp($selectedid2, $option) == 0) {
echo "selected='selected'";
}
;
echo ">$option</option>";
}
}
mysql_free_result($variableattributes);
}
mysql_free_result($variables);
foreach ($patienttables as &$patienttable) {
$attributes = mysql_query("DESCRIBE `$patienttable`");
if (!$attributes)
error(mysql_error());
while ($attributerow = mysql_fetch_array($attributes)) {
if ((endsWith($attributerow[0], "id")) && (!endsWith($attributerow[0], "snomedctconceptid"))
&& (strcmp($attributerow[0], "patientid") != 0)) {
$option = "$patienttable.$attributerow[0]";
echo "<option value='$option'";
if (strcmp($selectedid2, $option) == 0) {
echo "selected='selected'";
}
;
echo ">$option</option>";
}
}
}
mysql_free_result($attributes);
mysql_select_db($dbname);
?>
</select></td>
<td></td>
</tr>
</table>
<span style="color: red"> <?php echo $_SESSION['iderror']; ?>
</span>
</form>
</div>
<?php include_once("inc/comment.inc") ?>
</div>
</body>
</html>
<?php
}
}
mysql_free_result($user);
mysql_close($db_link);
} else {
header("Location: login.php");
return;
}
?>