|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# |
|
3
|
|
|
# This file is part of SENAITE.HEALTH. |
|
4
|
|
|
# |
|
5
|
|
|
# SENAITE.HEALTH is free software: you can redistribute it and/or modify it |
|
6
|
|
|
# under the terms of the GNU General Public License as published by the Free |
|
7
|
|
|
# Software Foundation, version 2. |
|
8
|
|
|
# |
|
9
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
|
10
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
11
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
12
|
|
|
# details. |
|
13
|
|
|
# |
|
14
|
|
|
# You should have received a copy of the GNU General Public License along with |
|
15
|
|
|
# this program; if not, write to the Free Software Foundation, Inc., 51 |
|
16
|
|
|
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
17
|
|
|
# |
|
18
|
|
|
# Copyright 2018-2019 by it's authors. |
|
19
|
|
|
# Some rights reserved, see README and LICENSE. |
|
20
|
|
|
|
|
21
|
|
|
from bika.health.catalog.patient_catalog import CATALOG_PATIENTS |
|
22
|
|
|
from bika.health.interfaces import IPatient |
|
23
|
|
|
from bika.lims import api |
|
24
|
|
|
from plone.indexer import indexer |
|
25
|
|
|
|
|
26
|
|
|
@indexer(IPatient) |
|
27
|
|
|
def listing_searchable_text(instance): |
|
28
|
|
|
"""Fulltext search for the Patient |
|
29
|
|
|
""" |
|
30
|
|
|
attributes = [ |
|
31
|
|
|
"Title", |
|
32
|
|
|
"getFullname", |
|
33
|
|
|
"getId", |
|
34
|
|
|
"getPrimaryReferrerID", |
|
35
|
|
|
"getPrimaryReferrerTitle", |
|
36
|
|
|
"getClientPatientID", |
|
37
|
|
|
"getPatientIdentifiersStr" |
|
38
|
|
|
] |
|
39
|
|
|
|
|
40
|
|
|
def get_value(instance, func_name): |
|
41
|
|
|
value = api.safe_getattr(instance, func_name, None) |
|
42
|
|
|
if not value: |
|
43
|
|
|
return None |
|
44
|
|
|
parsed = api.to_searchable_text_metadata(value) |
|
45
|
|
|
return parsed or None |
|
46
|
|
|
|
|
47
|
|
|
out_values = set() |
|
48
|
|
|
for attr in attributes: |
|
49
|
|
|
value = get_value(instance, attr) |
|
50
|
|
|
if value: |
|
51
|
|
|
out_values.add(value) |
|
52
|
|
|
|
|
53
|
|
|
return " ".join(out_values) |
|
54
|
|
|
|
|
55
|
|
|
# TODO Remove Patient's client_uid indexer? |
|
56
|
|
|
@indexer(IPatient) |
|
57
|
|
|
def client_uid(instance): |
|
58
|
|
|
"""Returns the uid of the Client assigned to the Patient, if any. Otherwise |
|
59
|
|
|
returns "-1". |
|
60
|
|
|
""" |
|
61
|
|
|
client = instance.getClient() |
|
62
|
|
|
if client: |
|
63
|
|
|
return api.get_uid(client) |
|
64
|
|
|
return "-1" |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
# TODO Remove Patient's client_assigned indexer? |
|
68
|
|
|
@indexer(IPatient) |
|
69
|
|
|
def client_assigned(instance): |
|
70
|
|
|
"""Returns whether the Patient belongs to a Client or not |
|
71
|
|
|
""" |
|
72
|
|
|
if instance.getClient(): |
|
73
|
|
|
return True |
|
74
|
|
|
return False |
|
75
|
|
|
|