public Patient(Integer id){
        if(id != null){
            this.setId(id);
            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," +
                    "documents.id as doc_id," +
                    "documents.type," +
                    "documents.series," +
                    "documents.number," +
                    "documents.date_i," +
                    "documents.date_e," +
                    "documents.active," +
                    "documents.notes as doc_notes," +
                    "sp_categ.name as cat_name," +
                    "sp_categ.id as cat_id " +
                    "FROM patients " +
                    "LEFT JOIN documents ON documents.patient = patients.id " +
                    "LEFT JOIN sp_categ ON sp_categ.id = patients.sp_categ " +
                    "WHERE patients.id = ?";
            try {
                PreparedStatement statement = Patient.getConnection().prepareStatement(q);
                statement.setInt(1, this.getId());
                ResultSet resultSet = statement.executeQuery();
                if(resultSet.next()){
                    this.setGender(Patient.getGenderString(resultSet.getInt("gender")));
                    this.setFirstName(resultSet.getString("first_name"));
                    this.setMiddleName(resultSet.getString("middle_name"));
                    this.setLastName(resultSet.getString("last_name"));
                    this.setAge(resultSet.getInt("age"));
                    this.setBirthDate(resultSet.getDate("birth_date"));
                    this.setUnknown(resultSet.getBoolean("unknown"));
                    this.setNotes(resultSet.getString("notes"));
                    this.setSnils(resultSet.getString("snils"));
                    this.setCategory(new Category(resultSet.getString("cat_name"),
                            resultSet.getInt("cat_id")));
                    this.setWorkplace(resultSet.getString("work_place"));
                    this.setRegAddress(new Address(resultSet.getString("registration"),
                            resultSet.getString("registration_house"),
                            resultSet.getString("registration_apt")));
                    this.setResAddress(new Address(resultSet.getString("residence"),
                            resultSet.getString("residence_house"),
                            resultSet.getString("residence_apt")));
                    //setting documents
                    if(resultSet.getInt("type") == Passport.getType()){
                        //this is passport
                        Passport p = new Passport(resultSet.getString("series"),
                                resultSet.getString("number"));
                        p.setActive(resultSet.getBoolean("active"));
                        p.setId(resultSet.getInt("doc_id"));
                        p.setIssueDate(resultSet.getDate("date_i"));
                        p.setNotes(resultSet.getString("doc_notes"));
                        p.setPatient(this);
                        this.setPassport(p);
                    } else if(resultSet.getInt("type") == Policy.getType()){
                       //this is policy
                        Policy p = new Policy(resultSet.getString("series"),
                                resultSet.getString("number"));
                        p.setActive(resultSet.getBoolean("active"));
                        p.setExpiryDate(resultSet.getDate("date_e"));
                        p.setId(resultSet.getInt("doc_id"));
                        p.setIssueDate(resultSet.getDate("date_i"));
                        p.setNotes(resultSet.getString("doc_notes"));
                        p.setPatient(this);
                        this.setPolicy(p);
                    }
                }
                if(resultSet.next()){
                    if(resultSet.getInt("type") == Passport.getType()){
                        //this is passport
                        Passport p = new Passport(resultSet.getString("series"),
                                resultSet.getString("number"));
                        p.setActive(resultSet.getBoolean("active"));
                        p.setId(resultSet.getInt("doc_id"));
                        p.setIssueDate(resultSet.getDate("date_i"));
                        p.setNotes(resultSet.getString("doc_notes"));
                        p.setPatient(this);
                        this.setPassport(p);
                    } else {
                        //this is policy
                        Policy p = new Policy(resultSet.getString("series"),
                                resultSet.getString("number"));
                        p.setActive(resultSet.getBoolean("active"));
                        p.setExpiryDate(resultSet.getDate("date_e"));
                        p.setId(resultSet.getInt("doc_id"));
                        p.setIssueDate(resultSet.getDate("date_i"));
                        p.setNotes(resultSet.getString("doc_notes"));
                        p.setPatient(this);
                        this.setPolicy(p);
                    }
                }
            } catch (SQLException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }
    }