1 """GNUmed SOAP related defintions"""
2
3 __author__ = "Karsten Hilbert <Karsten.Hilbert@gmx.net>"
4 __license__ = 'GPL v2 or later (for details see http://gnu.org)'
5
6 try:
7 _('dummy-no-need-to-translate-but-make-epydoc-happy')
8 except NameError:
9 _ = lambda x:x
10
11
12 _U_ELLIPSIS = '\u2026'
13
14 KNOWN_SOAP_CATS = list('soapu')
15 KNOWN_SOAP_CATS.append(None)
16
17
18 soap_cat2l10n = {
19 's': _('SOAP_char_S=S').replace('SOAP_char_S=', ''),
20 'o': _('SOAP_char_O=O').replace('SOAP_char_O=', ''),
21 'a': _('SOAP_char_A=A').replace('SOAP_char_A=', ''),
22 'p': _('SOAP_char_P=P').replace('SOAP_char_P=', ''),
23 'u': _('SOAP_char_U=U').replace('SOAP_char_U=', ''),
24 '': _U_ELLIPSIS,
25 None: _U_ELLIPSIS
26 }
27
28
29 soap_cat2l10n_str = {
30 's': _('SOAP_string_Subjective=Subjective').replace('SOAP_string_Subjective=', ''),
31 'o': _('SOAP_string_Objective=Objective').replace('SOAP_string_Objective=', ''),
32 'a': _('SOAP_string_Assessment=Assessment').replace('SOAP_string_Assessment=', ''),
33 'p': _('SOAP_string_Plan=Plan').replace('SOAP_string_Plan=', ''),
34 'u': _('SOAP_string_Unspecified=Unspecified').replace('SOAP_string_Unspecified=', ''),
35 '': _('SOAP_string_Administrative=Administrative').replace('SOAP_string_Administrative=', ''),
36 None: _('SOAP_string_Administrative=Administrative').replace('SOAP_string_Administrative=', '')
37 }
38
39
40 l10n2soap_cat = {
41 _('SOAP_char_S=S').replace('SOAP_char_S=', ''): 's',
42 _('SOAP_char_O=O').replace('SOAP_char_O=', ''): 'o',
43 _('SOAP_char_A=A').replace('SOAP_char_A=', ''): 'a',
44 _('SOAP_char_P=P').replace('SOAP_char_P=', ''): 'p',
45 _('SOAP_char_U=U').replace('SOAP_char_U=', ''): 'u',
46 _U_ELLIPSIS: None,
47 '.': None,
48 ' ': None,
49 '': None
50 }
51
52
54 """Normalizes a string or list of SOAP categories, preserving order.
55
56 None -> gmSoapDefs.KNOWN_SOAP_CATS (all)
57 [] -> []
58 u'' -> []
59 u' ' -> [None] (admin)
60 """
61 if soap_cats is None:
62 return KNOWN_SOAP_CATS
63
64 normalized_cats = []
65 for cat in soap_cats:
66 if cat in [' ', None]:
67 if None in normalized_cats:
68 continue
69 normalized_cats.append(None)
70 continue
71 cat = cat.lower()
72 if cat in KNOWN_SOAP_CATS:
73 if cat in normalized_cats:
74 continue
75 normalized_cats.append(cat)
76
77 return normalized_cats
78
79
81 for cat2test in soap_cats:
82 if cat2test in KNOWN_SOAP_CATS:
83 continue
84 if not allow_upper:
85 return False
86 if cat2test.upper() in KNOWN_SOAP_CATS:
87 continue
88 return False
89 return True
90
91
99
100
101 if __name__ == '__main__':
102
103 import sys
104
105 if len(sys.argv) < 2:
106 sys.exit()
107
108 if sys.argv[1] != 'test':
109 sys.exit()
110
111 sys.path.insert(0, '../../')
112
113 from Gnumed.pycommon import gmI18N
114
115 gmI18N.activate_locale()
116 gmI18N.install_domain()
117
118
122
123
125 cats = [
126 list('soap'),
127 list('soapSOAP'),
128 list('soapx'),
129 list('soapX'),
130 list('soapSOAPx'),
131 [None],
132 ['s', None],
133 ['s', None, 'O'],
134 ['s', None, 'x'],
135 ['s', None, 'X'],
136 ]
137 for cat_list in cats:
138 print(cat_list)
139 print(' valid (plain):', are_valid_soap_cats(cat_list, False))
140 print(' valid (w/ upper):', are_valid_soap_cats(cat_list, True))
141
142
143 test_translation()
144 test_are_valid_cats()
145