package com.jasamedika.medifirst2000.entities;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.jasamedika.medifirst2000.base.BaseMaster;
import com.jasamedika.medifirst2000.helper.Caption;
import com.jasamedika.medifirst2000.listener.MyEventListener;
import com.jasamedika.medifirst2000.util.Age;
import com.jasamedika.medifirst2000.util.AgeCalculator;

@Entity
@EntityListeners(value = { MyEventListener.class })
@Table(name = "Pasien_M")
public class Pasien extends BaseMaster {

	private static final long serialVersionUID = -7771356073340836706L;

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "public.pasien_m_id_seq")
	@SequenceGenerator(name = "public.pasien_m_id_seq", sequenceName = "public.pasien_m_id_seq", allocationSize = 1)
	@Column(name = "id")
	protected Integer id;

	@Transient
	private String umur;

	@Column(name = "TglMeninggal", nullable = true)
	@Caption(value = "Tanggal Meninggal")
	private Date tanggalMeninggal;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "DokumenRekamMedis")
	@Caption(value = "DokumenRekamMedis")
	private Dokumen dokumenRekamMedis;

	@Column(name = "DokumenRekamMedis", insertable = false, updatable = false, nullable = true)
	private Integer dokumenRekamMedisId;

	@ManyToOne
	@JoinColumn(name = "ObjectAgamaFk")
	@Caption(value = "Object Agama")
	private Agama agama;

	@Column(name = "ObjectAgamaFk", insertable = false, updatable = false)
	private Integer agamaId;

	@ManyToOne
	@JoinColumn(name = "ObjectGolonganDarahFk")
	@Caption(value = "Object Golongan Darah")
	private GolonganDarah golonganDarah;

	@Column(name = "ObjectGolonganDarahFk", insertable = false, updatable = false)
	private Integer golonganDarahId;

	@ManyToOne
	@JoinColumn(name = "ObjectJenisKelaminFk")
	@Caption(value = "Object Jenis Kelamin")
	private JenisKelamin jenisKelamin;

	@Column(name = "ObjectJenisKelaminFk", insertable = false, updatable = false)
	private Integer jenisKelaminId;

	@ManyToOne
	@JoinColumn(name = "ObjectPekerjaanFk")
	@Caption(value = "Object Pekerjaan")
	private Pekerjaan pekerjaan;

	@Column(name = "ObjectPekerjaanFk", insertable = false, updatable = false)
	private Integer pekerjaanId;

	@ManyToOne
	@JoinColumn(name = "ObjectNegaraFk")
	@Caption(value = "Object Negara")
	private Negara negara;

	@Column(name = "ObjectNegaraFk", insertable = false, updatable = false, nullable = true)
	private Integer negaraId;

	@ManyToOne
	@JoinColumn(name = "ObjectKebangsaanFk")
	@Caption(value = "Object kebangsaan")
	private Kebangsaan kebangsaan;

	@Column(name = "ObjectKebangsaanFk", insertable = false, updatable = false, nullable = true)
	private Integer kebangsaanId;

	@ManyToOne
	@JoinColumn(name = "ObjectPendidikanFk")
	@Caption(value = "Object Pendidikan")
	private Pendidikan pendidikan;

	@Column(name = "ObjectPendidikanFk", insertable = false, updatable = false, nullable = false)
	private Integer pendidikanId;

	@ManyToOne
	@JoinColumn(name = "ObjectStatusPerkawinanFk")
	@Caption(value = "Object Status Perkawinan")
	private StatusPerkawinan statusPerkawinan;

	@Column(name = "ObjectStatusPerkawinanFk", insertable = false, updatable = false, nullable = false)
	private Integer statusPerkawinanId;

	@ManyToOne
	@JoinColumn(name = "ObjectTitleFk")
	@Caption(value = "Object Title")
	private TitlePasien titlePasien;

	@Column(name = "ObjectTitleFk", insertable = false, updatable = false)
	private Integer titlePasienId;

	@NotNull(message = "Nama Pasien tidak boleh kosong")
	@Column(name = "NamaPasien", nullable = false, length = 40)
	@Caption(value = "Nama Pasien")
	private String namaPasien;

	@Column(name = "NamaIbu", nullable = true, length = 40)
	@Caption(value = "Nama Ibu")
	private String namaIbu;

	@Column(name = "NamaAyah", nullable = true, length = 40)
	@Caption(value = "Nama Ayah")
	private String namaAyah;

	@Column(name = "namaKeluarga", nullable = true, length = 40)
	@Caption(value = "namaKeluarga")
	private String namaKeluarga;

	@Column(name = "NamaSuamiIstri", nullable = true, length = 40)
	@Caption(value = "Nama Suami/Istri")
	private String namaSuamiIstri;

	@Column(name = "NoTelepon", nullable = true, length = 40)
	@Caption(value = "No Telepon")
	private String noTelepon;

	@Generated(GenerationTime.INSERT)
	@Column(name = "noCm")
	@Caption(value = "No C M")
	private String noCm;

	@Column(name = "QPasien", nullable = true)
	@Caption(value = "QPasien")
	private Integer qPasien;

	@NotNull(message = "Tgl Daftar tidak boleh kosong")
	@Column(name = "TglDaftar", nullable = false)
	@Caption(value = "Tanggal Daftar")
	private Date tglDaftar;

	@Column(name = "TglLahir", nullable = true)
	@Caption(value = "Tanggal Lahir")
	private Date tglLahir;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "pasien")
	private Set<Alamat> alamats = new HashSet<Alamat>();

	@JsonBackReference
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "pasien")
	private Set<CatatanPasien> catatanPasien = new HashSet<CatatanPasien>();

	@JsonBackReference
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "pasien")
	private Set<AntrianPasienRegistrasi> antrianPasienRegistrasis = new HashSet<AntrianPasienRegistrasi>();

	@Column(name = "noIdentitas")
	@Caption(value = "NoIdentitas")
	private String noIdentitas;

	@Column(name = "Paspor", nullable = true)
	@Caption(value = "Paspor")
	private String paspor;

	@Column(name = "NoAditional", nullable = true)
	@Caption(value = "noAditional")
	private String noAditional;

	@Column(name = "namaDepan", nullable = true)
	@Caption(value = "namaDepan")
	private String namaDepan;

	@Column(name = "namaBelakang", nullable = true)
	@Caption(value = "namaBelakang")
	private String namaBelakang;

	@Column(name = "TempatLahir", nullable = true)
	@Caption(value = "Tempat Lahir")
	private String tempatLahir;

	@Column(name = "NoBpjs", nullable = true)
	@Caption(value = "No Bpjs")
	private String noBpjs;

	@Column(name = "NoAsuransiLain", nullable = true)
	@Caption(value = "No AsuransiLain")
	private String noAsuransiLain;

	@Column(name = "NoHp", nullable = true)
	@Caption(value = "No Hp")
	private String noHp;

	@Column(name = "JamLahir", nullable = true)
	@Caption(value = "JamLahir")
	private Date jamLahir;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Date getTglLahir() {
		// Age age = AgeCalculator.calculateAge(tglLahir);
		// this.umur = age.toString();
		return tglLahir;
	}

	public void setTglLahir(Date tglLahir) {
		this.tglLahir = tglLahir;
		Age age = AgeCalculator.calculateAge(tglLahir);
		this.umur = age.toString();
	}

	public String getUmur() {
		return umur;
	}

	public void setUmur(String umur) {
		this.umur = umur;
	}

	public Date getTanggalMeninggal() {
		return tanggalMeninggal;
	}

	public void setTanggalMeninggal(Date tanggalMeninggal) {
		this.tanggalMeninggal = tanggalMeninggal;
	}

	public Dokumen getDokumenRekamMedis() {
		return dokumenRekamMedis;
	}

	public void setDokumenRekamMedis(Dokumen dokumenRekamMedis) {
		this.dokumenRekamMedis = dokumenRekamMedis;
	}

	public Integer getDokumenRekamMedisId() {
		return dokumenRekamMedisId;
	}

	public void setDokumenRekamMedisId(Integer dokumenRekamMedisId) {
		this.dokumenRekamMedisId = dokumenRekamMedisId;
	}

	public Agama getAgama() {
		return agama;
	}

	public void setAgama(Agama agama) {
		this.agama = agama;
	}

	public Integer getAgamaId() {
		return agamaId;
	}

	public void setAgamaId(Integer agamaId) {
		this.agamaId = agamaId;
	}

	public GolonganDarah getGolonganDarah() {
		return golonganDarah;
	}

	public void setGolonganDarah(GolonganDarah golonganDarah) {
		this.golonganDarah = golonganDarah;
	}

	public Integer getGolonganDarahId() {
		return golonganDarahId;
	}

	public void setGolonganDarahId(Integer golonganDarahId) {
		this.golonganDarahId = golonganDarahId;
	}

	public JenisKelamin getJenisKelamin() {
		return jenisKelamin;
	}

	public void setJenisKelamin(JenisKelamin jenisKelamin) {
		this.jenisKelamin = jenisKelamin;
	}

	public Integer getJenisKelaminId() {
		return jenisKelaminId;
	}

	public void setJenisKelaminId(Integer jenisKelaminId) {
		this.jenisKelaminId = jenisKelaminId;
	}

	public Pekerjaan getPekerjaan() {
		return pekerjaan;
	}

	public void setPekerjaan(Pekerjaan pekerjaan) {
		this.pekerjaan = pekerjaan;
	}

	public Integer getPekerjaanId() {
		return pekerjaanId;
	}

	public void setPekerjaanId(Integer pekerjaanId) {
		this.pekerjaanId = pekerjaanId;
	}

	public Negara getNegara() {
		return negara;
	}

	public void setNegara(Negara negara) {
		this.negara = negara;
	}

	public Integer getNegaraId() {
		return negaraId;
	}

	public void setNegaraId(Integer negaraId) {
		this.negaraId = negaraId;
	}

	public Kebangsaan getKebangsaan() {
		return kebangsaan;
	}

	public void setKebangsaan(Kebangsaan kebangsaan) {
		this.kebangsaan = kebangsaan;
	}

	public Integer getKebangsaanId() {
		return kebangsaanId;
	}

	public void setKebangsaanId(Integer kebangsaanId) {
		this.kebangsaanId = kebangsaanId;
	}

	public Pendidikan getPendidikan() {
		return pendidikan;
	}

	public void setPendidikan(Pendidikan pendidikan) {
		this.pendidikan = pendidikan;
	}

	public Integer getPendidikanId() {
		return pendidikanId;
	}

	public void setPendidikanId(Integer pendidikanId) {
		this.pendidikanId = pendidikanId;
	}

	public StatusPerkawinan getStatusPerkawinan() {
		return statusPerkawinan;
	}

	public void setStatusPerkawinan(StatusPerkawinan statusPerkawinan) {
		this.statusPerkawinan = statusPerkawinan;
	}

	public Integer getStatusPerkawinanId() {
		return statusPerkawinanId;
	}

	public void setStatusPerkawinanId(Integer statusPerkawinanId) {
		this.statusPerkawinanId = statusPerkawinanId;
	}

	public TitlePasien getTitlePasien() {
		return titlePasien;
	}

	public void setTitlePasien(TitlePasien titlePasien) {
		this.titlePasien = titlePasien;
	}

	public Integer getTitlePasienId() {
		return titlePasienId;
	}

	public void setTitlePasienId(Integer titlePasienId) {
		this.titlePasienId = titlePasienId;
	}

	public String getNamaPasien() {
		return namaPasien;
	}

	public void setNamaPasien(String namaPasien) {
		this.namaPasien = namaPasien;
	}

	public String getNamaIbu() {
		return namaIbu;
	}

	public void setNamaIbu(String namaIbu) {
		this.namaIbu = namaIbu;
	}

	public String getNoTelepon() {
		return noTelepon;
	}

	public void setNoTelepon(String noTelepon) {
		this.noTelepon = noTelepon;
	}

	public String getNoCm() {
		return noCm;
	}

	public void setNoCm(String noCm) {
		this.noCm = noCm;
	}

	public Integer getqPasien() {
		return qPasien;
	}

	public void setqPasien(Integer qPasien) {
		this.qPasien = qPasien;
	}

	public Date getTglDaftar() {
		return tglDaftar;
	}

	public void setTglDaftar(Date tglDaftar) {
		this.tglDaftar = tglDaftar;
	}

	public Set<Alamat> getAlamats() {
		return alamats;
	}

	public void setAlamats(Set<Alamat> alamats) {
		this.alamats = alamats;
	}

	public Set<CatatanPasien> getCatatanPasien() {
		return catatanPasien;
	}

	public void setCatatanPasien(Set<CatatanPasien> catatanPasien) {
		this.catatanPasien = catatanPasien;
	}

	public Set<AntrianPasienRegistrasi> getAntrianPasienRegistrasis() {
		return antrianPasienRegistrasis;
	}

	public void setAntrianPasienRegistrasis(Set<AntrianPasienRegistrasi> antrianPasienRegistrasis) {
		this.antrianPasienRegistrasis = antrianPasienRegistrasis;
	}

	public String getNoIdentitas() {
		return noIdentitas;
	}

	public void setNoIdentitas(String noIdentitas) {
		this.noIdentitas = noIdentitas;
	}

	public String getPaspor() {
		return paspor;
	}

	public void setPaspor(String paspor) {
		this.paspor = paspor;
	}

	public String getNoAditional() {
		return noAditional;
	}

	public void setNoAditional(String noAditional) {
		this.noAditional = noAditional;
	}

	public String getNamaDepan() {
		return namaDepan;
	}

	public void setNamaDepan(String namaDepan) {
		this.namaDepan = namaDepan;
	}

	public String getNamaBelakang() {
		return namaBelakang;
	}

	public void setNamaBelakang(String namaBelakang) {
		this.namaBelakang = namaBelakang;
	}

	public String getTempatLahir() {
		return tempatLahir;
	}

	public void setTempatLahir(String tempatLahir) {
		this.tempatLahir = tempatLahir;
	}

	public String getNoBpjs() {
		return noBpjs;
	}

	public void setNoBpjs(String noBpjs) {
		this.noBpjs = noBpjs;
	}

	public String getNoAsuransiLain() {
		return noAsuransiLain;
	}

	public void setNoAsuransiLain(String noAsuransiLain) {
		this.noAsuransiLain = noAsuransiLain;
	}

	public String getNoHp() {
		return noHp;
	}

	public void setNoHp(String noHp) {
		this.noHp = noHp;
	}

	public String getNamaAyah() {
		return namaAyah;
	}

	public void setNamaAyah(String namaAyah) {
		this.namaAyah = namaAyah;
	}

	public String getNamaSuamiIstri() {
		return namaSuamiIstri;
	}

	public void setNamaSuamiIstri(String namaSuamiIstri) {
		this.namaSuamiIstri = namaSuamiIstri;
	}

	public Date getJamLahir() {
		return jamLahir;
	}

	public void setJamLahir(Date jamLahir) {
		this.jamLahir = jamLahir;
	}

	public String getNamaKeluarga() {
		return namaKeluarga;
	}

	public void setNamaKeluarga(String namaKeluarga) {
		this.namaKeluarga = namaKeluarga;
	}
}
