@SuppressWarnings("unchecked")
  @Transactional
  public Clinic findByClinicName(String clinicname) {
    logger.debug("findByClinicName start " + clinicname);
    Clinic c = null;
    Session session = this.getSession();

    List<Clinic> list =
        session
            .createQuery("from Clinic where name=:clinicname")
            .setParameter("clinicname", clinicname)
            .list();

    if (list.size() > 0) {
      logger.debug("Clinic List > 0 ");
      c = list.get(0);
      logger.debug("Clinic found : " + c.getName());
    }
    logger.debug("findByClinicName end ");
    return c;
  }
  @SuppressWarnings("unchecked")
  @Transactional
  public void AddTestToClinic(String clinicname, ClinicTest t) {
    logger.debug("AddTestToClinic start " + clinicname);
    Clinic c = null;
    Session session = this.getSession();

    List<Clinic> list =
        session
            .createQuery("from Clinic where name=:clinicname")
            .setParameter("clinicname", clinicname)
            .list();

    if (list.size() > 0) {
      logger.debug("Clinic List > 0 ");

      c = list.get(0);
      logger.debug("Clinic found : " + c.getName());
      c.getTests().add(t);
      t.setClinic(c);
      session.saveOrUpdate(c);
    }
    logger.debug("AddTestToClinic end ");
  }
  private ClinicTest findClinicTestByNameForClinic(Session session, Clinic clinic, String testName)
      throws Exception {
    ClinicTest test = null;
    for (ClinicTest t : clinic.getTests()) {
      if (t.getTest_name().equals(testName)) {
        test = t;
        break;
      }
    }

    if (test == null) {
      logger.debug("Not Found : " + testName);
      throw new Exception("Not Found : " + testName);
    }
    return test;
  }
  @SuppressWarnings("unchecked")
  @Transactional
  public List<ClinicModel> getPharmacy(String speciality, String location) {
    logger.debug("getPharmacy start");
    List<ClinicModel> list = new ArrayList<ClinicModel>();
    Session session = this.getSession();
    List<Clinic> clinics =
        session
            .createQuery("from Clinic where type=:paramType")
            .setParameter("paramType", "pharmacy")
            .list();
    for (Clinic c : clinics) {
      logger.debug(c.getName() + " " + c.getSpecialities() + " " + c.getAddresses());
      boolean specialityMatch = false;
      if (c.getSpecialities() != null) {
        for (String spec : c.getSpecialities().split(",")) {
          logger.debug(spec);
          if (spec.toLowerCase().equals(speciality.toLowerCase())) {
            specialityMatch = true;
            break;
          }
        }
      }
      logger.debug("Speciality Match : " + specialityMatch);
      if (!specialityMatch) continue;
      boolean addressMatch = false;
      for (ClinicAddress addr : c.getAddresses()) {
        if (addr.getCity().toLowerCase().equals(location.toLowerCase())) {
          addressMatch = true;
          break;
        }
      }
      logger.debug("addressMatch Match : " + addressMatch);
      if (!addressMatch) continue;
      ClinicModel model = new ClinicModel();
      model.setClinicName(c.getName());
      model.setClinicDesc(c.getDescription());

      model.setClinicAddress(c.getAddresses().toString());
      model.setClinicPhones(c.getPhoneNos().toString());
      list.add(model);
    }
    logger.debug("getPharmacy end");
    return list;
  }