USE [master]
GO
/****** Object:  Database [pacsdbname]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE DATABASE [pacsdbname]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'pacsdbname', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\pacsdbname.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'pacsdbname_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\pacsdbname_log.ldf' , SIZE = 3840KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [pacsdbname] SET COMPATIBILITY_LEVEL = 100
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [pacsdbname].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [pacsdbname] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [pacsdbname] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [pacsdbname] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [pacsdbname] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [pacsdbname] SET ARITHABORT OFF 
GO
ALTER DATABASE [pacsdbname] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [pacsdbname] SET AUTO_CREATE_STATISTICS ON 
GO
ALTER DATABASE [pacsdbname] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [pacsdbname] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [pacsdbname] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [pacsdbname] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [pacsdbname] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [pacsdbname] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [pacsdbname] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [pacsdbname] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [pacsdbname] SET  DISABLE_BROKER 
GO
ALTER DATABASE [pacsdbname] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [pacsdbname] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [pacsdbname] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [pacsdbname] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [pacsdbname] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [pacsdbname] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [pacsdbname] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [pacsdbname] SET RECOVERY FULL 
GO
ALTER DATABASE [pacsdbname] SET  MULTI_USER 
GO
ALTER DATABASE [pacsdbname] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [pacsdbname] SET DB_CHAINING OFF 
GO
ALTER DATABASE [pacsdbname] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO
ALTER DATABASE [pacsdbname] SET TARGET_RECOVERY_TIME = 0 SECONDS 
GO
EXEC sys.sp_db_vardecimal_storage_format N'pacsdbname', N'ON'
GO
USE [pacsdbname]
GO
/****** Object:  StoredProcedure [dbo].[sp_Create_CaseStudy]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_Create_CaseStudy] 
	@Description nvarchar(2000),
	@Bodypart nvarchar(200),
	@DicomId [nvarchar](100),
	@KTVId [int],
	@PatientId [int],
	@StationId [int],
	@WorklistId [int],
	@AccessionNo nvarchar(255),
	@HISVisitId nvarchar(50),
	-- Add the parameters for the stored procedure here
	@StudyId int OUTPUT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	--DECLARE @StudyId int;
	SET NOCOUNT ON;
	BEGIN TRY
		BEGIN TRANSACTION 
			SET @StudyId = (SELECT TOP 1 Id FROM [dbo].[CaseStudy] WHERE [DicomId] = @DicomId);
			IF (@StudyId IS NULL)
			BEGIN
				INSERT [dbo].[CaseStudy]
				(
					[Description],
					[Bodypart],
					[DicomId],
					[KTVId],
					[PatientId],
					[StationId],
					[WorklistId],
					[AccessionNo],
					[HISVisitId],
					[SeriesCount],
					[ImageCount],
					[DoctorId],
					[Status],
					[DateScanned],
					[UnMatched],
					[StudyType]
				)
				VALUES (
					@Description,
					@Bodypart,
					@DicomId,
					@KTVId,
					@PatientId,
					@StationId,
					@WorklistId,
					@AccessionNo,
					@HISVisitId,
					0,
					0,
					0,
					20,
					GETDATE(),
					1,
					0
				);

				SET @StudyId = SCOPE_IDENTITY();
			END
		COMMIT
	END TRY
	BEGIN CATCH
		SET @StudyId = -1;
		IF @@TRANCOUNT > 0
			ROLLBACK
	END CATCH
END




GO
/****** Object:  StoredProcedure [dbo].[sp_Create_CaseStudy_Full]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_Create_CaseStudy_Full] 
	@Description nvarchar(2000),
	@Bodypart nvarchar(200),
	@DicomId [nvarchar](100),
	@KTVId [int],
	@PatientId [int],
	@StationId [int],
	@WorklistId [int],
	@AccessionNo nvarchar(255),
	@HISVisitId nvarchar(50),
	@DateScanned	datetime,
	@Uploaded	bit,
	@Modality	nvarchar(50),
	@ChanDoan	nvarchar(4000),
	@StationName	nvarchar(50),
	@UploadUserId int = 0,
	-- Add the parameters for the stored procedure here
	@StudyId int OUTPUT,
	@NewStudyCreated bit OUTPUT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	--DECLARE @StudyId int;
	SET NOCOUNT ON;
	BEGIN TRY
		BEGIN TRANSACTION 
			SET @StudyId = (SELECT TOP 1 Id FROM [dbo].[CaseStudy] WHERE [DicomId] = @DicomId);
			IF (@StudyId IS NULL)
			BEGIN
				INSERT [dbo].[CaseStudy]
				(
					[Description],
					[Bodypart],
					[DicomId],
					[KTVId],
					[PatientId],
					[StationId],
					[WorklistId],
					[AccessionNo],
					[HISVisitId],
					[SeriesCount],
					[ImageCount],
					[DoctorId],
					[Status],
					[DateScanned],
					[UnMatched],
					[Uploaded],
					[Modality],
					[ChanDoan],
					[StationName],
					[DateUploaded],
					[StudyType],
					[Uploading],
					[UploadUserId]
				)
				VALUES (
					@Description,
					@Bodypart,
					@DicomId,
					@KTVId,
					@PatientId,
					@StationId,
					@WorklistId,
					@AccessionNo,
					@HISVisitId,
					0,
					0,
					0,
					20,
					@DateScanned,
					1,
					@Uploaded,
					@Modality,
					@ChanDoan,
					@StationName,
					GETDATE(),
					0,
					1,
					@UploadUserId
				);
				
				SET @StudyId = SCOPE_IDENTITY();
				SET @NewStudyCreated = 1;
			END
			ELSE
			BEGIN
				SET @NewStudyCreated = 0;
			END
		COMMIT
	END TRY
	BEGIN CATCH
		SET @StudyId = -1;
		SET @NewStudyCreated = 0;
		IF @@TRANCOUNT > 0
			ROLLBACK
	END CATCH
END

/* Thêm config trong web.config:
 * - Thêm <binding name="AuthLocalServiceSoap" /> trong <basicHttpBinding> trong <bindings> trong <system.serviceModel>
 * - Thêm <endpoint address="http://pacsteledemo.stc.vn/WS/AuthLocalService.asmx"
        binding="basicHttpBinding" bindingConfiguration="AuthLocalServiceSoap"
        contract="TeleAuthService.AuthLocalServiceSoap" name="AuthLocalServiceSoap" /> trong <client> trong <system.serviceModel>
 * - Với các site PACS local, giá trị endpoint address phải trỏ đến service của PACS Tele
 * - Với site PACS Tele, giữ nguyên như trên
 */

/* Thêm config trong web.config:
 * - Thêm <add key="EnableGetHISOrderByPatient" value="false" />
 * - Giá trị  true với site kết nối HIS và có service lấy ds chỉ định theo bệnh nhân. Hiện tại có HIS MinhLo đã support service
 */
 



GO
/****** Object:  StoredProcedure [dbo].[sp_Create_Series]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_Create_Series] 
	@Description nvarchar(100),
	@DicomId nvarchar(100),
	@StudyId int,
	-- Add the parameters for the stored procedure here
	@SeriesId int OUTPUT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	--DECLARE @StudyId int;
	SET NOCOUNT ON;
	BEGIN TRY
		BEGIN TRANSACTION 
			SET @SeriesId = (SELECT TOP 1 Id FROM [dbo].[Series] WHERE [DicomId] = @DicomId);
			IF (@SeriesId IS NULL)
			BEGIN
				INSERT [dbo].[Series]
				(
					[Description],
					[DicomId],
					[StudyId]
				)
				VALUES (
					@Description,
					@DicomId,
					@StudyId
				);

				SET @SeriesId = SCOPE_IDENTITY();

				UPDATE [dbo].[CaseStudy]
				SET [SeriesCount] = [SeriesCount] + 1
				WHERE Id = @StudyId
			END
		COMMIT
	END TRY
	BEGIN CATCH
		SET @SeriesId = -1;
		IF @@TRANCOUNT > 0
			ROLLBACK
	END CATCH
END



GO
/****** Object:  StoredProcedure [dbo].[sp_Create_Series_New]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_Create_Series_New] 
	@Description nvarchar(100),
	@DicomId nvarchar(100),
	@StudyId int,
	@SeriesNumber varchar(10),
	-- Add the parameters for the stored procedure here
	@SeriesId int OUTPUT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	--DECLARE @StudyId int;
	SET NOCOUNT ON;
	BEGIN TRY
		BEGIN TRANSACTION 
			SET @SeriesId = (SELECT TOP 1 Id FROM [dbo].[Series] WHERE [DicomId] = @DicomId AND [StudyId] = @StudyId);
			IF (@SeriesId IS NULL)
			BEGIN
				INSERT [dbo].[Series]
				(
					[Description],
					[DicomId],
					[StudyId],
					[SeriesNumber]
				)
				VALUES (
					@Description,
					@DicomId,
					@StudyId,
					@SeriesNumber
				);

				SET @SeriesId = SCOPE_IDENTITY();

				UPDATE [dbo].[CaseStudy]
				SET [SeriesCount] = [SeriesCount] + 1
				WHERE Id = @StudyId
			END
		COMMIT
	END TRY
	BEGIN CATCH
		SET @SeriesId = -1;
		IF @@TRANCOUNT > 0
			ROLLBACK
	END CATCH
END

-- 28/7/2020, LeHT bổ sung config cho 1 số site RIS còn thiếu

-- 	<!-- Max count cua Dicom Worklist trả về cho MDWorklistService -->
--    <add key="DicomWorklistMaxCount" value="180" />

--  <!--Mô hình pacs/ris có theo mô hình mới hay không -->
--    <add key="PACSRISConnected" value="true" />

GO
/****** Object:  StoredProcedure [dbo].[sp_Get_Current_Worklist_Index]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_Get_Current_Worklist_Index] 
	-- Add the parameters for the stored procedure here
	@stt int OUTPUT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	BEGIN TRANSACTION

	DECLARE @now Date = CONVERT (date, GETDATE());

    -- Insert statements for procedure here
	IF NOT EXISTS (SELECT 1 FROM dbo.WorklistIndex WITH (TABLOCKX, HOLDLOCK))
	BEGIN
		INSERT INTO dbo.WorklistIndex VALUES (@now, 0);
	END
	
	SET @stt = (SELECT STT FROM dbo.WorklistIndex WHERE [Date] = @now);
	
	IF @stt IS NULL
	BEGIN
		UPDATE dbo.WorklistIndex
		SET [Date] = @now,
		STT = 1;
		
		SET @stt = 1;
	END
	ELSE
	BEGIN
		SET @stt = @stt + 1;
		
		UPDATE dbo.WorklistIndex
		SET STT = @stt;
	END
	
	COMMIT TRANSACTION
END



GO
/****** Object:  StoredProcedure [dbo].[sp_GetStudyByApproveDoctor]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_GetStudyByApproveDoctor] 
	@fromDate datetime,
	@toDate datetime,
	@teleGroupId int

AS
BEGIN	
	
	
	select R.ApproverId, count(*) as 'Total' from(
		select distinct D.ApproverId, D.StudyId from(
			select A.ApproverId, A.StudyId, A.LastApproveDate from StudyReport A
			Join CaseStudy C on C.Id = A.StudyId
			where A.LastApproveDate >= @fromDate and A.LastApproveDate <=@toDate and A.ApproverId is not null and C.TeleGroupId = @teleGroupId and A.Status = 50
		) D
	) R
	group by R.ApproverId

END

/* Thêm StoredProcedure [sp_GetStudyBySite]*/

/****** Object:  StoredProcedure [dbo].[sp_GetStudyBySite]    Script Date: 8/1/2019 3:46:20 PM ******/
SET ANSI_NULLS ON



GO
/****** Object:  StoredProcedure [dbo].[sp_GetStudyBySite]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_GetStudyBySite] 
	@fromDate datetime,
	@toDate datetime,
	@teleGroupId int

AS
BEGIN
	select TeleSiteLocalId,count(*) as 'Total' from CaseStudy
	where DateScanned >= @fromDate and DateScanned <= @toDate and TeleGroupId = @teleGroupId
	group by TeleSiteLocalId
END




GO
/****** Object:  StoredProcedure [dbo].[sp_GetStudyReporting]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[sp_GetStudyReporting]
@fromDate datetime,
@toDate datetime,
@teleGroupId int
AS
BEGIN

IF (@teleGroupId = -1)
BEGIN
	--Select Modality, [Status], count(0) as 'Total' from [dbo].[CaseStudy] where DateScanned >= @fromDate and DateScanned <= @toDate and Modality is not null
	Select Modality, R.[Status], count(0) as 'Total' from [dbo].[StudyReport] R
	Join CaseStudy C On c.Id=R.StudyId
	where R.LastApproveDate >= @fromDate and R.LastApproveDate <=@toDate and Modality is not null and (R.Status = 45 or R.Status = 50)
		group by Modality, R.[Status]
	
		UNION ALL
		---trang thai 30: dang doc, 40: cho duyet
		Select Modality, R.[Status], count(0) as 'Total' from [dbo].[StudyReport] R
	Join CaseStudy C On c.Id=R.StudyId
	where R.LastReadingDate >= @fromDate and R.LastReadingDate <=@toDate and Modality is not null and (R.Status =30 or R.Status = 40)
		group by Modality, R.[Status]
END
ELSE
BEGIN
	--Select Modality, R.[Status], count(0) as 'Total' from [dbo].[StudyReport] R
	--Join CaseStudy C On c.Id=R.StudyId
	--where R.DateCreated >= @fromDate and DateScanned <= @toDate and Modality is not null
	--group by Modality, R.[Status]
	--order by Modality

	--Select Modality, [Status], count(0) as 'Total' from [dbo].[CaseStudy] where DateScanned >= @fromDate and DateScanned <= @toDate and Modality is not null and TeleGroupId = @teleGroupId
	--group by Modality, [Status]

	--sua them code
	---trang thai 45: dang duyet, 50: da duyet
	Select Modality, R.[Status], count(0) as 'Total' from [dbo].[StudyReport] R
	Join CaseStudy C On c.Id=R.StudyId
	where R.LastApproveDate >= @fromDate and R.LastApproveDate <=@toDate and Modality is not null and (R.Status = 45 or R.Status = 50) and C.TeleGroupId = @teleGroupId
		group by Modality, R.[Status]
	
		UNION ALL
		---trang thai 30: dang doc, 40: cho duyet
		Select Modality, R.[Status], count(0) as 'Total' from [dbo].[StudyReport] R
	Join CaseStudy C On c.Id=R.StudyId
	where R.LastReadingDate >= @fromDate and R.LastReadingDate <=@toDate and Modality is not null and (R.Status =30 or R.Status = 40) and C.TeleGroupId = @teleGroupId
		group by Modality, R.[Status]
END


END

/* Thêm StoredProcedure [sp_GetStudyByApproveDoctor]*/

/****** Object:  StoredProcedure [dbo].[sp_GetStudyByApproveDoctor]    Script Date: 8/1/2019 3:45:31 PM ******/
SET ANSI_NULLS ON



