Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Show doctor in Analysis Requests listings #63

Merged
merged 8 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
**Added**

- #56 Option for making Client Patient IDs unique
- #63 Display Doctor column in Analysis Requests listings

**Removed**

Expand Down
52 changes: 35 additions & 17 deletions bika/health/browser/analysisrequests/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
# Copyright 2018 by it's authors.
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst.

from bika.lims import api
from bika.lims.browser.analysisrequest import AnalysisRequestsView as BaseView
from bika.health import bikaMessageFactory as _
from Products.CMFCore.utils import getToolByName
from bika.health.catalog import CATALOG_PATIENT_LISTING
from bika.lims.utils import get_link
from plone.memoize import view as viewcache


class AnalysisRequestsView(BaseView):
def __init__(self, context, request):
super(AnalysisRequestsView, self).__init__(context, request)
self.patient_catalog = None
self.columns['BatchID']['title'] = _('Case ID')
# Add Client Patient fields
self.columns['getPatientID'] = {
Expand All @@ -24,6 +26,8 @@ def __init__(self, context, request):
'sortable': False, }
self.columns['getPatient'] = {
'title': _('Patient'), }
self.columns['getDoctor'] = {
'title': _('Doctor'), }

def folderitems(self, full_objects=False):
pm = getToolByName(self.context, "portal_membership")
Expand All @@ -34,34 +38,48 @@ def folderitems(self, full_objects=False):
if 'Manager' not in roles \
and 'LabManager' not in roles \
and 'LabClerk' not in roles:
del self.columns['getPatientID']
del self.columns['getClientPatientID']
del self.columns['getPatient']
self.remove_column('getPatientID')
self.remove_column('getClientPatientID')
self.remove_column('getPatient')
self.remove_column('getDoctor')
# Otherwise show the columns in the list
else:
for rs in self.review_states:
i = rs['columns'].index('BatchID') + 1
rs['columns'].insert(i, 'getClientPatientID')
rs['columns'].insert(i, 'getPatientID')
rs['columns'].insert(i, 'getPatient')
# Setting ip the patient catalog to be used in folderitem()
self.patient_catalog = getToolByName(
self.context, CATALOG_PATIENT_LISTING)
rs['columns'].insert(i, 'getDoctor')
return super(AnalysisRequestsView, self).folderitems(
full_objects=False, classic=False)

@viewcache.memoize
def get_brain(self, uid, catalog):
if not api.is_uid(uid):
return None
query = dict(UID=uid)
brains = api.search(query, catalog)
if brains and len(brains) == 1:
return brains[0]
return None

def folderitem(self, obj, item, index):
item = super(AnalysisRequestsView, self)\
.folderitem(obj, item, index)
patient = self.patient_catalog(UID=obj.getPatientUID)
patient = self.get_brain(obj.getPatientUID, CATALOG_PATIENT_LISTING)
if patient:
item['getPatientID'] = patient[0].getId
item['replace']['getPatientID'] = "<a href='%s'>%s</a>" % \
(patient[0].getURL(), patient[0].getId)
item['getClientPatientID'] = patient[0].getClientPatientID
item['replace']['getClientPatientID'] = "<a href='%s'>%s</a>" % \
(patient[0].getURL(), patient[0].getClientPatientID)
item['getPatient'] = patient[0].Title
item['replace']['getPatient'] = "<a href='%s'>%s</a>" % \
(patient[0].getURL(), patient[0].Title)
cpid = patient.getClientPatientID
url = '%s/analysisrequests' % api.get_url(patient)
item['getPatientID'] = patient.getId
item['getClientPatientID'] = patient.getClientPatientID
item['getPatient'] = patient.Title
item['replace']['getPatientID'] = get_link(url, patient.getId)
item['replace']['getClientPatientID'] = get_link(url, cpid)
item['replace']['getPatient'] = get_link(url, patient.Title)

doctor = self.get_brain(obj.getDoctorUID, "portal_catalog")
if doctor:
url = '%s/analysisrequests' % api.get_url(doctor)
item['getDoctor'] = doctor.Title
item['replace']['getDoctor'] = get_link(url, doctor.Title)
return item