/**
   * If you set a time scheme this method will set the DosisSchemes correlated to the timescheme's
   * timeschemetimes. The new DosisSchemes will be ordered by time ascending.
   *
   * @param timeScheme
   */
  public void setPrescriptionTimeScheme(TimeScheme timeScheme) {
    Prescription prescription = context.getPrescription();
    if (prescription.getDosisSchemes() != null) {
      for (DosisScheme d : prescription.getDosisSchemes()) {
        DosisScheme toDel =
            (DosisScheme) dosisSchemeRepo.getById(DosisScheme.class, d.getDosisSchemeId());
        dosisSchemeRepo.remove(toDel);
      }
      prescription.getDosisSchemes().clear();
    }

    prescription.setTimeScheme(timeScheme);
    List<TimeSchemeTime> timeSchemeTimes = timeScheme.getTimeSchemeTimes();
    Collections.sort(
        timeSchemeTimes,
        new Comparator<TimeSchemeTime>() {
          @Override
          public int compare(TimeSchemeTime o1, TimeSchemeTime o2) {
            return o1.getTimespan().compareTo(o2.getTimespan());
          }
        });

    if (prescription.getDosisSchemes() != null) {
      prescription.getDosisSchemes().clear();
    }
    for (TimeSchemeTime timeSchemeTime : timeSchemeTimes) {
      DosisScheme d = new DosisScheme();
      d.setPrescription(prescription);
      prescription.getDosisSchemes().add(d);
      d.setDosisSchemeName(timeSchemeTime.getTimeSchemeTimeName());
      d.setQuantityUnit(prescription.getMedicament().getQuantityUnit());
      d.setTime(timeSchemeTime.getTimespan());
      dosisSchemeRepo.persist(d);
    }
  }
 public Prescription getPrescription() {
   return context.getPrescription();
 }