Passed
Push — master ( bcb3c3...740c75 )
by Pau
04:01
created

bika.health.content.batch.getPatientID()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nop 1
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 Products.Archetypes import DisplayList
22
from Products.Archetypes.Widget import BooleanWidget
23
from Products.Archetypes.Widget import IntegerWidget
24
from Products.Archetypes.Widget import MultiSelectionWidget
25
from Products.Archetypes.Widget import StringWidget
26
from Products.Archetypes.Widget import TextAreaWidget
27
from Products.Archetypes.interfaces import IVocabulary
28
from Products.Archetypes.references import HoldingReference
29
from Products.CMFCore.utils import getToolByName
30
from archetypes.schemaextender.interfaces import IOrderableSchemaExtender
31
from archetypes.schemaextender.interfaces import ISchemaModifier
32
from zope.component import adapts
33
from zope.interface import implements
34
35
from bika.health import bikaMessageFactory as _
36
from bika.health.utils import get_field_value
37
from bika.health.widgets import CaseBasalBodyTempWidget
38
from bika.health.widgets import CaseMenstrualStatusWidget
39
from bika.health.widgets import CaseSymptomsWidget
40
from bika.health.widgets import SplittedDateWidget
41
from bika.health.widgets.casepatientconditionwidget import \
42
    CasePatientConditionWidget
43
from bika.lims import api
44
from bika.lims import bikaMessageFactory as _b
45
from bika.lims.browser.widgets import DateTimeWidget
46
from bika.lims.browser.widgets import RecordsWidget
47
from bika.lims.browser.widgets import ReferenceWidget
48
from bika.lims.fields import ExtBooleanField
49
from bika.lims.fields import ExtDateTimeField
50
from bika.lims.fields import ExtIntegerField
51
from bika.lims.fields import ExtLinesField
52
from bika.lims.fields import ExtRecordsField
53
from bika.lims.fields import ExtReferenceField
54
from bika.lims.fields import ExtStringField
55
from bika.lims.fields import ExtTextField
56
from bika.lims.interfaces import IBatch
57
58
59
class getCaseStatus:
60
    implements(IVocabulary)
61
    def getDisplayList(self, instance):
62
        """ return all case statuses"""
63
        bsc = getToolByName(instance, 'bika_setup_catalog')
64
        ret = []
65
        for p in bsc(portal_type = 'CaseStatus',
66
                      is_active = True,
67
                      sort_on = 'sortable_title'):
68
            ret.append((p.Title, p.Title))
69
        return DisplayList(ret)
70
71
72
class getCaseOutcome:
73
    implements(IVocabulary)
74
    def getDisplayList(self, instance):
75
        """ return all case Outcomes"""
76
        bsc = getToolByName(instance, 'bika_setup_catalog')
77
        ret = []
78
        for p in bsc(portal_type = 'CaseOutcome',
79
                      is_active = True,
80
                      sort_on = 'sortable_title'):
81
            ret.append((p.Title, p.Title))
82
        return DisplayList(ret)
83
84
85
class BatchSchemaExtender(object):
86
    adapts(IBatch)
87
    implements(IOrderableSchemaExtender)
