Coverage for cc_modules/cc_nhs.py: 73%

11 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-08 23:14 +0000

1#!/usr/bin/env python 

2 

3""" 

4camcops_server/cc_modules/cc_nhs.py 

5 

6=============================================================================== 

7 

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

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

10 

11 This file is part of CamCOPS. 

12 

13 CamCOPS is free software: you can redistribute it and/or modify 

14 it under the terms of the GNU General Public License as published by 

15 the Free Software Foundation, either version 3 of the License, or 

16 (at your option) any later version. 

17 

18 CamCOPS is distributed in the hope that it will be useful, 

19 but WITHOUT ANY WARRANTY; without even the implied warranty of 

20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

21 GNU General Public License for more details. 

22 

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

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

25 

26=============================================================================== 

27 

28**NHS constants.** 

29 

30""" 

31 

32from typing import Dict, Optional, TYPE_CHECKING 

33 

34from camcops_server.cc_modules.cc_string import AS 

35 

36if TYPE_CHECKING: 

37 from camcops_server.cc_modules.cc_request import CamcopsRequest 

38 

39 

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

41# Permitted values in fields and corresponding dictionaries 

42# ============================================================================= 

43 

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

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

46 

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

48PV_NHS_ETHNIC_CATEGORY = [ 

49 "A", 

50 "B", 

51 "C", 

52 "D", 

53 "E", 

54 "F", 

55 "G", 

56 "H", 

57 "J", 

58 "K", 

59 "L", 

60 "M", 

61 "N", 

62 "P", 

63 "R", 

64 "S", 

65 "Z", 

66] 

67 

68 

69def get_nhs_dd_person_marital_status( 

70 req: "CamcopsRequest", 

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

72 """ 

73 Returns a dictionary mapping NHS marital status codes to descriptive 

74 strings. 

75 """ 

76 return { 

77 None: None, 

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

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

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

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

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

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

84 } 

85 

86 

87def get_nhs_dd_ethnic_category_code( 

88 req: "CamcopsRequest", 

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

90 """ 

91 Returns a dictionary mapping NHS ethnicity codes to descriptive 

92 strings. 

93 """ 

94 return { 

95 None: None, 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

113 }