IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'PISReceivedPrescription')
BEGIN
CREATE TABLE [dbo].[PISReceivedPrescription](
	[Id] [UNIQUEIDENTIFIER] NOT NULL,
	[HID] [VARCHAR](50) NOT NULL,
	[Status] [TINYINT] NULL,
	[AdmissionDate] [DATETIME] NULL,
	[AdmissionTypeCode] [VARCHAR](10) NULL,
	[InsurerCode] [VARCHAR](10) NULL,
	[InsurerName] [NVARCHAR](MAX) NULL,
	[InsuranceBoxCode] [VARCHAR](10) NULL,
	[InsuranceBoxName] [NVARCHAR](MAX) NULL,
	[InsuranceExpirationDate] [DATETIME] NULL,
	[InsuredNumber] [VARCHAR](50) NULL,
	[NationalCode] [VARCHAR](10) NULL,
	[FirstName] [NVARCHAR](100) NULL,
	[LastName] [NVARCHAR](100) NULL,
	[FatherName] [NVARCHAR](100) NULL,
	[BirthDate] [DATETIME] NULL,
	[GenderCode] [TINYINT] NULL,
	[HomeTel] [VARCHAR](20) NULL,
	[MobileNumber] [VARCHAR](11) NULL,
	[IDCardNumber] [VARCHAR](10) NULL,
	[IssueDate] [DATETIME] NULL,
	[PrescriptionExpiryDate] [DATETIME] NULL,
	[MedicalId] [VARCHAR](10) NULL,
	[MedicalFirstName] [NVARCHAR](100) NULL,
	[MedicalLastName] [NVARCHAR](100) NULL,
	[MedicalRecordNumber] [VARCHAR](20) NULL,
	[Repeats] [SMALLINT] NULL,
	[EducationLevelCode] [VARCHAR](10) NULL,
	[PostalCode] [VARCHAR](10) NULL,
	[FullAddress] [NVARCHAR](MAX) NULL,
	[JobCode] [VARCHAR](10) NULL,
	[NationalityCode] [VARCHAR](10) NULL,
	[MaritalStatusCode] [VARCHAR](10) NULL,
	[ErrorMessage] [NVARCHAR](MAX) NULL,
	[PreviousSenderId] [UNIQUEIDENTIFIER] NULL,
	[CreatedBy] [SMALLINT] NULL,
	[CreatedOn] [DATETIME] NULL,
 CONSTRAINT [PK_PISPrescription] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)
) ON [PRIMARY] 

ALTER TABLE [dbo].[PISReceivedPrescription] ADD  CONSTRAINT [DF_PISPrescription_Id]  DEFAULT (NEWID()) FOR [Id]
ALTER TABLE [dbo].[PISReceivedPrescription] ADD  CONSTRAINT [DF_PISPrescription_Status]  DEFAULT ((0)) FOR [Status]
ALTER TABLE [dbo].[PISReceivedPrescription] ADD  CONSTRAINT [DF_PISPrescription_CratedOn]  DEFAULT (GETDATE()) FOR [CreatedOn]
END

