Coverage for crateweb/consent/teamlookup.py: 55%
20 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-08-27 10:34 -0500
« prev ^ index » next coverage.py v7.8.0, created at 2025-08-27 10:34 -0500
1"""
2crate_anon/crateweb/consent/teamlookup.py
4===============================================================================
6 Copyright (C) 2015, University of Cambridge, Department of Psychiatry.
7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
9 This file is part of CRATE.
11 CRATE is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 CRATE is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with CRATE. If not, see <https://www.gnu.org/licenses/>.
24===============================================================================
26**Function to get clinical teams from our clinical source database.**
28Note that ``teamlookup*.py`` files are separate from patient lookup files to
29avoid circular imports, because teams are cached very early on (including for
30Django field choices).
32"""
34import logging
35from typing import List
37from cardinal_pythonlib.django.function_cache import django_cache_function
38from django.conf import settings
40from crate_anon.crateweb.config.constants import ClinicalDatabaseType
41from crate_anon.crateweb.consent.teamlookup_dummy import get_dummy_teams
42from crate_anon.crateweb.consent.teamlookup_rio import get_rio_teams_rcep_crate
43from crate_anon.crateweb.consent.teamlookup_systmone import (
44 get_cpft_systmone_teams,
45)
47log = logging.getLogger(__name__)
50# =============================================================================
51# Fetch clinical team names
52# =============================================================================
55@django_cache_function(timeout=None)
56def get_teams() -> List[str]:
57 """
58 Return all clinical team names from our clinical source database (as
59 determined by ``settings.CLINICAL_LOOKUP_DB``).
60 """
61 log.debug("Fetching/caching clinical teams")
62 source_db = settings.CLINICAL_LOOKUP_DB
63 if settings.CLINICAL_LOOKUP_DB in (
64 ClinicalDatabaseType.CPFT_RIO_RCEP,
65 ClinicalDatabaseType.CPFT_RIO_CRATE_PREPROCESSED,
66 ):
67 return get_rio_teams_rcep_crate(source_db=source_db)
68 elif settings.CLINICAL_LOOKUP_DB == ClinicalDatabaseType.DUMMY_CLINICAL:
69 return get_dummy_teams()
70 elif settings.CLINICAL_LOOKUP_DB == ClinicalDatabaseType.CPFT_SYSTMONE:
71 return get_cpft_systmone_teams()
72 else:
73 return []