USE [GrpInsurance]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO


-- by Pribadi Pamungkas, 2014-06-09
ALTER Procedure [dbo].[proc_get_item_kontrak_provider]
@pi_kode_provider varchar(10),
@pi_tanggal datetime,
@po_message varchar(240) OUTPUT
AS
    DECLARE @p_info VARCHAR(200),
            @p_nama_provider VARCHAR(200)
            
    SELECT  TOP 1
            @p_info=CASE ri
              WHEN 1 THEN '- Rawat Inap'+CHAR(10)+CHAR(13)
            END
            +
            CASE rj
              WHEN 1 THEN '- Rawat Jalan'+CHAR(10)+CHAR(13)
            END
            +
            CASE rj_khusus
              WHEN 1 THEN '- Rawat Jalan Khusus'+CHAR(10)+CHAR(13)
            END
            +
            CASE ri_individu
              WHEN 1 THEN '- Rawat Inap Individu'+CHAR(10)+CHAR(13)
            END
    FROM    dbo.kontrak_provider 
    WHERE   kode_provider=@pi_kode_provider 
            AND tgl_mulai<=@pi_tanggal 
            AND tgl_selesai>=@pi_tanggal

    IF (@@ERROR <> 0)
		  BEGIN
			  SET @po_message = 'Error.'
			  RETURN 1
		  END
		  
		SELECT @p_nama_provider=Nama FROM dbo.Provider WHERE IDI=@pi_kode_provider
		
		IF @p_info IS NOT NULL
      BEGIN
        SET @po_message = 'Kontrak dengan'+CHAR(10)+CHAR(13)+@p_nama_provider+':'+CHAR(10)+CHAR(13)+@p_info
	      RETURN 0
	    END
	  ELSE
	    BEGIN
	      SET @po_message = 'Tidak ada kontrak dengan'+CHAR(10)+CHAR(13)+@p_nama_provider
	      RETURN 2
	    END
	    

GO


