MrNoOne07 commited on
Commit
11f4011
·
verified ·
1 Parent(s): a36059a

Add architecture diagrams

Browse files
Architecture Diagrams/secondlife high level architecture.drawio ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <mxfile host="app.diagrams.net">
2
+ <diagram id="E15GttQApXdkw6PukwBz" name="Page-1">
3
+ <mxGraphModel dx="2322" dy="2022" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="0" pageScale="1" pageWidth="1600" pageHeight="900" math="0" shadow="0">
4
+ <root>
5
+ <mxCell id="0" />
6
+ <mxCell id="1" parent="0" />
7
+ <mxCell id="userGroup" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#EEF4FF;strokeColor=#C7D8FF;strokeWidth=3;arcSize=18;opacity=70;fontSize=12;" value="" vertex="1">
8
+ <mxGeometry height="356.6470588235295" width="1824.563758389262" x="142.5503355704698" y="18.999411764705883" as="geometry" />
9
+ </mxCell>
10
+ <mxCell id="bg1" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#DCEBFF;strokeColor=none;opacity=55;" value="" vertex="1">
11
+ <mxGeometry height="394.59" width="383.76" x="1676.24" y="-110" as="geometry" />
12
+ </mxCell>
13
+ <mxCell id="bg2" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#DFF7EC;strokeColor=none;opacity=60;" value="" vertex="1">
14
+ <mxGeometry height="364.24" width="367.32" y="815.76" as="geometry" />
15
+ </mxCell>
16
+ <mxCell id="bg3" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#FFF1D7;strokeColor=none;opacity=65;" value="" vertex="1">
17
+ <mxGeometry height="273.1764705882353" width="237.98657718120808" x="1464.6979865771812" y="815.7647058823532" as="geometry" />
18
+ </mxCell>
19
+ <mxCell id="title" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=40;fontStyle=1;fontColor=#152641;align=center;verticalAlign=middle;" value="Second Life - High-Level Architecture" vertex="1">
20
+ <mxGeometry height="60.70588235294119" width="1216.3758389261745" x="446.64429530201346" y="-106.96470588235294" as="geometry" />
21
+ </mxCell>
22
+ <mxCell id="sec1" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=18;fontStyle=1;fontColor=#61728E;letterSpacing=1;" value="USER EXPERIENCE" vertex="1">
23
+ <mxGeometry height="36.423529411764704" width="224.76510067114094" x="261.5436241610738" y="49.35294117647058" as="geometry" />
24
+ </mxCell>
25
+ <mxCell id="sec3" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=18;fontStyle=1;fontColor=#61728E;letterSpacing=1;" value="DATA AND INTELLIGENCE" vertex="1">
26
+ <mxGeometry height="36.423529411764704" width="290.8724832214765" x="119.99624161073825" y="703.4629411764703" as="geometry" />
27
+ </mxCell>
28
+ <mxCell id="patientCard" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#EEF4FF;strokeColor=#5C8CF0;strokeWidth=3;arcSize=18;shadow=1;" value="" vertex="1">
29
+ <mxGeometry height="197.29411764705884" width="661.0738255033558" x="248.32214765100673" y="87.29411764705884" as="geometry" />
30
+ </mxCell>
31
+ <mxCell id="patientBadge" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#5C8CF0;strokeColor=#5C8CF0;fontColor=#FFFFFF;fontSize=18;fontStyle=1;align=center;verticalAlign=middle;" value="P" vertex="1">
32
+ <mxGeometry height="72.85" width="74.67" x="290" y="132.82" as="geometry" />
33
+ </mxCell>
34
+ <mxCell id="patientTitle" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=28;fontStyle=1;fontColor=#152641;align=left;" value="Patient Portal" vertex="1">
35
+ <mxGeometry height="51.60000000000001" width="343.758389261745" x="387.1476510067114" y="144.96470588235297" as="geometry" />
36
+ </mxCell>
37
+ <mxCell id="patientBody" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=20;fontColor=#5E708C;align=left;verticalAlign=top;" value="Profile, suggested trials, saved interests&lt;br&gt;Connections, inbox chat, document uploads" vertex="1">
38
+ <mxGeometry height="69.81176470588235" width="436.30872483221475" x="387.1476510067114" y="205.67058823529413" as="geometry" />
39
+ </mxCell>
40
+ <mxCell id="hospitalCard" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#EEF8F2;strokeColor=#41A56C;strokeWidth=3;arcSize=18;shadow=1;" value="" vertex="1">
41
+ <mxGeometry height="197.29411764705884" width="661.0738255033558" x="1200.268456375839" y="87.29411764705884" as="geometry" />
42
+ </mxCell>
43
+ <mxCell id="hospitalBadge" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#41A56C;strokeColor=#41A56C;fontColor=#FFFFFF;fontSize=18;fontStyle=1;align=center;verticalAlign=middle;" value="H" vertex="1">
44
+ <mxGeometry height="72.85" width="76.62" x="1240" y="132.82" as="geometry" />
45
+ </mxCell>
46
+ <mxCell id="hospitalTitle" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=28;fontStyle=1;fontColor=#152641;align=left;" value="Hospital Portal" vertex="1">
47
+ <mxGeometry height="51.60000000000001" width="370.2013422818792" x="1339.0939597315437" y="144.96470588235297" as="geometry" />
48
+ </mxCell>
49
+ <mxCell id="hospitalBody" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=20;fontColor=#5E708C;align=left;verticalAlign=top;" value="Available patients, search, and trial view&lt;br&gt;Connections, inbox chat, and profile tools" vertex="1">
50
+ <mxGeometry height="69.81176470588235" width="462.751677852349" x="1339.0939597315437" y="205.67058823529413" as="geometry" />
51
+ </mxCell>
52
+ <mxCell id="flaskCard" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#F3EEFF;strokeColor=#7A5CD3;strokeWidth=3;arcSize=18;shadow=1;" value="" vertex="1">
53
+ <mxGeometry height="265.5882352941176" width="819.7315436241612" x="644.9664429530202" y="375.6470588235295" as="geometry" />
54
+ </mxCell>
55
+ <mxCell id="flaskBadge" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#7A5CD3;strokeColor=#7A5CD3;fontColor=#FFFFFF;fontSize=18;fontStyle=1;align=center;verticalAlign=middle;" value="W" vertex="1">
56
+ <mxGeometry height="78.92" width="81.89" x="700" y="419.38" as="geometry" />
57
+ </mxCell>
58
+ <mxCell id="flaskTitle" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=30;fontStyle=1;fontColor=#152641;align=left;" value="Flask Web Application" vertex="1">
59
+ <mxGeometry height="57.67058823529412" width="502.41610738255036" x="814.203422818792" y="430.00352941176465" as="geometry" />
60
+ </mxCell>
61
+ <mxCell id="flaskBody" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=20;fontColor=#5E708C;align=left;verticalAlign=top;" value="Renders patient and hospital pages&lt;br&gt;Handles login, APIs, sessions, and requests&lt;br&gt;Coordinates matching, inbox, connections, and uploads" vertex="1">
62
+ <mxGeometry height="80.8" width="402.99" x="797.01" y="509.2" as="geometry" />
63
+ </mxCell>
64
+ <mxCell id="dbCard" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#EFF9F3;strokeColor=#39A66E;strokeWidth=3;arcSize=18;shadow=1;" value="" vertex="1">
65
+ <mxGeometry height="273.1764705882353" width="502.41610738255036" x="155.7718120805369" y="770.2352941176471" as="geometry" />
66
+ </mxCell>
67
+ <mxCell id="dbBadge" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#39A66E;strokeColor=#39A66E;fontColor=#FFFFFF;fontSize=18;fontStyle=1;align=center;verticalAlign=middle;" value="D" vertex="1">
68
+ <mxGeometry height="72.85" width="78.73" x="195.44" y="815.77" as="geometry" />
69
+ </mxCell>
70
+ <mxCell id="dbTitle" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=28;fontStyle=1;fontColor=#152641;align=left;" value="App Database + Files" vertex="1">
71
+ <mxGeometry height="51.60000000000001" width="383.4228187919463" x="289.9980536912752" y="826.3858823529412" as="geometry" />
72
+ </mxCell>
73
+ <mxCell id="dbBody" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=20;fontColor=#5E708C;align=left;verticalAlign=top;" value="SQLite for accounts, connections, and messages&lt;br&gt;Uploads folder for patient documents&lt;br&gt;Keeps local portal state for the demo" vertex="1">
74
+ <mxGeometry height="109.27058823529411" width="383.4228187919463" x="202.00993288590604" y="910.0011764705881" as="geometry" />
75
+ </mxCell>
76
+ <mxCell id="mlCard" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#FFF5E5;strokeColor=#DD8E1D;strokeWidth=3;arcSize=18;shadow=1;" value="" vertex="1">
77
+ <mxGeometry height="273.1764705882353" width="502.41610738255036" x="803.6241610738255" y="770.2352941176471" as="geometry" />
78
+ </mxCell>
79
+ <mxCell id="mlBadge" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#DD8E1D;strokeColor=#DD8E1D;fontColor=#FFFFFF;fontSize=18;fontStyle=1;align=center;verticalAlign=middle;" value="M" vertex="1">
80
+ <mxGeometry height="72.85" width="77.46" x="852.54" y="815.76" as="geometry" />
81
+ </mxCell>
82
+ <mxCell id="mlTitle" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=28;fontStyle=1;fontColor=#152641;align=left;" value="Trial Matching Engine" vertex="1">
83
+ <mxGeometry height="51.6" width="310" x="960" y="826.39" as="geometry" />
84
+ </mxCell>
85
+ <mxCell id="mlBody" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=20;fontColor=#5E708C;align=left;verticalAlign=top;" value="Pipeline loads patient and trial datasets&lt;br&gt;Feature engineering + Random Forest model&lt;br&gt;Returns ranked trial matches and hospital trial lists" vertex="1">
86
+ <mxGeometry height="109.27058823529411" width="403.255033557047" x="852.5422818791948" y="910.0011764705881" as="geometry" />
87
+ </mxCell>
88
+ <mxCell id="srcCard" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#EDF9F9;strokeColor=#2D9FA1;strokeWidth=3;arcSize=18;shadow=1;" value="" vertex="1">
89
+ <mxGeometry height="273.1764705882353" width="502.41610738255036" x="1451.476510067114" y="770.2352941176471" as="geometry" />
90
+ </mxCell>
91
+ <mxCell id="srcBadge" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#2D9FA1;strokeColor=#2D9FA1;fontColor=#FFFFFF;fontSize=18;fontStyle=1;align=center;verticalAlign=middle;" value="S" vertex="1">
92
+ <mxGeometry height="72.85" width="78.4" x="1491.61" y="815.76" as="geometry" />
93
+ </mxCell>
94
+ <mxCell id="srcTitle" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=28;fontStyle=1;fontColor=#152641;align=left;" value="Source Data" vertex="1">
95
+ <mxGeometry height="51.60000000000001" width="290.8724832214765" x="1600.0027516778523" y="826.3858823529412" as="geometry" />
96
+ </mxCell>
97
+ <mxCell id="srcBody" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=20;fontColor=#5E708C;align=left;verticalAlign=top;" value="Synthea patient CSVs&lt;br&gt;ClinicalTrials.gov / AACT trial CSVs&lt;br&gt;MIMIC demo data for validation" vertex="1">
98
+ <mxGeometry height="109.27058823529411" width="383.4228187919463" x="1507.4546308724832" y="897.7211764705881" as="geometry" />
99
+ </mxCell>
100
+ <mxCell id="lblUser" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeColor=none;fontSize=18;fontStyle=1;fontColor=#5C6E89;align=center;verticalAlign=middle;" value="user requests" vertex="1">
101
+ <mxGeometry height="48.56470588235294" width="156.01342281879195" x="976.8232214765102" y="287.6205882352941" as="geometry" />
102
+ </mxCell>
103
+ <mxCell id="lblRead" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeColor=none;fontSize=18;fontStyle=1;fontColor=#5C6E89;align=center;verticalAlign=middle;" value="read / write" vertex="1">
104
+ <mxGeometry height="48.56470588235294" width="145.43624161073825" x="439.9987919463087" y="660.0011764705882" as="geometry" />
105
+ </mxCell>
106
+ <mxCell id="lblMatch" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeColor=none;fontSize=18;fontStyle=1;fontColor=#5C6E89;align=center;verticalAlign=middle;" value="match" vertex="1">
107
+ <mxGeometry height="48.56470588235294" width="105.7718120805369" x="930.0036912751677" y="690.0011764705882" as="geometry" />
108
+ </mxCell>
109
+ <mxCell id="lblRank" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeColor=none;fontSize=18;fontStyle=1;fontColor=#5C6E89;align=center;verticalAlign=middle;" value="ranked results" vertex="1">
110
+ <mxGeometry height="48.56470588235294" width="166.59060402684565" x="1150.029932885906" y="689.9982352941176" as="geometry" />
111
+ </mxCell>
112
+ <mxCell id="lblFeed" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeColor=none;fontSize=18;fontStyle=1;fontColor=#5C6E89;align=center;verticalAlign=middle;" value="data feed" vertex="1">
113
+ <mxGeometry height="48.56470588235294" width="137.50335570469798" x="1633.9364429530203" y="697.3929411764708" as="geometry" />
114
+ </mxCell>
115
+ <mxCell id="e1" edge="1" parent="1" source="patientCard" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;endFill=1;strokeColor=#42536F;strokeWidth=3;" target="flaskCard" value="">
116
+ <mxGeometry relative="1" as="geometry">
117
+ <Array as="points">
118
+ <mxPoint x="730" y="320" />
119
+ <mxPoint x="730" y="320" />
120
+ </Array>
121
+ </mxGeometry>
122
+ </mxCell>
123
+ <mxCell id="e2" edge="1" parent="1" source="hospitalCard" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;endFill=1;strokeColor=#42536F;strokeWidth=3;" target="flaskCard" value="">
124
+ <mxGeometry relative="1" as="geometry">
125
+ <Array as="points">
126
+ <mxPoint x="1380" y="330" />
127
+ <mxPoint x="1380" y="330" />
128
+ </Array>
129
+ </mxGeometry>
130
+ </mxCell>
131
+ <mxCell id="e4" edge="1" parent="1" source="flaskCard" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;endFill=1;strokeColor=#42536F;strokeWidth=3;" target="mlCard" value="">
132
+ <mxGeometry relative="1" as="geometry" />
133
+ </mxCell>
134
+ <mxCell id="e5" edge="1" parent="1" source="srcCard" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;endFill=1;strokeColor=#42536F;strokeWidth=3;" target="mlCard" value="">
135
+ <mxGeometry relative="1" as="geometry" />
136
+ </mxCell>
137
+ <mxCell id="e6" edge="1" parent="1" source="mlCard" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;endFill=1;strokeColor=#42536F;strokeWidth=3;" target="flaskCard" value="">
138
+ <mxGeometry relative="1" as="geometry">
139
+ <Array as="points">
140
+ <mxPoint x="1130" y="700" />
141
+ <mxPoint x="1130" y="700" />
142
+ </Array>
143
+ </mxGeometry>
144
+ </mxCell>
145
+ <mxCell id="footer" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=18;fontStyle=1;fontColor=#667892;align=center;" value="FLOW: portals -&amp;gt; Flask app -&amp;gt; matching engine -&amp;gt; recommendations, with app state stored in SQLite" vertex="1">
146
+ <mxGeometry height="36.423529411764704" width="1322.1476510067116" x="393.758389261745" y="1113.2235294117647" as="geometry" />
147
+ </mxCell>
148
+ <mxCell id="sec2" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=18;fontStyle=1;fontColor=#61728E;letterSpacing=1;" value="APPLICATION LAYER" vertex="1">
149
+ <mxGeometry height="36.423529411764704" width="251.20805369127518" x="499.9986577181208" y="319.99823529411765" as="geometry" />
150
+ </mxCell>
151
+ <mxCell id="7qRbrwoMCzgDvgHPFRhy-5" edge="1" parent="1" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;endFill=1;strokeColor=#42536F;strokeWidth=3;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" target="dbCard" value="">
152
+ <mxGeometry relative="1" as="geometry">
153
+ <Array as="points">
154
+ <mxPoint x="407" y="550" />
155
+ </Array>
156
+ <mxPoint x="640" y="550" as="sourcePoint" />
157
+ <mxPoint x="400" y="709" as="targetPoint" />
158
+ </mxGeometry>
159
+ </mxCell>
160
+ </root>
161
+ </mxGraphModel>
162
+ </diagram>
163
+ </mxfile>
Architecture Diagrams/secondlife high level architecture.png ADDED

