Coverage for crateweb/consent/teamlookup_systmone.py: 60%
10 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_systmone.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 a TPP SystmOne Strategic Reporting
27Extract (SRE) database.**
29Note that ``teamlookup*.py`` files are separate from patient lookup files to
30avoid circular imports, because teams are cached very early on (including for
31Django field choices).
33"""
35from typing import List
37from cardinal_pythonlib.dbfunc import fetchallfirstvalues
38from django.db import connections
40from crate_anon.crateweb.config.constants import ClinicalDatabaseType
41from crate_anon.preprocess.systmone_ddgen import cpft_s1_tablename, S1Table
44# =============================================================================
45# Look up teams
46# =============================================================================
49def get_cpft_systmone_teams() -> List[str]:
50 """
51 Returns a list of clinical teams from a SystmOne Strategic Reporting
52 Extract (SRE) database in CPFT's Data Warehosue format.
53 """
54 cursor = connections[ClinicalDatabaseType.CPFT_SYSTMONE].cursor()
55 teams = cpft_s1_tablename(S1Table.TEAM)
56 cursor.execute(
57 f"""
58 SELECT DISTINCT TeamName
59 FROM {teams}
60 WHERE TeamDeleted IS NULL
61 ORDER BY TeamName
62 """
63 )
64 return fetchallfirstvalues(cursor)