88
89
    fields = [
90
        ExtReferenceField('Doctor',
91
            required=1,
92
            multiValued=0,
93
            allowed_types = ('Doctor',),
94
            referenceClass = HoldingReference,
95
            relationship = 'BatchDoctor',
96
            widget=ReferenceWidget(
97
                label=_("Doctor"),
98
                description="",
99
                render_own_label=False,
100
                visible={'edit': 'visible', 'view': 'visible'},
101
                base_query={'is_active': True},
102
                catalog_name='portal_catalog',
103
                showOn=True,
104
                colModel = [{'columnName':'DoctorID','width':'20','label':_('Doctor ID')},
105
                            {'columnName':'Title','width':'80','label':_('Full Name')},
106
                            ],
107
            ),
108
        ),
109
        ExtReferenceField('Patient',
110
            required=1,
111
            multiValued=0,
112
            allowed_types = ('Patient',),
113
            referenceClass = HoldingReference,
114
            relationship = 'BatchPatient',
115
            widget=ReferenceWidget(
116
                label=_("Patient"),
117
                description="",
118
                render_own_label=False,
119
                visible={'edit': 'visible',
120
                         'view': 'visible'},
121
                catalog_name='bikahealth_catalog_patient_listing',
122
                search_fields=('listing_searchable_text',),
123
                base_query={'is_active': True,
124
                            'sort_limit': 50,
125
                            'sort_on': 'getPatientID',
126
                            'sort_order': 'ascending'},
127
                colModel=[
128
                    {'columnName': "getPatientID",
129
                     'width': '30',
130
                     'label': _('PID'),
131
                     'align': 'left'},
132
                    {'columnName': "getClientPatientID",
133
                     'width': '30',
134
                     'label': _('CPID'),
135
                     'align': 'left'},
136
                    {'columnName': 'Title',
137
                     'width': '30',
138
                     'label': _('Title'),
139
                     'align': 'left'},
140
                ],
141
                showOn=True,
142
            ),
143
        ),
144
        ExtDateTimeField('OnsetDate',
145
              widget=DateTimeWidget(
146
                  label=_('Onset Date'),
147
              ),
148
        ),
149
        ExtRecordsField('PatientAgeAtCaseOnsetDate',
150
            widget=SplittedDateWidget(
151
                label=_('Patient Age at Case Onset Date'),
152
            ),
153
        ),
154
        ExtBooleanField('OnsetDateEstimated',
155
            default=False,
156
            widget=BooleanWidget(
157
                label = _("Onset Date Estimated"),
158
            ),
159
        ),
160
        ExtRecordsField('ProvisionalDiagnosis',
161
            type='provisionaldiagnosis',
162
            subfields=('Code', 'Title', 'Description', 'Onset'),
163
            # Temporary fix: https://github.com/bikalabs/bika.health/issues/89
164
            #required_subfields=('Title'),
165
            subfield_sizes={'Code': 7,
166
                            'Title': 20,
167
                            'Description': 35,
168
                            'Onset': 10},
169
            subfield_labels={'Code': _('Code'),
170
                             'Title': _('Provisional diagnosis'),
171
                             'Description': _('Description'),
172
                             'Onset': _('Onset')},
173
             subfield_types={'Onset': 'datepicker_nofuture'},
174
             widget=RecordsWidget(
175
                 label='Provisional diagnosis',
176
                 combogrid_options={
177
                     'Title': {
178
                         'colModel': [{'columnName':'Code', 'width':'10', 'label':_('Code')},
179
                                      {'columnName':'Title', 'width':'30', 'label':_('Title')},
180
                                      {'columnName':'Description', 'width':'60', 'label':_('Description')}],
181
                         'url': 'getsymptomsbytitle',
182
                         'showOn': True,
183
                         'width': "650px",
184
                     },
185
                     'Code': {
186
                         'colModel': [{'columnName':'Code', 'width':'10', 'label':_('Code')},
187
                                      {'columnName':'Title', 'width':'30', 'label':_('Title')},
188
                                      {'columnName':'Description', 'width':'60', 'label':_('Description')}],
189
                         'url': 'getsymptomsbycode',
190
                         'showOn': True,
191
                         'width': "650px",
192
                     },
193
                     'Description': {
194
                         'colModel': [{'columnName':'Code', 'width':'10', 'label':_('Code')},
195
                                      {'columnName':'Title', 'width':'30', 'label':_('Title')},
196
                                      {'columnName':'Description', 'width':'60', 'label':_('Description')}],
197
                         'url': 'getsymptomsbydesc',
198
                         'showOn': True,
199
                         'width': "650px",
200
                     },
201
                 },
202
             ),
203
        ),
204
        ExtTextField('AdditionalNotes',
205
            default_content_type='text/plain',
206
            allowable_content_types = ('text/plain', ),
207
            default_output_type="text/plain",
208
            widget=TextAreaWidget(
209
                label=_('Additional notes'),
210
            ),
211
        ),
212
        ExtLinesField('CaseStatus',
213
            vocabulary=getCaseStatus(),
214
            widget=MultiSelectionWidget(
215
                format='checkbox',
216
                label=_("Case status")
217
            ),
218
        ),
219
        ExtLinesField('CaseOutcome',
220
            vocabulary=getCaseOutcome(),
221
            widget=MultiSelectionWidget(
222
                format='checkbox',
223
                label=_("Case outcome")
224
            ),
225
        ),
226
        ExtRecordsField('Symptoms',
227
            type='symptoms',
228
            subfields=('UID', 'Title', 'Description', 'Severity'),
229
            widget=CaseSymptomsWidget(
230
                label='Symptoms',
231
            ),
232
        ),
233
        ExtRecordsField('AetiologicAgents',
234
            type='aetiologicagents',
235
            subfields=('Title', 'Description', 'Subtype'),
236
            subfield_sizes={'Title': 15,
237
                            'Description': 25,
238
                            'Subtype': 10},
239
            subfield_labels={'Title': _('Aetiologic agent'),
240
                             'Description': _b('Description'),
241
                             'Subtype': _('Subtype')},
242
            # Temporary fix: https://github.com/bikalabs/bika.health/issues/89
243
            # required_subfields=('Title'),
244
            widget=RecordsWidget(
245
                label='Aetiologic agents',
246
                combogrid_options={
247
                    'Title': {
248
                        'colModel': [{'columnName':'Title', 'width':'30', 'label':_('Aetiologic agent')},
249
                                     {'columnName':'Description', 'width':'60', 'label':_b('Description')},
250
                                     {'columnName':'Subtype', 'width':'30', 'label':_('Subtype')}],
251
                        'url': 'getaetiologicagents',
252
                        'showOn': True,
253
                        'width': "650px",
254
                    },
255
                },
256
            ),
257
        ),
258
        ExtIntegerField('HoursFasting',
259
            required = 0,
260
            widget=IntegerWidget(
261
                label=_('Hours fasting'),
262
            ),
263
        ),
264
        ExtRecordsField('PatientCondition',
265
            widget=CasePatientConditionWidget(
266
                label='Patient condition',
267
            ),
268
        ),
269
        ExtRecordsField('MenstrualStatus',
270
            widget=CaseMenstrualStatusWidget(
271
                label='Menstrual status',
272
            ),
273
        ),
274
        ExtRecordsField('BasalBodyTemperature',
275
            widget=CaseBasalBodyTempWidget(
276
                label='Basal body temperature',
277
            ),
278
        ),
279
        ExtStringField(
280
            'ClientPatientID',
281
            required=0,
282
            widget=ReferenceWidget(
283
                label=_b("Client Patient ID"),
284
                size=20,
285
                visible={'edit': 'visible',
286
                         'view': 'visible',
287
                         'add': 'edit'},
288
                catalog_name='bikahealth_catalog_patient_listing',
289
                portal_types=('Patient',),
290
                search_fields=('getClientPatientID',),
291
                base_query={'is_active': True,
292
                            'sort_limit': 50,
293
                            'sort_on': 'getClientPatientID',
294
                            'sort_order': 'ascending'},
295
                force_all = False,
296
                colModel = [
297
                    {'columnName': "getPatientID",
298
                     'width': '30',
299
                     'label': _('PID'),
300
                     'align': 'left'},
301
                    {'columnName': "getClientPatientID",
302
                     'width': '30',
303
                     'label': _('CPID'),
304
                     'align': 'left'},
305
                    {'columnName': 'Title',
306
                     'width': '30',
307
                     'label': _('Fullname'),
308
                     'align': 'left'},
309
                    # UID is required in colModel
310
                    {'columnName': 'UID', 'hidden': True},
311
                ],
312
                ui_item="getClientPatientID",
313
                showOn=False,
314
            ),
315
        ),
316
    ]
