Package Gnumed :: Package business :: Module gmSoapDefs
[frames] | no frames]

Source Code for Module Gnumed.business.gmSoapDefs

  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  #============================================================ 
53 -def soap_cats2list(soap_cats):
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 #============================================================
80 -def are_valid_soap_cats(soap_cats, allow_upper=True):
81 82 for cat in KNOWN_SOAP_CATS: 83 try: 84 while True: soap_cats.remove(cat) 85 except ValueError: 86 pass 87 88 if allow_upper: 89 for cat in KNOWN_SOAP_CATS: 90 if cat is None: 91 continue 92 try: 93 while True: soap_cats.remove(cat.upper()) 94 except ValueError: 95 pass 96 97 if len(soap_cats) == 0: 98 return True 99 100 return False
101 102 #============================================================
103 -def normalize_soap_cat(soap_cat):
104 if soap_cat in KNOWN_SOAP_CATS: 105 return soap_cat 106 soap_cat = soap_cat.lower() 107 if soap_cat in KNOWN_SOAP_CATS: 108 return soap_cat 109 return False
110 111 #============================================================ 112 if __name__ == '__main__': 113 114 import sys 115 116 if len(sys.argv) < 2: 117 sys.exit() 118 119 if sys.argv[1] != 'test': 120 sys.exit() 121 122 sys.path.insert(0, '../../') 123 124 from Gnumed.pycommon import gmI18N 125 126 gmI18N.activate_locale() 127 gmI18N.install_domain() 128 129 #--------------------------------------------------------
130 - def test_translation():
131 for c in KNOWN_SOAP_CATS: 132 print(c, soap_cat2l10n[c], soap_cat2l10n_str[c])
133 134 #--------------------------------------------------------
135 - def test_are_valid_cats():
136 cats = [ 137 list('soap'), 138 list('soapSOAP'), 139 list('soapx'), 140 list('soapX'), 141 list('soapSOAPx'), 142 [None], 143 ['s', None], 144 ['s', None, 'O'], 145 ['s', None, 'x'], 146 ['s', None, 'X'], 147 ] 148 for cat_list in cats: 149 print(cat_list) 150 print(' valid (plain):', are_valid_soap_cats(cat_list, False)) 151 print(' valid (w/ upper):', are_valid_soap_cats(cat_list, True))
152 153 #-------------------------------------------------------- 154 test_translation() 155 test_are_valid_cats() 156