GO
/****** Object:  StoredProcedure [dbo].[sp_Import_Nano_Worklist]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_Import_Nano_Worklist] 
	-- Add the parameters for the stored procedure here
	@MaChanDoanHinhAnh varchar(50), 
	@MaDichVu varchar(50),
	@YeuCau nvarchar(4000),
	@MaBenhNhan varchar(50),
	@TenBenhNhan nvarchar(100),
	@NgaySinh datetime,
	@NamSinh int,
	@DiaChi nvarchar(300),
	@MaGioiTinh varchar(50),
	@TinhThanh	nvarchar(100) = null,
	@LyDoKham	nvarchar(4000) = null,
	@BenhLy	nvarchar(4000) = null,
	@NgayKham	datetime = null,

	@TenPhongHienThi	nvarchar(200) = null,
	@TenKhoa	nvarchar(200) = null,
	@SoTheBHYT	varchar(50) = null,
	@NgayBatDau datetime = null,
	@NgayHetHan datetime = null,
	@ChanDoan	nvarchar(4000) = null,
	@TenGiuong	nvarchar(50) = null,
	@TenBuong	nvarchar(50) = null,

	@NoiTru	bit = null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	BEGIN TRY

		IF @MaChanDoanHinhAnh iS NOT NULL
		BEGIN
			-- Insert statements for procedure here
			IF (SELECT 1 FROM dbo.OSWorklist WHERE Code = @MaChanDoanHinhAnh) IS NULL
			BEGIN
				DECLARE @VisitDate DATETIME

				SET @VisitDate = ISNULL(@NgayKham, GETDATE())

				INSERT INTO [pacsdbname].[dbo].[OSWorklist]
						([Code]
						,[Modality]
						,[Description]
						,[Status]
						,[PatientCode]
						,[PatientName]
						,[PatientDOB]
						,[PatientYOB]
						,[PatientAddress]
						,[PatientSex]
						,PatientProvince
						,[SystemCode]
						,VisitReason
						,VisitHistory
						,VisitDate
						,[TenPhongHienThi]
						,[TenKhoa]
						,[SoTheBHYT]
						,[NgayBatDau]
						,[NgayHetHan]
						,[ChanDoan]
						,[TenGiuong]
						,[TenBuong]
						,[NoiTru]
						)
					VALUES
						(
						@MaChanDoanHinhAnh
						, @MaDichVu
						, @YeuCau
						, 0
						, @MaBenhNhan
						, @TenBenhNhan
						, @NgaySinh
						, @NamSinh
						, @DiaChi
						, CASE WHEN @MaGioiTinh = 'N' THEN 0 ELSE 1 END
						, @TinhThanh
						, 'NANO'
						, ISNULL(@LyDoKham, '')
						, ISNULL(@BenhLy, '')
						, @VisitDate
						, @TenPhongHienThi
						, @TenKhoa
						, @SoTheBHYT
						, @NgayBatDau
						, @NgayHetHan
						, @ChanDoan
						, @TenGiuong
						, @TenBuong
						, @NoiTru
					)
			
			END
			ELSE 
			BEGIN
				UPDATE [pacsdbname].[dbo].[OSWorklist]
				SET [TenPhongHienThi] = @TenPhongHienThi
				,	[TenKhoa] = @TenKhoa
				,	[SoTheBHYT] = @SoTheBHYT
				,	[NgayBatDau] = @NgayBatDau
				,	[NgayHetHan] = @NgayHetHan
				,	[ChanDoan] = @ChanDoan
				,	[TenGiuong] = @TenGiuong
				,	[TenBuong] = @TenBuong
				WHERE Code = @MaChanDoanHinhAnh

				DECLARE @CaseStudyId	int;

				SELECT @CaseStudyId = CaseStudyId
				FROM [dbo].[OSWorklist]
				WHERE Code = @MaChanDoanHinhAnh

				IF (@CaseStudyId IS NOT NULL)
					UPDATE [dbo].[CaseStudy]
					SET [TenPhongHienThi] = @TenPhongHienThi
					,	[TenKhoa] = @TenKhoa
					,	[ChanDoan] = @ChanDoan
					,	[TenGiuong] = @TenGiuong
					,	[TenBuong] = @TenBuong
					WHERE Id = @CaseStudyId
			END
		END
	END TRY
	BEGIN CATCH
	END CATCH
END



GO
/****** Object:  StoredProcedure [dbo].[sp_Insert_Image_file]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_Insert_Image_file]
	-- Add the parameters for the stored procedure here
	@file_tsuid varchar(255), 
	@filepath varchar(255),
	@series_iuid varchar(255),
	@series_desc varchar(255),
	@study_iuid varchar(255),
	@accession_no varchar(255),
	@pat_id varchar(255),
	@pat_name varchar(255),
	@pat_birthdate varchar(255),
	@pat_sex varchar(255),
	@study_datetime datetime,
	@modality varchar(255)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	DECLARE @csId int;

	IF @study_iuid IS NOT NULL AND @series_iuid IS NOT NULL AND @file_tsuid IS NOT NULL
	BEGIN
		--1. Lay study tuong ung @study_iuid xem co khong
		IF @study_iuid IS NOT NULL
		BEGIN
			SET @csId = (SELECT TOP 1 Id FROM dbo.CaseStudy WHERE DicomId = @study_iuid)
		END
	    
		--2. Neu ko co lay study tuong ung @accession_no xem co khong
		IF @csId IS NULL AND @accession_no IS NOT NULL
		BEGIN
			SET @csId = (SELECT TOP 1 Id FROM dbo.CaseStudy WHERE AccessionNo = @accession_no)
		END
	    
		--3. Neu ko co lay study tuong ung @pat_id va @study_datetime xem co khong
		IF @csId IS NULL AND @pat_id IS NOT NULL AND @study_datetime IS NOT NULL AND @modality IS NOT NULL
		BEGIN
			--select 3
			
			DECLARE @1Hour datetime = DATEADD(HOUR, -12, @study_datetime);
			
			SET @csId = (SELECT TOP 1 cs.Id FROM dbo.CaseStudy cs
							JOIN dbo.Patient pt ON cs.PatientId = pt.Id
							JOIN dbo.Worklist wl ON cs.WorklistId = wl.Id
							JOIN dbo.Station st ON cs.StationId = st.Id
							 WHERE cs.[Status] = 0
							 AND (pt.ReferenceCOde = @pat_id OR pt.Code = @pat_id)
							 AND wl.NgayChup > @1Hour 
							 AND (st.Modality = @modality OR st.OtherModality LIKE '%' + @modality + '%')
							 AND cs.SeriesCount = 0 
							 AND cs.ImageCount = 0
							 ORDER BY wl.NgayChup DESC)
		END
	    
		IF @csId IS NOT NULL
		BEGIN
			--4. Cap nhat lai studyUID va accession No tuong ung cua CaseStudy
			
	    
			--5. Lay series tuong ung @series_iuid
			DECLARE @sId int;
			DECLARE @sInc int = 0;
			
			SET @sId = (SELECT Id FROM dbo.Series WHERE DicomId = @series_iuid)
		    
			--6. Neu ko co insert Series
			IF @sId IS NULL
			BEGIN
				INSERT dbo.Series (DicomId, StudyId, [Description]) VALUES (@series_iuid, @csId, @series_desc)
				
				SET @sId = (SELECT SCOPE_IDENTITY())
				
				SET @sInc = 1
			END
		    
			--7. Insert ImageFile
			INSERT dbo.ImageFile (DicomId, FilePath, SeriesId, StudyId, Processed) VALUES (@file_tsuid, @filepath, @sId, @csId, 0)
		    
			--8. Cap nhat SeriesCount va ImageCount
			UPDATE dbo.CaseStudy
			SET DicomId = @study_iuid,
			AccessionNo = @accession_no,
			ImageCount = ImageCount + 1,
			SeriesCount = SeriesCount + @sInc,
			[Status] = CASE WHEN [Status] < 20 THEN 20 ELSE [Status] END,
			DateScanned = CASE WHEN DateScanned IS NULL THEN GETDATE() ELSE DateScanned END
			WHERE Id = @csId
			
			UPDATE dbo.Worklist
			SET [Status] = CASE WHEN wl.[Status] < 20 THEN 20 ELSE wl.[Status] END
			FROM dbo.Worklist wl
			JOIN dbo.CaseStudy cs ON wl.Id = cs.WorklistId
			WHERE cs.Id = @csId
		END
		ELSE
		BEGIN
			INSERT INTO [pacsdbname].[dbo].[TempImageFile]
				   ([file_tsuid]
				   ,[filepath]
				   ,[series_iuid]
				   ,[series_desc]
				   ,[study_iuid]
				   ,[accession_no]
				   ,[pat_id]
				   ,[pat_name]
				   ,[pat_birthdate]
				   ,[pat_sex]
				   ,[study_datetime]
				   ,[modality])
			 VALUES
				   (@file_tsuid
				   ,@filepath
				   ,@series_iuid
				   ,@series_desc
				   ,@study_iuid
				   ,@accession_no
				   ,@pat_id
				   ,@pat_name
				   ,@pat_birthdate
				   ,@pat_sex
				   ,@study_datetime
				   ,@modality
				   )
		END
	END
END



GO
/****** Object:  StoredProcedure [dbo].[sp_Study_Update_Result]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_Study_Update_Result] 
	@MaChanDoanHinhAnh varchar(50),
	@KetQua nvarchar(4000),
	@KetLuan nvarchar(4000)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	DECLARE @CaseStudyId int;

	SELECT @CaseStudyId = [CaseStudyId] FROM [dbo].[OSWorklist] WHERE [Code] = @MaChanDoanHinhAnh;

	UPDATE [dbo].[CaseStudy]
	SET [ReportReading] = @KetQua,
	[Conclusion] = @KetLuan
END



GO
/****** Object:  StoredProcedure [dbo].[sp_test]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_test] 
	-- Add the parameters for the stored procedure here
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT 'Success'
END



GO
/****** Object:  StoredProcedure [dbo].[sp_Worklist_Update_Status]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_Worklist_Update_Status] 
	@DicomId varchar(255),
	@StudyId varchar(255),
	@SeriesCount int,
	@ImageCount int,
	@Status int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

 --   -- Insert statements for procedure here
	--Update [dbo].[Worklist] set [Status] = @Status, NgayChup = GETDATE() where [DicomId] = @DicomId
	
	--Update dbo.CaseStudy 
	--set [Status] = @Status,
	--SeriesCount = @SeriesCount,
	--ImageCount = @ImageCount,
	--DateScanned = GETDATE()
	--where [DicomId] = @StudyId
	
	IF @Status = 10
	BEGIN
		Update [dbo].[Worklist] set [Status] = @Status where [DicomId] = @DicomId
		
		Update dbo.CaseStudy 
		set [Status] = @Status
		where [DicomId] = @StudyId
	END
END



GO
/****** Object:  StoredProcedure [dbo].[SqlQueryNotificationStoredProcedure-33364dcf-6d66-4b4c-bae2-de3e457ea3a4]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SqlQueryNotificationStoredProcedure-33364dcf-6d66-4b4c-bae2-de3e457ea3a4] AS BEGIN BEGIN TRANSACTION; RECEIVE TOP(0) conversation_handle FROM [SqlQueryNotificationService-33364dcf-6d66-4b4c-bae2-de3e457ea3a4]; IF (SELECT COUNT(*) FROM [SqlQueryNotificationService-33364dcf-6d66-4b4c-bae2-de3e457ea3a4] WHERE message_type_name = 'http://schemas.microsoft.com/SQL/ServiceBroker/DialogTimer') > 0 BEGIN if ((SELECT COUNT(*) FROM sys.services WHERE name = 'SqlQueryNotificationService-33364dcf-6d66-4b4c-bae2-de3e457ea3a4') > 0)   DROP SERVICE [SqlQueryNotificationService-33364dcf-6d66-4b4c-bae2-de3e457ea3a4]; if (OBJECT_ID('SqlQueryNotificationService-33364dcf-6d66-4b4c-bae2-de3e457ea3a4', 'SQ') IS NOT NULL)   DROP QUEUE [SqlQueryNotificationService-33364dcf-6d66-4b4c-bae2-de3e457ea3a4]; DROP PROCEDURE [SqlQueryNotificationStoredProcedure-33364dcf-6d66-4b4c-bae2-de3e457ea3a4]; END COMMIT TRANSACTION; END


GO
/****** Object:  StoredProcedure [dbo].[SqlQueryNotificationStoredProcedure-a53094e3-44dc-4c04-8367-199c77e35901]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SqlQueryNotificationStoredProcedure-a53094e3-44dc-4c04-8367-199c77e35901] AS BEGIN BEGIN TRANSACTION; RECEIVE TOP(0) conversation_handle FROM [SqlQueryNotificationService-a53094e3-44dc-4c04-8367-199c77e35901]; IF (SELECT COUNT(*) FROM [SqlQueryNotificationService-a53094e3-44dc-4c04-8367-199c77e35901] WHERE message_type_name = 'http://schemas.microsoft.com/SQL/ServiceBroker/DialogTimer') > 0 BEGIN if ((SELECT COUNT(*) FROM sys.services WHERE name = 'SqlQueryNotificationService-a53094e3-44dc-4c04-8367-199c77e35901') > 0)   DROP SERVICE [SqlQueryNotificationService-a53094e3-44dc-4c04-8367-199c77e35901]; if (OBJECT_ID('SqlQueryNotificationService-a53094e3-44dc-4c04-8367-199c77e35901', 'SQ') IS NOT NULL)   DROP QUEUE [SqlQueryNotificationService-a53094e3-44dc-4c04-8367-199c77e35901]; DROP PROCEDURE [SqlQueryNotificationStoredProcedure-a53094e3-44dc-4c04-8367-199c77e35901]; END COMMIT TRANSACTION; END


GO
/****** Object:  StoredProcedure [dbo].[SqlQueryNotificationStoredProcedure-bf7482c5-4c84-4cff-b7aa-09e9b37ea9e2]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SqlQueryNotificationStoredProcedure-bf7482c5-4c84-4cff-b7aa-09e9b37ea9e2] AS BEGIN BEGIN TRANSACTION; RECEIVE TOP(0) conversation_handle FROM [SqlQueryNotificationService-bf7482c5-4c84-4cff-b7aa-09e9b37ea9e2]; IF (SELECT COUNT(*) FROM [SqlQueryNotificationService-bf7482c5-4c84-4cff-b7aa-09e9b37ea9e2] WHERE message_type_name = 'http://schemas.microsoft.com/SQL/ServiceBroker/DialogTimer') > 0 BEGIN if ((SELECT COUNT(*) FROM sys.services WHERE name = 'SqlQueryNotificationService-bf7482c5-4c84-4cff-b7aa-09e9b37ea9e2') > 0)   DROP SERVICE [SqlQueryNotificationService-bf7482c5-4c84-4cff-b7aa-09e9b37ea9e2]; if (OBJECT_ID('SqlQueryNotificationService-bf7482c5-4c84-4cff-b7aa-09e9b37ea9e2', 'SQ') IS NOT NULL)   DROP QUEUE [SqlQueryNotificationService-bf7482c5-4c84-4cff-b7aa-09e9b37ea9e2]; DROP PROCEDURE [SqlQueryNotificationStoredProcedure-bf7482c5-4c84-4cff-b7aa-09e9b37ea9e2]; END COMMIT TRANSACTION; END


GO
/****** Object:  UserDefinedFunction [dbo].[fChuyenCoDauThanhKhongDau]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[fChuyenCoDauThanhKhongDau](@inputVar NVARCHAR(MAX) )
RETURNS NVARCHAR(MAX)
AS
BEGIN    
    IF (@inputVar IS NULL OR @inputVar = '')  RETURN ''
   
    DECLARE @RT NVARCHAR(MAX)
    DECLARE @SIGN_CHARS NCHAR(256)
    DECLARE @UNSIGN_CHARS NCHAR (256)
 
    SET @SIGN_CHARS = N'ăâđêôơưàảãạáằẳẵặắầẩẫậấèẻẽẹéềểễệếìỉĩịíòỏõọóồổỗộốờởỡợớùủũụúừửữựứỳỷỹỵýĂÂĐÊÔƠƯÀẢÃẠÁẰẲẴẶẮẦẨẪẬẤÈẺẼẸÉỀỂỄỆẾÌỈĨỊÍÒỎÕỌÓỒỔỖỘỐỜỞỠỢỚÙỦŨỤÚỪỬỮỰỨỲỶỸỴÝ' + NCHAR(272) + NCHAR(208)
    SET @UNSIGN_CHARS = N'aadeoouaaaaaaaaaaaaaaaeeeeeeeeeeiiiiiooooooooooooooouuuuuuuuuuyyyyyAADEOOUAAAAAAAAAAAAAAAEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOUUUUUUUUUUYYYYYDD'
 
    DECLARE @COUNTER int
    DECLARE @COUNTER1 int
   
    SET @COUNTER = 1
    WHILE (@COUNTER <= LEN(@inputVar))
    BEGIN  
        SET @COUNTER1 = 1
        WHILE (@COUNTER1 <= LEN(@SIGN_CHARS) + 1)
        BEGIN
            IF UNICODE(SUBSTRING(@SIGN_CHARS, @COUNTER1,1)) = UNICODE(SUBSTRING(@inputVar,@COUNTER ,1))
            BEGIN          
                IF @COUNTER = 1
                    SET @inputVar = SUBSTRING(@UNSIGN_CHARS, @COUNTER1,1) + SUBSTRING(@inputVar, @COUNTER+1,LEN(@inputVar)-1)      
                ELSE
                    SET @inputVar = SUBSTRING(@inputVar, 1, @COUNTER-1) +SUBSTRING(@UNSIGN_CHARS, @COUNTER1,1) + SUBSTRING(@inputVar, @COUNTER+1,LEN(@inputVar)- @COUNTER)
                BREAK
            END
            SET @COUNTER1 = @COUNTER1 +1
        END
        SET @COUNTER = @COUNTER +1
    END
    -- SET @inputVar = replace(@inputVar,' ','-')
    RETURN @inputVar
END



GO
/****** Object:  Table [dbo].[AccountToken]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[AccountToken](
	[Id] [int] NOT NULL,
	[Username] [nvarchar](50) NOT NULL,
	[Token] [varchar](50) NOT NULL,
	[DateCreated] [datetime] NOT NULL,
 CONSTRAINT [PK_AccountToken] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Annotation]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Annotation](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[SeriesId] [int] NOT NULL,
	[StudyId] [int] NOT NULL,
	[Index] [int] NOT NULL,
	[SlideIndex] [int] NULL,
	[Orientation] [nvarchar](50) NULL,
	[Type] [nvarchar](50) NULL,
	[Text] [nvarchar](max) NULL,
	[Data] [varchar](max) NULL,
	[TextPos] [varchar](2000) NULL,
	[Username] [nvarchar](50) NULL,
 CONSTRAINT [PK_Annotation] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[BodyPart]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
CREATE TABLE [dbo].[BodyPart](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[Code] [nvarchar](50) NOT NULL,
	[Modality] [varchar](20) NULL,
	[Keyword] [nvarchar](500) NULL,
 CONSTRAINT [PK_BodyPart] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Branch]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Branch](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[Address] [nvarchar](200) NULL,
	[Active] [bit] NOT NULL,
 CONSTRAINT [PK_Branch] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[BranchUser]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BranchUser](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[BranchId] [int] NULL,
	[UserId] [int] NOT NULL,
	[Active] [bit] NOT NULL,
 CONSTRAINT [PK_BranchUser] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CaseStudy]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[CaseStudy](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[DicomId] [nvarchar](100) NOT NULL,
	[WorklistId] [int] NOT NULL,
	[Status] [tinyint] NOT NULL,
	[KTVId] [int] NOT NULL,
	[PatientId] [int] NOT NULL,
	[StationId] [int] NOT NULL,
	[DoctorId] [int] NOT NULL,
	[ApproverId] [int] NULL,
	[Description] [nvarchar](2000) NULL,
	[Bodypart] [nvarchar](200) NULL,
	[Result] [nvarchar](2000) NULL,
	[Report] [nvarchar](max) NULL,
	[ReportContent] [nvarchar](max) NULL,
	[SeriesCount] [int] NULL,
	[ImageCount] [int] NULL,
	[DateScanned] [datetime] NULL,
	[TemplateReportId] [int] NULL,
	[TemplateReportMasterId] [int] NULL,
	[AccessionNo] [nvarchar](255) NULL,
	[HISVisitId] [nvarchar](50) NULL,
	[ReportReading] [nvarchar](max) NULL,
	[Conclusion] [nvarchar](max) NULL,
	[TenPhongHienThi] [nvarchar](200) NULL,
	[TenKhoa] [nvarchar](200) NULL,
	[ChanDoan] [nvarchar](4000) NULL,
	[TenGiuong] [nvarchar](50) NULL,
	[TenBuong] [nvarchar](50) NULL,
	[DraftReading] [nvarchar](max) NULL,
	[DraftConclusion] [nvarchar](max) NULL,
	[LastDraftDate] [datetime] NULL,
	[Modality] [nvarchar](50) NULL,
	[LastReadingDate] [datetime] NULL,
	[LastApproveDate] [datetime] NULL,
	[StationName] [nvarchar](50) NULL,
	[Printed] [bit] NULL,
	[LinkReportId] [int] NULL,
	[LastReportId] [int] NULL,
	[NoiTru] [bit] NULL,
	[SPSId] [varchar](255) NULL,
	[ReqProcId] [varchar](255) NULL,
	[SoTheBHYT] [varchar](50) NULL,
	[NgayBatDau] [datetime] NULL,
	[NgayHetHan] [datetime] NULL,
	[SiteId] [int] NULL,
	[RequestOutsider] [bit] NULL,
	[OutsiderRead] [bit] NULL,
	[OutsiderApproved] [bit] NULL,
	[PMRReportId] [varchar](50) NULL,
	[OrderDoctorId] [int] NULL,
	[Assigned] [bit] NULL,
	[BranchId] [int] NULL,
	[AssignHideName] [bit] NULL,
	[UnMatched] [bit] NULL,
	[OrderDoctor] [nvarchar](50) NULL,
	[HISCode] [varchar](50) NULL,
	[Uploaded] [bit] NULL,
	[OrderDoctorPhoneNo] [nvarchar](50) NULL,
	[DateUploaded] [datetime] NULL,
	[StudyType] [tinyint] NULL,
	[TeleEmergencyLevel] [int] NULL,
	[TeleGroupId] [int] NULL,
	[TeleServiceId] [int] NULL,
	[TeleDescription] [nvarchar](max) NULL,
	[MergedStudyIds] [nvarchar](200) NULL,
	[TeleIsSent] [bit] NULL,
	[TeleLocalStudyId] [int] NULL,
	[TeleSiteLocalId] [int] NULL,
	[TeleDateTimeSent] [datetime] NULL,
	[TeleIsVisible] [bit] NULL,
	[TeleIsError] [bit] NULL,
	[Uploading] [bit] NULL,
	[UploadUserId] [int] NULL,
	[RemoveBedInfo] [varchar](50) NULL,
	[VisibleAllTime] [datetime] NULL,
	[VisiblePriority1Time] [datetime] NULL,
	[VisiblePriority2Time] [datetime] NULL,
 CONSTRAINT [PK_CaseStudy] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[CaseStudyDrug]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CaseStudyDrug](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[DrugId] [int] NULL,
	[CaseStudyId] [int] NOT NULL,
	[FilmCount] [int] NULL,
	[FilmSize] [nvarchar](50) NULL,
	[DrugCount] [int] NULL,
	[DrugUnit] [nvarchar](50) NULL,
 CONSTRAINT [PK_CaseStudyDrug] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerColumn]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerColumn](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[UserId] [int] NOT NULL,
	[Fields] [nvarchar](2000) NULL,
 CONSTRAINT [PK_CustomFilter] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[CustomerExportColumn]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CustomerExportColumn](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[UserId] [int] NOT NULL,
	[Fields] [nvarchar](max) NULL,
	[TemplateTitle] [nvarchar](100) NULL,
 CONSTRAINT [PK_CustomerExportColumn] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[DailyUserLog]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DailyUserLog](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[UserId] [int] NOT NULL,
	[Date] [datetime] NOT NULL,
	[ActiveTime] [int] NOT NULL,
	[StudyOpened] [int] NOT NULL,
	[ReportCreated] [int] NOT NULL,
 CONSTRAINT [PK_DailyUserLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[DICOMServer]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[DICOMServer](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](max) NULL,
	[AETitle] [nvarchar](max) NULL,
	[IP] [varchar](50) NOT NULL,
	[Port] [int] NOT NULL,
	[SiteCode] [nvarchar](100) NULL,
 CONSTRAINT [PK_DICOMServer] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Drug]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Drug](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](500) NOT NULL,
	[Unit] [nvarchar](50) NOT NULL,
	[Description] [nvarchar](max) NULL,
	[HISCode] [nvarchar](50) NULL,
	[IsDisabled] [bit] NULL,
 CONSTRAINT [PK_Drug] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[EditPatientDetail]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EditPatientDetail](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[LogId] [int] NOT NULL,
	[ObjectType] [int] NOT NULL,
	[OldValue] [nvarchar](500) NULL,
	[NewValue] [nvarchar](500) NULL,
 CONSTRAINT [PK_EditPatientDetail] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[EditPatientLog]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EditPatientLog](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[UserId] [int] NOT NULL,
	[PatientId] [int] NOT NULL,
	[OldPatientCode] [nvarchar](50) NULL,
	[NewPatientCode] [nvarchar](50) NULL,
	[OldPatientName] [nvarchar](50) NULL,
	[NewPatientName] [nvarchar](50) NULL,
	[LyDo] [nvarchar](500) NULL,
	[DateCreated] [datetime] NOT NULL,
 CONSTRAINT [PK_EditPatientLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[FilterStation]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FilterStation](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[Display] [bit] NOT NULL,
	[Type] [tinyint] NULL,
	[HISCode] [nvarchar](50) NULL,
	[DisplayName] [nvarchar](50) NULL,
	[BranchId] [int] NULL,
	[AETitle] [nvarchar](50) NULL,
	[Keyword] [nvarchar](500) NULL,
	[SiteId] [int] NULL,
	[PrintTitle] [nvarchar](500) NULL,
	[Modalities] [nvarchar](50) NULL,
 CONSTRAINT [PK_FilterStation] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Folder]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Folder](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[CreatorId] [int] NOT NULL,
	[ParentId] [int] NOT NULL,
	[Name] [nvarchar](500) NOT NULL,
	[Level] [int] NULL,
 CONSTRAINT [PK_Folder] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[FolderStudy]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FolderStudy](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[FolderId] [int] NOT NULL,
	[StudyId] [int] NOT NULL,
 CONSTRAINT [PK_FolderStudy] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[GroupRole]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[GroupRole](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[GroupId] [bigint] NOT NULL,
	[RoleId] [int] NOT NULL,
	[Modalities] [varchar](50) NULL,
 CONSTRAINT [PK_GroupRole] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[ImageFile]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[ImageFile](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[DicomId] [nvarchar](100) NULL,
	[SeriesId] [int] NULL,
	[FilePath] [nvarchar](500) NULL,
	[FileZipPath] [nvarchar](500) NULL,
	[LocalPath] [nvarchar](500) NULL,
	[StudyId] [int] NOT NULL,
	[FileImagePath] [nvarchar](500) NULL,
	[Send2HIS] [bit] NULL,
	[SOP_IUID] [varchar](255) NULL,
	[SOP_CUID] [varchar](255) NULL,
	[InstanceNo] [varchar](255) NULL,
	[Attributes] [nvarchar](max) NULL,
	[DateCreated] [datetime] NULL,
	[Processed] [tinyint] NULL,
	[NotStored] [bit] NULL,
	[Modified] [bit] NULL,
	[TeleLocalImageFileId] [int] NULL,
	[TeleSiteLocalId] [int] NULL,
 CONSTRAINT [PK_ImageFile] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[ImageFile2Tele]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ImageFile2Tele](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[StudyId] [int] NOT NULL,
	[FileId] [int] NOT NULL,
	[Status] [int] NOT NULL,
	[DateCreated] [datetime] NOT NULL,
 CONSTRAINT [PK_ImageFile2Tele] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[JobQueue]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[JobQueue](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[UserId] [int] NOT NULL,
	[Type] [int] NOT NULL,
	[Title] [nvarchar](200) NULL,
	[DateCreated] [datetime] NOT NULL,
	[Status] [int] NOT NULL,
	[DateFinished] [datetime] NULL,
	[Percent] [decimal](5, 2) NULL,
	[StudyId] [int] NULL,
	[PatientName] [nvarchar](50) NULL,
	[IsDeleted] [int] NULL,
	[DateScanned] [datetime] NULL,
 CONSTRAINT [PK_JobQueue] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[LanguageResource]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[LanguageResource](
	[LanguageCode] [varchar](20) NOT NULL,
	[Key] [nvarchar](200) NOT NULL,
	[Value] [nvarchar](4000) NOT NULL,
 CONSTRAINT [PK_LanguageResource] PRIMARY KEY CLUSTERED 
(
	[LanguageCode] ASC,
	[Key] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[MergeStudyLog]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[MergeStudyLog](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[SeriesId] [int] NOT NULL,
	[OldStudyId] [int] NOT NULL,
	[NewStudyId] [int] NOT NULL,
	[AnnotationIds] [varchar](max) NULL,
	[OldPatientData] [nvarchar](max) NULL,
	[OldStudyData] [nvarchar](max) NULL,
	[UserId] [int] NOT NULL,
	[IP] [varchar](50) NULL,
	[Reason] [nvarchar](500) NULL,
	[DateCreated] [datetime] NOT NULL,
 CONSTRAINT [PK_MergeStudyLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[ModalityGroup]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[ModalityGroup](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[GroupName] [nvarchar](50) NOT NULL,
	[Modalities] [varchar](500) NOT NULL,
	[Order] [int] NULL,
	[Type] [tinyint] NULL,
 CONSTRAINT [PK_ModalityGroup] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Note]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Note](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[StudyId] [int] NOT NULL,
	[UserId] [int] NOT NULL,
	[DateCreated] [datetime] NOT NULL,
	[Title] [nvarchar](500) NULL,
	[Message] [nvarchar](max) NULL,
 CONSTRAINT [PK_Note] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[OrderDoctor]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[OrderDoctor](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[HISId] [nvarchar](50) NULL,
	[Active] [bit] NULL,
	[PhoneNo] [nvarchar](50) NULL,
	[Email] [nvarchar](50) NULL,
 CONSTRAINT [PK_OrderDoctor] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[OriginalDicomData]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[OriginalDicomData](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[StudyId] [int] NOT NULL,
	[SeriesId] [int] NULL,
	[FileId] [int] NULL,
	[Data] [nvarchar](max) NULL,
 CONSTRAINT [PK_InitialDicomData] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[OSWorklist]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[OSWorklist](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[Code] [varchar](50) NOT NULL,
	[Modality] [varchar](50) NOT NULL,
	[Description] [nvarchar](4000) NULL,
	[Status] [int] NULL,
	[PatientPMRCode] [nvarchar](50) NULL,
	[PatientCode] [varchar](50) NULL,
	[PatientVisitCode] [varchar](50) NULL,
	[PatientName] [nvarchar](100) NULL,
	[PatientDOB] [datetime] NULL,
	[PatientYOB] [int] NULL,
	[PatientAddress] [nvarchar](300) NULL,
	[PatientSex] [tinyint] NULL,
	[PatientEthnic] [nvarchar](50) NULL,
	[PatientPhoneNo] [varchar](50) NULL,
	[PatientJob] [nvarchar](500) NULL,
	[PatientProvince] [nvarchar](100) NULL,
	[SystemCode] [nvarchar](50) NULL,
	[VisitReason] [nvarchar](4000) NULL,
	[VisitHistory] [nvarchar](4000) NULL,
	[VisitDate] [datetime] NULL,
	[DateCreated] [datetime2](7) NULL,
	[PatientId] [int] NULL,
	[WorklistId] [int] NULL,
	[CaseStudyId] [int] NULL,
	[Processed] [tinyint] NULL,
	[TenPhongHienThi] [nvarchar](200) NULL,
	[TenKhoa] [nvarchar](200) NULL,
	[SoTheBHYT] [varchar](50) NULL,
	[NgayBatDau] [datetime] NULL,
	[NgayHetHan] [datetime] NULL,
	[ChanDoan] [nvarchar](4000) NULL,
	[TenGiuong] [nvarchar](50) NULL,
	[TenBuong] [nvarchar](50) NULL,
	[NoiTru] [bit] NULL,
	[SiteCode] [varchar](50) NULL,
	[VisitCode] [nvarchar](50) NULL,
	[OrderDoctor] [nvarchar](50) NULL,
	[OrderDoctorPhoneNo] [nvarchar](50) NULL,
	[ServiceId] [nvarchar](50) NULL,
	[AdditionalInfo] [nvarchar](max) NULL,
	[STT] [int] NULL,
	[PhongThucHien] [nvarchar](50) NULL,
	[PatientNote] [nvarchar](500) NULL,
	[PatientAltId] [varchar](50) NULL,
	[OBRId] [varchar](50) NULL,
	[OrderDate] [datetime] NULL,
	[ORCCode] [nvarchar](50) NULL,
 CONSTRAINT [PK_OSWorklist] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[PacsViewerConfig]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PacsViewerConfig](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Key] [nvarchar](500) NOT NULL,
	[JsonValue] [nvarchar](max) NOT NULL,
 CONSTRAINT [PK_PacsViewerConfig] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Patient]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Patient](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[ASCIIName] [varchar](50) NULL,
	[Code] [nvarchar](50) NULL,
	[ReferenceCOde] [nvarchar](50) NULL,
	[Sex] [tinyint] NULL,
	[YOB] [smallint] NULL,
	[PhoneNo] [varchar](50) NULL,
	[Address] [nvarchar](200) NULL,
	[CMND] [varchar](50) NULL,
	[HISId] [nvarchar](50) NULL,
	[Email] [nvarchar](50) NULL,
	[SoTheBHYT] [varchar](50) NULL,
	[NgayBatDau] [datetime] NULL,
	[NgayHetHan] [datetime] NULL,
	[Ethnic] [nvarchar](50) NULL,
	[Job] [nvarchar](500) NULL,
	[NotFromHIS] [bit] NULL,
	[DOB] [datetime] NULL,
	[TeleLocalSiteId] [int] NULL,
	[DefaultPassword] [nvarchar](50) NULL,
	[Username] [varchar](50) NULL,
 CONSTRAINT [PK_Patient] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[PatientFacility]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PatientFacility](
	[Id] [smallint] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](500) NOT NULL,
	[Code] [nvarchar](250) NULL,
	[FacilityGroup] [nvarchar](250) NULL,
	[Order] [smallint] NULL,
 CONSTRAINT [PK_PatientFacility] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PrintProxyConfig]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PrintProxyConfig](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[PrintName] [nvarchar](500) NOT NULL,
	[Manufacturer] [nvarchar](500) NOT NULL,
 CONSTRAINT [PK_PrintProxyConfig] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PrintProxyLog]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
CREATE TABLE [dbo].[PrintProxyLog](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[PrintName] [nvarchar](50) NOT NULL,
	[DateCreated] [datetime] NOT NULL,
	[FilmSize] [nvarchar](250) NOT NULL,
	[FilmCount] [int] NOT NULL,
	[Status] [int] NOT NULL,
	[Manufacturer] [nvarchar](500) NULL,
	[PatientId] [varchar](50) NULL,
	[Modality] [varchar](10) NULL,
	[StudyDate] [varchar](20) NULL,
	[StudyTime] [varchar](20) NULL,
	[StudyId] [int] NULL,
 CONSTRAINT [PK_PrintProxyLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[ReportLog]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ReportLog](
	[Id] [bigint] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[ReportId] [int] NULL,
	[Reading] [nvarchar](max) NULL,
	[Conclusion] [nvarchar](max) NULL,
	[Status] [tinyint] NULL,
	[ApproverId] [int] NULL,
	[ApproveDate] [datetime] NULL,
 CONSTRAINT [PK_ReportLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Role]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Role](
	[Id] [int] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_Role] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Series]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Series](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[DicomId] [nvarchar](100) NOT NULL,
	[StudyId] [int] NOT NULL,
	[Description] [nvarchar](100) NULL,
	[FileImagePath] [nvarchar](500) NULL,
	[Send2HIS] [bit] NULL,
	[IsAddition] [bit] NULL,
	[SeriesNumber] [varchar](10) NULL,
	[TeleLocalSerieId] [int] NULL,
	[TeleSiteLocalId] [int] NULL,
 CONSTRAINT [PK_Series] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[ServerStatus]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ServerStatus](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[creadted_date] [date] NOT NULL,
	[size] [float] NOT NULL,
	[file_number] [int] NOT NULL,
	[study_completed] [int] NULL,
 CONSTRAINT [PK_ServerStatus] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[ShareLinkStudy]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ShareLinkStudy](
	[Id] [bigint] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[ShareToken] [nvarchar](255) NULL,
	[ShareLink] [nvarchar](255) NULL,
	[UserId] [bigint] NULL,
	[StudyId] [bigint] NULL,
	[CreatedDate] [datetime] NULL,
	[ExpirationDate] [datetime] NULL,
	[HideInfo] [bit] NULL,
 CONSTRAINT [PK_ShareLinkStudy] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Site]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Site](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[Code] [nvarchar](50) NOT NULL,
	[IP] [varchar](50) NULL,
	[Port] [int] NULL,
	[ReqProcPrefix] [varchar](50) NULL,
	[AETitles] [varchar](500) NULL,
	[FileUrl] [nvarchar](500) NULL,
	[LocalLink] [bit] NULL,
	[BranchId] [int] NULL,
	[HISCode] [varchar](20) NULL,
 CONSTRAINT [PK_Site] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Station]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Station](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[DicomId] [numeric](19, 0) NULL,
	[Name] [nvarchar](50) NOT NULL,
	[IP] [varchar](50) NULL,
	[Port] [int] NULL,
	[AETitle] [nvarchar](50) NULL,
	[Modality] [nvarchar](50) NOT NULL,
	[OtherModality] [nvarchar](500) NULL,
	[DefaultCode] [nvarchar](50) NULL,
	[Description] [nvarchar](2000) NULL,
	[HL7Name] [bit] NULL,
	[OrderMapping] [nvarchar](100) NULL,
 CONSTRAINT [PK_Station] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[StudyChangeLog]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StudyChangeLog](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[LogId] [int] NOT NULL,
	[OldValue] [nvarchar](max) NULL,
	[NewValue] [nvarchar](max) NULL,
	[ObjectName] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_StudyChangeLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[StudyImages]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StudyImages](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Url] [nvarchar](1000) NOT NULL,
	[FileId] [int] NULL,
	[CaseStudyId] [int] NOT NULL,
	[Index] [int] NOT NULL,
	[ReportId] [int] NULL,
 CONSTRAINT [PK_StudyImages] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[StudyLog]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StudyLog](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[StudyId] [int] NULL,
	[DateCreated] [datetime] NOT NULL,
	[ActorId] [int] NULL,
	[ActionType] [int] NOT NULL,
	[Data] [nvarchar](max) NULL,
	[ReportId] [int] NULL,
	[OldPatientId] [int] NULL,
	[NewPatientId] [int] NULL,
 CONSTRAINT [PK_StudyLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[StudyReport]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StudyReport](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[StudyId] [int] NOT NULL,
	[Reading] [nvarchar](max) NULL,
	[Conclusion] [nvarchar](max) NULL,
	[LinkStudyId] [int] NULL,
	[Status] [tinyint] NOT NULL,
	[DoctorId] [int] NOT NULL,
	[ApproverId] [int] NULL,
	[DraftReading] [nvarchar](max) NULL,
	[DraftConclusion] [nvarchar](max) NULL,
	[LastDraftDate] [datetime] NULL,
	[LastReadingDate] [datetime] NULL,
	[LastApproveDate] [datetime] NULL,
	[DateCreated] [datetime] NOT NULL,
	[OutsiderRead] [bit] NULL,
	[OutsiderApproved] [bit] NULL,
	[FirstApproveDate] [datetime] NULL,
	[HISCode] [nvarchar](50) NULL,
	[TeleApproverId] [int] NULL,
	[TeleReportId] [int] NULL,
	[IsFromHIS] [bit] NULL,
	[SupervisorId] [int] NULL,
 CONSTRAINT [PK_StudyReport] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[StudyReportLink]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StudyReportLink](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[StudyId] [int] NOT NULL,
	[ReportId] [int] NOT NULL,
 CONSTRAINT [PK_StudyReportLink] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[StudySpecialIcon]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StudySpecialIcon](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[TenKhoa] [nvarchar](200) NULL,
	[TenPhongHienThi] [nvarchar](200) NULL,
	[Result] [nvarchar](2000) NULL,
	[TypeIcon] [int] NOT NULL,
 CONSTRAINT [PK_StudySpecialIcon] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[StudyStatus]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StudyStatus](
	[Id] [tinyint] NOT NULL,
	[Name] [nvarchar](80) NOT NULL,
	[Order] [tinyint] NOT NULL,
 CONSTRAINT [PK_StudyStatus] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[StudyViewing]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StudyViewing](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[StudyId] [int] NOT NULL,
	[UserId] [int] NOT NULL,
	[FullName] [nvarchar](50) NOT NULL,
	[DateView] [datetime] NOT NULL,
 CONSTRAINT [PK_StudyViewing] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Supervision]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Supervision](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[UserId] [int] NOT NULL,
	[SupervisorId] [int] NOT NULL,
	[Status] [int] NOT NULL,
	[CreateTime] [datetime] NOT NULL,
	[StartTime] [datetime] NULL,
	[EndTime] [datetime] NOT NULL,
 CONSTRAINT [PK_Supervision] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tbl_CustomFilter]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tbl_CustomFilter](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Title] [nvarchar](500) NULL,
	[Description] [nvarchar](500) NOT NULL,
	[SortField] [nvarchar](50) NULL,
	[SortValue] [nvarchar](50) NULL,
	[UseId] [int] NOT NULL,
	[ParentId] [nvarchar](50) NULL,
	[ParentName] [nvarchar](50) NULL,
 CONSTRAINT [PK_tbl_CustomFilter] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tbl_CustomFilterValue]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tbl_CustomFilterValue](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[CustomFilterId] [int] NOT NULL,
	[Field] [nvarchar](50) NULL,
	[Value] [nvarchar](50) NULL,
	[Text] [nvarchar](50) NULL,
	[FieldText] [nvarchar](50) NULL,
 CONSTRAINT [PK_tbl_CustomFilterValue] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TeleBill]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
CREATE TABLE [dbo].[TeleBill](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[BillCode] [varchar](30) NOT NULL,
	[Status] [int] NOT NULL,
	[SiteLocalId] [int] NOT NULL,
	[GroupId] [int] NOT NULL,
	[DateCreated] [datetime] NOT NULL,
	[Creator] [int] NOT NULL,
	[DatePay] [datetime] NOT NULL,
	[TotalInvoice] [int] NOT NULL,
	[TotalMoney] [money] NOT NULL,
	[FromDate] [datetime] NOT NULL,
	[ToDate] [datetime] NOT NULL,
 CONSTRAINT [PK_tele_Bill] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TeleBillDR]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
CREATE TABLE [dbo].[TeleBillDR](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[BillDRCode] [varchar](20) NOT NULL,
	[DoctorId] [int] NOT NULL,
	[CreatorId] [int] NOT NULL,
	[Status] [int] NOT NULL,
	[CreateDate] [datetime] NOT NULL,
	[PayDate] [datetime] NOT NULL,
	[GroupId] [int] NOT NULL,
	[TotalInvoice] [int] NOT NULL,
	[TotalMoney] [money] NOT NULL,
	[FromDate] [datetime] NOT NULL,
	[ToDate] [datetime] NOT NULL,
 CONSTRAINT [PK_TeleBillDR] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TeleFeeConfig]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TeleFeeConfig](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[TeleGroupId] [int] NOT NULL,
	[TeleServiceId] [int] NOT NULL,
	[Modality] [nvarchar](50) NOT NULL,
	[TimeType] [int] NOT NULL,
	[Fee] [money] NOT NULL,
	[DateCreated] [datetime] NOT NULL,
	[DateUpdate] [datetime] NOT NULL,
	[Creator] [int] NOT NULL,
	[UserUpdate] [int] NOT NULL,
	[Priority] [int] NOT NULL,
	[Status] [int] NOT NULL,
 CONSTRAINT [PK_TeleFeeConfig] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TeleGroup]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TeleGroup](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[CreatedDate] [datetime] NULL,
	[ModifiedDate] [datetime] NULL,
	[Name] [nvarchar](50) NULL,
	[Creator] [int] NOT NULL,
	[InvitationIds] [varchar](max) NULL,
	[MemberCDate] [datetime] NULL,
	[Status] [int] NOT NULL,
	[IsServiceGroup] [bit] NULL,
	[IsUserPriority] [bit] NULL,
	[DelayedTime] [int] NULL,
	[Priority1Users] [varchar](max) NULL,
	[Priority2Users] [varchar](max) NULL,
	[IsActive] [bit] NULL,
 CONSTRAINT [PK_TeleGroup] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TeleGroupService]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TeleGroupService](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[CreatedDate] [datetime] NULL,
	[ModifiedDate] [datetime] NULL,
	[TeleGroupId] [int] NOT NULL,
	[Name] [nvarchar](50) NULL,
	[ServiceGroupUsers] [varchar](max) NULL,
	[TeleServiceid] [int] NULL,
	[OrderService] [int] NOT NULL,
 CONSTRAINT [PK_TeleGroupService] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TeleInvitation]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TeleInvitation](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[CreatedDate] [datetime] NULL,
	[ModifiedDate] [datetime] NULL,
	[FirstName] [nvarchar](50) NULL,
	[MiddleName] [nvarchar](50) NULL,
	[LastName] [nvarchar](50) NULL,
	[FullName] [nvarchar](50) NULL,
	[Email] [varchar](50) NULL,
	[UserName] [varchar](50) NULL,
	[Note] [nvarchar](max) NULL,
	[UserType] [int] NULL,
	[InvitedUserId] [int] NOT NULL,
	[InvitedGroupId] [int] NOT NULL,
	[InviteByUserId] [int] NOT NULL,
	[Status] [int] NOT NULL,
 CONSTRAINT [PK_TeleInvitation] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TeleInvoice]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TeleInvoice](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[TeleStudyId] [int] NOT NULL,
	[TeleApproveId] [int] NOT NULL,
	[LocalStudyId] [int] NOT NULL,
	[LocalReportId] [int] NOT NULL,
	[PatientId] [int] NOT NULL,
	[TeleApproveDate] [datetime] NOT NULL,
	[Status] [int] NOT NULL,
	[TeleReportId] [int] NOT NULL,
	[TeleGroupId] [int] NOT NULL,
	[TeleServiceId] [int] NOT NULL,
	[SiteLocalId] [int] NOT NULL,
	[Fee] [money] NOT NULL,
	[BillId] [int] NULL,
	[BillDRId] [int] NULL,
	[SiteLocalRequestId] [int] NOT NULL,
 CONSTRAINT [PK_Invoice] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TeleLocalGroup]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TeleLocalGroup](
	[CreatedDate] [datetime] NULL,
	[Name] [nvarchar](50) NULL,
	[Status] [int] NOT NULL,
	[TeleGroupId] [int] NOT NULL,
	[Id] [int] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [PK_TeleLocalGroup_1] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TeleLocalService]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TeleLocalService](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[CreatedDate] [datetime] NOT NULL,
	[TeleLocalGroupId] [int] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[TeleLocalServiceId] [int] NOT NULL,
	[Status] [int] NOT NULL,
	[OrderService] [int] NOT NULL,
 CONSTRAINT [PK_TeleLocalService] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TeleMembers]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TeleMembers](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[CreatedDate] [datetime] NOT NULL,
	[TeleGroupId] [int] NOT NULL,
	[UserId] [int] NOT NULL,
	[IsAdmin] [bit] NULL,
 CONSTRAINT [PK_TeleMembers] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TeleService]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TeleService](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[CreatedDate] [datetime] NOT NULL,
	[ModifiedDate] [datetime] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[Status] [int] NOT NULL,
	[OrderService] [int] NOT NULL,
 CONSTRAINT [PK_TeleService] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TeleSiteLocal]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TeleSiteLocal](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](250) NOT NULL,
	[URL] [varchar](50) NOT NULL,
	[Description] [nvarchar](max) NULL,
	[Status] [int] NOT NULL,
	[AccountName] [nvarchar](50) NULL,
	[AccountPassword] [nvarchar](50) NULL,
	[GroupSiteLocal] [nvarchar](50) NULL,
 CONSTRAINT [PK_TeleSiteLocal] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TeleSiteLocalRequestService]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TeleSiteLocalRequestService](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[SiteLocalId] [int] NOT NULL,
	[TeleGroupId] [int] NOT NULL,
	[TeleServiceId] [int] NOT NULL,
	[DateCreated] [datetime] NOT NULL,
	[Status] [int] NOT NULL,
	[TeleGroupName] [nvarchar](50) NULL,
	[SiteLocalName] [nvarchar](50) NULL,
	[TeleServiceName] [nvarchar](50) NULL,
 CONSTRAINT [PK_TeleSiteLocalRequestService] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TempImageFile]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TempImageFile](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[file_tsuid] [varchar](255) NULL,
	[filepath] [varchar](255) NULL,
	[series_iuid] [varchar](255) NULL,
	[series_desc] [varchar](255) NULL,
	[study_iuid] [varchar](255) NULL,
	[accession_no] [varchar](255) NULL,
	[pat_id] [varchar](255) NULL,
	[pat_name] [varchar](255) NULL,
	[pat_birthdate] [varchar](255) NULL,
	[pat_sex] [varchar](255) NULL,
	[study_datetime] [datetime] NULL,
	[modality] [varchar](255) NULL,
	[DateCreated] [datetime] NOT NULL,
	[Processed] [tinyint] NOT NULL,
 CONSTRAINT [PK_TempImageFile] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TemplateReport]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TemplateReport](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[Description] [nvarchar](500) NULL,
	[TemplateReport] [nvarchar](max) NOT NULL,
	[TemplateReading] [nvarchar](max) NULL,
	[TemplateConclusion] [nvarchar](max) NULL,
	[GroupId] [int] NOT NULL,
	[Modality] [nvarchar](50) NULL,
 CONSTRAINT [PK_TemplateReport] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TemplateReportGroup]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TemplateReportGroup](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[Name] [nvarchar](200) NOT NULL,
	[Description] [nvarchar](2000) NULL,
	[Level] [int] NULL,
	[ParentId] [int] NULL,
	[TemplateReading] [nvarchar](max) NULL,
	[TemplateConclusion] [nvarchar](max) NULL,
	[Modality] [nvarchar](50) NULL,
 CONSTRAINT [PK_TemplateReportGroup] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TemplateReportMaster]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TemplateReportMaster](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[Name] [nvarchar](500) NOT NULL,
	[Content] [nvarchar](max) NOT NULL,
	[Modality] [nvarchar](50) NULL,
	[Send2PMR] [bit] NULL,
	[STT] [int] NULL,
	[Description] [nvarchar](1000) NULL,
 CONSTRAINT [PK_TemplateReportMaster] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TmpCS]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TmpCS](
	[Id] [int] NOT NULL,
	[SeriesCount] [int] NULL,
	[ImageCount] [int] NULL,
	[DateScanned] [datetime] NULL,
 CONSTRAINT [PK_TmpCS] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[UserConfig]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserConfig](
	[UserId] [int] NOT NULL,
	[BarcodeField] [nvarchar](50) NULL,
	[FontSize] [float] NULL,
	[GridFontSize] [float] NULL,
	[HideColumnIndex] [bit] NULL,
	[HideColumnStatusText] [bit] NULL,
	[ClickToEditReport] [bit] NULL,
	[Theme] [nvarchar](500) NULL,
	[ReportFields] [nvarchar](500) NULL,
	[UppercasePatientName] [bit] NULL,
	[ChooseOptionOpen] [smallint] NULL,
 CONSTRAINT [PK_UserConfig] PRIMARY KEY CLUSTERED 
(
	[UserId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[UserFolder]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserFolder](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[UserId] [int] NOT NULL,
	[FolderId] [int] NOT NULL,
 CONSTRAINT [PK_UserFolder] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[UserGroup]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserGroup](
	[Id] [bigint] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](200) NULL,
	[Desc] [nvarchar](200) NULL,
 CONSTRAINT [PK_UserGroup] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[UserGroupMapping]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserGroupMapping](
	[Id] [bigint] IDENTITY(1,1) NOT NULL,
	[GroupId] [bigint] NOT NULL,
	[UserId] [int] NOT NULL,
 CONSTRAINT [PK_UserGroupMapping] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[UserNotificationConfig]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[UserNotificationConfig](
	[UserId] [varchar](50) NOT NULL,
	[WANDomain] [nvarchar](50) NULL,
	[Study_LaBSDoc] [bit] NOT NULL,
	[Study_LaBSDuyet] [bit] NOT NULL,
	[Study_GanLaBSDoc] [bit] NOT NULL,
	[Study_GanLaBSDuyet] [bit] NOT NULL,
	[Study_GuiRequestDoc] [bit] NOT NULL,
	[Status_DangDoc] [bit] NOT NULL,
	[Status_ChoDuyet] [bit] NOT NULL,
	[Status_DangDuyet] [bit] NOT NULL,
	[Status_DaDuyet] [bit] NOT NULL,
	[Status_TaoReportMoi] [bit] NOT NULL,
	[Status_GuiChoChinhToi] [bit] NOT NULL,
	[Assign_BSDoc] [bit] NOT NULL,
	[Assign_BSDuyet] [bit] NOT NULL,
	[Assign_BoGanToi] [bit] NOT NULL,
	[Assign_RequestDocTuXa] [bit] NOT NULL,
	[Assign_GuiChoChinhToi] [bit] NOT NULL,
	[Chat_NhacDenToi] [bit] NOT NULL,
	[Chat_BSDoc] [bit] NOT NULL,
	[Chat_BSDuyet] [bit] NOT NULL,
	[Chat_GuiChoChinhToi] [bit] NOT NULL,
 CONSTRAINT [PK_UserNotificationConfig] PRIMARY KEY CLUSTERED 
(
	[UserId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[UserRole]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[UserRole](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[UserId] [int] NOT NULL,
	[RoleId] [int] NOT NULL,
	[Modalities] [varchar](50) NULL,
 CONSTRAINT [PK_UserRole_1] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Users]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Users](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[Fullname] [nvarchar](50) NOT NULL,
	[Username] [nvarchar](50) NOT NULL,
	[Email] [nvarchar](50) NULL,
	[PhoneNo] [nvarchar](50) NULL,
	[MSAId] [varchar](50) NOT NULL,
	[IsAdmin] [bit] NOT NULL,
	[ApproveConfig] [smallint] NULL,
	[IsDemo] [bit] NULL,
	[IsManager] [bit] NULL,
	[StudyEditable] [bit] NULL,
	[HISCode] [nvarchar](50) NULL
) ON [PRIMARY]
SET ANSI_PADDING OFF
ALTER TABLE [dbo].[Users] ADD [Avatar] [varchar](500) NULL
ALTER TABLE [dbo].[Users] ADD [ASCIIFullname] [varchar](50) NULL
ALTER TABLE [dbo].[Users] ADD [WorkPlace] [nvarchar](255) NULL
ALTER TABLE [dbo].[Users] ADD [isEnable] [bit] NULL
 CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[UsersTele]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UsersTele](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[UserId] [int] NOT NULL,
	[Fullname] [nvarchar](50) NOT NULL,
	[Username] [nvarchar](50) NOT NULL,
	[WorkPlace] [nvarchar](255) NULL,
 CONSTRAINT [PK_UsersTele] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[UserTemplateReport]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserTemplateReport](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[UserId] [int] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[Description] [nvarchar](2000) NULL,
	[Level] [int] NULL,
	[ParentId] [int] NULL,
	[TemplateReading] [nvarchar](max) NULL,
	[TemplateConclusion] [nvarchar](max) NULL,
	[Modality] [nvarchar](50) NULL,
 CONSTRAINT [PK_UserTemplateReport] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Worklist]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Worklist](
	[Id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[PId] [int] NOT NULL,
	[PatientId] [nvarchar](50) NULL,
	[NgayChup] [datetime] NOT NULL,
	[StationId] [int] NULL,
	[Status] [tinyint] NOT NULL,
	[Description] [nvarchar](2000) NULL,
	[Result] [nvarchar](2000) NULL,
	[DoctorId] [int] NULL,
	[DicomId] [varchar](255) NULL,
	[STT] [int] NULL,
	[HISCode] [nvarchar](50) NULL,
	[SiteId] [int] NULL,
	[OrderDoctorId] [int] NULL,
	[ReqProcId] [varchar](30) NULL,
	[AccessionNo] [varchar](20) NULL,
	[StudyInstanceUID] [nvarchar](200) NULL,
	[Modality] [varchar](5) NULL,
	[DateCreated] [datetime] NULL,
	[LastStatus] [tinyint] NULL,
 CONSTRAINT [PK_Worklist] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[WorklistIndex]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[WorklistIndex](
	[Date] [date] NOT NULL,
	[STT] [int] NOT NULL
) ON [PRIMARY]

GO
/****** Object:  View [dbo].[CaseStudyView]    Script Date: 06/04/2021 9:38:42 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE VIEW [dbo].[CaseStudyView]  WITH SCHEMABINDING
AS
SELECT        dbo.CaseStudy.Id, dbo.CaseStudy.DateScanned, dbo.CaseStudy.TeleIsError, dbo.CaseStudy.NoiTru, 
                         dbo.CaseStudy.TeleIsSent, dbo.CaseStudy.Bodypart, dbo.CaseStudy.TenPhongHienThi, dbo.CaseStudy.TenKhoa, dbo.CaseStudy.ChanDoan, dbo.CaseStudy.OrderDoctor, 
                         dbo.CaseStudy.Description, dbo.CaseStudy.Modality, dbo.CaseStudy.HISCode, dbo.CaseStudy.AccessionNo, dbo.CaseStudy.BranchId, dbo.CaseStudy.TeleSiteLocalId, 
                         dbo.CaseStudy.TeleServiceId, dbo.CaseStudy.TeleDateTimeSent, dbo.CaseStudy.StationName, dbo.CaseStudy.Uploaded, dbo.CaseStudy.RequestOutsider, dbo.CaseStudy.DoctorId, dbo.CaseStudy.ApproverId, 
                         dbo.CaseStudy.VisibleAllTime, dbo.CaseStudy.VisiblePriority1Time, dbo.CaseStudy.VisiblePriority2Time, dbo.CaseStudy.Status, dbo.StudyStatus.[Order] AS StatusOrder, 
						 dbo.Worklist.DateCreated AS WLDateCreated, dbo.Worklist.NgayChup AS WLNgayChup, dbo.Patient.Name AS PatientName, dbo.Patient.YOB, dbo.Patient.ReferenceCOde, dbo.Patient.ASCIIName, dbo.Patient.Sex
FROM            dbo.CaseStudy INNER JOIN
                         dbo.StudyStatus ON dbo.CaseStudy.Status = dbo.StudyStatus.Id INNER JOIN
                         dbo.Patient ON dbo.CaseStudy.PatientId = dbo.Patient.Id INNER JOIN
                         dbo.Worklist ON dbo.CaseStudy.WorklistId = dbo.Worklist.Id
WHERE StudyType <> 1



GO
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET NUMERIC_ROUNDABORT OFF

GO
/****** Object:  Index [CaseStudyView_Index_Id]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE UNIQUE CLUSTERED INDEX [CaseStudyView_Index_Id] ON [dbo].[CaseStudyView]
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[BodyPart] ON 

GO
INSERT [dbo].[BodyPart] ([Id], [Name], [Code], [Modality], [Keyword]) VALUES (1, N'HEAD', N'HEAD', N'CT,MR', N'sọ não, đầu, xoang')
GO
INSERT [dbo].[BodyPart] ([Id], [Name], [Code], [Modality], [Keyword]) VALUES (2, N'SKULL', N'SKULL', N'DX,DR,CR,CX', N'sọ não, đầu, xương sọ, hộp sọ, hàm mặt')
GO
INSERT [dbo].[BodyPart] ([Id], [Name], [Code], [Modality], [Keyword]) VALUES (3, N'CHEST', N'CHEST', N'ALL', N'tim phổi, ngực, phổi, trung thất, lồng ngực')
GO
INSERT [dbo].[BodyPart] ([Id], [Name], [Code], [Modality], [Keyword]) VALUES (4, N'ABDOMEN', N'ABDOMEN', N'ALL', N'ổ bụng, gan mật, tiêu hóa')
GO
INSERT [dbo].[BodyPart] ([Id], [Name], [Code], [Modality], [Keyword]) VALUES (5, N'CSPINE', N'CSPINE', N'ALL', N'cột sống cổ, csc')
GO
INSERT [dbo].[BodyPart] ([Id], [Name], [Code], [Modality], [Keyword]) VALUES (6, N'LSPINE', N'LSPINE', N'ALL', N'cột sống thắt lưng, cstl')
GO
INSERT [dbo].[BodyPart] ([Id], [Name], [Code], [Modality], [Keyword]) VALUES (7, N'KNEE', N'KNEE', N'ALL', N'khớp gối')
GO
INSERT [dbo].[BodyPart] ([Id], [Name], [Code], [Modality], [Keyword]) VALUES (8, N'ANKLE', N'ANKLE', N'ALL', N'cổ chân, cẳng chân')
GO
INSERT [dbo].[BodyPart] ([Id], [Name], [Code], [Modality], [Keyword]) VALUES (9, N'FOOT', N'FOOT', N'ALL', N'bàn chân')
GO
INSERT [dbo].[BodyPart] ([Id], [Name], [Code], [Modality], [Keyword]) VALUES (10, N'WRIST', N'WRIST', N'ALL', N'cổ tay, khuỷu tay')
GO
INSERT [dbo].[BodyPart] ([Id], [Name], [Code], [Modality], [Keyword]) VALUES (11, N'HAND', N'HAND', N'ALL', N'bàn tay')
GO
INSERT [dbo].[BodyPart] ([Id], [Name], [Code], [Modality], [Keyword]) VALUES (12, N'PELVIS', N'PELVIS', N'ALL', N'tiểu khung, xương chậu, khung chậu, khớp háng')
GO
INSERT [dbo].[BodyPart] ([Id], [Name], [Code], [Modality], [Keyword]) VALUES (13, N'HIP', N'HIP', N'ALL', N'xương đùi')
GO
SET IDENTITY_INSERT [dbo].[BodyPart] OFF
GO
SET IDENTITY_INSERT [dbo].[FilterStation] ON 

GO
INSERT [dbo].[FilterStation] ([Id], [Name], [Display], [Type], [HISCode], [DisplayName], [BranchId], [AETitle], [Keyword], [SiteId], [PrintTitle], [Modalities]) VALUES (20, N'ct99', 1, 2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
GO
SET IDENTITY_INSERT [dbo].[FilterStation] OFF
GO
SET IDENTITY_INSERT [dbo].[ModalityGroup] ON 

GO
INSERT [dbo].[ModalityGroup] ([Id], [GroupName], [Modalities], [Order], [Type]) VALUES (1, N'X-Quang', N'DX, DR, DRo, CR', NULL, 1)
GO
INSERT [dbo].[ModalityGroup] ([Id], [GroupName], [Modalities], [Order], [Type]) VALUES (2, N'CT', N'CT', NULL, 2)
GO
INSERT [dbo].[ModalityGroup] ([Id], [GroupName], [Modalities], [Order], [Type]) VALUES (3, N'MRI', N'MR', NULL, 3)
GO
INSERT [dbo].[ModalityGroup] ([Id], [GroupName], [Modalities], [Order], [Type]) VALUES (4, N'SA', N'US, SA', NULL, 4)
GO
SET IDENTITY_INSERT [dbo].[ModalityGroup] OFF
GO
SET IDENTITY_INSERT [dbo].[OSWorklist] ON 

GO
INSERT [dbo].[OSWorklist] ([Id], [Code], [Modality], [Description], [Status], [PatientPMRCode], [PatientCode], [PatientVisitCode], [PatientName], [PatientDOB], [PatientYOB], [PatientAddress], [PatientSex], [PatientEthnic], [PatientPhoneNo], [PatientJob], [PatientProvince], [SystemCode], [VisitReason], [VisitHistory], [VisitDate], [DateCreated], [PatientId], [WorklistId], [CaseStudyId], [Processed], [TenPhongHienThi], [TenKhoa], [SoTheBHYT], [NgayBatDau], [NgayHetHan], [ChanDoan], [TenGiuong], [TenBuong], [NoiTru], [SiteCode], [VisitCode], [OrderDoctor], [OrderDoctorPhoneNo], [ServiceId], [AdditionalInfo], [STT], [PhongThucHien], [PatientNote], [PatientAltId], [OBRId], [OrderDate], [ORCCode]) VALUES (1, N'', N'', N'', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, CAST(0x070000000000DAB937 AS DateTime2), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
GO
SET IDENTITY_INSERT [dbo].[OSWorklist] OFF
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (1, N'Điều phối viên')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (2, N'Bác sĩ')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (3, N'Bác sĩ duyệt')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (4, N'Xem PACS Viewer full')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (5, N'Bác sĩ đọc')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (6, N'Demo')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (7, N'Quản lý')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (8, N'Sửa thông tin ca chụp')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (9, N'Bác sĩ đọc từ xa')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (10, N'Yêu cầu đọc từ xa')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (12, N'Assign')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (13, N'Quản lý branch')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (14, N'Quản lý user')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (15, N'Quản lý group')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (16, N'Quản lý mẫu báo cáo / mẫu in')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (17, N'Quản lý site')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (18, N'Quản lý trạng trái ca chụp')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (19, N'Quản lý DS BS chỉ định')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (20, N'Quản lý log ca chụp')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (21, N'Share ca chụp')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (22, N'Cấu hình hệ thống')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (23, N'Sửa kết quả khi in')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (99, N'Admin')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (100, N'Yêu cầu đọc từ xa - telemedicin')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (101, N'Quản lý group BS')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (102, N'Quản lý site PACS Local')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (103, N'Quản lý invoice')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (104, N'Quản lý dịch vụ đọc')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (105, N'Quản lý thanh toán')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (106, N'Đẩy file DICOM sang hệ thống khác')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (107, N'Bác sĩ giám sát')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (108, N'Thêm thông tin lâm sàng')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (109, N'Lọc thống kê')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (110, N'Điều phối user')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (111, N'In báo cáo')
GO
INSERT [dbo].[Role] ([Id], [Name]) VALUES (112, N'Không đổi được mật khẩu')
GO
SET IDENTITY_INSERT [dbo].[Station] ON 

GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (1, NULL, N'Siêu âm', NULL, NULL, N'US', N'US', N'US', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (2, NULL, N'CT', NULL, NULL, N'CT', N'CT', N'CT', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (3, NULL, N'CR', NULL, NULL, N'CR', N'CR', N'CR', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (4, NULL, N'DR', NULL, NULL, N'DR', N'DR', N'DR', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (5, NULL, N'MR', NULL, NULL, N'MR', N'MR', N'MR', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (6, NULL, N'DX', NULL, NULL, N'DX', N'DX', N'DX', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (7, NULL, N'MG', NULL, NULL, N'MG', N'MG', N'MG', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (8, NULL, N'ES', NULL, NULL, N'ES', N'ES', N'ES', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (9, NULL, N'XA', NULL, NULL, N'XA', N'XA', N'XA', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (10, NULL, N'RF', NULL, NULL, N'RF', N'RF', N'RF', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (11, NULL, N'BM', NULL, NULL, N'BM', N'BM', N'BM', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (12, NULL, N'BI', NULL, NULL, N'BI', N'BI', N'BI', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (13, NULL, N'PT', NULL, NULL, N'PT', N'PT', N'PT', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (14, NULL, N'PX', NULL, NULL, N'PX', N'PX', N'PX', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (15, NULL, N'GM', NULL, NULL, N'GM', N'GM', N'GM', NULL, N'', 0, NULL)
GO
INSERT [dbo].[Station] ([Id], [DicomId], [Name], [IP], [Port], [AETitle], [Modality], [OtherModality], [DefaultCode], [Description], [HL7Name], [OrderMapping]) VALUES (16, NULL, N'SM', NULL, NULL, N'SM', N'SM', N'SM', NULL, N'', 0, NULL)
GO
SET IDENTITY_INSERT [dbo].[Station] OFF
GO
INSERT [dbo].[StudyStatus] ([Id], [Name], [Order]) VALUES (0, N'Queue', 100)
GO
INSERT [dbo].[StudyStatus] ([Id], [Name], [Order]) VALUES (10, N'Started', 101)
GO
INSERT [dbo].[StudyStatus] ([Id], [Name], [Order]) VALUES (20, N'Completed', 0)
GO
INSERT [dbo].[StudyStatus] ([Id], [Name], [Order]) VALUES (30, N'Reporting', 10)
GO
INSERT [dbo].[StudyStatus] ([Id], [Name], [Order]) VALUES (35, N'Reporting_Tele', 11)
GO
INSERT [dbo].[StudyStatus] ([Id], [Name], [Order]) VALUES (40, N'Reported', 20)
GO
INSERT [dbo].[StudyStatus] ([Id], [Name], [Order]) VALUES (45, N'Approving', 30)
GO
INSERT [dbo].[StudyStatus] ([Id], [Name], [Order]) VALUES (50, N'Approved', 40)
GO
INSERT [dbo].[StudyStatus] ([Id], [Name], [Order]) VALUES (55, N'Reported_Tele', 21)
GO
INSERT [dbo].[StudyStatus] ([Id], [Name], [Order]) VALUES (60, N'Canceled_Tele', 22)
GO
INSERT [dbo].[StudyStatus] ([Id], [Name], [Order]) VALUES (65, N'Error_Tele', 1)
GO
SET IDENTITY_INSERT [dbo].[TempImageFile] ON 

GO
INSERT [dbo].[TempImageFile] ([Id], [file_tsuid], [filepath], [series_iuid], [series_desc], [study_iuid], [accession_no], [pat_id], [pat_name], [pat_birthdate], [pat_sex], [study_datetime], [modality], [DateCreated], [Processed]) VALUES (1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, CAST(0x002D247F00000000 AS DateTime), 2)
GO
SET IDENTITY_INSERT [dbo].[TempImageFile] OFF
GO
INSERT [dbo].[UserConfig] ([UserId], [BarcodeField], [FontSize], [GridFontSize], [HideColumnIndex], [HideColumnStatusText], [ClickToEditReport], [Theme], [ReportFields], [UppercasePatientName], [ChooseOptionOpen]) VALUES (1, N'PatientCode', 14, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[UserConfig] ([UserId], [BarcodeField], [FontSize], [GridFontSize], [HideColumnIndex], [HideColumnStatusText], [ClickToEditReport], [Theme], [ReportFields], [UppercasePatientName], [ChooseOptionOpen]) VALUES (2, N'', 12, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[UserConfig] ([UserId], [BarcodeField], [FontSize], [GridFontSize], [HideColumnIndex], [HideColumnStatusText], [ClickToEditReport], [Theme], [ReportFields], [UppercasePatientName], [ChooseOptionOpen]) VALUES (4, N'', 14, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[WorklistIndex] ([Date], [STT]) VALUES (CAST(0x2A3F0B00 AS Date), 18)
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [CaseStudy_Accs_No_idx]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [CaseStudy_Accs_No_idx] ON [dbo].[CaseStudy]
(
	[AccessionNo] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [CaseStudy_DateScanned_idx]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [CaseStudy_DateScanned_idx] ON [dbo].[CaseStudy]
(
	[DateScanned] DESC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [CaseStudy_DicomId_idx]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [CaseStudy_DicomId_idx] ON [dbo].[CaseStudy]
(
	[DicomId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [CaseStudy_Modality_Idx]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [CaseStudy_Modality_Idx] ON [dbo].[CaseStudy]
(
	[Modality] ASC
)
INCLUDE ( 	[Id],
	[DicomId],
	[WorklistId],
	[Status],
	[KTVId],
	[PatientId],
	[StationId],
	[DoctorId],
	[ApproverId],
	[Description],
	[Bodypart],
	[Result],
	[Report],
	[ReportContent],
	[SeriesCount],
	[ImageCount],
	[DateScanned],
	[TemplateReportId],
	[TemplateReportMasterId],
	[AccessionNo],
	[HISVisitId],
	[ReportReading],
	[Conclusion],
	[TenPhongHienThi],
	[TenKhoa],
	[ChanDoan],
	[TenGiuong],
	[TenBuong],
	[DraftReading],
	[DraftConclusion],
	[LastDraftDate],
	[LastReadingDate],
	[LastApproveDate],
	[StationName],
	[Printed],
	[LinkReportId],
	[LastReportId],
	[NoiTru],
	[SPSId],
	[ReqProcId],
	[SoTheBHYT],
	[NgayBatDau],
	[NgayHetHan],
	[SiteId],
	[RequestOutsider],
	[OutsiderRead],
	[OutsiderApproved],
	[PMRReportId],
	[OrderDoctorId],
	[Assigned],
	[BranchId],
	[AssignHideName],
	[UnMatched],
	[OrderDoctor],
	[HISCode],
	[Uploaded],
	[OrderDoctorPhoneNo],
	[DateUploaded],
	[StudyType],
	[TeleEmergencyLevel],
	[TeleGroupId],
	[TeleServiceId],
	[TeleDescription],
	[MergedStudyIds],
	[TeleIsSent],
	[TeleLocalStudyId],
	[TeleSiteLocalId],
	[TeleDateTimeSent]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [CaseStudy_StationName_idx]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [CaseStudy_StationName_idx] ON [dbo].[CaseStudy]
(
	[StationName] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [CaseStudy_Status_idx]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [CaseStudy_Status_idx] ON [dbo].[CaseStudy]
(
	[Status] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [CaseStudy_TeleIsSent]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [CaseStudy_TeleIsSent] ON [dbo].[CaseStudy]
(
	[TeleIsSent] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [NonClusteredIndex-20190226-150913]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20190226-150913] ON [dbo].[CaseStudy]
(
	[WorklistId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [NonClusteredIndex-20190509-124845]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20190509-124845] ON [dbo].[CaseStudy]
(
	[RequestOutsider] ASC
)
INCLUDE ( 	[Id],
	[WorklistId],
	[PatientId],
	[StationId],
	[DoctorId],
	[ApproverId]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [NonClusteredIndex-20190624-091449]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20190624-091449] ON [dbo].[CaseStudy]
(
	[PatientId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [NonClusteredIndex-20190704-103607]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20190704-103607] ON [dbo].[CaseStudy]
(
	[Uploaded] ASC,
	[StudyType] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [NonClusteredIndex-CaseStudy-DateScanned]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-CaseStudy-DateScanned] ON [dbo].[CaseStudy]
(
	[DateScanned] DESC,
	[StudyType] ASC
)
INCLUDE ( 	[Id],
	[DicomId],
	[WorklistId],
	[Status],
	[KTVId],
	[PatientId],
	[StationId],
	[DoctorId],
	[ApproverId],
	[Description],
	[Bodypart],
	[Result],
	[Report],
	[ReportContent],
	[SeriesCount],
	[ImageCount],
	[TemplateReportId],
	[TemplateReportMasterId],
	[AccessionNo],
	[HISVisitId],
	[ReportReading],
	[Conclusion],
	[TenPhongHienThi],
	[TenKhoa],
	[ChanDoan],
	[TenGiuong],
	[TenBuong],
	[DraftReading],
	[DraftConclusion],
	[LastDraftDate],
	[Modality],
	[LastReadingDate],
	[LastApproveDate],
	[StationName],
	[Printed],
	[LinkReportId],
	[LastReportId],
	[NoiTru],
	[SPSId],
	[ReqProcId],
	[SoTheBHYT],
	[NgayBatDau],
	[NgayHetHan],
	[SiteId],
	[RequestOutsider],
	[OutsiderRead],
	[OutsiderApproved],
	[PMRReportId],
	[OrderDoctorId],
	[Assigned],
	[BranchId],
	[AssignHideName],
	[UnMatched],
	[OrderDoctor],
	[HISCode],
	[Uploaded],
	[OrderDoctorPhoneNo],
	[DateUploaded],
	[TeleEmergencyLevel],
	[TeleGroupId],
	[TeleServiceId],
	[TeleDescription],
	[MergedStudyIds],
	[TeleIsSent],
	[TeleLocalStudyId],
	[TeleSiteLocalId],
	[TeleDateTimeSent],
	[TeleIsVisible]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [NonClusteredIndex-20190703-142849]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20190703-142849] ON [dbo].[DailyUserLog]
(
	[Date] ASC,
	[UserId] ASC
)
INCLUDE ( 	[Id],
	[ActiveTime],
	[StudyOpened],
	[ReportCreated]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [ImageFile_StudyId_Idx]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [ImageFile_StudyId_Idx] ON [dbo].[ImageFile]
(
	[StudyId] ASC
)
INCLUDE ( 	[Id],
	[DicomId],
	[SeriesId],
	[FilePath],
	[FileZipPath],
	[LocalPath],
	[FileImagePath],
	[Send2HIS],
	[SOP_IUID],
	[SOP_CUID],
	[InstanceNo],
	[Attributes],
	[DateCreated],
	[Processed]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [NonClusteredIndex-20181011-155441]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20181011-155441] ON [dbo].[ImageFile]
(
	[SOP_IUID] ASC
)
INCLUDE ( 	[Id],
	[DicomId],
	[SeriesId],
	[FilePath],
	[FileZipPath],
	[LocalPath],
	[StudyId],
	[FileImagePath],
	[Send2HIS],
	[SOP_CUID],
	[InstanceNo],
	[Attributes],
	[DateCreated],
	[Processed],
	[NotStored]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [NonClusteredIndex-ImageFile-SeriesId]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-ImageFile-SeriesId] ON [dbo].[ImageFile]
(
	[SeriesId] ASC
)
INCLUDE ( 	[Id],
	[DicomId],
	[FilePath],
	[FileZipPath],
	[LocalPath],
	[StudyId],
	[FileImagePath],
	[Send2HIS],
	[SOP_IUID],
	[SOP_CUID],
	[InstanceNo],
	[Attributes],
	[DateCreated],
	[Processed],
	[NotStored],
	[Modified],
	[TeleLocalImageFileId],
	[TeleSiteLocalId]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [NonClusteredIndex-ImageFile2Tele-StudyId]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-ImageFile2Tele-StudyId] ON [dbo].[ImageFile2Tele]
(
	[StudyId] ASC,
	[FileId] ASC
)
INCLUDE ( 	[Id],
	[Status],
	[DateCreated]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [NonClusteredIndex-20190507-104403]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20190507-104403] ON [dbo].[OriginalDicomData]
(
	[StudyId] ASC,
	[SeriesId] ASC
)
INCLUDE ( 	[Id],
	[FileId],
	[Data]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [OS_Worklist_CaseStudyId]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [OS_Worklist_CaseStudyId] ON [dbo].[OSWorklist]
(
	[CaseStudyId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [OS_Worklist_Code]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [OS_Worklist_Code] ON [dbo].[OSWorklist]
(
	[Code] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [Patient_Code_Idx]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE UNIQUE NONCLUSTERED INDEX [Patient_Code_Idx] ON [dbo].[Patient]
(
	[Code] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [Patient_ReferenceCOde_Idx]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [Patient_ReferenceCOde_Idx] ON [dbo].[Patient]
(
	[ReferenceCOde] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [NonClusteredIndex-20190226-164828]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20190226-164828] ON [dbo].[Series]
(
	[StudyId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [Series_DicomId_idx]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [Series_DicomId_idx] ON [dbo].[Series]
(
	[DicomId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [NonClusteredIndex-20190226-164643]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20190226-164643] ON [dbo].[StudyReport]
(
	[StudyId] ASC
)
INCLUDE ( 	[Id],
	[Reading],
	[Conclusion],
	[LinkStudyId],
	[Status],
	[DoctorId],
	[ApproverId],
	[DraftReading],
	[DraftConclusion],
	[LastDraftDate],
	[LastReadingDate],
	[LastApproveDate],
	[DateCreated],
	[OutsiderRead],
	[OutsiderApproved],
	[FirstApproveDate]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [TempImageFile_StudyIUID_idx]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [TempImageFile_StudyIUID_idx] ON [dbo].[TempImageFile]
(
	[study_iuid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON

GO
/****** Object:  Index [NonClusteredIndex-20190425-145403]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20190425-145403] ON [dbo].[Worklist]
(
	[HISCode] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [Worklist_NgayChup_idx]    Script Date: 06/04/2021 9:38:42 AM ******/