317
318
    def __init__(self, context):
319
        self.context = context
320
321
    def getOrder(self, schematas):
322
        schematas['default'] = ['id',
323
                                'title',
324
                                'description',
325
                                'BatchID',
326
                                'ClientPatientID',
327
                                'Patient',
328
                                'Client',
329
                                'ClientBatchID',
330
                                'Doctor',
331
                                'BatchDate',
332
                                'OnsetDate',
333
                                'OnsetDateEstimated',
334
                                'PatientAgeAtCaseOnsetDate',
335
                                'HoursFasting',
336
                                'PatientCondition',
337
                                'BasalBodyTemperature',
338
                                'MenstrualStatus',
339
                                'Symptoms',
340
                                'ProvisionalDiagnosis',
341
                                'CaseStatus',
342
                                'CaseOutcome',
343
                                'AetiologicAgents',
344
                                'AdditionalNotes',
345
                                'Remarks',
346
                                'BatchLabels', ]
347
        return schematas
348
349
    def getFields(self):
350
        return self.fields
351
352
353
class BatchSchemaModifier(object):
354
    adapts(IBatch)
355
    implements(ISchemaModifier)
356
357
    def __init__(self, context):
358
        self.context = context
359
360
    def fiddle(self, schema):
361
        schema['title'].required = False
362
        schema['title'].widget.visible = False
363
        schema['description'].required = False
364
        schema['description'].widget.visible = False
365
        schema['BatchLabels'].widget.visible = False
366
        schema['ClientBatchID'].widget.label = _("Client Case ID")
367
        schema['BatchDate'].widget.visible = False
368
        schema['Remarks'].widget.visible = False
369
        setup = api.get_setup()
370
        doctor_required = get_field_value(setup, "CaseDoctorIsMandatory",
371
                                          default=False)
372
        schema['Doctor'].required = doctor_required
373
        return schema
374