public void actionTreatments() {

    List<Treatment> treatments =
        Treatment.getToBeActioned(); // Get all Treatments yet to be processed

    for (Treatment treatment : treatments) {
      Long ageInMins = (new Date().getTime() - treatment.date_requested) / 1000 / 60;
      if (ageInMins > 10) { // Treatment was requested as > 10mins old, its too old to be processed
        treatment.state = "error";
        treatment.details = "Treatment is older than 10mins, too old to be automated";
        treatment.delivered = false;
        treatment.rejected = true;
        treatment.happ_update = true;
        treatment.save();

      } else {
        Boolean isPumpOnline =
            true; // TODO: 16/01/2016 this should be a function to check if the pump is online
        Boolean isPumpBusy =
            false; // TODO: 16/01/2016 this should be a function to check if the pump is busy, for
                   // example if delivering a treatment

        if (!isPumpOnline || isPumpBusy) { // Cannot use pump right now
          treatment.state = "delayed";
          treatment.details = "Pump online: " + isPumpOnline + " | Pump busy: " + isPumpBusy;
          treatment.delivered = false;
          treatment.happ_update = true;
          treatment.save();

        } else { // Pump is online and available to accept a treatment
          // TODO: 16/01/2016 a function should be here to action the treatment
          treatment.state = "delivered";
          treatment.details = "Treatment has been sent to the pump";
          treatment.delivered =
              true; // TODO: 16/01/2016 logic should be set to check that the treatment was
                    // successfully delivered before setting this to true
          treatment.happ_update = true;
          treatment.save();
        }
      }
    }
    if (treatments.size() > 0) {
      connect_to_HAPP();
      Intent intent = new Intent("UPDATE_TREATMENTS"); // sends result to update UI if loaded
      MainApp.instance().sendBroadcast(intent);
    }
  }