Module Gnumed.business.gmSoapDefs

GNUmed SOAP related defintions

Functions

def are_valid_soap_cats(soap_cats: str, allow_upper: bool = True) ‑> bool
Expand source code
def are_valid_soap_cats(soap_cats:str, allow_upper:bool=True) -> bool:
        """Check whether _soap_cats_ contains valid category markers only.

        Args:
                soap_cats: string or list
                allow_upper: whether uppercase is considered valid
        """
        for cat2test in soap_cats:
                if cat2test in KNOWN_SOAP_CATS:
                        continue
                if not allow_upper:
                        return False

                if cat2test.casefold() in KNOWN_SOAP_CATS:
                        continue
                return False

        return True

Check whether soap_cats contains valid category markers only.

Args

soap_cats
string or list
allow_upper
whether uppercase is considered valid
def normalize_soap_cat(soap_cat: str) ‑> str
Expand source code
def normalize_soap_cat(soap_cat:str) -> str: # | bool:
        soap_cat = soap_cat.casefold()
        if soap_cat in KNOWN_SOAP_CATS:
                return soap_cat

        return False            # type: ignore [return-value]
def soap_cats_str2list(soap_cats: str) ‑> list[str]
Expand source code
def soap_cats_str2list(soap_cats:str) -> list[str]:
        """Normalize SOAP categories, preserving order.

        Args:
                soap_cats: string or list
                * None -> gmSoapDefs.KNOWN_SOAP_CATS (all)
                * [] -> []
                * '' -> []
                * ' ' -> [None] (admin)
        """
        if soap_cats is None:
                return KNOWN_SOAP_CATS

        normalized_cats:list = []
        for cat in soap_cats:
                if cat in [' ', None]:
                        if None in normalized_cats:
                                continue
                        normalized_cats.append(None)
                        continue
                cat = cat.casefold()
                if cat in KNOWN_SOAP_CATS:
                        if cat in normalized_cats:
                                continue
                        normalized_cats.append(cat)
        return normalized_cats

Normalize SOAP categories, preserving order.

Args

soap_cats
string or list
  • None -> gmSoapDefs.KNOWN_SOAP_CATS (all)
  • [] -> []
  • '' -> []
  • ' ' -> [None] (admin)