private void btnPatientRegisterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPatientRegisterActionPerformed
        String fullName = jFullName.getText();
        String dob = jDob.getText();
        String address = jAddress.getText();
        if (fullName.isEmpty() || dob.isEmpty() || address.isEmpty()) {
            JOptionPane.showMessageDialog(null, "Please fill up all fields.", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }

        String keyPath = System.getProperty("user.home") + File.separator + ".phr";
        File phrDir = new File(keyPath);
        if (!phrDir.exists()) {
            System.out.println("creating key directory: " + keyPath);
            phrDir.mkdirs();
        } else {
            System.out.println("Key directory exists: " + keyPath);
            System.out.println("Previous keys will be overwritten.");
        }

        Cpabe phr = new Cpabe();
        try {
            System.out.println("Generating master key and public parameters.");
            phr.setup(KeyConfig.getInstance().getPatientReadPublicKeyPath(), KeyConfig.getInstance().getPatientReadMasterKeyPath());
            phr.setup(KeyConfig.getInstance().getPatientWritePublicKeyPath(), KeyConfig.getInstance().getPatientWriteMasterKeyPath());

            String readMasterKeyChecksum = CryptoUtil.getFileChecksum(KeyConfig.getInstance().getPatientReadMasterKeyPath(), "SHA1");
            String writeMasterKeyChecksum = CryptoUtil.getFileChecksum(KeyConfig.getInstance().getPatientWriteMasterKeyPath(), "SHA1");

            DatabaseClient.getInstance().addPatient(fullName, dob, address, readMasterKeyChecksum, writeMasterKeyChecksum);
        } catch (Exception ex) {
            Logger.getLogger(PatientRegister.class.getName()).log(Level.SEVERE, null, ex);
            return;
        }
        // Also create a new user for patient
        DatabaseClient.getInstance().addUser(fullName, 0, "type:patient", "","");

        System.out.println("Patient registered successfully.)");

        JOptionPane.showMessageDialog(null, "You are successfully registered. Your keys are stored in following directory: "+phrDir+". Please login now using your keys", "Registration successful", JOptionPane.INFORMATION_MESSAGE);
        parent.nextPanel(Main.PATIENT_LOGIN);
        
//        int response = JOptionPane.showConfirmDialog(null, "You are registered now. Would you like to login now?", "Registration successful",
//                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
//        if (response == JOptionPane.NO_OPTION) {
//            System.out.println("No button clicked");
//        } else if (response == JOptionPane.YES_OPTION) {
//            System.out.println("Yes button clicked");
//
//        } else if (response == JOptionPane.CLOSED_OPTION) {
//            System.out.println("JOptionPane closed");
//        }
    }//GEN-LAST:event_btnPatientRegisterActionPerformed