Coverage for cc_modules/cc_nhs.py: 70%

10 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-15 14:23 +0100

1""" 

2camcops_server/cc_modules/cc_nhs.py 

3 

4=============================================================================== 

5 

6 Copyright (C) 2012, University of Cambridge, Department of Psychiatry. 

7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk). 

8 

9 This file is part of CamCOPS. 

10 

11 CamCOPS 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. 

15 

16 CamCOPS 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. 

20 

21 You should have received a copy of the GNU General Public License 

22 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>. 

23 

24=============================================================================== 

25 

26**NHS constants.** 

27 

28""" 

29 

30from typing import Dict, Optional, TYPE_CHECKING 

31 

32from camcops_server.cc_modules.cc_string import AS 

33 

34if TYPE_CHECKING: 

35 from camcops_server.cc_modules.cc_request import CamcopsRequest 

36 

37 

38# ============================================================================= 

39# Permitted values in fields and corresponding dictionaries 

40# ============================================================================= 

41 

42# Do not use wappstring in the module-level code; the strings file is only 

43# initialized later. However, PV* fields are used at table creation. 

44 

45PV_NHS_MARITAL_STATUS = ["S", "M", "D", "W", "P", "N"] 

46PV_NHS_ETHNIC_CATEGORY = [ 

47 "A", 

48 "B", 

49 "C", 

50 "D", 

51 "E", 

52 "F", 

53 "G", 

54 "H", 

55 "J", 

56 "K", 

57 "L", 

58 "M", 

59 "N", 

60 "P", 

61 "R", 

62 "S", 

63 "Z", 

64] 

65 

66 

67def get_nhs_dd_person_marital_status( 

68 req: "CamcopsRequest", 

69) -> Dict[Optional[str], Optional[str]]: 

70 """ 

71 Returns a dictionary mapping NHS marital status codes to descriptive 

72 strings. 

73 """ 

74 return { 

75 None: None, 

76 "S": req.wappstring(AS.NHS_PERSON_MARITAL_STATUS_CODE_S), 

77 "M": req.wappstring(AS.NHS_PERSON_MARITAL_STATUS_CODE_M), 

78 "D": req.wappstring(AS.NHS_PERSON_MARITAL_STATUS_CODE_D), 

79 "W": req.wappstring(AS.NHS_PERSON_MARITAL_STATUS_CODE_W), 

80 "P": req.wappstring(AS.NHS_PERSON_MARITAL_STATUS_CODE_P), 

81 "N": req.wappstring(AS.NHS_PERSON_MARITAL_STATUS_CODE_N), 

82 } 

83 

84 

85def get_nhs_dd_ethnic_category_code( 

86 req: "CamcopsRequest", 

87) -> Dict[Optional[str], Optional[str]]: 

88 """ 

89 Returns a dictionary mapping NHS ethnicity codes to descriptive 

90 strings. 

91 """ 

92 return { 

93 None: None, 

94 "A": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_A), 

95 "B": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_B), 

96 "C": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_C), 

97 "D": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_D), 

98 "E": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_E), 

99 "F": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_F), 

100 "G": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_G), 

101 "H": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_H), 

102 "J": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_J), 

103 "K": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_K), 

104 "L": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_L), 

105 "M": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_M), 

106 "N": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_N), 

107 "P": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_P), 

108 "R": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_R), 

109 "S": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_S), 

110 "Z": req.wappstring(AS.NHS_ETHNIC_CATEGORY_CODE_Z), 

111 }