CREATE NONCLUSTERED INDEX [Worklist_NgayChup_idx] ON [dbo].[Worklist]
(
	[NgayChup] DESC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE [dbo].[AccountToken] ADD  CONSTRAINT [DF_AccountToken_DateCreated]  DEFAULT (getdate()) FOR [DateCreated]
GO
ALTER TABLE [dbo].[Branch] ADD  CONSTRAINT [DF_Branch_Active]  DEFAULT ((1)) FOR [Active]
GO
ALTER TABLE [dbo].[BranchUser] ADD  CONSTRAINT [DF_BranchUser_Active]  DEFAULT ((1)) FOR [Active]
GO
ALTER TABLE [dbo].[CaseStudy] ADD  CONSTRAINT [Default_StudyType]  DEFAULT ((0)) FOR [StudyType]
GO
ALTER TABLE [dbo].[EditPatientLog] ADD  CONSTRAINT [DF_EditPatientLog_DateCreated]  DEFAULT (getdate()) FOR [DateCreated]
GO
ALTER TABLE [dbo].[FilterStation] ADD  CONSTRAINT [DF_FilterStation_Display]  DEFAULT ((1)) FOR [Display]
GO
ALTER TABLE [dbo].[ImageFile] ADD  CONSTRAINT [DF_ImageFile_DateCreated]  DEFAULT (getdate()) FOR [DateCreated]
GO
ALTER TABLE [dbo].[ImageFile] ADD  CONSTRAINT [DF_ImageFile_Processed]  DEFAULT ((0)) FOR [Processed]
GO
ALTER TABLE [dbo].[ImageFile2Tele] ADD  CONSTRAINT [DF_ImageFile2Tele_DateCreated]  DEFAULT (getdate()) FOR [DateCreated]
GO
ALTER TABLE [dbo].[JobQueue] ADD  CONSTRAINT [DF_JobQueue_DateCreated]  DEFAULT (getdate()) FOR [DateCreated]
GO
ALTER TABLE [dbo].[LanguageResource] ADD  CONSTRAINT [DF_LanguageResource_Value]  DEFAULT ('') FOR [Value]
GO
ALTER TABLE [dbo].[MergeStudyLog] ADD  CONSTRAINT [DF_MergeStudyLog_DateCreated]  DEFAULT (getdate()) FOR [DateCreated]
GO
ALTER TABLE [dbo].[Note] ADD  CONSTRAINT [DF_Note_DateCreated]  DEFAULT (getdate()) FOR [DateCreated]
GO
ALTER TABLE [dbo].[OSWorklist] ADD  CONSTRAINT [DF_OSWorklist_DateCreated]  DEFAULT (getdate()) FOR [DateCreated]
GO
ALTER TABLE [dbo].[OSWorklist] ADD  CONSTRAINT [DF_OSWorklist_Processed]  DEFAULT ((0)) FOR [Processed]
GO
ALTER TABLE [dbo].[StudyLog] ADD  CONSTRAINT [DF_StudyLog_DateCreated]  DEFAULT (getdate()) FOR [DateCreated]
GO
ALTER TABLE [dbo].[StudyReport] ADD  CONSTRAINT [DF_StudyReport_DateCreated]  DEFAULT (getdate()) FOR [DateCreated]
GO
ALTER TABLE [dbo].[StudyViewing] ADD  CONSTRAINT [DF_StudyViewing_DateView]  DEFAULT (getdate()) FOR [DateView]
GO
ALTER TABLE [dbo].[TeleGroupService] ADD  DEFAULT ((0)) FOR [OrderService]
GO
ALTER TABLE [dbo].[TeleLocalService] ADD  DEFAULT ((0)) FOR [OrderService]
GO
ALTER TABLE [dbo].[TeleService] ADD  DEFAULT ((0)) FOR [OrderService]
GO
ALTER TABLE [dbo].[TempImageFile] ADD  CONSTRAINT [DF_TempImageFile_DateCreated]  DEFAULT (getdate()) FOR [DateCreated]
GO
ALTER TABLE [dbo].[TempImageFile] ADD  CONSTRAINT [DF_TempImageFile_Processed]  DEFAULT ((0)) FOR [Processed]
GO
ALTER TABLE [dbo].[AccountToken]  WITH CHECK ADD  CONSTRAINT [FK_AccountToken_AccountToken] FOREIGN KEY([Id])
REFERENCES [dbo].[AccountToken] ([Id])
GO
ALTER TABLE [dbo].[AccountToken] CHECK CONSTRAINT [FK_AccountToken_AccountToken]
GO
ALTER TABLE [dbo].[Annotation]  WITH CHECK ADD  CONSTRAINT [FK_Annotation_Series] FOREIGN KEY([SeriesId])
REFERENCES [dbo].[Series] ([Id])
GO
ALTER TABLE [dbo].[Annotation] CHECK CONSTRAINT [FK_Annotation_Series]
GO
ALTER TABLE [dbo].[BranchUser]  WITH CHECK ADD  CONSTRAINT [FK_BranchUser_Branch] FOREIGN KEY([BranchId])
REFERENCES [dbo].[Branch] ([Id])
GO
ALTER TABLE [dbo].[BranchUser] CHECK CONSTRAINT [FK_BranchUser_Branch]
GO
ALTER TABLE [dbo].[BranchUser]  WITH CHECK ADD  CONSTRAINT [FK_BranchUser_Users] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[BranchUser] CHECK CONSTRAINT [FK_BranchUser_Users]
GO
ALTER TABLE [dbo].[CaseStudy]  WITH CHECK ADD  CONSTRAINT [FK_CaseStudy_Branch] FOREIGN KEY([BranchId])
REFERENCES [dbo].[Branch] ([Id])
GO
ALTER TABLE [dbo].[CaseStudy] CHECK CONSTRAINT [FK_CaseStudy_Branch]
GO
ALTER TABLE [dbo].[CaseStudy]  WITH CHECK ADD  CONSTRAINT [FK_CaseStudy_Patient] FOREIGN KEY([PatientId])
REFERENCES [dbo].[Patient] ([Id])
GO
ALTER TABLE [dbo].[CaseStudy] CHECK CONSTRAINT [FK_CaseStudy_Patient]
GO
ALTER TABLE [dbo].[CaseStudy]  WITH CHECK ADD  CONSTRAINT [FK_CaseStudy_Site] FOREIGN KEY([SiteId])
REFERENCES [dbo].[Site] ([Id])
GO
ALTER TABLE [dbo].[CaseStudy] CHECK CONSTRAINT [FK_CaseStudy_Site]
GO
ALTER TABLE [dbo].[CaseStudy]  WITH CHECK ADD  CONSTRAINT [FK_CaseStudy_Station] FOREIGN KEY([StationId])
REFERENCES [dbo].[Station] ([Id])
GO
ALTER TABLE [dbo].[CaseStudy] CHECK CONSTRAINT [FK_CaseStudy_Station]
GO
ALTER TABLE [dbo].[CaseStudy]  WITH CHECK ADD  CONSTRAINT [FK_CaseStudy_StudyStatus] FOREIGN KEY([Status])
REFERENCES [dbo].[StudyStatus] ([Id])
GO
ALTER TABLE [dbo].[CaseStudy] CHECK CONSTRAINT [FK_CaseStudy_StudyStatus]
GO
ALTER TABLE [dbo].[CaseStudy]  WITH CHECK ADD  CONSTRAINT [FK_CaseStudy_TemplateReport] FOREIGN KEY([TemplateReportId])
REFERENCES [dbo].[TemplateReport] ([Id])
GO
ALTER TABLE [dbo].[CaseStudy] CHECK CONSTRAINT [FK_CaseStudy_TemplateReport]
GO
ALTER TABLE [dbo].[CaseStudy]  WITH CHECK ADD  CONSTRAINT [FK_CaseStudy_TemplateReportMaster] FOREIGN KEY([TemplateReportMasterId])
REFERENCES [dbo].[TemplateReportMaster] ([Id])
GO
ALTER TABLE [dbo].[CaseStudy] CHECK CONSTRAINT [FK_CaseStudy_TemplateReportMaster]
GO
ALTER TABLE [dbo].[CaseStudy]  WITH CHECK ADD  CONSTRAINT [FK_CaseStudy_Worklist] FOREIGN KEY([WorklistId])
REFERENCES [dbo].[Worklist] ([Id])
GO
ALTER TABLE [dbo].[CaseStudy] CHECK CONSTRAINT [FK_CaseStudy_Worklist]
GO
ALTER TABLE [dbo].[CaseStudyDrug]  WITH CHECK ADD  CONSTRAINT [FK_CaseStudyDrug_CaseStudy] FOREIGN KEY([CaseStudyId])
REFERENCES [dbo].[CaseStudy] ([Id])
GO
ALTER TABLE [dbo].[CaseStudyDrug] CHECK CONSTRAINT [FK_CaseStudyDrug_CaseStudy]
GO
ALTER TABLE [dbo].[CaseStudyDrug]  WITH CHECK ADD  CONSTRAINT [FK_CaseStudyDrug_Drug] FOREIGN KEY([DrugId])
REFERENCES [dbo].[Drug] ([Id])
GO
ALTER TABLE [dbo].[CaseStudyDrug] CHECK CONSTRAINT [FK_CaseStudyDrug_Drug]
GO
ALTER TABLE [dbo].[CustomerExportColumn]  WITH CHECK ADD  CONSTRAINT [FK_CustomerExportColumn_Users] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[CustomerExportColumn] CHECK CONSTRAINT [FK_CustomerExportColumn_Users]
GO
ALTER TABLE [dbo].[EditPatientDetail]  WITH CHECK ADD  CONSTRAINT [FK_EditPatientDetail_EditPatientLog] FOREIGN KEY([LogId])
REFERENCES [dbo].[EditPatientLog] ([Id])
GO
ALTER TABLE [dbo].[EditPatientDetail] CHECK CONSTRAINT [FK_EditPatientDetail_EditPatientLog]
GO
ALTER TABLE [dbo].[FilterStation]  WITH CHECK ADD  CONSTRAINT [FK_FilterStation_Branch] FOREIGN KEY([BranchId])
REFERENCES [dbo].[Branch] ([Id])
GO
ALTER TABLE [dbo].[FilterStation] CHECK CONSTRAINT [FK_FilterStation_Branch]
GO
ALTER TABLE [dbo].[FilterStation]  WITH CHECK ADD  CONSTRAINT [FK_FilterStation_Site] FOREIGN KEY([SiteId])
REFERENCES [dbo].[Site] ([Id])
GO
ALTER TABLE [dbo].[FilterStation] CHECK CONSTRAINT [FK_FilterStation_Site]
GO
ALTER TABLE [dbo].[FolderStudy]  WITH CHECK ADD  CONSTRAINT [FK_FolderStudy_CaseStudy] FOREIGN KEY([StudyId])
REFERENCES [dbo].[CaseStudy] ([Id])
GO
ALTER TABLE [dbo].[FolderStudy] CHECK CONSTRAINT [FK_FolderStudy_CaseStudy]
GO
ALTER TABLE [dbo].[FolderStudy]  WITH CHECK ADD  CONSTRAINT [FK_FolderStudy_Folder] FOREIGN KEY([FolderId])
REFERENCES [dbo].[Folder] ([Id])
GO
ALTER TABLE [dbo].[FolderStudy] CHECK CONSTRAINT [FK_FolderStudy_Folder]
GO
ALTER TABLE [dbo].[GroupRole]  WITH CHECK ADD  CONSTRAINT [FK_GroupRole_Role] FOREIGN KEY([RoleId])
REFERENCES [dbo].[Role] ([Id])
GO
ALTER TABLE [dbo].[GroupRole] CHECK CONSTRAINT [FK_GroupRole_Role]
GO
ALTER TABLE [dbo].[GroupRole]  WITH CHECK ADD  CONSTRAINT [FK_GroupRole_UserGroup] FOREIGN KEY([GroupId])
REFERENCES [dbo].[UserGroup] ([Id])
GO
ALTER TABLE [dbo].[GroupRole] CHECK CONSTRAINT [FK_GroupRole_UserGroup]
GO
ALTER TABLE [dbo].[ImageFile]  WITH CHECK ADD  CONSTRAINT [FK_ImageFile_CaseStudy] FOREIGN KEY([StudyId])
REFERENCES [dbo].[CaseStudy] ([Id])
GO
ALTER TABLE [dbo].[ImageFile] CHECK CONSTRAINT [FK_ImageFile_CaseStudy]
GO
ALTER TABLE [dbo].[ImageFile]  WITH CHECK ADD  CONSTRAINT [FK_ImageFile_Series] FOREIGN KEY([SeriesId])
REFERENCES [dbo].[Series] ([Id])
GO
ALTER TABLE [dbo].[ImageFile] CHECK CONSTRAINT [FK_ImageFile_Series]
GO
ALTER TABLE [dbo].[Note]  WITH CHECK ADD  CONSTRAINT [FK_Note_CaseStudy] FOREIGN KEY([StudyId])
REFERENCES [dbo].[CaseStudy] ([Id])
GO
ALTER TABLE [dbo].[Note] CHECK CONSTRAINT [FK_Note_CaseStudy]
GO
ALTER TABLE [dbo].[Note]  WITH CHECK ADD  CONSTRAINT [FK_Note_Users] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[Note] CHECK CONSTRAINT [FK_Note_Users]
GO
ALTER TABLE [dbo].[Role]  WITH CHECK ADD  CONSTRAINT [FK_Role_Role] FOREIGN KEY([Id])
REFERENCES [dbo].[Role] ([Id])
GO
ALTER TABLE [dbo].[Role] CHECK CONSTRAINT [FK_Role_Role]
GO
ALTER TABLE [dbo].[Series]  WITH CHECK ADD  CONSTRAINT [FK_Series_CaseStudy] FOREIGN KEY([StudyId])
REFERENCES [dbo].[CaseStudy] ([Id])
GO
ALTER TABLE [dbo].[Series] CHECK CONSTRAINT [FK_Series_CaseStudy]
GO
ALTER TABLE [dbo].[Site]  WITH CHECK ADD  CONSTRAINT [FK_Site_Branch] FOREIGN KEY([BranchId])
REFERENCES [dbo].[Branch] ([Id])
GO
ALTER TABLE [dbo].[Site] CHECK CONSTRAINT [FK_Site_Branch]
GO
ALTER TABLE [dbo].[StudyChangeLog]  WITH CHECK ADD  CONSTRAINT [FK_StudyChangeLog_StudyLog] FOREIGN KEY([LogId])
REFERENCES [dbo].[StudyLog] ([Id])
GO
ALTER TABLE [dbo].[StudyChangeLog] CHECK CONSTRAINT [FK_StudyChangeLog_StudyLog]
GO
ALTER TABLE [dbo].[StudyImages]  WITH CHECK ADD  CONSTRAINT [FK_StudyImages_CaseStudy] FOREIGN KEY([CaseStudyId])
REFERENCES [dbo].[CaseStudy] ([Id])
GO
ALTER TABLE [dbo].[StudyImages] CHECK CONSTRAINT [FK_StudyImages_CaseStudy]
GO
ALTER TABLE [dbo].[StudyLog]  WITH CHECK ADD  CONSTRAINT [FK_StudyLog_CaseStudy] FOREIGN KEY([StudyId])
REFERENCES [dbo].[CaseStudy] ([Id])
GO
ALTER TABLE [dbo].[StudyLog] CHECK CONSTRAINT [FK_StudyLog_CaseStudy]
GO
ALTER TABLE [dbo].[StudyReport]  WITH CHECK ADD  CONSTRAINT [FK_StudyReport_CaseStudy] FOREIGN KEY([StudyId])
REFERENCES [dbo].[CaseStudy] ([Id])
GO
ALTER TABLE [dbo].[StudyReport] CHECK CONSTRAINT [FK_StudyReport_CaseStudy]
GO
ALTER TABLE [dbo].[StudyReportLink]  WITH CHECK ADD  CONSTRAINT [FK_StudyReportLink_CaseStudy] FOREIGN KEY([StudyId])
REFERENCES [dbo].[CaseStudy] ([Id])
GO
ALTER TABLE [dbo].[StudyReportLink] CHECK CONSTRAINT [FK_StudyReportLink_CaseStudy]
GO
ALTER TABLE [dbo].[StudyReportLink]  WITH CHECK ADD  CONSTRAINT [FK_StudyReportLink_StudyReport] FOREIGN KEY([ReportId])
REFERENCES [dbo].[StudyReport] ([Id])
GO
ALTER TABLE [dbo].[StudyReportLink] CHECK CONSTRAINT [FK_StudyReportLink_StudyReport]
GO
ALTER TABLE [dbo].[StudyViewing]  WITH CHECK ADD  CONSTRAINT [FK_StudyViewing_CaseStudy] FOREIGN KEY([StudyId])
REFERENCES [dbo].[CaseStudy] ([Id])
GO
ALTER TABLE [dbo].[StudyViewing] CHECK CONSTRAINT [FK_StudyViewing_CaseStudy]
GO
ALTER TABLE [dbo].[tbl_CustomFilterValue]  WITH CHECK ADD  CONSTRAINT [FK_tbl_CustomFilterValue_tbl_CustomFilter] FOREIGN KEY([CustomFilterId])
REFERENCES [dbo].[tbl_CustomFilter] ([Id])
GO
ALTER TABLE [dbo].[tbl_CustomFilterValue] CHECK CONSTRAINT [FK_tbl_CustomFilterValue_tbl_CustomFilter]
GO
ALTER TABLE [dbo].[TeleGroupService]  WITH CHECK ADD  CONSTRAINT [FK_TeleGroupService_TeleGroup] FOREIGN KEY([TeleGroupId])
REFERENCES [dbo].[TeleGroup] ([Id])
GO
ALTER TABLE [dbo].[TeleGroupService] CHECK CONSTRAINT [FK_TeleGroupService_TeleGroup]
GO
ALTER TABLE [dbo].[TeleGroupService]  WITH CHECK ADD  CONSTRAINT [FK_TeleGroupService_TeleService] FOREIGN KEY([TeleServiceid])
REFERENCES [dbo].[TeleService] ([Id])
GO
ALTER TABLE [dbo].[TeleGroupService] CHECK CONSTRAINT [FK_TeleGroupService_TeleService]
GO
ALTER TABLE [dbo].[TeleInvoice]  WITH CHECK ADD  CONSTRAINT [FK_TeleInvoice_CaseStudy] FOREIGN KEY([TeleStudyId])
REFERENCES [dbo].[CaseStudy] ([Id])
GO
ALTER TABLE [dbo].[TeleInvoice] CHECK CONSTRAINT [FK_TeleInvoice_CaseStudy]
GO
ALTER TABLE [dbo].[TeleInvoice]  WITH CHECK ADD  CONSTRAINT [FK_TeleInvoice_Patient] FOREIGN KEY([PatientId])
REFERENCES [dbo].[Patient] ([Id])
GO
ALTER TABLE [dbo].[TeleInvoice] CHECK CONSTRAINT [FK_TeleInvoice_Patient]
GO
ALTER TABLE [dbo].[TeleInvoice]  WITH CHECK ADD  CONSTRAINT [FK_TeleInvoice_TeleBill] FOREIGN KEY([BillId])
REFERENCES [dbo].[TeleBill] ([Id])
GO
ALTER TABLE [dbo].[TeleInvoice] CHECK CONSTRAINT [FK_TeleInvoice_TeleBill]
GO
ALTER TABLE [dbo].[TeleInvoice]  WITH CHECK ADD  CONSTRAINT [FK_TeleInvoice_TeleBill1] FOREIGN KEY([BillId])
REFERENCES [dbo].[TeleBill] ([Id])
GO
ALTER TABLE [dbo].[TeleInvoice] CHECK CONSTRAINT [FK_TeleInvoice_TeleBill1]
GO
ALTER TABLE [dbo].[TeleInvoice]  WITH CHECK ADD  CONSTRAINT [FK_TeleInvoice_TeleBillDR] FOREIGN KEY([BillDRId])
REFERENCES [dbo].[TeleBillDR] ([Id])
GO
ALTER TABLE [dbo].[TeleInvoice] CHECK CONSTRAINT [FK_TeleInvoice_TeleBillDR]
GO
ALTER TABLE [dbo].[TeleInvoice]  WITH CHECK ADD  CONSTRAINT [FK_TeleInvoice_TeleSiteLocalRequestService] FOREIGN KEY([SiteLocalRequestId])
REFERENCES [dbo].[TeleSiteLocalRequestService] ([Id])
GO
ALTER TABLE [dbo].[TeleInvoice] CHECK CONSTRAINT [FK_TeleInvoice_TeleSiteLocalRequestService]
GO
ALTER TABLE [dbo].[TeleInvoice]  WITH CHECK ADD  CONSTRAINT [FK_TeleInvoice_Users] FOREIGN KEY([TeleApproveId])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[TeleInvoice] CHECK CONSTRAINT [FK_TeleInvoice_Users]
GO
ALTER TABLE [dbo].[TeleMembers]  WITH CHECK ADD  CONSTRAINT [FK_TeleMembers_TeleGroup] FOREIGN KEY([TeleGroupId])
REFERENCES [dbo].[TeleGroup] ([Id])
GO
ALTER TABLE [dbo].[TeleMembers] CHECK CONSTRAINT [FK_TeleMembers_TeleGroup]
GO
ALTER TABLE [dbo].[TeleMembers]  WITH CHECK ADD  CONSTRAINT [FK_TeleMembers_Users] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[TeleMembers] CHECK CONSTRAINT [FK_TeleMembers_Users]
GO
ALTER TABLE [dbo].[TemplateReport]  WITH CHECK ADD  CONSTRAINT [FK_TemplateReport_TemplateReportGroup] FOREIGN KEY([GroupId])
REFERENCES [dbo].[TemplateReportGroup] ([Id])
GO
ALTER TABLE [dbo].[TemplateReport] CHECK CONSTRAINT [FK_TemplateReport_TemplateReportGroup]
GO
ALTER TABLE [dbo].[TemplateReportGroup]  WITH NOCHECK ADD  CONSTRAINT [FK_TemplateReportGroup_TemplateReportGroup] FOREIGN KEY([ParentId])
REFERENCES [dbo].[TemplateReportGroup] ([Id])
GO
ALTER TABLE [dbo].[TemplateReportGroup] NOCHECK CONSTRAINT [FK_TemplateReportGroup_TemplateReportGroup]
GO
ALTER TABLE [dbo].[UserFolder]  WITH CHECK ADD  CONSTRAINT [FK_UserFolder_Folder] FOREIGN KEY([FolderId])
REFERENCES [dbo].[Folder] ([Id])
GO
ALTER TABLE [dbo].[UserFolder] CHECK CONSTRAINT [FK_UserFolder_Folder]
GO
ALTER TABLE [dbo].[UserFolder]  WITH CHECK ADD  CONSTRAINT [FK_UserFolder_Users] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[UserFolder] CHECK CONSTRAINT [FK_UserFolder_Users]
GO
ALTER TABLE [dbo].[UserGroupMapping]  WITH CHECK ADD  CONSTRAINT [FK_UserGroupMapping_UserGroup] FOREIGN KEY([GroupId])
REFERENCES [dbo].[UserGroup] ([Id])
GO
ALTER TABLE [dbo].[UserGroupMapping] CHECK CONSTRAINT [FK_UserGroupMapping_UserGroup]
GO
ALTER TABLE [dbo].[UserGroupMapping]  WITH CHECK ADD  CONSTRAINT [FK_UserGroupMapping_Users] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[UserGroupMapping] CHECK CONSTRAINT [FK_UserGroupMapping_Users]
GO
ALTER TABLE [dbo].[UserRole]  WITH CHECK ADD  CONSTRAINT [FK_UserRole_Role] FOREIGN KEY([RoleId])
REFERENCES [dbo].[Role] ([Id])
GO
ALTER TABLE [dbo].[UserRole] CHECK CONSTRAINT [FK_UserRole_Role]
GO
ALTER TABLE [dbo].[UserRole]  WITH CHECK ADD  CONSTRAINT [FK_UserRole_Users] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[UserRole] CHECK CONSTRAINT [FK_UserRole_Users]
GO
ALTER TABLE [dbo].[UserTemplateReport]  WITH CHECK ADD  CONSTRAINT [FK_UserTemplateReport_Users] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[UserTemplateReport] CHECK CONSTRAINT [FK_UserTemplateReport_Users]
GO
ALTER TABLE [dbo].[UserTemplateReport]  WITH CHECK ADD  CONSTRAINT [FK_UserTemplateReport_UserTemplateReport] FOREIGN KEY([ParentId])
REFERENCES [dbo].[UserTemplateReport] ([Id])
GO
ALTER TABLE [dbo].[UserTemplateReport] CHECK CONSTRAINT [FK_UserTemplateReport_UserTemplateReport]
GO
ALTER TABLE [dbo].[Worklist]  WITH CHECK ADD  CONSTRAINT [FK_Worklist_Patient] FOREIGN KEY([PId])
REFERENCES [dbo].[Patient] ([Id])
GO
ALTER TABLE [dbo].[Worklist] CHECK CONSTRAINT [FK_Worklist_Patient]
GO
ALTER TABLE [dbo].[Worklist]  WITH CHECK ADD  CONSTRAINT [FK_Worklist_Site] FOREIGN KEY([SiteId])
REFERENCES [dbo].[Site] ([Id])
GO
ALTER TABLE [dbo].[Worklist] CHECK CONSTRAINT [FK_Worklist_Site]
GO
ALTER TABLE [dbo].[Worklist]  WITH CHECK ADD  CONSTRAINT [FK_Worklist_Station] FOREIGN KEY([StationId])
REFERENCES [dbo].[Station] ([Id])
GO
ALTER TABLE [dbo].[Worklist] CHECK CONSTRAINT [FK_Worklist_Station]
GO
ALTER TABLE [dbo].[Worklist]  WITH CHECK ADD  CONSTRAINT [FK_Worklist_Users] FOREIGN KEY([DoctorId])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[Worklist] CHECK CONSTRAINT [FK_Worklist_Users]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Co can bs ben local duyet report thi moi cho thanh toan invoice k' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TeleInvoice', @level2type=N'COLUMN',@level2name=N'Status'
GO
USE [master]
GO
ALTER DATABASE [pacsdbname] SET  READ_WRITE 
GO
