Class MedicationInventoryDB

java.lang.Object
sc2002.repositories.MedicationInventoryDB

public class MedicationInventoryDB extends Object
The MedicationInventoryDB class provides methods for managing medication inventory, including retrieving, adding, removing, updating stock levels, and setting low stock alerts.
  • Constructor Details

    • MedicationInventoryDB

      public MedicationInventoryDB()
  • Method Details

    • getMedicationInventory

      public static List<MedicationInventory> getMedicationInventory() throws IOException
      Retrieves the list of all medications in the inventory.
      Returns:
      a list of MedicationInventory objects
      Throws:
      IOException - if an error occurs while reading the file
    • addMedication

      public static void addMedication(MedicationInventory newMedication) throws IOException
      Adds a new medication to the inventory.
      Parameters:
      newMedication - the MedicationInventory object to add
      Throws:
      IOException - if an error occurs while updating the file
    • removeMedication

      public static void removeMedication(String medicineName) throws IOException
      Removes a medication from the inventory based on the medicine name.
      Parameters:
      medicineName - the name of the medicine to remove
      Throws:
      IOException - if an error occurs while updating the file
    • updateStockLevel

      public static void updateStockLevel(String medicineName, int restockAmount) throws IOException
      Updates the stock level of a specified medication.
      Parameters:
      medicineName - the name of the medication
      restockAmount - the amount to add to the current stock
      Throws:
      IOException - if an error occurs while updating the file
    • updateLowAlert

      public static void updateLowAlert(String medicineName, int updatedLowLevelAlert) throws IOException
      Updates the low stock alert level of a specified medication.
      Parameters:
      medicineName - the name of the medication
      updatedLowLevelAlert - the new low stock level alert
      Throws:
      IOException - if an error occurs while updating the file
    • findMedicine

      public static int findMedicine(String medicine)
      Finds if a specific medication exists in the inventory.
      Parameters:
      medicine - the name of the medicine to find
      Returns:
      1 if the medicine is found, 0 otherwise
    • lowStockLevelAlert

      public static String lowStockLevelAlert() throws IOException
      Returns a list of medicines that have low stock levels.
      Returns:
      a comma-separated string of medicines with low stock or "NO" if none
      Throws:
      IOException - if an error occurs while reading the file