CREATE VIEW [dbo].[pal_vAccountClaimResponseDetail]
AS

SELECT	T.recId
		,R.recId responseId 
		,R.claimLogId
		,T.code + ': '+T.description + CASE WHEN LEN(T.nappiCode)>0 THEN ' ('+T.nappiCode+')' ELSE '' END AS [description]
		,T.claimRefTrackingNo
		,CASE T.responseResultCode
			WHEN '01' THEN 'Treatment Accepted for delivery'
			WHEN '02' THEN 'Treatment Accepted for processing'
			WHEN '03' THEN 'Treatment Rejected'
			WHEN '04' THEN 'Treatment Approved for Payment'
			WHEN '05' THEN 'Treatment Approved for Part Payment'
			WHEN '06' THEN 'Treatment Reversal Accepted'
			WHEN '07' THEN 'Treatment Reversal Rejected'
			END AS ResponseResult
		,CASE T.respondingParty
			WHEN '01' THEN 'MediSwitch'
			WHEN '02' THEN 'Medical Scheme / Administrator'
			END AS RespondingParty
		,CASE T.msDeliveryTypeInd
			WHEN '01' THEN 'Real-Time'
			WHEN '02' THEN 'Batched'
			WHEN '03' THEN 'Queued'
			WHEN '04' THEN 'Rejected'
			END AS DeliveryType
		,CAST(T.treatmentClaimedAmount/100 AS DECIMAL(18,2)) treatmentClaimedAmount
		,CAST(T.patientLiableAmount/100 AS DECIMAL(18,2)) patientLiableAmount
		,CAST(T.authAmountToProvider/100 AS DECIMAL(18,2)) authAmountToProvider
		,CAST(T.discountAmount/100 AS DECIMAL(18,2)) discountAmount
		,CAST(T.overchargedAmount/100 AS DECIMAL(18,2)) overchargedAmount
		,CAST(T.patientLevyAmount/100 AS DECIMAL(18,2)) patientLevyAmount
		,CAST(T.mmapSurcharge/100 AS DECIMAL(18,2)) mmapSurcharge
		,CAST(T.patientCoPaymentAmount/100 AS DECIMAL(18,2)) patientCoPaymentAmount
		,CAST(T.medicalFundLiableAmount/100 AS DECIMAL(18,2)) medicalFundLiableAmount
		,CAST(T.memberReimbursementAmount/100 AS DECIMAL(18,2)) memberReimbursementAmount
		,CAST(R.claimGrossAmount/100 AS DECIMAL(18,2)) totalAmount
		,CAST(R.claimPatientLiableAmount/100 AS DECIMAL(18,2)) totalPatientLiable
		,CAST(R.authAmountToProvider/100 AS DECIMAL(18,2)) totalMedicalLiable
FROM	pal_MSClaimResponse R
		JOIN pal_MSClaimResponseTreatment T
			ON T.claimResponseId = R.recId


GO


