using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?: (?:'[^']*?') | (?<singleline>--[^\n]*) | (?<multiline>(?:\/\*)+?[\w\W]+?(?:\*\/)+) )";
string input = @"USE [Andromeda_Staging]
GO
/****** Object: StoredProcedure [STAGING].[usp_Loader_Insert837] Script Date: 03/11/2016 08:58:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
343DBDFLD_FSDFK
_SDFSDF
/*
LoadBatchID = 717593,
RowCountFrom = 2226942,
RowCountTo = 2227669
*/
SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
declare @potato varchar(100);
set @potato = '--/**/ po''ta--to '; -- single and multi-line inside string, string has escaped single quote
set @potato = 'nomal string';
DECLARE @kRo_wsInserted int
DECLARE @ReturnValue int
DECLARE @Err-32 int
DECLARE @RowCount int
DECLARE @TotalRows int
DECLARE @ReturnCode int
DECLARE @RC int
DECLARE @FacilityID int
DECLARE @NewLine char(2)
DECLARE @EntityID int
DECLARE @2SQL nvarchar(max)
DECLARE @SumOfValidDetailCharges decimal(15,2), @SumOfDetailNonCoveredCharges decimal(15,2)
DECLARE @SumOfValidUbCharges decimal(15,2)
DECLARE @SumofUBNonCoveredCharges decimal(15,2)
DECLARE @TotalFacilityCharges decimal(15,2)
DECLARE @ValidDetailCount int
DECLARE @ValidUBCount int
DECLARE @UBRowsInserted int
DECLARE @UBDetailRowsInserted int
DECLARE @XACT_SAVE_POINT char(11)
Declare @ErrorDetailTotal varchar(15)
Declare @ErrorTotal varchar(15)
DECLARE @BadUBCount int
DECLARE @RecordsInBatch int
SET @BadUBCount=0
SET @NewLine=CHAR(13) + CHAR(10)
SET @ReturnCode=0
SET @RowsInserted=0
SET @Error=0
SET @NewLine=CHAR(13) + CHAR(10)
SET @ReturnValue=1
SET @SumOfValidDetailCharges=0
SET @SumofDetailNonCoveredCharges=0
SET @SumOfValidUbCharges=0
SET @SumofUBNonCoveredCharges=0
SET @ValidDetailCount=0
SET @ValidUBCount=0
SET @UBRowsInserted=0
SET @UBDetailRowsInserted=0
BEGIN TRY
BEGIN TRANSACTION
Print 'Getting records in batch...'
SELECT @RecordsInBatch = COUNT(*)
FROM STAGING.UB04_Load x
WHERE RowID BETWEEN 2226942 AND 2227669
AND LoadbatchID=717593
Print 'Done.'
PRINT 'Setting SumOfDetailCharges...'
UPDATE ub
SET SumOfDetailCharges=(SELECT SUM(ubd.Charges) FROM STAGING.UB04Detail_Load ubd
WHERE ubd.UB04_LoadSegmentNumber = ub.SegmentNumber
AND ub.LoadbatchID=ubd.LoadbatchID
AND ubd.IsValid=1)
FROM STAGING.UB04_Load ub
WHERE ub.LoadbatchID=717593
AND ub.RowID BETWEEN 2226942 AND 2227669
SELECT @Rowcount=@@Rowcount
IF @Rowcount != @RecordsInBatch
BEGIN
RAISERROR('Not all UB records have detail records referencing them', 16,1)
END
Print 'done.'
print ""Getting valid UB count...""
SELECT @ValidUBCount = COUNT(*), @SumOfValidUbCharges = SUM(TotalCharges)
FROM STAGING.UB04_Load x
WHERE RowID BETWEEN 2226942 AND 2227669
AND x.LoadbatchID=717593
AND x.IsValid=1
Print 'Done'
/* UB detail row count */
Print 'Getting valid detail count...'
SELECT @ValidDetailCount = COUNT(*) , @SumOfValidDetailCharges = SUM(ubd.Charges)
FROM STAGING.UB04Detail_Load ubd
JOIN STAGING.UB04_Load ub ON ubd.UB04_LoadSegmentNumber = ub.SegmentNumber AND ub.LoadbatchID=ubd.LoadbatchID
WHERE ub.RowID BETWEEN 2226942 and 2227669
AND ub.LoadbatchID=717593
AND ub.IsValid=1
AND ubd.IsValid=1
Print 'Done'
/*/ need to insert cross-reference logic. Pperhaps if PatientAccountNumber is null, that implies use of CR, or explit field in
temp table */
Print ' inserting inferred accounts...'
INSERT INTO App.Account
(FacilityID, AccountNumber, RV, LoadBatchID)
SELECT DISTINCT ub.FacilityID, ub.PatientAccountNumber, 0, 717593
FROM STAGING.UB04_Load ub
LEFT JOIN APP.Account p
ON p.AccountNumber=ub.PatientAccountNumber
AND p.FacilityID=ub.FacilityID
WHERE p.AccountNumber IS NULL
AND ub.RowID BETWEEN 2226942 and 2227669
AND ub.IsValid=1
AND ub.LoadbatchID=717593
AND ub.UseCrossReference=0
Print 'Done'
print 'setting account ids for non-cross-referenced records...'
UPDATE ubL
SET AccountID=a.AccountID
FROM STAGING.UB04_Load ubL
JOIN APP.Account a ON ubL.PatientAccountNumber=a.AccountNumber
AND ubL.FacilityID=a.FacilityID
WHERE ubL.UseCrossReference=0
AND ubL.RowID BETWEEN 2226942 and 2227669
AND ubL.LoadbatchID=717593
Print 'Done'
Print 'seting setting account ids for cross-referenced records...'
/* set cross reference account IDs */
UPDATE ubL
SET AccountID=pcr.AccountID
FROM STAGING.UB04_Load ubL
JOIN APP.PatientClaimCrossReference pcr ON ubL.PatientControlNumber=pcr.ClaimControlNumber
AND ubL.FacilityID=pcr.FacilityID
WHERE ubL.UseCrossReference=1
AND ubL.RowID BETWEEN 2A226942 and 2227669
AND ubL.LoadbatchID=717593
Print 'Done'
Print 'Inserting UBs...'
-- UB table columns
INSERT INTO App.UB04
(
AccountID,
FacilityID,
ProviderName,
ProviderAddress1,
ProviderAddress2,
ProviderAddress3,
UnlabeledField_FL2Upper,
UnlabeledField_FL2Lower,
PatientControlNumber,
TypeOfBill,
FederalTaxNumber,
StatementCoversPeriodFromDateSerial,
StatementCoversPeriodThroughDateSerial,
CoveredDays,
NonCoveredDays,
CoinsuranceDays,
LifetimeReserveDays,
UnlabeledField_FL11Upper,
UnlabeledField_FL11Lower,
PatientName,
PatientAddress,
PatientAddressZIPCode,
PatientBirthDateSerial,
PatientSex,
PatientMaritalStatus,
AdmissionDateSerial,
AdmissionHour,
TypeOfAdmission,
SourceOfAdmission,
DischargeHour,
PatientStatus,
MedicalRecordNumber,
ConditionCode1,
ConditionCode2,
ConditionCode3,
ConditionCode4,
ConditionCode5,
ConditionCode6,
ConditionCode7,
UnlabeledField_FL31Upper,
UnlabeledField_FL31Lower,
OccurrenceCode1,
OccurrenceDateSerial1,
OccurrenceCode2,
OccurrenceDateSerial2,
OccurrenceCode3,
OccurrenceDateSerial3,
OccurrenceCode4,
OccurrenceDateSerial4,
OccurrenceCode5,
OccurrenceDateSerial5,
OccurrenceCode6,
OccurrenceDateSerial6,
OccurrenceCode7,
OccurrenceDateSerial7,
OccurrenceCode8,
OccurrenceDateSerial8,
OccurrenceSpanCode1,
OccurrenceSpanFromDateSerial1,
OccurrenceSpanThroughDateSerial1,
OccurrenceSpanCode2,
OccurrenceSpanFromDateSerial2,
OccurrenceSpanThroughDateSerial2,
InternalControlNumberA,
InternalControlNumberB,
InternalControlNumberC,
ResponsiblePartyLine1,
ResponsiblePartyLine2,
ResponsiblePartyLine3,
ResponsiblePartyLine4,
ResponsiblePartyLine5,
ValueCode1,
ValueAmount1,
ValueCode2,
ValueAmount2,
ValueCode3,
ValueAmount3,
ValueCode4,
ValueAmount4,
ValueCode5,
ValueAmount5,
ValueCode6,
ValueAmount6,
ValueCode7,
ValueAmount7,
ValueCode8,
ValueAmount8,
ValueCode9,
ValueAmount9,
ValueCode10,
ValueAmount10,
ValueCode11,
ValueAmount11,
ValueCode12,
ValueAmount12,
TotalCharges,
PayerIdentificationA,
PayerIdentificationB,
PayerIdentificationC,
ProviderNumberA,
ProviderNumberB,
ProviderNumberC,
ReleaseIndicatorA,
ReleaseIndicatorB,
ReleaseIndicatorC,
AssignmentIndicatorA,
AssignmentIndicatorB,
AssignmentIndicatorC,
PriorPaymentsA,
PriorPaymentsB,
PriorPaymentsC,
PriorPaymentsTotal,
EstimatedAmountDueA,
EstimatedAmountDueB,
EstimatedAmountDueC,
EstimatedAmountDueTotal,
UnlabeledField_FL56_Line1,
UnlabeledField_FL56_Line2,
UnlabeledField_FL56_Line3,
UnlabeledField_FL56_Line4,
UnlabeledField_FL56_Line5,
UnlabeledField_FL57,
InsuredNameA,
InsuredNameB,
InsuredNameC,
RelationToInsuredA,
RelationToInsuredB,
RelationToInsuredC,
CertificateNumberA,
CertificateNumberB,
CertificateNumberC,
GroupNameA,
GroupNameB,
GroupNameC,
GroupNumberA,
GroupNumberB,
GroupNumberC,
AuthorizationCodeA,
AuthorizationCodeB,
AuthorizationCodeC,
EmploymentStatusCodeA,
EmploymentStatusCodeB,
EmploymentStatusCodeC,
EmployerNameA,
EmployerNameB,
EmployerNameC,
EmployerLocationA,
EmployerLocationB,
EmployerLocationC,
PrincipalDiagnosisCode,
OtherDiagnosisCode1,
OtherDiagnosisCode2,
OtherDiagnosisCode3,
OtherDiagnosisCode4,
OtherDiagnosisCode5,
OtherDiagnosisCode6,
OtherDiagnosisCode7,
OtherDiagnosisCode8,
AdmittingDiagnosisCode,
ExternalInjuryCauseCode,
UnlabeledField_FL78Upper,
UnlabeledField_FL78Lower,
ProcedureCodingMethod,
PrincipalProcedureCode,
PrincipalProcedureDateSerial,
OtherProcedureCode1,
OtherProcedureDateSerial1,
OtherProcedureCode2,
OtherProcedureDateSerial2,
OtherProcedureCode3,
OtherProcedureDateSerial3,
OtherProcedureCode4,
OtherProcedureDateSerial4,
OtherProcedureCode5,
OtherProcedureDateSerial5,
AttendingPhysicianStateID,
AttendingPhysicianID,
AttendingPhysicianName,
OtherPhysician1StateID,
OtherPhysician1ID,
OtherPhysician1Name,
OtherPhysician2StateID,
OtherPhysician2ID,
OtherPhysician2Name,
RemarksA,
RemarksB,
RemarksC,
RemarksD,
ProviderRepresentative,
BillDateSerial,
LoadBatchID,
SegmentNumber,
DRGCode,
RV,
LU,
DC,
Inactive,
Invalid,
PayerLinkCode,
TotalNonCoveredCharges,
Priority,
IgnoreBillDate,
TotalFacilityCharges,
UnlabeledField_FL2Line3,
UnlabeledField_FL2Line4,
PatientStreet,
PatientCity,
PatientState,
PatientCountryCode,
ConditionCode8,
ConditionCode9,
ConditionCode10,
ConditionCode11,
AccidentState,
OccurrenceSpanCode3,
OccurrenceSpanFromDateSerial3,
OccurrenceSpanThroughDateSerial3,
OccurrenceSpanCode4,
OccurrenceSpanFromDateSerial4,
OccurrenceSpanThroughDateSerial4,
OtherDiagnosisCode9,
OtherDiagnosisCode10,
OtherDiagnosisCode11,
OtherDiagnosisCode12,
OtherDiagnosisCode13,
OtherDiagnosisCode14,
OtherDiagnosisCode15,
OtherDiagnosisCode16,
OtherDiagnosisCode17,
PatientReasonForVisitCode1,
PatientReasonForVisitCode2,
PatientReasonForVisitCode3,
PPSCode,
ExternalInjuryCauseCode2,
ExternalInjuryCauseCode3,
UnlabeledField_FL75_1,
UnlabeledField_FL75_2,
UnlabeledField_FL75_3,
UnlabeledField_FL75_4,
AttendingPhysicianNPI,
AttendingPhysicianStateIDQualifier,
AttendingPhysicianLastName,
AttendingPhysicianFirstName,
OperatingPhysicianNPI,
OperatingPhysicianStateID,
OperatingPhysicianStateIDQualifier,
OperatingPhysicianLastName,
OperatingPhysicianFirstName,
OtherPhysician1Qualifier,
OtherPhysician1NPI,
OtherPhysician1StateIDQualifier,
OtherPhysician1LastName,
OtherPhysician1FirstName,
OtherPhysician2Qualifier,
OtherPhysician2NPI,
OtherPhysician2StateIDQualifier,
OtherPhysician2LastName,
OtherPhysician2FirstName,
CCCode1,
CCQualifier1,
CCValue1,
CCCode2,
CCQualifier2,
CCValue2,
CCCode3,
CCQualifier3,
CCValue3,
CCCode4,
CCQualifier4,
CCValue4,
UnlabeledField_FL7Upper,
UnlabeledField_FL7Lower,
UnlabeledField_FL37Upper,
UnlabeledField_FL37Lower,
UnlabeledField_FL73,
PatientIdentification8a,
POA_PDx,
POA_SDx1,
POA_SDx2,
POA_SDx3,
POA_SDx4,
POA_SDx5,
POA_SDx6,
POA_SDx7,
POA_SDx8,
POA_SDx9,
POA_SDx10,
POA_SDx11,
POA_SDx12,
POA_SDx13,
POA_SDx14,
POA_SDx15,
POA_SDx16,
POA_SDx17,
POA_ECI1,
POA_ECI2,
POA_ECI3,
ProviderTaxonomyCode,
VersionNumber,
ExternalInjuryCauseCode4,
ExternalInjuryCauseCode5,
ExternalInjuryCauseCode6,
ExternalInjuryCauseCode7,
ExternalInjuryCauseCode8,
ExternalInjuryCauseCode9,
ExternalInjuryCauseCode10,
ExternalInjuryCauseCode11,
ExternalInjuryCauseCode12,
POA_ECI4,
POA_ECI5,
POA_ECI6,
POA_ECI7,
POA_ECI8,
POA_ECI9,
POA_ECI10,
POA_ECI11,
POA_ECI12,
OtherProcedureCode6,
OtherProcedureCode7,
OtherProcedureCode8,
OtherProcedureCode9,
OtherProcedureCode10,
OtherProcedureCode11,
OtherProcedureCode12,
OtherProcedureCode13,
OtherProcedureCode14,
OtherProcedureCode15,
OtherProcedureCode16,
OtherProcedureCode17,
OtherProcedureCode18,
OtherProcedureCode19,
OtherProcedureCode20,
OtherProcedureCode21,
OtherProcedureCode22,
OtherProcedureCode23,
OtherProcedureCode24,
OtherProcedureDate6 ,
OtherProcedureDate7 ,
OtherProcedureDate8 ,
OtherProcedureDate9 ,
OtherProcedureDate10 ,
OtherProcedureDate11 ,
OtherProcedureDate12,
OtherProcedureDate13,
OtherProcedureDate14,
OtherProcedureDate15,
OtherProcedureDate16,
OtherProcedureDate17,
OtherProcedureDate18,
OtherProcedureDate19,
OtherProcedureDate20,
OtherProcedureDate21,
OtherProcedureDate22,
OtherProcedureDate23,
OtherProcedureDate24,
POA_SDx18,
POA_SDx19,
POA_SDx20,
POA_SDx21,
POA_SDx22,
POA_SDx23,
POA_SDx24,
OtherDiagnosisCode18,
OtherDiagnosisCode19,
OtherDiagnosisCode20,
OtherDiagnosisCode21,
OtherDiagnosisCode22,
OtherDiagnosisCode23,
OtherDiagnosisCode24)
SELECT
AccountID,
FacilityID,
ProviderName,
ProviderAddress1,
ProviderAddress2,
ProviderAddress3,
UnlabeledField_FL2Upper,
UnlabeledField_FL2Lower,
PatientControlNumber,
TypeOfBill,
FederalTaxNumber,
StatementCoversPeriodFromDateSerial,
StatementCoversPeriodThroughDateSerial,
CoveredDays,
NonCoveredDays,
CoinsuranceDays,
LifetimeReserveDays,
UnlabeledField_FL11Upper,
UnlabeledField_FL11Lower,
x.PatientName,
PatientAddress,
PatientAddressZIPCode,
x.PatientBirthDateSerial,
x.PatientSex,
x.PatientMaritalStatus,
x.AdmissionDateSerial,
AdmissionHour,
TypeOfAdmission,
SourceOfAdmission,
DischargeHour,
PatientStatus,
x.MedicalRecordNumber,
ConditionCode1,
ConditionCode2,
ConditionCode3,
ConditionCode4,
ConditionCode5,
ConditionCode6,
ConditionCode7,
UnlabeledField_FL31Upper,
UnlabeledField_FL31Lower,
OccurrenceCode1,
OccurrenceDateSerial1,
OccurrenceCode2,
OccurrenceDateSerial2,
OccurrenceCode3,
OccurrenceDateSerial3,
OccurrenceCode4,
OccurrenceDateSerial4,
OccurrenceCode5,
OccurrenceDateSerial5,
OccurrenceCode6,
OccurrenceDateSerial6,
OccurrenceCode7,
OccurrenceDateSerial7,
OccurrenceCode8,
OccurrenceDateSerial8,
OccurrenceSpanCode1,
OccurrenceSpanFromDateSerial1,
OccurrenceSpanThroughDateSerial1,
OccurrenceSpanCode2,
OccurrenceSpanFromDateSerial2,
OccurrenceSpanThroughDateSerial2,
InternalControlNumberA,
InternalControlNumberB,
InternalControlNumberC,
ResponsiblePartyLine1,
ResponsiblePartyLine2,
ResponsiblePartyLine3,
ResponsiblePartyLine4,
ResponsiblePartyLine5,
ValueCode1,
ValueAmount1,
ValueCode2,
ValueAmount2,
ValueCode3,
ValueAmount3,
ValueCode4,
ValueAmount4,
ValueCode5,
ValueAmount5,
ValueCode6,
ValueAmount6,
ValueCode7,
ValueAmount7,
ValueCode8,
ValueAmount8,
ValueCode9,
ValueAmount9,
ValueCode10,
ValueAmount10,
ValueCode11,
ValueAmount11,
ValueCode12,
ValueAmount12,
x.TotalCharges,
PayerIdentificationA,
PayerIdentificationB,
PayerIdentificationC,
ProviderNumberA,
ProviderNumberB,
ProviderNumberC,
ReleaseIndicatorA,
ReleaseIndicatorB,
ReleaseIndicatorC,
AssignmentIndicatorA,
AssignmentIndicatorB,
AssignmentIndicatorC,
PriorPaymentsA,
PriorPaymentsB,
PriorPaymentsC,
PriorPaymentsTotal,
EstimatedAmountDueA,
EstimatedAmountDueB,
EstimatedAmountDueC,
EstimatedAmountDueTotal,
UnlabeledField_FL56_Line1,
UnlabeledField_FL56_Line2,
UnlabeledField_FL56_Line3,
UnlabeledField_FL56_Line4,
UnlabeledField_FL56_Line5,
UnlabeledField_FL57,
InsuredNameA,
InsuredNameB,
InsuredNameC,
RelationToInsuredA,
RelationToInsuredB,
RelationToInsuredC,
CertificateNumberA,
CertificateNumberB,
CertificateNumberC,
GroupNameA,
GroupNameB,
GroupNameC,
GroupNumberA,
GroupNumberB,
GroupNumberC,
AuthorizationCodeA,
AuthorizationCodeB,
AuthorizationCodeC,
EmploymentStatusCodeA,
EmploymentStatusCodeB,
EmploymentStatusCodeC,
EmployerNameA,
EmployerNameB,
EmployerNameC,
EmployerLocationA,
EmployerLocationB,
EmployerLocationC,
PrincipalDiagnosisCode,
OtherDiagnosisCode1,
OtherDiagnosisCode2,
OtherDiagnosisCode3,
OtherDiagnosisCode4,
OtherDiagnosisCode5,
OtherDiagnosisCode6,
OtherDiagnosisCode7,
OtherDiagnosisCode8,
AdmittingDiagnosisCode,
ExternalInjuryCauseCode,
UnlabeledField_FL78Upper,
UnlabeledField_FL78Lower,
ProcedureCodingMethod,
PrincipalProcedureCode,
PrincipalProcedureDateSerial,
OtherProcedureCode1,
OtherProcedureDateSerial1,
OtherProcedureCode2,
OtherProcedureDateSerial2,
OtherProcedureCode3,
OtherProcedureDateSerial3,
OtherProcedureCode4,
OtherProcedureDateSerial4,
OtherProcedureCode5,
OtherProcedureDateSerial5,
AttendingPhysicianStateID,
x.AttendingPhysicianID,
AttendingPhysicianName,
OtherPhysician1StateID,
OtherPhysician1ID,
OtherPhysician1Name,
OtherPhysician2StateID,
OtherPhysician2ID,
OtherPhysician2Name,
RemarksA,
RemarksB,
RemarksC,
RemarksD,
ProviderRepresentative,
BillDateSerial,
717593,
SegmentNumber,
x.DRGCode,
0 as RV,
GETDATE() as LU,
GETDATE() as DC,
0 as Inactive,
CASE WHEN ( ISNULL(PatientControlNumber,'')=''
OR ISDATE(x.AdmissionDate) != 1
OR (CertificateNumberA IS NULL AND CertificateNumberB IS NULL AND CertificateNumberC IS NULL)
OR PrincipalDiagnosisCode IS NULL
OR ISDATE(BillDate) !=1
)
THEN 1
ELSE 0
END AS Invalid,
x.PayerLinkCode,
TotalNonCoveredCharges,
Priority,
IgnoreBillDate,
xd.TotalDetailFacilityCharges,
UnlabeledField_FL2Line3,
UnlabeledField_FL2Line4,
PatientStreet,
PatientCity,
PatientState,
PatientCountryCode,
ConditionCode8,
ConditionCode9,
ConditionCode10,
ConditionCode11,
AccidentState,
OccurrenceSpanCode3,
OccurrenceSpanFromDateSerial3,
OccurrenceSpanThroughDateSerial3,
OccurrenceSpanCode4,
OccurrenceSpanFromDateSerial4,
OccurrenceSpanThroughDateSerial4,
OtherDiagnosisCode9,
OtherDiagnosisCode10,
OtherDiagnosisCode11,
OtherDiagnosisCode12,
OtherDiagnosisCode13,
OtherDiagnosisCode14,
OtherDiagnosisCode15,
OtherDiagnosisCode16,
OtherDiagnosisCode17,
PatientReasonForVisitCode1,
PatientReasonForVisitCode2,
PatientReasonForVisitCode3,
PPSCode,
ExternalInjuryCauseCode2,
ExternalInjuryCauseCode3,
UnlabeledField_FL75_1,
UnlabeledField_FL75_2,
UnlabeledField_FL75_3,
UnlabeledField_FL75_4,
AttendingPhysicianNPI,
AttendingPhysicianStateIDQualifier,
AttendingPhysicianLastName,
AttendingPhysicianFirstName,
OperatingPhysicianNPI,
OperatingPhysicianStateID,
OperatingPhysicianStateIDQualifier,
OperatingPhysicianLastName,
OperatingPhysicianFirstName,
OtherPhysician1Qualifier,
OtherPhysician1NPI,
OtherPhysician1StateIDQualifier,
OtherPhysician1LastName,
OtherPhysician1FirstName,
OtherPhysician2Qualifier,
OtherPhysician2NPI,
OtherPhysician2StateIDQualifier,
OtherPhysician2LastName,
OtherPhysician2FirstName,
CCCode1,
CCQualifier1,
CCValue1,
CCCode2,
CCQualifier2,
CCValue2,
CCCode3,
CCQualifier3,
CCValue3,
CCCode4,
CCQualifier4,
CCValue4,
UnlabeledField_FL7Upper,
UnlabeledField_FL7Lower,
UnlabeledField_FL37Upper,
UnlabeledField_FL37Lower,
UnlabeledField_FL73,
PatientIdentification8a,
POA_PDx,
POA_SDx1,
POA_SDx2,
POA_SDx3,
POA_SDx4,
POA_SDx5,
POA_SDx6,
POA_SDx7,
POA_SDx8,
POA_SDx9,
POA_SDx10,
POA_SDx11,
POA_SDx12,
POA_SDx13,
POA_SDx14,
POA_SDx15,
POA_SDx16,
POA_SDx17,
POA_ECI1,
POA_ECI2,
POA_ECI3,
ProviderTaxonomyCode,
VersionNumber,
ExternalInjuryCauseCode4,
ExternalInjuryCauseCode5,
ExternalInjuryCauseCode6,
ExternalInjuryCauseCode7,
ExternalInjuryCauseCode8,
ExternalInjuryCauseCode9,
ExternalInjuryCauseCode10,
ExternalInjuryCauseCode11,
ExternalInjuryCauseCode12,
POA_ECI4,
POA_ECI5,
POA_ECI6,
POA_ECI7,
POA_ECI8,
POA_ECI9,
POA_ECI10,
POA_ECI11,
POA_ECI12,
asdfs.sdfsadfaf=OtherProcedureCode6,
OtherProcedureCode7,
OtherProcedureCode8,
OtherProcedureCode9,
OtherProcedureCode10,
OtherProcedureCode11,
OtherProcedureCode12,
OtherProcedureCode13,
OtherProcedureCode14,
OtherProcedureCode15,
OtherProcedureCode16,
OtherProcedureCode17,
OtherProcedureCode18,
OtherProcedureCode19,
OtherProcedureCode20,
OtherProcedureCode21,
OtherProcedureCode22,
OtherProcedureCode23,
OtherProcedureCode24,
OtherProcedureDate6 ,
OtherProcedureDate7 ,
OtherProcedureDate8 ,
OtherProcedureDate9 ,
OtherProcedureDate10 ,
OtherProcedureDate11 ,
OtherProcedureDate12,
OtherProcedureDate13,
OtherProcedureDate14,
OtherProcedureDate15,
OtherProcedureDate16,
OtherProcedureDate17,
OtherProcedureDate18,
OtherProcedureDate19,
OtherProcedureDate20,
OtherProcedureDate21,
OtherProcedureDate22,
OtherProcedureDate23,
OtherProcedureDate24,
POA_SDx18,
POA_SDx19,
POA_SDx20,
POA_SDx21,
POA_SDx22,
POA_SDx23,
POA_SDx24,
OtherDiagnosisCode18,
OtherDiagnosisCode19,
OtherDiagnosisCode20,
OtherDiagnosisCode21,
OtherDiagnosisCode22,
OtherDiagnosisCode23,
OtherDiagnosisCode24
FROM STAGING.UB04_Load x
JOIN (SELECT UB04_LoadSegmentNumber, SUM(Charges) as TotalDetailCharges, SUM(CASE WHEN IsFacilityCharge = 1 THEN Charges ELSE 0 END) as TotalDetailFacilityCharges
FROM STAGING.UB04Detail_Load
WHERE LoadBatchID=717593
AND IsValid=1
GROUP BY UB04_LoadSegmentNumber
) xd ON x.SegmentNumber=xd.UB04_LoadSegmentNumber
WHERE x.RowID BETWEEN 2226942 AND 2227669
AND x.LoadbatchID=717593
AND x.IsValid=1
SELECT @UBRowsInserted=@@ROWCOUNT
Print 'Done. Inserted ' + cast(@UbRowsInserted as varchar(10)) + 'UB records.'
Print 'Inserting detail...'
/* INSERT UB DETAIL RECORDS */
INSERT INTO app.UB04Detail (
UB04ID,
RevenueCode,
Description,
HCPCSRates,
ProcedureCode,
RoomRate,
ServiceDateSerial,
ServiceUnits,
Charges,
NonCoveredCharges,
UnlabeledField_FL49,
RV)
SELECT ub.UB04ID,
ubd.RevenueCode,
ubd.Description,
ubd.HCPCSRates,
ubd.CPTCode,
ubd.RoomRate,
ubd.ServiceDateSerial,
ubd.ServiceUnits,
ISNULL(ubd.Charges,0),
ubd.NonCoveredCharges,
ubd.UnlabeledField_FL49,
0 as RV
FROM STAGING.UB04Detail_Load ubd
JOIN App.UB04 ub ON ubd.UB04_LoadSegmentNumber=ub.SegmentNumber AND ubd.LoadBatchID=ub.LoadBatchID
JOIN Staging.UB04_Load x ON x.SegmentNumber=ubd.UB04_LoadSegmentNumber AND ubd.LoadbatchID=x.LoadbatchID
WHERE ubd.IsValid=1
AND x.IsValid=1
AND ub.LoadbatchID=x.LoadbatchID
AND x.RowID BETWEEN 2226942 AND 2227669
AND x.LoadbatchID=717593
SELECT @UBDetailRowsInserted=@@ROWCOUNT
Print 'Done. Inserted ' + cast(@UBDetailRowsInserted as varchar(10)) + ' detail records.'
Print 'Checking for errors...'
IF (ISNULL(@ValidUBCount,0) < @RecordsInBatch) OR ISNULL(@UBRowsInserted,0) != ISNULL(@ValidUBCount,0)
BEGIN
Print 'Found errors. Inserting UB level errors into LoadbatchError...'
INSERT INTO STAGING.LoadBatchError
(LoadBatchID,
RowID,
ErrorDescription)
SELECT
717593,
RowID,
ValidationMessage
FROM STAGING.UB04_Load x
WHERE IsValid=0
AND x.LoadbatchID=717593
AND x.RowID BETWEEN 2226942 and 2227669
Print 'Done inserting UB errors'
Print 'Inserting detail errors...'
INSERT INTO STAGING.LoadBatchError
(LoadBatchID,
RowID,
ErrorDescription)
SELECT
717593,
ubd.RowID,
'Invalid Detail record:' + ISNULL(ubd.ValidationMessage,'(EMPTY)')
FROM STAGING.UB04Detail_Load ubd
JOIN Staging.UB04_Load xw ON x.SegmentNumber=ubd.UB04_LoadSegmentNumber AND ubd.LoadbatchID=x.LoadbatchID
WHERE ubd.IsValid=0
AND x.LoadbatchID=717593
AND x.RowID BETWEEN 2226942 and 2227669
Print ' Done inserting detail errors.'
END
PROC_CLEANUP:
Print 'Cleaning up load records...'
DELETE ubd
FROM STAGING.UB04Detail_Load ubd
JOIN App.UB04 ub ON ubd.UB04_LoadSegmentNumber=ub.SegmentNumber AND ub.LoadBatchID=717593
WHERE ubd.LoadbatchID=717593
AND ubd.IsValid=1
Print 'Done with UB cleanup.'
Print 'Cleaning up detail records...'
DELETE x
FROM STAGING.UB04_Load x
JOIN APP.UB04 ub ON x.RowID = ub.SegmentNumber AND ub.LoadBatchID=717593
LEFT JOIN STAGING.UB04Detail_Load ubd ON ubd.UB04_LoadSegmentNumber=ub.SegmentNumber AND ub.LoadBatchID=717593
WHERE x.RowID BETWEEN 2226942 AND 2227669
AND x.LoadbatchID=717593
AND ubd.RowID IS NULL
Print 'Done with detail..'
SET @ReturnValue=0
COMMIT TRANSACTION
END TRY
BEGIN CATCH
Exec usp_PrintErrorInfo
RaisError('Problem in Ub Loader for LoadbatchID %d. Details to follow...', 16,1, 717593)
ROLLBACK TRANSACTION
END CATCH
IF ISNULL(@UBRowsInserted,0) != ISNULL(@ValidUBCount,0)
BEGIN
RaisError('Number of UB records inserted %d does not match the number of valid records %d. Check to make sure each UB record has a detail record.', 16,1,@UbRowsInserted, @ValidUBCount)
SET @ReturnValue=99
END
--RETURN @ReturnValue
";
RegexOptions options = RegexOptions.IgnorePatternWhitespace;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx