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

NMRL-182 Sort on Patient not working in lists (Analysis Requests, Samples and Patients) #10

Merged
merged 9 commits into from
Mar 24, 2017
Next Next commit
catalog.py -> catalog folder
  • Loading branch information
Pau Soliva committed Feb 13, 2017
commit a26fb2e3171fb3e14e30c3c44d4d8f2b067877de
14 changes: 14 additions & 0 deletions bika/health/catalog/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file is part of Bika Health
#
# Copyright 2011-2016 by it's authors.
# Some rights reserved. See LICENSE.txt, AUTHORS.txt.

# Catalog IDs static constant
from .patient_catalog import CATALOG_PATIENT_LISTING
# Catalog classes
from .patient_catalog import BikaPatientCatalog
from .patient_catalog import BikaHealthCatalogPatientListing
# Catalog public functions
from .catalog_utilities import getCatalogDefinitions
from .catalog_utilities import getCatalogExtensions
from .catalog_utilities import getCatalog
21 changes: 21 additions & 0 deletions bika/health/catalog/analysisrequest_catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is part of Bika Health
#
# Copyright 2011-2016 by it's authors.
# Some rights reserved. See LICENSE.txt, AUTHORS.txt.

from bika.lims.catalog import CATALOG_ANALYSIS_REQUEST_LISTING

# Defines the extension for catalogs created in Bika LIMS.
# Only add the items you would like to add!
analysisrequest_catalog_definition = {
CATALOG_ANALYSIS_REQUEST_LISTING: {
'indexes': {
'getDoctorUID': 'FieldIndex',
'getPatientUID': 'FieldIndex',
},
'columns': [
'getDoctorUID',
'getPatientUID',
]
}
}
41 changes: 41 additions & 0 deletions bika/health/catalog/catalog_utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from Products.CMFCore.utils import getToolByName
from bika.health.catalog.analysisrequest_catalog import\
analysisrequest_catalog_definition
from bika.health.catalog.patient_catalog import patient_catalog_definition


def getCatalogDefinitions():
"""
Returns a dictionary with catalog definitions
"""
return patient_catalog_definition


def getCatalogExtensions():
"""
Returns a dictionary with catalog extensions
"""
return analysisrequest_catalog_definition


# TODO-catalog: Function to review its use. Good candidate to be removed
def getCatalog(instance, field='UID'):
""" Return the catalog which indexes objects of instance's type.
If an object is indexed by more than one catalog, the first match
will be returned.
"""
uid = instance.UID()
if 'workflow_skiplist' in instance.REQUEST \
and [x for x in instance.REQUEST['workflow_skiplist']
if x.find(uid) > -1]:
return None
else:
# grab the first catalog we are indexed in.
# we're only indexed in one.
at = getToolByName(instance, 'archetype_tool')
plone = instance.portal_url.getPortalObject()
catalog_name = instance.portal_type in at.catalog_map \
and at.catalog_map[instance.portal_type][0] or 'portal_catalog'

catalog = getToolByName(plone, catalog_name)
return catalog
145 changes: 49 additions & 96 deletions bika/health/catalog.py → bika/health/catalog/patient_catalog.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# This file is part of Bika Health
#
# Copyright 2011-2016 by it's authors.
# Some rights reserved. See LICENSE.txt, AUTHORS.txt.

import sys
import traceback
from zope.interface import implements
from AccessControl import ClassSecurityInfo
from App.class_init import InitializeClass
from Products.CMFCore.permissions import ManagePortal
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.CatalogTool import CatalogTool
from Products.ZCatalog.ZCatalog import ZCatalog
from zope.interface import implements
# from bika.lims import deprecated
from bika.health.interfaces import IBikaHealthCatalogPatientListing
from bika.lims.catalog import CATALOG_ANALYSIS_REQUEST_LISTING
# Bika Health imports
from bika.health import logger

from bika.health.interfaces import IBikaHealthCatalogPatientListing

# Using a variable to avoid plain strings in code
CATALOG_PATIENT_LISTING = 'bikahealth_catalog_patient_listing'

