-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
141 lines (114 loc) · 6.18 KB
/
functions.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
<?php
//This function parses an XML result for a trial. Two inputs are needed, first an XML object, and second the STRING of the outcome being measured
function trialParser ($xmlObject, $userDefinedOutcome, $condition, $intervention)
{
//Process: a) Searching outcomes for first occurence of of the outcomes word
//For the sake of sanity, convert the XML object to an array:
$input = json_decode(json_encode($xmlObject), TRUE);
//$outcome contains the matched outcome
//The outcomes list is stored in: $input['clinical_results']['outcome_list']
//Cycle through the outcomes list, and try to identify the first
foreach ($input['clinical_results']['outcome_list']['outcome'] as $key=>$value)
{
//So explode the subobject by the user defined outcome.
$tempArray = explode($userDefinedOutcome, strtolower($value['title']));
//rint_r($tempArray);
//Now we count the number of array elements. If >1, then the term is found
if (count($tempArray) >= 2)
{
//Set the $outcome variable [i.e. the one we are meeting]
$outcome = $value;
break;
}
}
//$outcome contains the matched outcome
/*echo "<pre>";
print_r($outcome);
echo "</pre>";*/
//Next we need to pull the desired figures from $outcome, i.e Treated VS untreated out from this
//Take the outcome, and convert to a 2D Array
//In 1 direction: group ID, in the other: value
//First populate an array with groupdata
if(isset($outcome)) {
$groupData = array();
$counter = 0;
foreach ($outcome['group_list']['group'] as $key=>$value)
{
$groupData[$counter]['id'] = $value['@attributes']['group_id'];
$groupData[$counter]['title'] = $value['title'];
if(isset($value['description'])) {
$groupData[$counter]['description'] = $value['description'];
}
$counter++;
}
//Set a value for units
foreach ($outcome['measure_list']['measure'] as $key=>$value)
{
$globalUnits=$value['units'];
}
//Now populate it with the POPULATION SIZE data
foreach ($outcome['measure_list']['measure'][0]['category_list']['category']['measurement_list']['measurement'] as $key=>$value)
{
//Lookup $value['@attributes']['group_id'] in [$groupData][$counter]['id'] and set $value['@attributes']['value']
//Cycle through the group data
foreach ($groupData as $key => $groupValue) {
if ($groupData[$key]['id'] == $value['@attributes']['group_id'])
{
$groupData[$key]['datasetSize'] = $value['@attributes']['value'];
$groupData[$key]['units'] = $globalUnits;
}
}
}
//Now populate it with NUMBER MEETING CONDITION data
if(isset($outcome['measure_list']['measure'][1]['category_list']['category']['measurement_list']['measurement']) && isset($outcome['population'])) {
foreach ($outcome['measure_list']['measure'][1]['category_list']['category']['measurement_list']['measurement'] as $key=>$value)
{
//Lookup $value['@attributes']['group_id'] in [$groupData][$counter]['id'] and set $value['@attributes']['value']
//Cycle through the group data
foreach ($groupData as $key => $groupValue) {
if ($groupData[$key]['id'] == $value['@attributes']['group_id'])
{
$groupData[$key]['numberMeetingCondition'] = $value['@attributes']['value'];
}
}
}
//Now we do the stastical analysis
/*echo "<pre>";
print_r($groupData);
echo "</pre>";*/
$outputArray = array();
$outputArray['trialID'] = $input['id_info']['nct_id'];
$outputArray['studyDesignText'] = $input['study_design'];
$outputArray['eligibilityText'] = $input['eligibility']['criteria']['textblock'];
$outputArray['eligibilityGender'] = $input['eligibility']['gender'];
$outputArray['eligibilityMinAge'] = $input['eligibility']['minimum_age'];
$outputArray['eligibilityMaxAge'] = $input['eligibility']['maximum_age'];
// Check blinding of trial.
if(strpos(strtolower($outputArray['studyDesignText']), "double blind") || strpos(strtolower($outputArray['studyDesignText']), "double-blind")) {
$outputArray['studyDesignBlind'] = "double";
} elseif(strpos(strtolower($outputArray['studyDesignText']), "single blind") || strpos(strtolower($outputArray['studyDesignText']), "single-blind")) {
$outputArray['studyDesignBlind'] = "single";
} else {
$outputArray['studyDesignBlind'] = "not";
}
// Pass query terms -- TODO: pass these better, only once.
$outputArray['conditionTerms'] = $condition;
$outputArray['interventionTerms'] = $intervention;
$outputArray['outcomeTerms'] = $userDefinedOutcome;
$outputArray['outcome']=array('type'=>$outcome['type'], 'title'=>$outcome['title'], 'description'=>$outcome['description'],'time_frame'=>$outcome['time_frame'],'population'=>$outcome['population']);
$outputArray['trialResults'] = $groupData;
return $outputArray;
}
}
//Next we need to run stats on this to work out relative risk
//To do this, we define the group with index $group
//Now we output the relative risk however Ali wants it.
//This function identifies
//print_r($xmlObject);
//matchOutcomeMeasures($xmlObject, $outcome);
//For this, we pull in the data for the results
//Do Statistics
//Offer an option for user exclusion
//Output in JSON for a forrest plot.
}
?>