Coverage for cc_modules/cc_ipuse.py: 93%

29 statements  

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

1""" 

2camcops_server/cc_modules/cc_ipuse.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 

26IP Use flags that determine the contexts in which CamCOPS is to be used (and 

27hence the tasks that will be permitted). 

28 

29""" 

30 

31from typing import Any 

32 

33from cardinal_pythonlib.reprfunc import auto_repr, auto_str 

34from sqlalchemy.orm import Mapped, mapped_column 

35 

36from camcops_server.cc_modules.cc_sqlalchemy import Base 

37 

38 

39_DEFAULT_APPLICABILITY = False 

40 

41 

42class IpContexts(object): 

43 """ 

44 String constants, used as form parameter names etc. 

45 """ 

46 

47 CLINICAL = "clinical" 

48 COMMERCIAL = "commercial" 

49 EDUCATIONAL = "educational" 

50 RESEARCH = "research" 

51 

52 

53class IpUse(Base): 

54 __tablename__ = "_security_ip_use" 

55 

56 CONTEXTS = ( 

57 IpContexts.CLINICAL, 

58 IpContexts.COMMERCIAL, 

59 IpContexts.EDUCATIONAL, 

60 IpContexts.RESEARCH, 

61 ) 

62 _DEFAULT = False 

63 

64 id: Mapped[int] = mapped_column( 

65 primary_key=True, 

66 autoincrement=True, 

67 index=True, 

68 comment="IP Use ID", 

69 ) 

70 

71 clinical: Mapped[bool] = mapped_column( 

72 default=_DEFAULT, 

73 comment="Applicable to a clinical context", 

74 ) 

75 commercial: Mapped[bool] = mapped_column( 

76 default=_DEFAULT, 

77 comment="Applicable to a commercial context", 

78 ) 

79 educational: Mapped[bool] = mapped_column( 

80 default=_DEFAULT, 

81 comment="Applicable to an educational context", 

82 ) 

83 research: Mapped[bool] = mapped_column( 

84 default=_DEFAULT, 

85 comment="Applicable to a research context", 

86 ) 

87 

88 def __init__( 

89 self, 

90 clinical: bool = _DEFAULT_APPLICABILITY, 

91 commercial: bool = _DEFAULT_APPLICABILITY, 

92 educational: bool = _DEFAULT_APPLICABILITY, 

93 research: bool = _DEFAULT_APPLICABILITY, 

94 **kwargs: Any 

95 ) -> None: 

96 """ 

97 We provide __init__() so we can create a default object without 

98 touching the database. 

99 """ 

100 super().__init__(**kwargs) 

101 self.clinical = clinical 

102 self.commercial = commercial 

103 self.educational = educational 

104 self.research = research 

105 

106 def __repr__(self) -> str: 

107 return auto_repr(self) 

108 

109 def __str__(self) -> str: 

110 return auto_str(self)