_catalogs_definition = {
patient_catalog_definition = {
# This catalog contains the metacolumns to list patients in bikalisting
CATALOG_PATIENT_LISTING: {
'types': ['Patient', ],
Expand Down Expand Up @@ -72,96 +77,6 @@
}


# Defines the extension for catalogs created in Bika LIMS.
# Only add the items you would like to add!
_catalogs_extensions = {
CATALOG_ANALYSIS_REQUEST_LISTING: {
'indexes': {
'getDoctorUID': 'FieldIndex',
'getPatientUID': 'FieldIndex',
},
'columns': [
'getDoctorUID',
'getPatientUID',
]
}
}


def getCatalogDefinitions():
"""
Returns a dictionary with catalog definitions
"""
return _catalogs_definition


def getCatalogExtensions():
"""
Returns a dictionary with catalog extensions
"""
return _catalogs_extensions

# TODO-catalog: Function to review its use. Good candidate to be removed
def getCatalog(instance, field='UID'):
""" Return the catalog which indexes objects of instance's type.
If an object is indexed by more than one catalog, the first match
will be returned.
"""
uid = instance.UID()
if 'workflow_skiplist' in instance.REQUEST \
and [x for x in instance.REQUEST['workflow_skiplist']
if x.find(uid) > -1]:
return None
else:
# grab the first catalog we are indexed in.
# we're only indexed in one.
at = getToolByName(instance, 'archetype_tool')
plone = instance.portal_url.getPortalObject()
catalog_name = instance.portal_type in at.catalog_map \
and at.catalog_map[instance.portal_type][0] or 'portal_catalog'

catalog = getToolByName(plone, catalog_name)
return catalog


# TODO: Remove BikaPatientCatalog
# @deprecated(comment="bika.health.catalog.BikaPatientCatalog "
# "is deprecated and will be removed "
# "in Bika Health 3.3. Please, use "
# "BikaHealthCatalogPatientListing intead")
class BikaPatientCatalog(CatalogTool):

""" Catalog for patients
"""
security = ClassSecurityInfo()
_properties = ({'id': 'title', 'type': 'string', 'mode': 'w'},)

title = 'Bika Patient Catalog'
id = 'bika_patient_catalog'
portal_type = meta_type = 'BikaPatientCatalog'
plone_tool = 1

def __init__(self):
ZCatalog.__init__(self, self.id)

security.declareProtected(ManagePortal, 'clearFindAndRebuild')

def clearFindAndRebuild(self):
"""
"""

def indexObject(obj, path):
self.reindexObject(obj)

self.manage_catalogClear()
portal = getToolByName(self, 'portal_url').getPortalObject()
portal.ZopeFindAndApply(portal,
obj_metatypes=('Patient',),
search_sub=True,
apply_func=indexObject)
InitializeClass(BikaPatientCatalog)


class BikaHealthCatalogPatientListing(CatalogTool):
"""
Catalog to list patients in BikaListing
Expand Down Expand Up @@ -208,3 +123,41 @@ def indexObject(obj, path):


InitializeClass(BikaHealthCatalogPatientListing)


# TODO: Remove BikaPatientCatalog
# @deprecated(comment="bika.health.catalog.BikaPatientCatalog "
# "is deprecated and will be removed "
# "in Bika Health 3.3. Please, use "
# "BikaHealthCatalogPatientListing intead")
class BikaPatientCatalog(CatalogTool):

""" Catalog for patients
"""
security = ClassSecurityInfo()
_properties = ({'id': 'title', 'type': 'string', 'mode': 'w'},)

title = 'Bika Patient Catalog'
id = 'bika_patient_catalog'
portal_type = meta_type = 'BikaPatientCatalog'
plone_tool = 1

def __init__(self):
ZCatalog.__init__(self, self.id)

security.declareProtected(ManagePortal, 'clearFindAndRebuild')

def clearFindAndRebuild(self):
"""
"""

def indexObject(obj, path):
self.reindexObject(obj)

self.manage_catalogClear()
portal = getToolByName(self, 'portal_url').getPortalObject()
portal.ZopeFindAndApply(portal,
obj_metatypes=('Patient',),
search_sub=True,
apply_func=indexObject)
InitializeClass(BikaPatientCatalog)