public void insertData(PatientIdentityType patientIdentityType) throws LIMSRuntimeException {
    try {

      if (duplicatePatientIdentityTypeExists(patientIdentityType)) {
        throw new LIMSDuplicateRecordException(
            "Duplicate record exists for " + patientIdentityType.getIdentityType());
      }

      String id = (String) HibernateUtil.getSession().save(patientIdentityType);
      patientIdentityType.setId(id);

      AuditTrailDAO auditDAO = new AuditTrailDAOImpl();
      auditDAO.saveNewHistory(
          patientIdentityType, patientIdentityType.getSysUserId(), "PATIENT_IDENTITY_TYPE");

      HibernateUtil.getSession().flush();
      HibernateUtil.getSession().clear();
    } catch (HibernateException e) {
      handleException(e, "insertData");
    } catch (LIMSDuplicateRecordException e) {
      handleException(e, "insertData");
    }
  }
  @SuppressWarnings("unchecked")
  private boolean duplicatePatientIdentityTypeExists(PatientIdentityType patientIdentityType)
      throws LIMSRuntimeException {
    try {
      String sql = "from PatientIdentityType t where upper(t.identityType) = :identityType";
      Query query = HibernateUtil.getSession().createQuery(sql);

      query.setString("identityType", patientIdentityType.getIdentityType().toUpperCase());

      List<PatientIdentityType> list = query.list();
      closeSession();

      return list.size() > 0;

    } catch (HibernateException e) {
      handleException(e, "duplicatePatientIdentityTypeExists");
    }

    return false;
  }