Coverage for crateweb/consent/teamlookup_rio.py: 57%
7 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_rio.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 team names from RiO.**
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"""
34from typing import List
36from cardinal_pythonlib.dbfunc import fetchallfirstvalues
37from django.db import connections
40# =============================================================================
41# Look up teams
42# =============================================================================
45def get_rio_teams_rcep_crate(source_db: str) -> List[str]:
46 """
47 Returns a list of clinical teams from a RiO database that has been
48 preprocessed through RCEP or CRATE.
50 Args:
51 source_db: the type of the source database; see
52 :class:`crate_anon.crateweb.config.constants.ClinicalDatabaseType`
53 """
54 cursor = connections[source_db].cursor()
55 cursor.execute(
56 """
57 SELECT DISTINCT Team_Description
58 FROM Referral_Team_History
59 ORDER BY Team_Description
60 """
61 )
62 return fetchallfirstvalues(cursor)