public void save() {
        try{
            //saving new patient
            if(this.getId() == null){
                String query = "INSERT INTO patients (" +
                        "last_name," +
                        "middle_name," +
                        "first_name," +
                        "age," +
                        "gender," +
                        "birth_date," +
                        "code," +
                        "notes," +
                        "unknown, " +
                        "sp_categ, " +
                        "registration, " +
                        "registration_house, " +
                        "registration_apt, " +
                        "residence, " +
                        "residence_house, " +
                        "residence_apt, " +
                        "work_place," +
                        "snils" +
                        ")" +
                        "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                PreparedStatement st = this.getConnection().prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
                st.setString(1, this.lastName);
                st.setString(2, this.middleName);
                st.setString(3, this.firstName);
                st.setInt(4, this.age);
                st.setInt(5, this.gender);
                if(this.unknown){
                    st.setDate(6, new java.sql.Date(new Date().getTime()));
                    st.setBoolean(9, true);
                } else {
                    st.setDate(6, new java.sql.Date(this.birthDate.getTime()));
                    st.setBoolean(9, false);
                }
                st.setString(7, this.getCode());
                st.setString(8, this.notes);
                st.setInt(10, this.getCategory().getId());
                st.setString(11, this.getRegAddress().getCode());
                st.setString(12, this.getRegAddress().getHouse());
                st.setString(13, this.getRegAddress().getApt());
                st.setString(14, this.getResAddress().getCode());
                st.setString(15, this.getResAddress().getHouse());
                st.setString(16, this.getResAddress().getApt());
                st.setString(17, this.getWorkplace());
                st.setString(18, this.getSnils());

                st.executeUpdate();
                ResultSet rs = st.getGeneratedKeys();
                if(rs.next()){
                    this.setId(rs.getInt(1));
                    this.getPassport().setPatient(this);
                    this.getPassport().save();
                }
            } else {
                //updating existing patient
                String q = "SELECT patients.id," +
                        "patients.last_name," +
                        "patients.middle_name," +
                        "patients.first_name," +
                        "patients.age," +
                        "patients.gender," +
                        "patients.birth_date," +
                        "patients.snils," +
                        "patients.code," +
                        "patients.sp_categ," +
                        "patients.registration," +
                        "patients.registration_house," +
                        "patients.registration_apt," +
                        "patients.residence," +
                        "patients.residence_house," +
                        "patients.residence_apt," +
                        "patients.notes," +
                        "patients.unknown," +
                        "patients.work_place " +
                        "FROM patients " +
                        "WHERE patients.id = ?";
                PreparedStatement statement = Patient.getConnection().prepareStatement(q,
                        ResultSet.TYPE_FORWARD_ONLY,
                        ResultSet.CONCUR_UPDATABLE);
                statement.setInt(1, this.getId());
                ResultSet resultSet = statement.executeQuery();
                if(resultSet.next()){
                    resultSet.updateString("last_name", this.getLastName());
                    resultSet.updateString("middle_name", this.getMiddleName());
                    resultSet.updateString("first_name", this.getFirstName());
                    resultSet.updateInt("age", this.getAge());
                    resultSet.updateInt("gender", this.getGender());
                    resultSet.updateDate("birth_date", new java.sql.Date(this.getBirthDate().getTime()));
                    resultSet.updateString("snils", this.getSnils());
                    resultSet.updateString("code", this.getCode());
                    resultSet.updateInt("sp_categ", this.getCategory().getId());
                    resultSet.updateString("registration", this.getRegAddress().getCode());
                    resultSet.updateString("registration_house", this.getRegAddress().getHouse());
                    resultSet.updateString("registration_apt", this.getRegAddress().getApt());
                    resultSet.updateString("residence", this.getResAddress().getCode());
                    resultSet.updateString("residence_house", this.getResAddress().getHouse());
                    resultSet.updateString("residence_apt", this.getResAddress().getApt());
                    resultSet.updateString("notes", this.getNotes());
                    resultSet.updateBoolean("unknown", this.getUnknown());
                    resultSet.updateString("work_place", this.getWorkplace());
                    resultSet.updateRow();
                }
                if(this.getPassport() != null){
                    this.getPassport().save();
                }
                if(this.getPolicy() != null){
                    this.getPolicy().save();
                }

            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }

    }