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

dict

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

dict

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

dict

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

dict

pharmaship.inventory.parsers.first_aid.get_required(params)

Get required quantities.

Parameters

params (object) – Global Parameters of the application (pharmaship.gui.view.GlobalParameters)

Returns

A dictionary of required quantities sorted by type (molecule or equipment) and subsequent item ID.

Return type

dict

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

dict

pharmaship.inventory.parsers.first_aid.get_transactions(content_type, items)

Get transactions for selected items.

Parameters
  • content_type (int) – ID of ContentType of items

  • items (list) – List of items ID

Returns

Dictionary of compiled quantities for each item. Dict keys are items ID.

Return type

dict

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

list

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:

  1. Get required quantities: get_required()

  2. Get transactions get_transactions():

    • for articles of required equipments;

    • for medicines of required molecules.

  3. Parse each molecule:

  1. Parse each equipment:

    • Create the equipment dictionary: create_equipment()

    • Add the available articles: get_available_articless()

  2. Create kits dictionaries:

Parameters
Returns

Dictionnary of First Aid Kits.

Return type

list(dict)

pharmaship.inventory.parsers.first_aid.subitem_nc(nc_string)

Return the non-conformities dict if any and flag if non-conformity.