Concate_test_REsult-to-HI HIS

PHOTO EMBED

Wed Apr 19 2023 08:57:16 GMT+0000 (Coordinated Universal Time)

Saved by @HUMRARE7 #sql

BEGIN
	SET NOCOUNT ON;
	
	--
	declare @LN nvarchar(20);
	declare @Testcode nvarchar(10);
	declare @Data nvarchar(MAX);
	declare @Result nvarchar(MAX);


	select @LN = LN from inserted;
	select @Result = Result from inserted;
	select @Testcode = Result_Test_Code from inserted;

	--

	if (@Testcode = 'UA001')
	BEGIN
	delete tbl_lab_concate_test where LN = @LN
	INSERT INTO tbl_lab_concate_test VALUES (@LN,'','N');   
    END

	if (@Testcode = 'URT203' and @Result is not null) -- Bacreria
	BEGIN
	
    update 	tbl_lab_concate_test set LN = @LN,Temp_Data = Temp_Data+'Bacteria = '+@Result	where LN = @LN
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT203'
    END

	if (@Testcode = 'URT203' and @Result is  null) -- Bacreria
	BEGIN
	
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT203'
    END


	if (@Testcode = 'URT200' and @Result is not null) --Hyaline Cast
	BEGIN
	
    update 	tbl_lab_concate_test set LN = @LN,Temp_Data = Temp_Data+',Hyaline Cast = '+@Result+'/LPF'	where LN = @LN
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT200'
    END

	if (@Testcode = 'URT200' and @Result is  null) --Hyaline Cast
	BEGIN
	
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT200'
    END

	
	if (@Testcode = 'URT204' and @Result is not null) -- Calcium Oxalate
	BEGIN
	
    update 	tbl_lab_concate_test set LN = @LN,Temp_Data = Temp_Data+',CaOx monohydrate = '+@Result+'/HPF'	where LN = @LN
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT204'
    END
	
	if (@Testcode = 'URT204' and @Result is null) -- Calcium Oxalate
	BEGIN
	
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT204'
    END 

	if (@Testcode = 'URT205' and @Result is not null) -- CaOx Dihydrate
	BEGIN
	
    update 	tbl_lab_concate_test set LN = @LN,Temp_Data = Temp_Data+',CaOx Dihydrate = '+@Result+'/HPF'	where LN = @LN
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT205'
    END
	
	if (@Testcode = 'URT205' and @Result is null) -- CaOx Dihydrate
	BEGIN
	
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT205'
    END
	
	if (@Testcode = 'URT209' and @Result is not null) -- Triple Phosphate Crystals
	BEGIN
	
    update 	tbl_lab_concate_test set LN = @LN,Temp_Data = Temp_Data+',Triple Phosphate Crystals = '+@Result+'/HPF'	where LN = @LN
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT209'
    END
	
	if (@Testcode = 'URT209' and @Result is null) --Triple Phosphate Crystals
	BEGIN
	
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT209'
    END

	--if (@Testcode = 'URT202' and @Result is not null) -- None Sq.EPI.
	--BEGIN
	
 --   update 	tbl_lab_concate_test set LN = @LN,Temp_Data = Temp_Data+',None Sq.EPI. = '+@Result+'/HPF'	where LN = @LN
	--update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT202'
 --   END
	
	--if (@Testcode = 'URT202' and @Result is null) --None Sq.EPI.
	--BEGIN
	
	--update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT202'
 --   END

	if (@Testcode = 'URT201' and @Result is not null and @Result <> '0') -- PAT
	BEGIN
	
    update 	tbl_lab_concate_test set LN = @LN,Temp_Data = Temp_Data+',PAT = '+@Result	where LN = @LN
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT201'
    END

	if (@Testcode = 'URT201' and @Result is null) -- PAT
	BEGIN

	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT201'
    END



	if (@Testcode = 'URT208' and @Result is not null) -- Mucous Thread
	BEGIN
	
    update 	tbl_lab_concate_test set LN = @LN,Temp_Data = Temp_Data+',Mucous = '+@Result	where LN = @LN
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT208'
    END

	if (@Testcode = 'URT208' and @Result is null) -- Mucous Thread
	BEGIN

	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT208'
    END

	if (@Testcode = 'URT071' and @Result is not null) -- Amorphous
	BEGIN
    update 	tbl_lab_concate_test set LN = @LN,Temp_Data = Temp_Data+',Amorphous = '+@Result	where LN = @LN
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT071'
    END

	if (@Testcode = 'URT071' and @Result is null) -- Amorphous
	BEGIN
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT071'
    END

	if (@Testcode = 'URT207' and @Result is not null) -- Yeast cell
	BEGIN
	
    update 	tbl_lab_concate_test set LN = @LN,Temp_Data = Temp_Data+',Yeast cell = '+@Result	where LN = @LN
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT207'
    END

	if (@Testcode = 'URT207' and @Result is null) -- Yeast cell
	BEGIN

	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT207'
    END

	if (@Testcode = 'URT230' and @Result is not null) -- Uric acid Crytal
	BEGIN
	
    update 	tbl_lab_concate_test set LN = @LN,Temp_Data = Temp_Data+',Uric acid Crytal = '+@Result	where LN = @LN
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT230'
    END

	if (@Testcode = 'URT230' and @Result is null) -- Uric acid Crytal
	BEGIN

	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT230'
    END

	if (@Testcode = 'URT231' and @Result is not null) -- Spermatozao
	BEGIN
	
    update 	tbl_lab_concate_test set LN = @LN,Temp_Data = Temp_Data+',Uric acid Crytal = '+@Result	where LN = @LN
	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT231'
    END

	if (@Testcode = 'URT231' and @Result is null) -- Spermatozao
	BEGIN

	update 	tbl_lab_information_ExportToHIS set CanDelete = 'Y'	where LN = @LN and Result_Test_Code = 'URT231'
    END

	if (@Testcode = 'URT500') -- Other
	BEGIN
	 if (@Result = '-')
	 update B set B.Result = A.Temp_Data
	 from tbl_lab_concate_test A, tbl_lab_information_ExportToHIS B
	 where A.LN = B.LN and B.Result_Test_Code = 'URT500'

	 if (@Result <> '-')
	 update B set B.Result = A.Temp_Data+','+@Result
	 from tbl_lab_concate_test A, tbl_lab_information_ExportToHIS B
	 where A.LN = B.LN and B.Result_Test_Code = 'URT500'

    update 	tbl_lab_concate_test set Inactive = 'Y'	where LN = @LN

    END
END
content_copyCOPY