Git LFS Details

  • SHA256: f275ea340ea91d6993d2fe1b36c3154248d03aecf00394b1b2162db9e5953e1a
  • Pointer size: 131 Bytes
  • Size of remote file: 348 kB
Architecture Diagrams/secondlife low level architecture.drawio ADDED
@@ -0,0 +1,306 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <mxGraphModel dx="1422" dy="762" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1700" pageHeight="1100" math="0" shadow="0">
3
+ <root>
4
+ <mxCell id="0" />
5
+ <mxCell id="1" parent="0" />
6
+
7
+ <!-- ============================================================
8
+ TITLE
9
+ ============================================================ -->
10
+ <mxCell id="TITLE" value="Second Life — System Architecture | DSCI 5260 · Group 7 | AI-Powered Clinical Trial Matching" style="text;html=1;strokeColor=none;fillColor=none;fontSize=16;fontStyle=1;fontColor=#003366;align=center;" vertex="1" parent="1">
11
+ <mxGeometry x="10" y="1078" width="1680" height="30" as="geometry" />
12
+ </mxCell>
13
+
14
+ <!-- ============================================================
15
+ LAYER 1 — BROWSER
16
+ ============================================================ -->
17
+ <mxCell id="L1" value="🌐 Browser (Client)" style="swimlane;startSize=32;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14;fontStyle=1;fontColor=#003366;swimlaneLine=1;" vertex="1" parent="1">
18
+ <mxGeometry x="10" y="10" width="1680" height="235" as="geometry" />
19
+ </mxCell>
20
+
21
+ <!-- Patient Portal -->
22
+ <mxCell id="PPG" value="Patient Portal — patient.html" style="swimlane;startSize=24;fillColor=#cce5ff;strokeColor=#0066cc;fontSize=11;fontStyle=1;" vertex="1" parent="L1">
23
+ <mxGeometry x="20" y="37" width="574" height="183" as="geometry" />
24
+ </mxCell>
25
+ <mxCell id="PP1" value="My Profile&#xa;conditions · meds&#xa;documents upload" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e8f4fd;strokeColor=#0066cc;fontSize=9;" vertex="1" parent="PPG">
26
+ <mxGeometry x="10" y="30" width="120" height="65" as="geometry" />
27
+ </mxCell>
28
+ <mxCell id="PP2" value="Suggested Trials&#xa;AI-ranked top-20&#xa;combined_score" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e8f4fd;strokeColor=#0066cc;fontSize=9;" vertex="1" parent="PPG">
29
+ <mxGeometry x="140" y="30" width="120" height="65" as="geometry" />
30
+ </mxCell>
31
+ <mxCell id="PP3" value="My Connections&#xa;status · chat modal&#xa;view history" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e8f4fd;strokeColor=#0066cc;fontSize=9;" vertex="1" parent="PPG">
32
+ <mxGeometry x="270" y="30" width="120" height="65" as="geometry" />
33
+ </mxCell>
34
+ <mxCell id="PP4" value="Inbox 🔴&#xa;unread count badge&#xa;all message threads" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e8f4fd;strokeColor=#0066cc;fontSize=9;" vertex="1" parent="PPG">
35
+ <mxGeometry x="400" y="30" width="120" height="65" as="geometry" />
36
+ </mxCell>
37
+ <mxCell id="PP_NOTE" value="Bootstrap 5.3 dark SPA · escH() / escA() XSS guards · DOM API only (no innerHTML for user data) · startStatusPoll() 5s interval · cookie session auth" style="text;html=1;strokeColor=none;fillColor=none;fontSize=8;fontColor=#555;align=left;" vertex="1" parent="PPG">
38
+ <mxGeometry x="10" y="106" width="554" height="16" as="geometry" />
39
+ </mxCell>
40
+
41
+ <!-- Landing Page -->
42
+ <mxCell id="LP" value="landing.html&#xa;&#xa;Login · Register&#xa;Patient &amp; Hospital" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e6f3ff;strokeColor=#3385ff;fontSize=10;fontStyle=1;" vertex="1" parent="L1">
43
+ <mxGeometry x="651" y="70" width="158" height="95" as="geometry" />
44
+ </mxCell>
45
+
46
+ <!-- Hospital Portal -->
47
+ <mxCell id="HPG" value="Hospital Portal — hospital.html" style="swimlane;startSize=24;fillColor=#d5e8d4;strokeColor=#5b9e5b;fontSize=11;fontStyle=1;" vertex="1" parent="L1">
48
+ <mxGeometry x="866" y="37" width="804" height="183" as="geometry" />
49
+ </mxCell>
50
+ <mxCell id="HP1" value="Available&#xa;Patients&#xa;opt-in only" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e8f5e8;strokeColor=#5b9e5b;fontSize=9;" vertex="1" parent="HPG">
51
+ <mxGeometry x="10" y="30" width="113" height="65" as="geometry" />
52
+ </mxCell>
53
+ <mxCell id="HP2" value="Search by&#xa;Condition&#xa;incl. connected" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e8f5e8;strokeColor=#5b9e5b;fontSize=9;" vertex="1" parent="HPG">
54
+ <mxGeometry x="133" y="30" width="113" height="65" as="geometry" />
55
+ </mxCell>
56
+ <mxCell id="HP3" value="My Trials&#xa;3-tier active&#xa;match" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e8f5e8;strokeColor=#5b9e5b;fontSize=9;" vertex="1" parent="HPG">
57
+ <mxGeometry x="256" y="30" width="113" height="65" as="geometry" />
58
+ </mxCell>
59
+ <mxCell id="HP4" value="Inbox 🔴&#xa;unread badge&#xa;message threads" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e8f5e8;strokeColor=#5b9e5b;fontSize=9;" vertex="1" parent="HPG">
60
+ <mxGeometry x="379" y="30" width="113" height="65" as="geometry" />
61
+ </mxCell>
62
+ <mxCell id="HP5" value="My&#xa;Connections&#xa;accept / reject" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e8f5e8;strokeColor=#5b9e5b;fontSize=9;" vertex="1" parent="HPG">
63
+ <mxGeometry x="502" y="30" width="113" height="65" as="geometry" />
64
+ </mxCell>
65
+ <mxCell id="HP6" value="My Profile&#xa;name · location&#xa;conditions" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e8f5e8;strokeColor=#5b9e5b;fontSize=9;" vertex="1" parent="HPG">
66
+ <mxGeometry x="625" y="30" width="113" height="65" as="geometry" />
67
+ </mxCell>
68
+ <mxCell id="HP_NOTE" value="Bootstrap 5.3 dark SPA · escH() / escA() XSS guards · navbar name updates live on profile save · Search includes already-connected toggle" style="text;html=1;strokeColor=none;fillColor=none;fontSize=8;fontColor=#555;align=left;" vertex="1" parent="HPG">
69
+ <mxGeometry x="10" y="106" width="784" height="16" as="geometry" />
70
+ </mxCell>
71
+
72
+ <!-- ============================================================
73
+ LAYER 2 — FLASK SERVER
74
+ ============================================================ -->
75
+ <mxCell id="L2" value="⚙️ Flask Server — app.py (port 5000) · TEMPLATES_AUTO_RELOAD=True · MAX_CONTENT_LENGTH=10 MB · server-side cookie sessions" style="swimlane;startSize=32;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=13;fontStyle=1;fontColor=#3d0066;" vertex="1" parent="1">
76
+ <mxGeometry x="10" y="255" width="1680" height="280" as="geometry" />
77
+ </mxCell>
78
+
79
+ <mxCell id="AR" value="🔐 Auth Routes&#xa;(no session required)&#xa;&#xa;POST /auth/patient/register&#xa;POST /auth/patient/login&#xa;POST /auth/hospital/register&#xa;POST /auth/hospital/login&#xa;POST /auth/logout" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f3e5f5;strokeColor=#9673a6;fontSize=9;align=left;spacingLeft=8;verticalAlign=top;spacingTop=8;" vertex="1" parent="L2">
80
+ <mxGeometry x="20" y="40" width="215" height="220" as="geometry" />
81
+ </mxCell>
82
+
83
+ <mxCell id="PAR" value="👤 Patient API&#xa;(patient session)&#xa;&#xa;GET | POST /api/patient/profile&#xa;GET /api/patient/matches&#xa;GET | POST | DELETE&#xa; /api/patient/interest&#xa;GET /api/patient/connections&#xa;POST /api/patient/connect&#xa;GET /api/patient/hospitals-for-trial" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#cce5ff;strokeColor=#0066cc;fontSize=9;align=left;spacingLeft=8;verticalAlign=top;spacingTop=8;" vertex="1" parent="L2">
84
+ <mxGeometry x="248" y="40" width="250" height="220" as="geometry" />
85
+ </mxCell>
86
+
87
+ <mxCell id="HAR" value="🏥 Hospital API&#xa;(hospital session)&#xa;&#xa;GET | POST /api/hospital/profile&#xa;GET /api/hospital/patients&#xa;GET /api/hospital/trials&#xa;POST /api/hospital/connect&#xa;GET /api/hospital/connections&#xa;PUT /api/hospital/connections/&#xa; &lt;cid&gt;/status" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#5b9e5b;fontSize=9;align=left;spacingLeft=8;verticalAlign=top;spacingTop=8;" vertex="1" parent="L2">
88
+ <mxGeometry x="511" y="40" width="265" height="220" as="geometry" />
89
+ </mxCell>
90
+
91
+ <mxCell id="MR" value="💬 Messaging + Inbox&#xa;&#xa;GET | POST&#xa; /api/patient/connections/&lt;cid&gt;/messages&#xa;GET /api/patient/inbox&#xa;&#xa;GET | POST&#xa; /api/hospital/connections/&lt;cid&gt;/messages&#xa;GET /api/hospital/inbox&#xa;&#xa;→ mark_messages_read() on GET&#xa;→ get_*_inbox_threads() + unread_count" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=9;align=left;spacingLeft=8;verticalAlign=top;spacingTop=8;" vertex="1" parent="L2">
92
+ <mxGeometry x="789" y="40" width="280" height="220" as="geometry" />
93
+ </mxCell>
94
+
95
+ <mxCell id="DR" value="📄 Documents&#xa;&#xa;GET /api/patient/documents&#xa;POST /api/patient/documents&#xa; → multipart/form-data&#xa; → secure_filename()&#xa; → ALLOWED: .pdf .docx .doc&#xa; .txt .png .jpg .jpeg&#xa; → max 10 MB&#xa;DELETE /api/patient/documents/&lt;id&gt;&#xa;GET /api/patient/documents/&lt;id&gt;/download" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=9;align=left;spacingLeft=8;verticalAlign=top;spacingTop=8;" vertex="1" parent="L2">
96
+ <mxGeometry x="1082" y="40" width="255" height="220" as="geometry" />
97
+ </mxCell>
98
+
99
+ <mxCell id="SR" value="🔧 Shared + Boot Thread&#xa;&#xa;GET /api/status&#xa; → ready: true|false + stats&#xa;GET /api/conditions/autocomplete&#xa;&#xa;─────────────────────&#xa;🚀 Boot Thread (background)&#xa;① db.init_db()&#xa; → create 5 tables&#xa; → seed 25 patients + 3 hospitals&#xa;② pipeline.load()&#xa; → read 11 CSV files into memory&#xa;③ pipeline.train()&#xa; → build RF or load model_cache.pkl" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=9;align=left;spacingLeft=8;verticalAlign=top;spacingTop=8;" vertex="1" parent="L2">
100
+ <mxGeometry x="1350" y="40" width="310" height="220" as="geometry" />
101
+ </mxCell>
102
+
103
+ <!-- ============================================================
104
+ LAYER 3 — BUSINESS LOGIC
105
+ ============================================================ -->
106
+ <mxCell id="L3" value="🧠 Business Logic" style="swimlane;startSize=32;fillColor=#fff8e1;strokeColor=#d6a000;fontSize=14;fontStyle=1;fontColor=#5a3e00;" vertex="1" parent="1">
107
+ <mxGeometry x="10" y="545" width="1680" height="300" as="geometry" />
108
+ </mxCell>
109
+
110
+ <!-- database.py -->
111
+ <mxCell id="DBG" value="database.py — SQLite Layer" style="swimlane;startSize=24;fillColor=#d5e8d4;strokeColor=#5b9e5b;fontSize=11;fontStyle=1;" vertex="1" parent="L3">
112
+ <mxGeometry x="20" y="38" width="705" height="252" as="geometry" />
113
+ </mxCell>
114
+ <mxCell id="T1" value="patient_accounts&#xa;25 rows&#xa;5 demo + 20 Synthea" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=12;fillColor=#d5e8d4;strokeColor=#5b9e5b;fontSize=9;" vertex="1" parent="DBG">
115
+ <mxGeometry x="10" y="32" width="122" height="68" as="geometry" />
116
+ </mxCell>
117
+ <mxCell id="T2" value="hospital_accounts&#xa;3 rows&#xa;mgh, cleveland, jhopkins" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=12;fillColor=#d5e8d4;strokeColor=#5b9e5b;fontSize=9;" vertex="1" parent="DBG">
118
+ <mxGeometry x="144" y="32" width="122" height="68" as="geometry" />
119
+ </mxCell>
120
+ <mxCell id="T3" value="patient_trial_interests&#xa;UNIQUE(patient_id,&#xa;trial_id)" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=12;fillColor=#d5e8d4;strokeColor=#5b9e5b;fontSize=9;" vertex="1" parent="DBG">
121
+ <mxGeometry x="278" y="32" width="122" height="68" as="geometry" />
122
+ </mxCell>
123
+ <mxCell id="T4" value="connections&#xa;UNIQUE(patient, hospital,&#xa;COALESCE(trial,''))" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=12;fillColor=#d5e8d4;strokeColor=#5b9e5b;fontSize=9;" vertex="1" parent="DBG">
124
+ <mxGeometry x="412" y="32" width="132" height="68" as="geometry" />
125
+ </mxCell>
126
+ <mxCell id="T5" value="connection_messages&#xa;sender_role: patient|hospital&#xa;is_read: 0 | 1" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=12;fillColor=#d5e8d4;strokeColor=#5b9e5b;fontSize=9;" vertex="1" parent="DBG">
127
+ <mxGeometry x="556" y="32" width="132" height="68" as="geometry" />
128
+ </mxCell>
129
+ <mxCell id="DBF1" value="Key functions: authenticate_patient / authenticate_hospital · update_patient_profile / update_hospital_profile · get_open_patients_for_hospital(condition, include_connected) · create_connection / connection_exists · update_connection_status · create_connection_message · mark_messages_read · get_hospital_inbox_threads / get_patient_inbox_threads · _seed_dataset_patients(20)" style="text;html=1;strokeColor=none;fillColor=none;fontSize=8;fontColor=#333;align=left;" vertex="1" parent="DBG">
130
+ <mxGeometry x="10" y="112" width="685" height="30" as="geometry" />
131
+ </mxCell>
132
+ <mxCell id="DBF2" value="JSON columns (conditions, medications, documents, research_conditions) stored as TEXT · parsed by _row_to_dict() · passwords: SHA-256 via _hash() · idx_conn_unique handles NULL trial_id · idx_msgs_conn on (connection_id, created_at)" style="text;html=1;strokeColor=none;fillColor=none;fontSize=8;fontColor=#555;align=left;" vertex="1" parent="DBG">
133
+ <mxGeometry x="10" y="148" width="685" height="30" as="geometry" />
134
+ </mxCell>
135
+
136
+ <!-- pipeline.py -->
137
+ <mxCell id="PLG" value="pipeline.py — SecondLifePipeline (ML Engine)" style="swimlane;startSize=24;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=11;fontStyle=1;" vertex="1" parent="L3">
138
+ <mxGeometry x="745" y="38" width="925" height="252" as="geometry" />
139
+ </mxCell>
140
+ <mxCell id="PL1" value="load()&#xa;Reads 11 CSV files → memory&#xa;trial_profiles · active_trial_ids&#xa;trial_us_states · facility_tokens&#xa;drug_keywords · summaries&#xa;patient_conditions · meds · labs&#xa;~2–3 min on first boot" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff3e0;strokeColor=#d79b00;fontSize=9;" vertex="1" parent="PLG">
141
+ <mxGeometry x="10" y="32" width="165" height="115" as="geometry" />
142
+ </mxCell>
143
+ <mxCell id="PL2" value="train()&#xa;3000 patients × 30 trials&#xa;_compute_features() 17 feats&#xa;pseudo-label: 6-feat weighted score&#xa;GroupShuffleSplit 80/20 (patient-level)&#xa;RandomForest n=200, depth=12&#xa;CalibratedClassifierCV isotonic cv=3&#xa;→ save model_cache.pkl" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff3e0;strokeColor=#d79b00;fontSize=9;" vertex="1" parent="PLG">
144
+ <mxGeometry x="188" y="32" width="180" height="115" as="geometry" />
145
+ </mxCell>
146
+ <mxCell id="PL3" value="match_patient()&#xa;Input: conditions, age,&#xa; gender, patient_id&#xa;Scores all active trials&#xa;combined = 0.6 × RF_prob&#xa; + 0.4 × match_score&#xa;Returns top-20 ranked trials" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff3e0;strokeColor=#d79b00;fontSize=9;" vertex="1" parent="PLG">
147
+ <mxGeometry x="382" y="32" width="170" height="115" as="geometry" />
148
+ </mxCell>
149
+ <mxCell id="PL4" value="trials_for_hospital()&#xa;Input: name, location,&#xa; research_conditions&#xa;Tier1: facility Jaccard ≥ 0.25&#xa;Tier2: same US state&#xa;Tier3: condition overlap&#xa;Active-only filter every tier" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff3e0;strokeColor=#d79b00;fontSize=9;" vertex="1" parent="PLG">
150
+ <mxGeometry x="566" y="32" width="165" height="115" as="geometry" />
151
+ </mxCell>
152
+ <mxCell id="PL5" value="hospitals_for_trial()&#xa;Input: trial_id&#xa;Tier1: Jaccard ≥ 0.25 → 🟢&#xa;Tier2: same state → ⬜&#xa;Tier3: cond overlap → ⬜&#xa;Tier4: fallback → ⬜&#xa;Modal: green vs grey sections" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff3e0;strokeColor=#d79b00;fontSize=9;" vertex="1" parent="PLG">
153
+ <mxGeometry x="745" y="32" width="165" height="115" as="geometry" />
154
+ </mxCell>
155
+ <mxCell id="PLM" value="17 Features: condition_overlap · jaccard_similarity · overlap_ratio_trial · overlap_ratio_patient · condition_rarity_score · trial_specificity · condition_burden · active_ratio · resolved_ratio · age_distance · age_centered · age_compatibility · gender_compatibility · geo_feasibility · med_compatibility · lab_availability · data_completeness" style="text;html=1;strokeColor=none;fillColor=none;fontSize=8;fontColor=#333;align=left;" vertex="1" parent="PLG">
156
+ <mxGeometry x="10" y="158" width="905" height="20" as="geometry" />
157
+ </mxCell>
158
+ <mxCell id="PLM2" value="AUC-ROC: 0.60 · Accuracy: 85.1% · F1: 0.917 · Precision: 0.852 · Recall: 0.993 · 90,994 training pairs · 82.1% pseudo-label positive rate · GroupShuffleSplit prevents patient-level data leakage" style="text;html=1;strokeColor=none;fillColor=none;fontSize=8;fontColor=#555;align=left;" vertex="1" parent="PLG">
159
+ <mxGeometry x="10" y="182" width="905" height="20" as="geometry" />
160
+ </mxCell>
161
+
162
+ <!-- ============================================================
163
+ LAYER 4 — STORAGE
164
+ ============================================================ -->
165
+ <mxCell id="L4" value="💾 Storage" style="swimlane;startSize=32;fillColor=#f5f5f5;strokeColor=#666666;fontSize=14;fontStyle=1;fontColor=#333;" vertex="1" parent="1">
166
+ <mxGeometry x="10" y="855" width="1680" height="215" as="geometry" />
167
+ </mxCell>
168
+
169
+ <mxCell id="S1" value="secondlife.db&#xa;SQLite file&#xa;5 tables · auto-created&#xa;on init_db()" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=14;fillColor=#d5e8d4;strokeColor=#5b9e5b;fontStyle=1;fontSize=10;" vertex="1" parent="L4">
170
+ <mxGeometry x="75" y="45" width="155" height="120" as="geometry" />
171
+ </mxCell>
172
+
173
+ <mxCell id="S2" value="model_cache.pkl&#xa;RandomForest +&#xa;CalibratedClassifierCV&#xa;delete to force retrain" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=14;fillColor=#ffe6cc;strokeColor=#d79b00;fontStyle=1;fontSize=10;" vertex="1" parent="L4">
174
+ <mxGeometry x="325" y="45" width="155" height="120" as="geometry" />
175
+ </mxCell>
176
+
177
+ <mxCell id="S3" value="uploads/patient_docs/&#xa;&lt;patient_id&gt;/&#xa;&lt;doc_id&gt;_filename&#xa;10 MB max · auto-created" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=14;fillColor=#cce5ff;strokeColor=#0066cc;fontStyle=1;fontSize=10;" vertex="1" parent="L4">
178
+ <mxGeometry x="575" y="45" width="155" height="120" as="geometry" />
179
+ </mxCell>
180
+
181
+ <mxCell id="S4" value="Synthea Patient CSVs&#xa;&#xa;patients_details.csv&#xa; 265,893 patients · demographics&#xa;final_patients_conditions.csv&#xa; 967k rows · 106 conditions&#xa;patients_medications.csv&#xa; 213,182 patients&#xa;patients_observations.csv&#xa; 23,231 patients with lab data" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e8f5e8;strokeColor=#5b9e5b;fontSize=9;align=left;spacingLeft=8;verticalAlign=top;spacingTop=8;" vertex="1" parent="L4">
182
+ <mxGeometry x="855" y="38" width="275" height="158" as="geometry" />
183
+ </mxCell>
184
+
185
+ <mxCell id="S5" value="ClinicalTrials.gov / AACT CSVs&#xa;&#xa;trail_studies.csv — 65k recruiting trials&#xa;trail_conditions.csv — 34k with conditions&#xa;trail_eligibilities.csv — age · gender&#xa;trail_facilities.csv — 189k with US geo&#xa;trail_interventions.csv — 196k with drugs&#xa;trail_brief_summaries.csv — summaries&#xa;trail_keywords.csv — keyword index" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff3e0;strokeColor=#d79b00;fontSize=9;align=left;spacingLeft=8;verticalAlign=top;spacingTop=8;" vertex="1" parent="L4">
186
+ <mxGeometry x="1230" y="38" width="310" height="158" as="geometry" />
187
+ </mxCell>
188
+
189
+ <!-- ============================================================
190
+ LEGEND
191
+ ============================================================ -->
192
+ <mxCell id="LEG" value="Legend" style="swimlane;startSize=22;fillColor=#ffffff;strokeColor=#999999;fontSize=10;fontStyle=1;" vertex="1" parent="1">
193
+ <mxGeometry x="10" y="1085" width="1680" height="0" as="geometry" />
194
+ </mxCell>
195
+
196
+ <!-- ============================================================
197
+ ARROWS — DATA FLOW
198
+ ============================================================ -->
199
+
200
+ <!-- Patient Portal → Patient API (REST/JSON) -->
201
+ <mxCell id="E1" value="REST/JSON" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#0066cc;strokeWidth=2;fontStyle=2;fontSize=8;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" source="PPG" target="PAR" parent="1">
202
+ <mxGeometry relative="1" as="geometry" />
203
+ </mxCell>
204
+
205
+ <!-- Patient Portal → Messaging/Inbox (dashed) -->
206
+ <mxCell id="E2" value="chat / inbox" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#d6b656;strokeWidth=1.5;dashed=1;fontStyle=2;fontSize=8;" edge="1" source="PP4" target="MR" parent="1">
207
+ <mxGeometry relative="1" as="geometry" />
208
+ </mxCell>
209
+
210
+ <!-- Patient Portal → Documents (dashed) -->
211
+ <mxCell id="E3" value="upload / download" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#d79b00;strokeWidth=1.5;dashed=1;fontStyle=2;fontSize=8;" edge="1" source="PP1" target="DR" parent="1">
212
+ <mxGeometry relative="1" as="geometry" />
213
+ </mxCell>
214
+
215
+ <!-- Landing → Auth -->
216
+ <mxCell id="E4" value="login / register" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#9673a6;strokeWidth=2;fontStyle=2;fontSize=8;" edge="1" source="LP" target="AR" parent="1">
217
+ <mxGeometry relative="1" as="geometry" />
218
+ </mxCell>
219
+
220
+ <!-- Hospital Portal → Hospital API -->
221
+ <mxCell id="E5" value="REST/JSON" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#5b9e5b;strokeWidth=2;fontStyle=2;fontSize=8;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" source="HPG" target="HAR" parent="1">
222
+ <mxGeometry relative="1" as="geometry" />
223
+ </mxCell>
224
+
225
+ <!-- Hospital Portal → Messaging (dashed) -->
226
+ <mxCell id="E6" value="chat / inbox" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#d6b656;strokeWidth=1.5;dashed=1;fontStyle=2;fontSize=8;" edge="1" source="HP4" target="MR" parent="1">
227
+ <mxGeometry relative="1" as="geometry" />
228
+ </mxCell>
229
+
230
+ <!-- Auth → DB -->
231
+ <mxCell id="E7" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#9673a6;strokeWidth=1.5;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.1;entryY=0;entryDx=0;entryDy=0;" edge="1" source="AR" target="DBG" parent="1">
232
+ <mxGeometry relative="1" as="geometry" />
233
+ </mxCell>
234
+
235
+ <!-- Patient API → DB -->
236
+ <mxCell id="E8" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#0066cc;strokeWidth=2;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.3;entryY=0;entryDx=0;entryDy=0;" edge="1" source="PAR" target="DBG" parent="1">
237
+ <mxGeometry relative="1" as="geometry" />
238
+ </mxCell>
239
+
240
+ <!-- Patient API → match_patient() -->
241
+ <mxCell id="E9" value="match_patient()" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#d79b00;strokeWidth=2;fontStyle=3;fontSize=8;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" source="PAR" target="PL3" parent="1">
242
+ <mxGeometry relative="1" as="geometry" />
243
+ </mxCell>
244
+
245
+ <!-- Patient API → hospitals_for_trial() -->
246
+ <mxCell id="E10" value="hospitals_for_trial()" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#d79b00;strokeWidth=1.5;dashed=1;fontStyle=3;fontSize=8;exitX=0.75;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" source="PAR" target="PL5" parent="1">
247
+ <mxGeometry relative="1" as="geometry" />
248
+ </mxCell>
249
+
250
+ <!-- Hospital API → DB -->
251
+ <mxCell id="E11" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#5b9e5b;strokeWidth=2;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" source="HAR" target="DBG" parent="1">
252
+ <mxGeometry relative="1" as="geometry" />
253
+ </mxCell>
254
+
255
+ <!-- Hospital API → trials_for_hospital() -->
256
+ <mxCell id="E12" value="trials_for_hospital()" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#d79b00;strokeWidth=2;fontStyle=3;fontSize=8;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" source="HAR" target="PL4" parent="1">
257
+ <mxGeometry relative="1" as="geometry" />
258
+ </mxCell>
259
+
260
+ <!-- Messaging → DB (connections + messages tables) -->
261
+ <mxCell id="E13" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#d6b656;strokeWidth=1.5;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.75;entryY=0;entryDx=0;entryDy=0;" edge="1" source="MR" target="DBG" parent="1">
262
+ <mxGeometry relative="1" as="geometry" />
263
+ </mxCell>
264
+
265
+ <!-- Documents → DB (updates patient documents JSON) -->
266
+ <mxCell id="E14" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#d79b00;strokeWidth=1.5;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.88;entryY=0;entryDx=0;entryDy=0;" edge="1" source="DR" target="DBG" parent="1">
267
+ <mxGeometry relative="1" as="geometry" />
268
+ </mxCell>
269
+
270
+ <!-- Documents → File Storage -->
271
+ <mxCell id="E15" value="file I/O" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#d79b00;strokeWidth=1.5;dashed=1;fontStyle=3;fontSize=8;" edge="1" source="DR" target="S3" parent="1">
272
+ <mxGeometry relative="1" as="geometry" />
273
+ </mxCell>
274
+
275
+ <!-- Boot Thread → DB (seed data) -->
276
+ <mxCell id="E16" value="① seed" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#666;strokeWidth=1.5;dashed=1;fontStyle=3;fontSize=8;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0;entryDx=0;entryDy=0;" edge="1" source="SR" target="DBG" parent="1">
277
+ <mxGeometry relative="1" as="geometry" />
278
+ </mxCell>
279
+
280
+ <!-- Boot Thread → Pipeline (load + train) -->
281
+ <mxCell id="E17" value="② load ③ train" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#666;strokeWidth=1.5;dashed=1;fontStyle=3;fontSize=8;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0;entryDx=0;entryDy=0;" edge="1" source="SR" target="PLG" parent="1">
282
+ <mxGeometry relative="1" as="geometry" />
283
+ </mxCell>
284
+
285
+ <!-- DB → secondlife.db file -->
286
+ <mxCell id="E18" value="read / write" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#5b9e5b;strokeWidth=2;fontStyle=2;fontSize=8;" edge="1" source="DBG" target="S1" parent="1">
287
+ <mxGeometry relative="1" as="geometry" />
288
+ </mxCell>
289
+
290
+ <!-- Pipeline → model_cache.pkl -->
291
+ <mxCell id="E19" value="load / save" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#d79b00;strokeWidth=2;fontStyle=2;fontSize=8;" edge="1" source="PLG" target="S2" parent="1">
292
+ <mxGeometry relative="1" as="geometry" />
293
+ </mxCell>
294
+
295
+ <!-- pipeline.load() → Synthea CSVs -->
296
+ <mxCell id="E20" value="read on boot" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#5b9e5b;strokeWidth=1.5;dashed=1;fontStyle=3;fontSize=8;exitX=0.2;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" source="PL1" target="S4" parent="1">
297
+ <mxGeometry relative="1" as="geometry" />
298
+ </mxCell>
299
+
300
+ <!-- pipeline.load() → Trial CSVs -->
301
+ <mxCell id="E21" value="read on boot" style="edgeStyle=orthogonalEdgeStyle;html=1;rounded=1;strokeColor=#d79b00;strokeWidth=1.5;dashed=1;fontStyle=3;fontSize=8;exitX=0.8;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" source="PL1" target="S5" parent="1">
302
+ <mxGeometry relative="1" as="geometry" />
303
+ </mxCell>
304
+
305
+ </root>
306
+ </mxGraphModel>
Architecture Diagrams/secondlife workflow architecture diagrams.html ADDED
@@ -0,0 +1,828 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Second Life — Architecture Diagrams</title>
7
+ <script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
8
+ <style>
9
+ * { box-sizing: border-box; margin: 0; padding: 0; }
10
+
11
+ body {
12
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
13
+ background: #0d1117;
14
+ color: #c9d1d9;
15
+ padding: 2rem;
16
+ max-width: 1600px;
17
+ margin: 0 auto;
18
+ line-height: 1.6;
19
+ }
20
+
21
+ header {
22
+ border-bottom: 1px solid #30363d;
23
+ padding-bottom: 1.5rem;
24
+ margin-bottom: 2rem;
25
+ }
26
+
27
+ header h1 {
28
+ font-size: 2rem;
29
+ color: #58a6ff;
30
+ margin-bottom: 0.25rem;
31
+ }
32
+
33
+ header p { color: #8b949e; font-size: 0.95rem; }
34
+
35
+ .toc {
36
+ background: #161b22;
37
+ border: 1px solid #30363d;
38
+ border-radius: 8px;
39
+ padding: 1.25rem 1.5rem;
40
+ margin-bottom: 3rem;
41
+ }
42
+
43
+ .toc h3 { color: #79c0ff; font-size: 0.875rem; text-transform: uppercase;
44
+ letter-spacing: 0.05em; margin-bottom: 0.75rem; }
45
+
46
+ .toc ol { padding-left: 1.25rem; }
47
+
48
+ .toc li { margin-bottom: 0.3rem; }
49
+
50
+ .toc a { color: #58a6ff; text-decoration: none; font-size: 0.9rem; }
51
+ .toc a:hover { text-decoration: underline; }
52
+
53
+ section {
54
+ margin-bottom: 4rem;
55
+ scroll-margin-top: 2rem;
56
+ }
57
+
58
+ section h2 {
59
+ font-size: 1.4rem;
60
+ color: #79c0ff;
61
+ margin-bottom: 0.4rem;
62
+ }
63
+
64
+ .subtitle {
65
+ color: #8b949e;
66
+ font-size: 0.875rem;
67
+ margin-bottom: 1.25rem;
68
+ }
69
+
70
+ .diagram-wrap {
71
+ background: #161b22;
72
+ border: 1px solid #30363d;
73
+ border-radius: 10px;
74
+ padding: 2rem;
75
+ overflow-x: auto;
76
+ }
77
+
78
+ .mermaid {
79
+ display: flex;
80
+ justify-content: center;
81
+ }
82
+
83
+ .legend {
84
+ margin-top: 1.25rem;
85
+ display: flex;
86
+ flex-wrap: wrap;
87
+ gap: 0.75rem;
88
+ }
89
+
90
+ .legend-item {
91
+ display: flex;
92
+ align-items: center;
93
+ gap: 0.4rem;
94
+ font-size: 0.8rem;
95
+ color: #8b949e;
96
+ }
97
+
98
+ .legend-dot {
99
+ width: 10px;
100
+ height: 10px;
101
+ border-radius: 50%;
102
+ flex-shrink: 0;
103
+ }
104
+
105
+ .note {
106
+ margin-top: 1rem;
107
+ padding: 0.75rem 1rem;
108
+ background: #1c2128;
109
+ border-left: 3px solid #388bfd;
110
+ border-radius: 0 6px 6px 0;
111
+ font-size: 0.85rem;
112
+ color: #8b949e;
113
+ }
114
+
115
+ .note strong { color: #c9d1d9; }
116
+
117
+ .grid-2 {
118
+ display: grid;
119
+ grid-template-columns: 1fr 1fr;
120
+ gap: 1.5rem;
121
+ }
122
+
123
+ @media (max-width: 900px) {
124
+ .grid-2 { grid-template-columns: 1fr; }
125
+ body { padding: 1rem; }
126
+ }
127
+ </style>
128
+ </head>
129
+ <body>
130
+
131
+ <header>
132
+ <h1>⚕️ Second Life — Architecture Diagrams</h1>
133
+ <p>DSCI 5260 · Group 7 · AI-powered Patient-to-Clinical-Trial Matching Platform · Flask + SQLite + Random Forest</p>
134
+ </header>
135
+
136
+ <div class="toc">
137
+ <h3>Contents</h3>
138
+ <ol>
139
+ <li><a href="#s1">System Architecture Overview</a></li>
140
+ <li><a href="#s2">Database Schema (ER Diagram)</a></li>
141
+ <li><a href="#s3">ML Pipeline — Boot, Train, Infer</a></li>
142
+ <li><a href="#s4">Patient User Journey (Sequence)</a></li>
143
+ <li><a href="#s5">Hospital User Journey (Sequence)</a></li>
144
+ <li><a href="#s6">Tiered Matching Logic</a></li>
145
+ <li><a href="#s7">Feature Engineering — 17 Features</a></li>
146
+ </ol>
147
+ </div>
148
+
149
+ <!-- =========================================================
150
+ 1. SYSTEM ARCHITECTURE OVERVIEW
151
+ ========================================================= -->
152
+ <section id="s1">
153
+ <h2>1. System Architecture Overview</h2>
154
+ <p class="subtitle">
155
+ Four-layer architecture: Browser &rarr; Flask Server &rarr; Business Logic (DB + ML) &rarr; Storage.
156
+ The pipeline boots in a background thread so the server is immediately available.
157
+ </p>
158
+ <div class="diagram-wrap">
159
+ <div class="mermaid">
160
+ flowchart LR
161
+ subgraph BROWSER["🌐 Browser (Client)"]
162
+ direction TB
163
+ LAND["<b>landing.html</b><br/>Login · Register<br/>(Patient &amp; Hospital)"]
164
+ subgraph PAT_SPA["Patient Portal — patient.html"]
165
+ direction TB
166
+ PA["My Profile<br/><small>conditions · meds · docs upload</small>"]
167
+ PB["Suggested Trials<br/><small>AI-ranked top-20</small>"]
168
+ PC["My Connections<br/><small>status · chat</small>"]
169
+ PD["Inbox 🔴<br/><small>unread count badge</small>"]
170
+ end
171
+ subgraph HOSP_SPA["Hospital Portal — hospital.html"]
172
+ direction TB
173
+ HA["Available Patients<br/><small>opt-in only, excl. connected</small>"]
174
+ HB["Search by Condition<br/><small>incl. connected toggle</small>"]
175
+ HC["My Trials<br/><small>active trials matched to hospital</small>"]
176
+ HD["Inbox 🔴<br/><small>unread count badge</small>"]
177
+ HE["My Connections<br/><small>accept · reject · complete · chat</small>"]
178
+ HF["My Profile<br/><small>name · location · conditions</small>"]
179
+ end
180
+ end
181
+
182
+ subgraph SERVER["⚙️ Flask Server — app.py (:5000)"]
183
+ direction TB
184
+ subgraph AUTH_GRP["Auth (no session required)"]
185
+ AU["/auth/patient/register<br/>/auth/patient/login<br/>/auth/hospital/register<br/>/auth/hospital/login<br/>/auth/logout"]
186
+ end
187
+ subgraph PAT_GRP["Patient API"]
188
+ PAR["/api/patient/profile GET · POST<br/>/api/patient/matches GET<br/>/api/patient/interests GET · POST · DELETE<br/>/api/patient/connections GET<br/>/api/patient/connect POST<br/>/api/patient/hospitals-for-trial GET"]
189
+ end
190
+ subgraph MSG_GRP["Messaging + Inbox"]
191
+ MR["/api/patient/connections/&lt;cid&gt;/messages GET · POST<br/>/api/patient/inbox GET<br/>/api/hospital/connections/&lt;cid&gt;/messages GET · POST<br/>/api/hospital/inbox GET"]
192
+ end
193
+ subgraph HOSP_GRP["Hospital API"]
194
+ HAR["/api/hospital/profile GET · POST<br/>/api/hospital/patients GET<br/>/api/hospital/trials GET<br/>/api/hospital/connect POST<br/>/api/hospital/connections GET<br/>/api/hospital/connections/&lt;cid&gt;/status PUT"]
195
+ end
196
+ subgraph DOC_GRP["Documents"]
197
+ DR["/api/patient/documents GET · POST<br/>/api/patient/documents/&lt;id&gt; DELETE<br/>/api/patient/documents/&lt;id&gt;/download GET"]
198
+ end
199
+ subgraph SHARED_GRP["Shared"]
200
+ SR["/api/status GET<br/>/api/conditions/autocomplete GET"]
201
+ end
202
+ BOOT["<b>Boot Thread</b><br/>init_db()<br/>pipeline.load()<br/>pipeline.train()"]
203
+ end
204
+
205
+ subgraph LOGIC["🧠 Business Logic"]
206
+ direction TB
207
+ subgraph DB_LAYER["database.py — SQLite Layer"]
208
+ T1[("patient_accounts<br/><small>25 rows</small>")]
209
+ T2[("hospital_accounts<br/><small>3 rows</small>")]
210
+ T3[("patient_trial_interests")]
211
+ T4[("connections")]
212
+ T5[("connection_messages")]
213
+ end
214
+ subgraph ML_LAYER["pipeline.py — ML Engine"]
215
+ ML1["Data Loader<br/><small>CSV → in-memory dicts</small>"]
216
+ ML2["Feature Engineer<br/><small>17 features per patient-trial pair</small>"]
217
+ ML3["RF + Isotonic Cal.<br/><small>90k pairs · AUC 0.60</small>"]
218
+ ML4["match_patient()"]
219
+ ML5["trials_for_hospital()"]
220
+ ML6["hospitals_for_trial()"]
221
+ end
222
+ end
223
+
224
+ subgraph STORAGE["💾 Storage"]
225
+ direction TB
226
+ SDB[("secondlife.db<br/><small>SQLite file</small>")]
227
+ SCACHE[("model_cache.pkl<br/><small>RF + calibrator</small>")]
228
+ SFILES["uploads/patient_docs/<br/><small>per-patient dirs</small>"]
229
+ SCSV_P["Synthea CSVs<br/><small>4 files · ~1M rows</small>"]
230
+ SCSV_T["ClinicalTrials CSVs<br/><small>7 files · ~2M rows</small>"]
231
+ end
232
+
233
+ LAND -->|"POST /auth/*"| AU
234
+ PAT_SPA -->|"REST/JSON"| PAR
235
+ PAT_SPA -->|"REST/JSON"| MSG_GRP
236
+ PAT_SPA -->|"multipart"| DOC_GRP
237
+ HOSP_SPA -->|"REST/JSON"| HAR
238
+ HOSP_SPA -->|"REST/JSON"| MSG_GRP
239
+ PAT_SPA & HOSP_SPA -->|"GET"| SHARED_GRP
240
+
241
+ AU & PAR & HAR --> DB_LAYER
242
+ MSG_GRP --> T4 & T5
243
+ DOC_GRP --> T1
244
+ DOC_GRP -->|"file I/O"| SFILES
245
+
246
+ PAR -->|"match_patient()"| ML4
247
+ PAR -->|"hospitals_for_trial()"| ML6
248
+ HAR -->|"trials_for_hospital()"| ML5
249
+
250
+ BOOT -->|"seeds data"| T1
251
+ BOOT -->|"load + train"| ML_LAYER
252
+
253
+ DB_LAYER <-->|"read/write"| SDB
254
+ ML3 <-->|"load/save"| SCACHE
255
+ ML1 -->|"read on boot"| SCSV_P
256
+ ML1 -->|"read on boot"| SCSV_T
257
+
258
+ ML1 --> ML2 --> ML3 --> ML4 & ML5 & ML6
259
+ </div>
260
+ <div class="note">
261
+ <strong>Boot sequence:</strong> On startup a background thread calls <code>init_db()</code> (seeds 25 patients + 3 hospitals),
262
+ then <code>pipeline.load()</code> (reads all CSVs into memory), then <code>pipeline.train()</code>
263
+ (builds RF model or loads <code>model_cache.pkl</code>). The Flask server is immediately available during boot;
264
+ <code>GET /api/status</code> returns <code>ready: false</code> until the thread completes.
265
+ </div>
266
+ </div>
267
+ </section>
268
+
269
+ <!-- =========================================================
270
+ 2. DATABASE SCHEMA
271
+ ========================================================= -->
272
+ <section id="s2">
273
+ <h2>2. Database Schema</h2>
274
+ <p class="subtitle">
275
+ SQLite database (<code>secondlife.db</code>) with 5 tables.
276
+ JSON columns (conditions, medications, documents, research_conditions) are stored as TEXT and parsed by
277
+ <code>_row_to_dict()</code> in database.py.
278
+ </p>
279
+ <div class="diagram-wrap">
280
+ <div class="mermaid">
281
+ erDiagram
282
+ patient_accounts {
283
+ TEXT id PK
284
+ TEXT username UK
285
+ TEXT password_hash
286
+ TEXT synthea_id "null for hand-made patients"
287
+ TEXT first_name
288
+ TEXT last_name
289
+ TEXT dob
290
+ TEXT gender
291
+ TEXT address
292
+ TEXT conditions "JSON array of strings"
293
+ TEXT medications "JSON array of strings"
294
+ TEXT documents "JSON array of file metadata dicts"
295
+ INTEGER open_to_trials "0 or 1"
296
+ TEXT created_at
297
+ }
298
+
299
+ hospital_accounts {
300
+ TEXT id PK
301
+ TEXT username UK
302
+ TEXT password_hash
303
+ TEXT hospital_name
304
+ TEXT location "City, ST format"
305
+ TEXT research_conditions "JSON array of strings"
306
+ TEXT created_at
307
+ }
308
+
309
+ patient_trial_interests {
310
+ TEXT id PK
311
+ TEXT patient_id FK
312
+ TEXT trial_id "NCT number"
313
+ TEXT trial_title
314
+ REAL match_score
315
+ TEXT status "interested or withdrawn"
316
+ TEXT created_at
317
+ }
318
+
319
+ connections {
320
+ TEXT id PK
321
+ TEXT patient_id FK
322
+ TEXT hospital_id FK
323
+ TEXT trial_id "nullable NCT number"
324
+ TEXT trial_title
325
+ TEXT initiated_by "patient or hospital"
326
+ TEXT status "pending accepted rejected completed"
327
+ TEXT message
328
+ TEXT created_at
329
+ }
330
+
331
+ connection_messages {
332
+ TEXT id PK
333
+ TEXT connection_id FK
334
+ TEXT sender_role "patient or hospital"
335
+ TEXT sender_id
336
+ TEXT body "max 2000 chars"
337
+ TEXT created_at
338
+ INTEGER is_read "0 or 1"
339
+ }
340
+
341
+ patient_accounts ||--o{ patient_trial_interests : "saves interests"
342
+ patient_accounts ||--o{ connections : "initiates or receives"
343
+ hospital_accounts ||--o{ connections : "initiates or receives"
344
+ connections ||--o{ connection_messages : "contains messages"
345
+ </div>
346
+ <div class="note">
347
+ <strong>Uniqueness:</strong> <code>connections</code> has a composite unique index
348
+ <code>idx_conn_unique ON connections(patient_id, hospital_id, COALESCE(trial_id, ''))</code>
349
+ to prevent duplicate connection requests even when <code>trial_id</code> is NULL.
350
+ <code>patient_trial_interests</code> has <code>UNIQUE(patient_id, trial_id)</code>.
351
+ <code>connection_messages</code> has index <code>idx_msgs_conn ON (connection_id, created_at)</code>.
352
+ </div>
353
+ </div>
354
+ </section>
355
+
356
+ <!-- =========================================================
357
+ 3. ML PIPELINE
358
+ ========================================================= -->
359
+ <section id="s3">
360
+ <h2>3. ML Pipeline — Boot, Train, Infer</h2>
361
+ <p class="subtitle">
362
+ <code>pipeline.py</code> — Data loading from 11 CSV files, pseudo-label generation,
363
+ Random Forest training with isotonic calibration, and 3 inference functions.
364
+ </p>
365
+ <div class="diagram-wrap">
366
+ <div class="mermaid">
367
+ flowchart TD
368
+ subgraph BOOT_TH["Boot Thread (background, server stays live during this)"]
369
+ direction LR
370
+ BT1["pipeline.load()"] --> BT2["pipeline.train()"]
371
+ end
372
+
373
+ subgraph LOAD_PHASE["load() — CSV Ingestion into Memory"]
374
+ direction LR
375
+ subgraph TRIAL_CSV["ClinicalTrials.gov CSVs"]
376
+ TC1["trail_studies.csv<br/><small>→ trial_profiles dict<br/>→ active_trial_ids set<br/>65k recruiting trials</small>"]
377
+ TC2["trail_conditions.csv<br/><small>→ trial_conditions dict<br/>34k trials with conditions</small>"]
378
+ TC3["trail_eligibilities.csv<br/><small>→ age range + gender per trial</small>"]
379
+ TC4["trail_facilities.csv<br/><small>→ trial_us_states dict<br/>→ trial_facility_tokens dict<br/>189k trials with US geo</small>"]
380
+ TC5["trail_interventions.csv<br/><small>→ trial_drug_keywords dict<br/>196k trials with drug data</small>"]
381
+ TC6["trail_brief_summaries.csv<br/><small>→ trial_summaries dict</small>"]
382
+ TC7["trail_keywords.csv<br/><small>→ trial_keywords dict</small>"]
383
+ end
384
+ subgraph SYNTHEA_CSV["Synthea Patient CSVs"]
385
+ SC1["patients_details.csv<br/><small>→ patient_demographics dict<br/>265k patients</small>"]
386
+ SC2["final_patients_conditions.csv<br/><small>→ patient_conditions dict<br/>106 overlapping conditions</small>"]
387
+ SC3["patients_medications.csv<br/><small>→ patient_medications dict<br/>213k patients</small>"]
388
+ SC4["patients_observations.csv<br/><small>→ patient_lab_types dict<br/>23k patients</small>"]
389
+ end
390
+ end
391
+
392
+ subgraph TRAIN_PHASE["train() — Model Training"]
393
+ direction TB
394
+ TR1["Sample 3000 patients × 30 trials<br/>+ random negatives<br/><small>GroupShuffleSplit 80/20 patient-level</small>"]
395
+ TR2["_compute_features()<br/><small>17-feature vector per patient-trial pair<br/>~90k training pairs total</small>"]
396
+ TR3["Pseudo-label generation<br/><small>6-feature weighted score >= 0.5<br/>+ 15% hash-deterministic noise<br/>→ 82.1% positive rate</small>"]
397
+ TR4["RandomForestClassifier<br/><small>n_estimators=200, max_depth=12<br/>class_weight=balanced</small>"]
398
+ TR5["CalibratedClassifierCV<br/><small>method=isotonic, cv=3</small>"]
399
+ TR6["Save model_cache.pkl<br/><small>skip training on next boot</small>"]
400
+ TR1 --> TR2 --> TR3 --> TR4 --> TR5 --> TR6
401
+ end
402
+
403
+ subgraph INFER["Inference — 3 Matching Functions"]
404
+ direction LR
405
+ IN1["<b>match_patient()</b><br/><small>Input: conditions, age, gender, patient_id<br/>Output: top-k trials ranked by<br/>combined_score = 0.6×eligibility_prob + 0.4×match_score</small>"]
406
+ IN2["<b>trials_for_hospital()</b><br/><small>Input: hospital name, location, research_conditions<br/>Output: active trials in 3 tiers<br/>Tier1: facility name Jaccard >= 0.25<br/>Tier2: same US state<br/>Tier3: condition overlap</small>"]
407
+ IN3["<b>hospitals_for_trial()</b><br/><small>Input: trial_id<br/>Output: DB hospitals in 4 tiers<br/>Tier1: name Jaccard >= 0.25<br/>Tier2: same state<br/>Tier3: condition overlap<br/>Tier4: fallback</small>"]
408
+ end
409
+
410
+ BOOT_TH --> LOAD_PHASE
411
+ BOOT_TH --> TRAIN_PHASE
412
+ LOAD_PHASE --> TR1
413
+ TR5 --> IN1
414
+ LOAD_PHASE --> IN2
415
+ LOAD_PHASE --> IN3
416
+ </div>
417
+ <div class="note">
418
+ <strong>Cache behaviour:</strong> If <code>model_cache.pkl</code> exists on disk, <code>train()</code> loads the cached RF + calibrator
419
+ and skips the ~2-3 min training step. Delete the file to force a full retrain (required after changing features or pipeline logic).
420
+ </div>
421
+ </div>
422
+ </section>
423
+
424
+ <!-- =========================================================
425
+ 4. PATIENT JOURNEY
426
+ ========================================================= -->
427
+ <section id="s4">
428
+ <h2>4. Patient User Journey</h2>
429
+ <p class="subtitle">
430
+ Key request-response flows through the patient portal, from registration to messaging.
431
+ </p>
432
+ <div class="diagram-wrap">
433
+ <div class="mermaid">
434
+ sequenceDiagram
435
+ actor Patient
436
+ participant UI as patient.html
437
+ participant Flask as Flask (app.py)
438
+ participant DB as database.py
439
+ participant ML as pipeline.py
440
+ participant FS as File System
441
+
442
+ Note over Patient,FS: Registration / Login
443
+ Patient->>UI: Fill register form
444
+ UI->>Flask: POST /auth/patient/register
445
+ Flask->>DB: create_patient()
446
+ DB-->>Flask: patient dict (or 409 username taken)
447
+ Flask-->>UI: session cookie + patient JSON
448
+ UI->>UI: Render portal, call checkStatus()
449
+
450
+ Note over Patient,FS: Pipeline ready check
451
+ UI->>Flask: GET /api/status
452
+ Flask-->>UI: ready: false (202) or ready: true + stats
453
+ UI->>UI: Show yellow banner if not ready; startStatusPoll() every 5s
454
+
455
+ Note over Patient,FS: Profile update
456
+ Patient->>UI: Edit conditions / medications / toggle open_to_trials
457
+ UI->>Flask: POST /api/patient/profile
458
+ Flask->>DB: update_patient_profile()
459
+
460
+ Note over Patient,FS: Get AI trial matches
461
+ Patient->>UI: Click "Suggested Trials" tab
462
+ UI->>Flask: GET /api/patient/matches
463
+ Flask->>ML: match_patient(conditions, age, gender, patient_id)
464
+ ML->>ML: _compute_features() x all active trials
465
+ ML->>ML: RF.predict_proba() → calibrated eligibility prob
466
+ ML->>ML: combined_score = 0.6×prob + 0.4×match_score
467
+ ML-->>Flask: top-20 trials sorted by combined_score
468
+ Flask-->>UI: results array with 24 fields per trial
469
+
470
+ Note over Patient,FS: Connect with a hospital
471
+ Patient->>UI: Click "Connect with Hospital" on a trial card
472
+ UI->>Flask: GET /api/patient/hospitals-for-trial?trial_id=NCT...
473
+ Flask->>ML: hospitals_for_trial(trial_id)
474
+ ML-->>Flask: tiered hospital list (Tier 1..4)
475
+ Flask-->>UI: hospitals array
476
+ UI->>UI: Render modal — green section (Tier1) + grey section (Tier2-4)
477
+ Patient->>UI: Select hospital + enter message + submit
478
+ UI->>Flask: POST /api/patient/connect
479
+ Flask->>DB: connection_exists()? if no → create_connection()
480
+ DB-->>Flask: connection dict (or 409 duplicate)
481
+ Flask-->>UI: success redirect to connections tab
482
+
483
+ Note over Patient,FS: Inbox and messaging
484
+ Patient->>UI: Click "Inbox" tab
485
+ UI->>Flask: GET /api/patient/inbox
486
+ Flask->>DB: get_patient_inbox_threads(patient_id)
487
+ DB-->>Flask: threads with last_message + unread_count
488
+ Flask-->>UI: threads array + update badge
489
+ Patient->>UI: Click "Open" on a thread
490
+ UI->>Flask: GET /api/patient/connections/{cid}/messages
491
+ Flask->>DB: mark_messages_read(role=hospital)
492
+ Flask->>DB: get_connection_messages(cid)
493
+ Flask-->>UI: messages array
494
+ Patient->>UI: Type reply + Enter or Send
495
+ UI->>Flask: POST /api/patient/connections/{cid}/messages
496
+ Flask->>DB: create_connection_message(role=patient)
497
+
498
+ Note over Patient,FS: Document upload
499
+ Patient->>UI: Select file in Documents section
500
+ UI->>Flask: POST /api/patient/documents (multipart/form-data)
501
+ Flask->>Flask: secure_filename, validate extension + 10MB limit
502
+ Flask->>FS: Save to uploads/patient_docs/{pid}/{doc_id}_filename
503
+ Flask->>DB: update_patient_profile(documents=[...append])
504
+ Flask-->>UI: document metadata dict
505
+ </div>
506
+ </div>
507
+ </section>
508
+
509
+ <!-- =========================================================
510
+ 5. HOSPITAL JOURNEY
511
+ ========================================================= -->
512
+ <section id="s5">
513
+ <h2>5. Hospital User Journey</h2>
514
+ <p class="subtitle">
515
+ Key request-response flows through the hospital portal, from login to connection management and messaging.
516
+ </p>
517
+ <div class="diagram-wrap">
518
+ <div class="mermaid">
519
+ sequenceDiagram
520
+ actor Hospital
521
+ participant UI as hospital.html
522
+ participant Flask as Flask (app.py)
523
+ participant DB as database.py
524
+ participant ML as pipeline.py
525
+
526
+ Note over Hospital,ML: Login
527
+ Hospital->>UI: Enter credentials
528
+ UI->>Flask: POST /auth/hospital/login
529
+ Flask->>DB: authenticate_hospital()
530
+ DB-->>Flask: hospital dict
531
+ Flask-->>UI: session cookie + hospital JSON
532
+
533
+ Note over Hospital,ML: Browse available patients
534
+ Hospital->>UI: Click "Available Patients" tab (default)
535
+ UI->>Flask: GET /api/hospital/patients
536
+ Flask->>DB: get_open_patients_for_hospital(include_connected=False)
537
+ DB-->>Flask: patients with open_to_trials=1 excluding already-connected
538
+ Flask-->>UI: patient cards (25 opt-in patients total)
539
+
540
+ Note over Hospital,ML: Search by condition
541
+ Hospital->>UI: Type condition + toggle "include connected"
542
+ UI->>Flask: GET /api/hospital/patients?condition=diabetes&include_connected=true
543
+ Flask->>DB: get_open_patients_for_hospital(condition_filter, include_connected=True)
544
+ Flask-->>UI: filtered patient list
545
+
546
+ Note over Hospital,ML: View matched trials
547
+ Hospital->>UI: Click "My Trials" tab
548
+ UI->>Flask: GET /api/hospital/trials
549
+ Flask->>ML: trials_for_hospital(hospital_name, location, research_conditions)
550
+ ML->>ML: Tier1 — facility name Jaccard >= 0.25 + is_active
551
+ ML->>ML: Tier2 — same US state + is_active
552
+ ML->>ML: Tier3 — condition overlap + is_active
553
+ ML-->>Flask: active trial list with match_tier and match_reason
554
+ Flask-->>UI: trial cards with status, phase, facility, ClinicalTrials.gov link
555
+
556
+ Note over Hospital,ML: Connect with a patient
557
+ Hospital->>UI: Click "Connect" on a patient card
558
+ UI->>Flask: POST /api/hospital/connect
559
+ Flask->>DB: create_connection(initiated_by=hospital)
560
+ DB-->>Flask: connection dict (or 409 duplicate)
561
+
562
+ Note over Hospital,ML: Manage connections
563
+ Hospital->>UI: Click "My Connections" tab
564
+ UI->>Flask: GET /api/hospital/connections
565
+ Flask->>DB: get_hospital_connections(hospital_id)
566
+ Flask-->>UI: connection table with patient details
567
+ Hospital->>UI: Click "Accept" / "Reject" / "Complete"
568
+ UI->>Flask: PUT /api/hospital/connections/{cid}/status
569
+ Flask->>DB: update_connection_status(cid, status)
570
+
571
+ Note over Hospital,ML: Inbox and messaging
572
+ Hospital->>UI: Click "Inbox" tab
573
+ UI->>Flask: GET /api/hospital/inbox
574
+ Flask->>DB: get_hospital_inbox_threads(hospital_id)
575
+ DB-->>Flask: threads sorted by last_message_at DESC
576
+ Flask-->>UI: thread list with unread_count, update nav badge
577
+ Hospital->>UI: Click "Open" on a thread
578
+ UI->>Flask: GET /api/hospital/connections/{cid}/messages
579
+ Flask->>DB: mark_messages_read(role=hospital)
580
+ Flask->>DB: get_connection_messages(cid)
581
+ Flask-->>UI: messages in chronological order
582
+ Hospital->>UI: Type reply + Send
583
+ UI->>Flask: POST /api/hospital/connections/{cid}/messages
584
+ Flask->>DB: create_connection_message(role=hospital)
585
+
586
+ Note over Hospital,ML: Update profile
587
+ Hospital->>UI: Edit name / location / research conditions
588
+ UI->>Flask: POST /api/hospital/profile
589
+ Flask->>DB: update_hospital_profile()
590
+ Flask-->>UI: updated hospital dict
591
+ UI->>UI: Update navbar name live (no page reload)
592
+ </div>
593
+ </div>
594
+ </section>
595
+
596
+ <!-- =========================================================
597
+ 6. TIERED MATCHING
598
+ ========================================================= -->
599
+ <section id="s6">
600
+ <h2>6. Tiered Matching Logic</h2>
601
+ <p class="subtitle">
602
+ Two reverse-matching functions sharing the same 4-tier cascade. Both use
603
+ <code>_name_tokens()</code> + Jaccard similarity for Tier 1, US state extraction for Tier 2,
604
+ and condition set intersection for Tier 3.
605
+ </p>
606
+ <div class="grid-2">
607
+ <div>
608
+ <h3 style="color:#3fb950;margin-bottom:.75rem;font-size:1rem;">
609
+ hospitals_for_trial(trial_id) — Patient selects a trial
610
+ </h3>
611
+ <div class="diagram-wrap">
612
+ <div class="mermaid">
613
+ flowchart TD
614
+ START_A["Patient clicks<br/>'Connect with Hospital'<br/>on trial NCTxxxxxx"]
615
+
616
+ subgraph T1A["Tier 1 — Verified Site"]
617
+ C1A["For each hospital in DB:<br/>Jaccard(hospital name tokens,<br/>ANY trial facility name tokens) >= 0.25"]
618
+ R1A["🟢 match_reason:<br/>'verified site on this trial'"]
619
+ end
620
+
621
+ subgraph T2A["Tier 2 — Same State"]
622
+ C2A["Hospital state extracted from<br/>'City, ST' location field<br/>== any trial US facility state"]
623
+ R2A["⬜ match_reason:<br/>'in same state as a trial site'"]
624
+ end
625
+
626
+ subgraph T3A["Tier 3 — Condition Overlap"]
627
+ C3A["hospital.research_conditions<br/>∩ trial.conditions ≠ empty"]
628
+ R3A["⬜ match_reason:<br/>'researches related conditions'"]
629
+ end
630
+
631
+ subgraph T4A["Tier 4 — Fallback"]
632
+ C4A["Trial has no US facility data<br/>all remaining hospitals included"]
633
+ R4A["⬜ match_reason: ''"]
634
+ end
635
+
636
+ MODAL["Render connect modal<br/>🟢 VERIFIED TRIAL SITES header<br/>⬜ RELATED HOSPITALS header<br/>(Tiers 2–4)"]
637
+
638
+ START_A --> T1A --> T2A --> T3A --> T4A --> MODAL
639
+ </div>
640
+ </div>
641
+ </div>
642
+
643
+ <div>
644
+ <h3 style="color:#79c0ff;margin-bottom:.75rem;font-size:1rem;">
645
+ trials_for_hospital(name, loc, conditions) — Hospital views My Trials
646
+ </h3>
647
+ <div class="diagram-wrap">
648
+ <div class="mermaid">
649
+ flowchart TD
650
+ START_B["Hospital opens<br/>'My Trials' tab"]
651
+
652
+ subgraph T1B["Tier 1 — Name Matched"]
653
+ C1B["For each active trial:<br/>Jaccard(hospital name tokens,<br/>trial facility name tokens) >= 0.25<br/>+ is_active = True"]
654
+ R1B["match_tier: 1<br/>match_reason:<br/>'name matched to trial site'"]
655
+ end
656
+
657
+ subgraph T2B["Tier 2 — Same State"]
658
+ C2B["Hospital state<br/>== trial US facility state<br/>+ is_active = True"]
659
+ R2B["match_tier: 2<br/>match_reason:<br/>'in same state as trial site'"]
660
+ end
661
+
662
+ subgraph T3B["Tier 3 — Condition Overlap"]
663
+ C3B["hospital.research_conditions<br/>∩ trial.conditions ≠ empty<br/>+ is_active = True"]
664
+ R3B["match_tier: 3<br/>match_reason:<br/>'researches related conditions'"]
665
+ end
666
+
667
+ SORT["Sort by match_tier ASC<br/>cap at top_k=20<br/>Return trial cards with<br/>status · phase · facility · summary"]
668
+
669
+ START_B --> T1B --> T2B --> T3B --> SORT
670
+ </div>
671
+ </div>
672
+ </div>
673
+ </div>
674
+
675
+ <div style="margin-top:1.5rem">
676
+ <h3 style="color:#c9d1d9;margin-bottom:.75rem;font-size:1rem;">Shared Helpers</h3>
677
+ <div class="diagram-wrap">
678
+ <div class="mermaid">
679
+ flowchart LR
680
+ subgraph TOK["_name_tokens(name)"]
681
+ TK1["Lowercase all words"]
682
+ TK2["Remove stopwords:<br/>hospital, medical, center, clinic, university,<br/>health, care, system, institute, general,<br/>regional, national, community, the, of, and, at…"]
683
+ TK3["Remove words shorter than 3 chars"]
684
+ TK4["Return frozenset of tokens"]
685
+ TK1 --> TK2 --> TK3 --> TK4
686
+ end
687
+
688
+ subgraph JAC["Jaccard Similarity"]
689
+ J1["score = |A ∩ B| / |A ∪ B|"]
690
+ J2["Best score across ALL<br/>facility names for the trial"]
691
+ J1 --> J2
692
+ end
693
+
694
+ subgraph STATE["State Extraction"]
695
+ S1["Parse 'City, ST' location string"]
696
+ S2["Lookup ST abbreviation<br/>in US_STATE_MAP dict<br/>→ full name e.g. 'Massachusetts'"]
697
+ S3["Compare against<br/>trial_us_states set<br/>(from trail_facilities.csv)"]
698
+ S1 --> S2 --> S3
699
+ end
700
+
701
+ TOK --> JAC
702
+ TOK --> STATE
703
+ </div>
704
+ </div>
705
+ </div>
706
+ </section>
707
+
708
+ <!-- =========================================================
709
+ 7. FEATURE ENGINEERING
710
+ ========================================================= -->
711
+ <section id="s7">
712
+ <h2>7. Feature Engineering — 17 Features</h2>
713
+ <p class="subtitle">
714
+ All features are normalised to 0–1. Computed by <code>_compute_features(patient_row, trial_id)</code>
715
+ in pipeline.py. Used for both training pseudo-labels and inference scoring.
716
+ </p>
717
+ <div class="diagram-wrap">
718
+ <div class="mermaid">
719
+ flowchart LR
720
+ INPUT["Patient Profile<br/>+ Trial Profile"]
721
+
722
+ subgraph COND_GRP["Condition Overlap (4)"]
723
+ direction TB
724
+ CF1["condition_overlap<br/><small>raw count: |patient_conds ∩ trial_conds|</small>"]
725
+ CF2["jaccard_similarity<br/><small>overlap / union</small>"]
726
+ CF3["overlap_ratio_trial<br/><small>overlap / |trial_conds|</small>"]
727
+ CF4["overlap_ratio_patient<br/><small>overlap / |patient_conds|</small>"]
728
+ end
729
+
730
+ subgraph PROF_GRP["Condition Profile (5)"]
731
+ direction TB
732
+ PF1["condition_rarity_score<br/><small>mean(1/log2(n_trials_per_cond + 2)), norm 0-1</small>"]
733
+ PF2["trial_specificity<br/><small>1 / |trial_conds|</small>"]
734
+ PF3["condition_burden<br/><small>total_patient_conds / 10</small>"]
735
+ PF4["active_ratio<br/><small>active_conds / total_conds</small>"]
736
+ PF5["resolved_ratio<br/><small>resolved_conds / total_conds</small>"]
737
+ end
738
+
739
+ subgraph ELIG_GRP["Eligibility (4)"]
740
+ direction TB
741
+ EF1["age_distance<br/><small>norm distance outside [min_age, max_age]</small>"]
742
+ EF2["age_centered<br/><small>position within range, -1 to +1</small>"]
743
+ EF3["age_compatibility<br/><small>1.0 in range; decays over 30yr gap</small>"]
744
+ EF4["gender_compatibility<br/><small>1.0 match/ALL; 0.1 mismatch</small>"]
745
+ end
746
+
747
+ subgraph EXT_GRP["External Signals (3)"]
748
+ direction TB
749
+ XF1["geo_feasibility<br/><small>1.0 same state · 0.75 other US state · 0.5 no data</small>"]
750
+ XF2["med_compatibility<br/><small>patient med keywords ∩ trial drug intervention keywords</small>"]
751
+ XF3["lab_availability<br/><small>patient observation types covered by trial / 20</small>"]
752
+ end
753
+
754
+ subgraph META_GRP["Metadata (1)"]
755
+ MF1["data_completeness<br/><small>fraction of key fields non-empty<br/>importance: ~0.0 in trained RF</small>"]
756
+ end
757
+
758
+ RF["RandomForest<br/>predict_proba()<br/>→ eligibility_prob"]
759
+
760
+ INPUT --> COND_GRP
761
+ INPUT --> PROF_GRP
762
+ INPUT --> ELIG_GRP
763
+ INPUT --> EXT_GRP
764
+ INPUT --> META_GRP
765
+
766
+ COND_GRP --> RF
767
+ PROF_GRP --> RF
768
+ ELIG_GRP --> RF
769
+ EXT_GRP --> RF
770
+ META_GRP --> RF
771
+ </div>
772
+
773
+ <div class="note" style="margin-top:1rem">
774
+ <strong>Top features by importance (Random Forest):</strong>
775
+ age_distance (20.4%) · age_compatibility (16.9%) · gender_compatibility (12.9%) · age_centered (7.9%) ·
776
+ jaccard_similarity (7.5%) · condition_rarity_score (6.2%) · overlap_ratio_trial (5.2%) · overlap_ratio_patient (5.1%) ·
777
+ condition_overlap (4.0%) · remaining 8 features (&lt;3% each).
778
+ <br/><br/>
779
+ <strong>Note on AUC (0.60):</strong> The 82.1% positive pseudo-label rate makes the classification trivially high-accuracy
780
+ but limits discriminative power. Raising the label threshold from 0.5 → 0.6 or enforcing equal pos/neg sampling would improve AUC.
781
+ </div>
782
+ </div>
783
+ </section>
784
+
785
+ <footer style="border-top:1px solid #30363d;margin-top:3rem;padding-top:1.5rem;color:#8b949e;font-size:0.8rem;text-align:center">
786
+ Second Life · DSCI 5260 · Group 7 · Generated 2026-04-25
787
+ </footer>
788
+
789
+ <script>
790
+ mermaid.initialize({
791
+ startOnLoad: true,
792
+ theme: 'dark',
793
+ themeVariables: {
794
+ primaryColor: '#1f6feb',
795
+ primaryTextColor: '#c9d1d9',
796
+ primaryBorderColor: '#388bfd',
797
+ lineColor: '#58a6ff',
798
+ secondaryColor: '#161b22',
799
+ tertiaryColor: '#1c2128',
800
+ background: '#0d1117',
801
+ mainBkg: '#161b22',
802
+ nodeBorder: '#30363d',
803
+ clusterBkg: '#13161b',
804
+ clusterBorder: '#30363d',
805
+ titleColor: '#79c0ff',
806
+ edgeLabelBackground: '#161b22',
807
+ fontFamily: 'system-ui, sans-serif',
808
+ },
809
+ flowchart: {
810
+ useMaxWidth: false,
811
+ htmlLabels: true,
812
+ curve: 'basis',
813
+ padding: 20,
814
+ },
815
+ sequence: {
816
+ useMaxWidth: false,
817
+ mirrorActors: false,
818
+ messageAlign: 'center',
819
+ actorFontFamily:'system-ui, sans-serif',
820
+ noteFontFamily: 'system-ui, sans-serif',
821
+ },
822
+ er: {
823
+ useMaxWidth: false,
824
+ }
825
+ });
826
+ </script>
827
+ </body>
828
+ </html>