USE `apotek-online`;

CREATE TABLE IF NOT EXISTS `barang_dpho` (
  `ID` int NOT NULL AUTO_INCREMENT,
  `DPHO` char(20) NOT NULL,
  `BARANG` int NOT NULL,
  `GROUP` int DEFAULT NULL,
  `STATUS` smallint DEFAULT '1',
  `INPUT_TIME` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `UPDATE_TIME` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `OLEH` int DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `DPHO` (`DPHO`),
  KEY `BARANG` (`BARANG`),
  KEY `STATUS` (`STATUS`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `dokter` (
  `kode` char(15) NOT NULL,
  `dokter_simrs` int DEFAULT NULL,
  `nama` char(250) DEFAULT NULL,
  `spesialistik` char(3) DEFAULT NULL,
  `status` smallint DEFAULT '1',
  `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`kode`),
  KEY `dokter_simrs` (`dokter_simrs`),
  KEY `status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `dpho` (
  `kodeobat` char(20) NOT NULL,
  `namaobat` text NOT NULL,
  `prb` smallint NOT NULL,
  `kronis` smallint NOT NULL,
  `kemo` smallint NOT NULL,
  `harga` decimal(10,2) NOT NULL DEFAULT '0.00',
  `restriksi` text NOT NULL,
  `generik` text NOT NULL,
  `status` smallint DEFAULT '1',
  `oleh` int DEFAULT NULL,
  `input_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`kodeobat`),
  KEY `status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `log_kirim_resep` (
  `ID` BIGINT(20) NOT NULL AUTO_INCREMENT,
  `TGLSJP` char(30) NOT NULL DEFAULT '0',
  `REFASALSJP` char(30) NOT NULL DEFAULT '0',
  `POLIRSP` char(30) NOT NULL DEFAULT '0',
  `KDJNSOBAT` char(30) NOT NULL DEFAULT '0',
  `KUNJUNGAN` char(30) NOT NULL DEFAULT '0',
  `NORESEP` char(30) NOT NULL DEFAULT '0' COMMENT 'No.Resep RS (Generate By RS)',
  `IDUSERSJP` char(30) NOT NULL DEFAULT '0',
  `TGLRSP` char(30) NOT NULL DEFAULT '0',
  `TGLPELRSP` char(30) NOT NULL DEFAULT '0',
  `KdDokter` char(30) NOT NULL DEFAULT '0',
  `iterasi` char(30) NOT NULL DEFAULT '0',
  `RESPONSE` longtext,
  `STATUS` smallint DEFAULT '0' COMMENT 'Status Kirim (1=Sukses,0=Gagal)',
  `NOSJP` char(50) DEFAULT '0',
  `INPUT_TIME` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `UPDATE_TIME` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`ID`),
  KEY `STATUS` (`STATUS`),
  KEY `NORESEP` (`NORESEP`),
  KEY `KUNJUNGAN` (`KUNJUNGAN`),
  KEY `REFASALSJP` (`REFASALSJP`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `log_kirim_resep_detil` (
  `ID` BIGINT(20) NOT NULL AUTO_INCREMENT,
  `KUNJUNGAN` char(20) NOT NULL COMMENT 'No.Kunjungan',
  `REF_FARMASI` char(30) NOT NULL COMMENT 'ID Farmasi',
  `JNSROBT` char(30) DEFAULT NULL COMMENT 'Jenis Obat (Jika Resep Racikan)',
  `KDOBT` char(30) DEFAULT NULL COMMENT 'Kode DPHO',
  `SIGNA1OBT` int DEFAULT NULL,
  `SIGNA2OBT` int DEFAULT NULL,
  `PERMINTAAN` int DEFAULT NULL,
  `JMLOBT` int DEFAULT NULL,
  `JHO` int DEFAULT NULL,
  `CatKhsObt` char(75) DEFAULT NULL,
  `RESPONSE` longtext,
  `STATUS` smallint DEFAULT '0' COMMENT 'Status Kirim (1=Sukses,0=Gagal)',
  `INPUT_TIME` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `UPDATE_TIME` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`ID`),
  KEY `NOSJP` (`REF_FARMASI`),
  KEY `KDOBT` (`KDOBT`),
  KEY `STATUS` (`STATUS`),
  KEY `KUNJUNGAN` (`KUNJUNGAN`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `no_resep` (
  `SEP` char(50) NOT NULL,
  `KUNJUNGAN` char(19) NOT NULL,
  `NOMOR` smallint NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`SEP`,`NOMOR`),
  UNIQUE KEY `NO_RESEP` (`KUNJUNGAN`),
  KEY `KUNJUNGAN` (`KUNJUNGAN`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `spesialistik` (
  `kode` char(10) NOT NULL,
  `nama` char(150) NOT NULL,
  `input_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`kode`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;