pharmaship.inventory.parsers.first_aid¶
Utility functions for parsing/serializing First Aid Kit related data.
-
pharmaship.inventory.parsers.first_aid.
create_equipment
(item, content_type, required)¶ Return a dictionary of an equipment.
- Parameters
item (models.Equipment) – An Equipment instance.
content_type (int) – ContentType ID of Molecule model.
required – Dictionary of required quantities for equipments (keys are Molecule ID).
- Returns
Dictionary of parsed Equipment data
- Return type
-
pharmaship.inventory.parsers.first_aid.
create_molecule
(item, content_type, required=None)¶ Return a dictionary of a molecule.
- Parameters
item (models.Molecule) – A Molecule instance.
content_type (int) – ContentType ID of Molecule model.
required – Dictionary of required quantities for molecules (keys are Molecule ID).
- Returns
Dictionary of parsed Molecule data
- Return type
-
pharmaship.inventory.parsers.first_aid.
get_available_articles
(element, content_type_id, qty_transactions)¶ Get the list of available articles (in “chest”) for a given equipment.
- Parameters
element (models.Molecule) – An Equipment instance
content_type_id (int) – ContentType ID of Article model.
qty_transactions (dict) – Dictionary of compiled quantities. This dictionary is obtained from
get_transactions()
.
- Returns
A list of available articles for the selected equipment with quantities available.
- Return type
-
pharmaship.inventory.parsers.first_aid.
get_available_medicines
(element, content_type_id, qty_transactions)¶ Get the list of available medicines (in “chest”) for a given molecule.
- Parameters
element (models.Molecule) – A Molecule instance
content_type_id (int) – ContentType ID of Medicine model.
qty_transactions (dict) – Dictionary of compiled quantities. This dictionary is obtained from
get_transactions()
.
- Returns
A list of available medicines for the selected molecule with quantities available.
- Return type
-
pharmaship.inventory.parsers.first_aid.
get_required
(params)¶ Get required quantities.
-
pharmaship.inventory.parsers.first_aid.
get_subitems
(params, kit, common)¶ Get the list of items currently in a First Aid Kit instance.
- Parameters
params (object) – Global Parameters of the application (
pharmaship.gui.view.GlobalParameters
)kit (models.FirstAidKit) – First Aid Kit instance.
common (dict) – Dictionary of all parsed and available elements.
- Returns
common
dictionary with additional key containing the list of First Aid Kit items.- Return type
-
pharmaship.inventory.parsers.first_aid.
get_transactions
(content_type, items)¶ Get transactions for selected items.
-
pharmaship.inventory.parsers.first_aid.
merge_elements
(elements_dict)¶ Merge elements of each dictionary key into a unique list.
- Parameters
elements_dict (dict) –
Input dictionary. It must have the following keys:
molecules
equipments
- Returns
A list of all values of the dictionary, without the keys.
- Return type
- Example
>>> data = {"molecules": {1: "A", 2: "B"}, "equipments": {8: "C", 9: "D"}} >>> merge_elements(data) ["A", "B", "C", "D"]
-
pharmaship.inventory.parsers.first_aid.
parser
(params, kits=None)¶ Parse the database to render a list of Kits with their contents.
This function processes database data and sets flags on articles missing, expired or reaching near expiry.
It parses also the available items in “chest” according to the required elements (Molecules and Equipments).
Only elements with
pharmaship.inventory.models.FirstAidKitReqQty
are listed.See
pharmaship/schemas/parsers/first_aid
for details.Resumed architecture of the method:
Get required quantities:
get_required()
Get transactions
get_transactions()
:for articles of required equipments;
for medicines of required molecules.
Parse each molecule:
Create the molecule dictionary:
create_molecule()
Add the available medicines:
get_available_medicines()
Parse each equipment:
Create the equipment dictionary:
create_equipment()
Add the available articles:
get_available_articless()
Create kits dictionaries:
Get the contents (
pharmaship.inventory.models.FirstAidKitItem
):get_subitems()
Merge the contents:
merge_elements()
- Parameters
params (object) – Global Parameters of the application (
pharmaship.gui.view.GlobalParameters
)kits (django.db.models.query.QuerySet) – List of First Aid Kits.
- Returns
Dictionnary of First Aid Kits.
- Return type
-
pharmaship.inventory.parsers.first_aid.
subitem_nc
(nc_string)¶ Return the non-conformities dict if any and flag if non-conformity.