mex.common.organigram package¶
Submodules¶
mex.common.organigram.extract module¶
- mex.common.organigram.extract.extract_organigram_units() list[OrganigramUnit] ¶
Extract organizational units from the organigram JSON file.
- Settings:
organigram_path: Resolved path to the organigram file
- Returns:
List of organigram units
- mex.common.organigram.extract.get_unit_merged_ids_by_emails(extracted_units: Iterable[ExtractedOrganizationalUnit]) dict[str, MergedOrganizationalUnitIdentifier] ¶
Return a mapping from unit emails to their merged IDs.
There may be multiple emails per unit mapping to the same merged ID.
- Parameters:
extracted_units – Iterable of extracted units
- Raises:
MExError – If the same entry maps to different merged IDs
- Returns:
Mapping from lowercased email to stableTargetIds
- mex.common.organigram.extract.get_unit_merged_ids_by_synonyms(extracted_units: Iterable[ExtractedOrganizationalUnit]) dict[str, MergedOrganizationalUnitIdentifier] ¶
Return a mapping from unit alt_label and label to their merged IDs.
There will be multiple entries per unit mapping to the same merged ID.
- Parameters:
extracted_units – Iterable of extracted units
- Raises:
MExError – If the same entry maps to different merged IDs
- Returns:
Mapping from unit synonyms to stableTargetIds
- mex.common.organigram.extract.get_unit_synonyms(extracted_unit: ExtractedOrganizationalUnit) list[str] ¶
Generate synonyms for a unit using its name fields.
- Parameters:
extracted_unit – Extracted organizational unit
- Returns:
Sorted list of unique unit synonyms
mex.common.organigram.helpers module¶
- mex.common.organigram.helpers._collect_descendants(child_map: dict[str, list[str]], unit_id: str, descendant_ids: set[str]) None ¶
Recursion to collect all children and their children, etc., depth first.
- Parameters:
child_map – Dictionary with all child units of a unit by unit id
unit_id – Unit identifier
descendant_ids – Set of all descendant units
- Returns:
None, the set descendant_ids is mutated in-place
- mex.common.organigram.helpers.build_child_map(units: list[_TOrganizationalUnit]) dict[str, list[str]] ¶
Builds a dictionary with all children per unit from a list of units.
- Parameters:
units – list of organizational units (Extracted, Merged, or OrganigramUnit)
- Returns:
Dictionary with a list of all child unit ids by unit id
- Return type:
dict[str, list[str]]
- mex.common.organigram.helpers.find_descendants(units: list[_TOrganizationalUnit], parent_id: str) list[str] ¶
Find ids of all descendant (great{n}/grand/child) units for any parent unit id.
- Parameters:
units – list of organizational units (Extracted, Merged, or OrganigramUnit) in which to search for descendants
parent_id – identifier of the parent unit
- Returns:
- list of all unique descendant organizational unit ids (children,
grandchildren, …), excluding the starting parent_id
- mex.common.organigram.helpers.get_extracted_organizational_unit_with_parents(name: str, primary_source_id: MergedPrimarySourceIdentifier, rki_organization: ExtractedOrganization) list[ExtractedOrganizationalUnit] ¶
Pick the unit with the given name and transform it along with its parents.
- Parameters:
name – Name (identifierInPrimarySource) of the organigram unit
primary_source_id – Extracted primary source for the organigram
rki_organization – RKI organization to which the unit belongs
- Returns:
ExtractedOrganizationalUnit with its parents
mex.common.organigram.models module¶
- class mex.common.organigram.models.OrganigramUnit(*, shortName: list[Text], email: list[str] = [], identifier: str, name: list[Text], alternativeName: list[Text] = [], parentUnit: None | str = None, website: None | Link = None)¶
Bases:
BaseModel
Organizational units in the format of the organigram JSON file.
- email: list[str]¶
- identifier: str¶
- model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'populate_by_name': True, 'str_max_length': 100000, 'str_min_length': 1, 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_assignment': True, 'validate_by_alias': True, 'validate_by_name': True, 'validate_default': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- parentUnit: None | str¶
mex.common.organigram.transform module¶
- mex.common.organigram.transform.transform_organigram_unit_to_extracted_organizational_unit(organigram_unit: OrganigramUnit, primary_source_id: MergedPrimarySourceIdentifier, rki_organization: ExtractedOrganization) ExtractedOrganizationalUnit ¶
Transform an organigram unit into an ExtractedOrganizationalUnit.
- Parameters:
organigram_unit – Iterable of organigram units coming from the JSON file
primary_source_id – Primary source identifier for organigram
rki_organization – RKI organization to which the unit belongs
- Returns:
ExtractedOrganizationalUnit
- mex.common.organigram.transform.transform_organigram_units_to_organizational_units(organigram_units: Iterable[OrganigramUnit], primary_source_id: MergedPrimarySourceIdentifier, rki_organization: ExtractedOrganization) list[ExtractedOrganizationalUnit] ¶
Transform organigram units into ExtractedOrganizationalUnits.
Beware that the order of the output is not necessarily the order of the input.
- Parameters:
organigram_units – Iterable of organigram units coming from the JSON file
primary_source_id – Primary source for organigram
rki_organization – RKI organization to which the units belong
- Returns:
List of ExtractedOrganizationalUnit
Module contents¶
Helper extractor to extract organigram data.
Common use cases: - extract organizational units of your organization (e.g. president, departments, units)
Configuration¶
The extractor reads data from a json file, whose path is set with the settings parameter organigram_path (see mex.common.settings for further info).
Extracting data¶
The module organigram.extract contains functions for data extraction.
Transforming data¶
The module organigram.transform contains functions for data transformation.
Use the stableTargetId attribute of the transformed objects to set attributes requiring an MergedOrganizationalUnitIdentifier.
Convenience Functions¶
The module organigram.extract holds convenience functions, e.g. for building a mapping from email addresses or synonyms to ExtractedOrganizationalUnit.
JSON file format¶
See example file in assets/raw-data/organigram/organizational_units.json. For mandatory / optional attributes, see model in mex/common/organigram/models.py.