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
|
/*
* This file is part of Clinica.
*
* Clinica is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Clinica is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Clinica. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Leonardo Robol <leo@robol.it>
*/
#if HAVE_UNITY
namespace Clinica {
internal class PatientsScope : Unity.Scope {
private ResourceManager resource_manager;
public PatientsScope (ResourceManager resources) {
base (Config.RESOURCE_BASE + "scope/patients");
resource_manager = resources;
search_changed.connect (on_search_changed);
activate_uri.connect (on_uri_activated);
}
private void on_search_changed (Unity.LensSearch? search, Unity.SearchType type) {
if (search == null || search.search_string == null)
return;
string lsearch = search.search_string.down ();
results_model.clear ();
// Search the patients visited recently
List<int64?> recent_patients = new List<int64?> ();
foreach (Visit v in resource_manager.data_provider.visits ()) {
if (recent_patients.index (v.patient.id) == -1 && lsearch in v.patient.get_complete_name ()) {
results_model.append (@"patient:$(v.patient.id)",
resource_manager.prefix + "/share/pixmaps/clinica.svg",
0, "", v.patient.get_complete_name (), "Patient", "");
recent_patients.append (v.patient.id);
}
if (recent_patients.length () > 5)
break;
}
// Search in the patients the ones that match the
// search string specified by the user.
foreach (Patient p in resource_manager.data_provider.patients ()) {
if (lsearch in p.get_complete_name ().down ()) {
results_model.append (@"patient:$(p.id)",
resource_manager.prefix + "/share/pixmaps/clinica.svg",
1, "text/html",
p.get_complete_name (), "Patient", "");
}
}
}
private Unity.ActivationResponse on_uri_activated (string uri) {
if ("patient" in uri) {
int64 patient_id = int64.parse (uri.split (":")[1]);
// Use our application wrapper that will instantiate a UserInterface
// if one is not running yet.
resource_manager.application.show_visits (
resource_manager.data_provider.get_patient (patient_id));
return new Unity.ActivationResponse (Unity.HandledType.HIDE_DASH);
}
return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED);
}
}
}
#endif
|