Example #1
0
        public void TransformToInstitutionalClaim4010Test()
        {
            var service = new ClaimTransformationService();

            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("OopFactory.X12.Hipaa.Tests.Unit.Claims.TestData.InstitutionalClaim4010.txt");

            var document = service.Transform837ToClaimDocument(stream);

            string xml = document.Serialize();

            Trace.Write(xml);

            Assert.AreEqual(1, document.Claims.Count, "Expected one claim");

            Claim claim = document.Claims.First();

            // Box 1 - Service Location
            Assert.AreEqual("JONES HOSPITAL", claim.ServiceLocation.Name.LastName, "Unexpected Billing Provider Last Name");
            Assert.AreEqual("225 MAIN STREET BARKLEY BUILDING", claim.ServiceLocation.Address.Line1, "Unexpected Billing Provider Adddress Line 1");
            Assert.AreEqual("CENTERVILLE", claim.ServiceLocation.Address.City, "Unexpected Billing Provider Address City");
            Assert.AreEqual("PA", claim.ServiceLocation.Address.StateCode, "Unexpected Billing Provider Address State Code");
            Assert.AreEqual("17111", claim.ServiceLocation.Address.PostalCode, "Unexpected Billing Provider Address Postal Code");
            // Box 2 - Pay To Provider
            Assert.AreEqual(ClaimTypeEnum.Institutional, claim.Type);
            Assert.AreEqual("JONES HOSPITAL", claim.PayToProvider.Name.LastName, "Unexpected Billing Provider Last Name");
            Assert.AreEqual("225 MAIN STREET BARKLEY BUILDING", claim.PayToProvider.Address.Line1, "Unexpected Billing Provider Adddress Line 1");
            Assert.AreEqual("CENTERVILLE", claim.PayToProvider.Address.City, "Unexpected Billing Provider Address City");
            Assert.AreEqual("PA", claim.PayToProvider.Address.StateCode, "Unexpected Billing Provider Address State Code");
            Assert.AreEqual("17111", claim.PayToProvider.Address.PostalCode, "Unexpected Billing Provider Address Postal Code");
            // Box 3a - Patient Control Number
            Assert.AreEqual("756048Q", claim.PatientControlNumber, "Unexpected PatientControlNumber");
            // Box 3b - Type of Bill
            Assert.AreEqual("TEST MEDICAL RECORD NUMBER", claim.MedicalRecordNumber, "Unexpected MedicalRecordNumber");
            // Box 4 - Type of Bill
            Assert.AreEqual("14", claim.ServiceLocationInfo.FacilityCode, "Unexpected facility code");
            Assert.AreEqual("A", claim.ServiceLocationInfo.Qualifier, "Unexpected facility code qualifier");
            Assert.AreEqual("1", claim.ServiceLocationInfo.FrequencyTypeCode, "Unexpected frequency type code");
            // Box 5 - Federal Tax Number
            Assert.AreEqual("123456789", claim.PayToProvider.TaxId, "Unexpected Federal Tax ID");
            // Box 6 Statement Covers Period
            Assert.AreEqual(DateTime.Parse("1996-9-11"), claim.StatementFromDate, "Unexpected statement from date");
            Assert.AreEqual(DateTime.Parse("1996-9-11"), claim.StatementToDate, "Unexpected statement through date");
            // Box 7 - Filler

            ClaimMember patient = claim.Patient ?? claim.Subscriber;

            // Box 8 - Patient Name
            Assert.AreEqual("DOE", patient.Name.LastName, "Unexpected patient last name");
            Assert.AreEqual("JOHN", patient.Name.FirstName, "Unexpected patient first name");
            Assert.AreEqual("T", patient.Name.MiddleName, "Unexpected patient middle name");
            Assert.AreEqual("030005074A", patient.MemberId);
            // Box 9 Patient Address
            Assert.AreEqual("125 CITY AVENUE", patient.Address.Line1, "Unexpected patient address line 1");
            Assert.AreEqual("CENTERVILLE", patient.Address.City, "Unexpected patient address city");
            Assert.AreEqual("PA", patient.Address.StateCode, "Unexpected patient address state code");
            Assert.AreEqual("17111", patient.Address.PostalCode, "Unexpected patient address postal code");
            // Box 10 Birthdate
            Assert.AreEqual(DateTime.Parse("1926-11-11"), patient.DateOfBirth);
            // Box 11 Sex
            Assert.AreEqual(GenderEnum.Male, patient.Gender);
            // Box 12 & 13 Admission Date and Hour
            Assert.AreEqual(DateTime.Parse("1996-09-10 2:02 PM"), claim.AdmissionDate);
            // Box 14 Admission Type

            // Box 15 Admission Source


            Assert.AreEqual(2, claim.ServiceLines.Count, "Unexpected number of service lines.");

            ServiceLine line = claim.ServiceLines[0];

            Assert.AreEqual("305", line.RevenueCode);
            Assert.AreEqual("85025", line.Procedure.ProcedureCode);
        }
Example #2
0
        /// <summary>
        /// Takes a generic claim object stream parameter and maps properties to
        /// corresponding properties in the HCFA 1500 claim. Returns a HCFA1500 claim.
        /// Follows crosswalk published at http://www.nucc.org/images/stories/PDF/1500_form_map_to_837p_4010a1_v1-0_112008.pdf
        /// </summary>
        /// <param name="claim"></param>
        /// <returns></returns>
        public virtual HCFA1500Claim TransformClaimToHcfa1500(Claim claim)
        {
            var hcfa = new HCFA1500Claim();

            if (claim == null)
            {
                hcfa.Field24_ServiceLines = new List <HCFA1500ServiceLine>();
                hcfa.Field24_ServiceLines.Add(new HCFA1500ServiceLine());
                return(hcfa);
            }

            String indicatorCode = null;

            if (claim.SubscriberInformation != null &&
                claim.SubscriberInformation.ClaimFilingIndicatorCode != null)
            {
                indicatorCode = claim.SubscriberInformation.ClaimFilingIndicatorCode;
            }

            switch (indicatorCode)
            {
            case "CH":
                hcfa.Field01_TypeOfCoverageIsTricareChampus = true;
                break;

            case "MB":
                hcfa.Field01_TypeOfCoverageIsMedicare = true;
                break;

            case "MC":
                hcfa.Field01_TypeOfCoverageIsMedicaid = true;
                break;

            case "VA":
                hcfa.Field01_TypeOfCoverageIsChampVa = true;
                break;

            default:
                if (claim.SubscriberInformation != null && claim.SubscriberInformation.ClaimFilingIndicatorCode != null)
                {
                    hcfa.Field01_TypeOfCoverageIsOther = true;
                }
                break;
            }

            // XXX: I don't see any code corresponding to FECA Black Lung in the 837P standard
            hcfa.Field01_TypeOfCoverageIsFECABlkLung     = false;
            hcfa.Field01_TypeOfCoverageIsGroupHealthPlan = false;

            ClaimMember patient    = claim.Patient ?? claim.Subscriber;
            ClaimMember subscriber = claim.Subscriber;

            if (!String.IsNullOrEmpty(patient.MemberId))
            {
                hcfa.Field01a_InsuredsIDNumber = patient.MemberId;
            }
            else if (patient != null &&
                     patient.Name != null &&
                     patient.Name.Identification != null &&
                     !string.IsNullOrEmpty(patient.Name.Identification.Id))
            {
                hcfa.Field01a_InsuredsIDNumber = patient.Name.Identification.Id;
            }
            else if (!String.IsNullOrEmpty(subscriber.MemberId))
            {
                hcfa.Field01a_InsuredsIDNumber = subscriber.MemberId;
            }
            else if (subscriber != null &&
                     subscriber.Name != null &&
                     subscriber.Name.Identification != null &&
                     !string.IsNullOrEmpty(subscriber.Name.Identification.Id))
            {
                hcfa.Field01a_InsuredsIDNumber = subscriber.Name.Identification.Id;
            }
            hcfa.Field01a_InsuredsIDNumber = hcfa.Field01a_InsuredsIDNumber;

            // Patient Name
            if (patient.Name != null)
            {
                hcfa.Field02_PatientsName = patient.Name.Formatted();
            }

            // patient birthdate
            if (patient.DateOfBirth != null)
            {
                hcfa.Field03_PatientsDateOfBirth = formatFormDate(patient.DateOfBirth);
            }

            hcfa.Field03_PatientsSexFemale = patient.Gender == GenderEnum.Female;
            hcfa.Field03_PatientsSexMale   = patient.Gender == GenderEnum.Male;

            if (subscriber.Name != null)
            {
                hcfa.Field04_InsuredsName = subscriber.Name.Formatted();
            }

            // Patient Address
            if (patient.Address != null)
            {
                hcfa.Field05_PatientsAddress_Street = String.Format("{0} {1}", patient.Address.Line1, patient.Address.Line2).TrimEnd();
                hcfa.Field05_PatientsAddress_City   = patient.Address.City;
                hcfa.Field05_PatientsAddress_State  = patient.Address.StateCode;
                hcfa.Field05_PatientsAddress_Zip    = patient.Address.PostalCode;
            }

            // Relationship information from https://www.cahabagba.com/part_b/msp/Providers_Electronic_Billing_Instructions.htm
            String patientRelationship = String.Empty;

            if (claim.Patient != null && claim.Patient.Relationship != null)
            {
                patientRelationship = claim.Patient.Relationship.Code;
            }
            else if (claim.SubscriberInformation != null)
            {
                patientRelationship = claim.SubscriberInformation.IndividualRelationshipCode;
            }
            switch (patientRelationship)
            {
            case "01":
                hcfa.Field06_PatientRelationshipToInsuredIsSpouseOf = true;
                break;

            case "19":
                hcfa.Field06_PatientRelationshipToInsuredIsChildOf = true;
                break;

            case "18":
                hcfa.Field06_PatientRelationshipToInsuredIsSelf = true;
                break;

            default:
                if (claim.SubscriberInformation != null && claim.SubscriberInformation.ClaimFilingIndicatorCode != null)
                {
                    hcfa.Field06_PatientRelationshipToInsuredIsOther = true;
                }
                break;
            }

            if (subscriber.Address != null)
            {
                hcfa.Field07_InsuredsAddress_Street = subscriber.Address.Line1;
                hcfa.Field07_InsuredsAddress_City   = subscriber.Address.City;
                hcfa.Field07_InsuredsAddress_State  = subscriber.Address.StateCode;
                hcfa.Field07_InsuredsAddress_Zip    = subscriber.Address.PostalCode;
            }

            // Not present on 837P
            hcfa.Field07_InsuredsAreaCode    = String.Empty;
            hcfa.Field07_InsuredsPhoneNumber = String.Empty;

            // Not present on 837P
            hcfa.Field08_PatientStatusIsEmployed        = false;
            hcfa.Field08_PatientStatusIsFullTimeStudent = false;
            hcfa.Field08_PatientStatusIsMarried         = false;
            hcfa.Field08_PatientStatusIsOther           = false;
            hcfa.Field08_PatientStatusIsPartTimeStudent = false;
            hcfa.Field08_PatientStatusIsSingle          = false;

            OtherSubscriberInformation otherSubscriber = null;

            if (claim.OtherSubscriberInformations != null)
            {
                otherSubscriber = claim.OtherSubscriberInformations.FirstOrDefault();
            }


            // No way to get below three fields using 837P
            hcfa.Field09b_OtherInsuredIsFemale     = false;
            hcfa.Field09b_OtherInsuredIsMale       = false;
            hcfa.Field09b_OtherInsuredsDateOfBirth = new FormDate();

            if (otherSubscriber != null)
            {
                if (otherSubscriber.Name != null)
                {
                    hcfa.Field09_OtherInsuredsName = otherSubscriber.Name.Formatted();
                }
                if (otherSubscriber.SubscriberInformation != null)
                {
                    hcfa.Field09a_OtherInsuredsPolicyOrGroup = otherSubscriber.SubscriberInformation.ReferenceIdentification;
                }
                hcfa.Field09b_OtherInsuredsDateOfBirth = formatFormDate(otherSubscriber.DateOfBirth);
                hcfa.Field09b_OtherInsuredIsFemale     = otherSubscriber.Gender == GenderEnum.Female;
                hcfa.Field09b_OtherInsuredIsMale       = otherSubscriber.Gender == GenderEnum.Male;
                hcfa.Field09c_OtherInsuredsEmployerNameOrSchoolName = String.Empty;         // XXX: OK to assume org in last name? , Edit: this field should be left blank
                if (otherSubscriber.OtherPayer != null)
                {
                    hcfa.Field09d_OtherInsuredsInsurancePlanNameOrProgramName = otherSubscriber.OtherPayer.LastName;
                }
            }

            hcfa.Field10a_PatientConditionRelatedToEmployment    = claim.RelatedCauseCode1 == "EM" || claim.RelatedCauseCode2 == "EM" || claim.RelatedCauseCode3 == "EM";
            hcfa.Field10b_PatientConditionRelatedToAutoAccident  = claim.RelatedCauseCode1 == "AA" || claim.RelatedCauseCode2 == "AA" || claim.RelatedCauseCode3 == "AA";
            hcfa.Field10c_PatientConditionRelatedToOtherAccident = claim.RelatedCauseCode1 == "AB" || claim.RelatedCauseCode1 == "AP" || claim.RelatedCauseCode1 == "OA" ||
                                                                   claim.RelatedCauseCode2 == "AB" || claim.RelatedCauseCode2 == "AP" || claim.RelatedCauseCode2 == "OA" ||
                                                                   claim.RelatedCauseCode3 == "AB" || claim.RelatedCauseCode3 == "AP" || claim.RelatedCauseCode3 == "OA";
            hcfa.Field10b_PatientConditionRelToAutoAccidentState = claim.AutoAccidentState;

            if (hcfa.Field10a_PatientConditionRelatedToEmployment)
            {
                hcfa.Field10d_ReservedForLocalUse = String.Empty;
            }

            if (claim.SubscriberInformation != null)
            {
                hcfa.Field11_InsuredsPolicyGroupOfFECANumber = claim.SubscriberInformation.ReferenceIdentification;
            }
            if (subscriber != null)
            {
                hcfa.Field11a_InsuredsDateOfBirth = formatFormDate(subscriber.DateOfBirth);
                hcfa.Field11a_InsuredsSexIsFemale = subscriber.Gender == GenderEnum.Female;
                hcfa.Field11a_InsuredsSexIsMale   = subscriber.Gender == GenderEnum.Male;
            }
            if (claim.Payer != null)
            {
                hcfa.Field11b_InsuredsEmployerOrSchool = String.Empty;         // should be left blank
                if (claim.Payer.Name != null)
                {
                    hcfa.Field11c_InsuredsPlanOrProgramName = claim.Payer.Name.LastName;
                }
            }

            hcfa.Field11d_IsThereOtherHealthBenefitPlan = otherSubscriber != null;

            hcfa.Field12_PatientsOrAuthorizedSignature = claim.ReleaseOfInformationCode == "Y" ? "Signature on file" : String.Empty;

            hcfa.Field12_PatientsOrAuthorizedSignatureDate = new FormDate();

            hcfa.Field13_InsuredsOrAuthorizedSignature = claim.BenefitsAssignmentCertificationIndicator == "Y" ? "Signature on file" : String.Empty;

            var onsetDate = claim.Dates.FirstOrDefault(dr => dr.Qualifier == "431") ?? claim.Dates.FirstOrDefault(dr => dr.Qualifier == "439");

            if (onsetDate != null)
            {
                hcfa.Field14_DateOfCurrentIllnessInjuryOrPregnancy = formatFormDate(onsetDate.Date);
            }

            var similarIllnessDate = claim.Dates.FirstOrDefault(dr => dr.Qualifier == "438");     // only supported in 4010 837P

            if (similarIllnessDate != null)
            {
                hcfa.Field15_DatePatientHadSameOrSimilarIllness = formatFormDate(similarIllnessDate.Date);
            }

            var disabilityStart = claim.Dates.FirstOrDefault(dr => dr.Qualifier == "360");
            var disabilityEnd   = claim.Dates.FirstOrDefault(dr => dr.Qualifier == "361");

            if (disabilityStart != null)
            {
                hcfa.Field16_DatePatientUnableToWork_Start = formatFormDate(disabilityStart.Date);
            }
            if (disabilityEnd != null)
            {
                hcfa.Field16_DatePatientUnableToWork_End = formatFormDate(disabilityEnd.Date);
            }

            var referringProvider = claim.Providers.FirstOrDefault(pr => pr.Name.Type.Identifier == "DN" && pr.Name.Identification.Qualifier == "XX");

            if (referringProvider != null)
            {
                hcfa.Field17_ReferringProviderOrOtherSource_Name = referringProvider.Name.Formatted();

                var id = referringProvider.Identifications.FirstOrDefault();
                if (id != null)
                {
                    hcfa.Field17a_OtherID_Number    = id.Id;
                    hcfa.Field17a_OtherID_Qualifier = id.Qualifier;
                }

                hcfa.Field17b_NationalProviderIdentifier = referringProvider.Npi;
            }

            // Admission date and hour
            hcfa.Field18_HospitalizationDateFrom = new FormDate();
            hcfa.Field18_HospitalizationDateTo   = new FormDate();
            if (claim.AdmissionDate.HasValue)
            {
                hcfa.Field18_HospitalizationDateFrom = formatFormDate(claim.AdmissionDate);
            }
            if (claim.DischargeTime.HasValue)
            {
                hcfa.Field18_HospitalizationDateTo = formatFormDate(claim.DischargeTime);
            }

            // Populating Loc19 with notes from 837
            // There can only be one note
            hcfa.Field19_ReservedForLocalUse = (claim.Notes.Count >= 1) ? claim.Notes[0].Description : System.String.Empty;

            // Outside services are stored in claim service lines
            double totalAmountSpent = 0.0;

            foreach (var line in claim.ServiceLines)
            {
                if (line.PurchasedServiceIdentifier != null)
                {
                    hcfa.Field20_OutsideLab = true;
                    if (line.PurchasedServiceAmount != null)
                    {
                        totalAmountSpent += Convert.ToDouble(line.PurchasedServiceAmount);
                    }
                }
            }

            hcfa.Field20_OutsideLabCharges = (Decimal)totalAmountSpent;

            var principalDiagnosis = claim.Diagnoses.FirstOrDefault(d => d.DiagnosisType == DiagnosisTypeEnum.Principal);
            var otherDiagnoses     = claim.Diagnoses.Where(d => d.DiagnosisType == DiagnosisTypeEnum.Other).ToList();

            // Diagnosis codes
            if (principalDiagnosis != null)
            {
                hcfa.Field21_Diagnosis1 = principalDiagnosis.FormattedCode();
            }
            if (otherDiagnoses.Count >= 1)
            {
                hcfa.Field21_Diagnosis2 = otherDiagnoses[0].FormattedCode();
            }
            if (otherDiagnoses.Count >= 2)
            {
                hcfa.Field21_Diagnosis3 = otherDiagnoses[1].FormattedCode();
            }
            if (otherDiagnoses.Count >= 3)
            {
                hcfa.Field21_Diagnosis4 = otherDiagnoses[2].FormattedCode();
            }

            var frequencyType = "";

            if (claim.BillTypeCode.Length == 3)
            {
                frequencyType = claim.BillTypeCode.Substring(2, 1);
            }
            if (frequencyType == "7" || frequencyType == "8")
            {
                hcfa.Field22_MedicaidSubmissionCode = frequencyType;
            }
            else
            {
                hcfa.Field22_MedicaidSubmissionCode = String.Empty;
            }

            var originalRef = claim.Identifications.FirstOrDefault(id => id.Qualifier == "F8");

            if (originalRef != null)
            {
                hcfa.Field22_OriginalReferenceNumber = originalRef.Id;
            }
            else
            {
                hcfa.Field22_OriginalReferenceNumber = String.Empty;
            }

            hcfa.Field23_PriorAuthorizationNumber = claim.PriorAuthorizationNumber;

            var hcfaServiceLines = new List <HCFA1500ServiceLine>();

            // Service Lines
            foreach (var line in claim.ServiceLines)
            {
                var hcfaLine = new HCFA1500ServiceLine();
                hcfaLine.DateFrom = new FormDate
                {
                    MM = String.Format("{0:MM}", line.ServiceDateFrom),
                    DD = String.Format("{0:dd}", line.ServiceDateFrom),
                    YY = String.Format("{0:yy}", line.ServiceDateFrom)
                };
                hcfaLine.DateTo = new FormDate
                {
                    MM = String.Format("{0:MM}", line.ServiceDateTo),
                    DD = String.Format("{0:dd}", line.ServiceDateTo),
                    YY = String.Format("{0:yy}", line.ServiceDateTo)
                };

                if (line.PlaceOfService != null && !string.IsNullOrWhiteSpace(line.PlaceOfService.Code))
                {
                    hcfaLine.PlaceOfService = line.PlaceOfService.Code;
                }
                else
                {
                    hcfaLine.PlaceOfService = claim.ServiceLocationInfo.FacilityCode;
                }

                hcfaLine.EmergencyIndicator = line.EmergencyIndicator;

                hcfaLine.ProcedureCode = line.Procedure.ProcedureCode;
                hcfaLine.ProcedureCode = line.Procedure.ProcedureCode;
                hcfaLine.Mod1          = line.Procedure.Modifier1;
                hcfaLine.Mod2          = line.Procedure.Modifier2;
                hcfaLine.Mod3          = line.Procedure.Modifier3;
                hcfaLine.Mod4          = line.Procedure.Modifier4;

                hcfaLine.DiagnosisPointer1 = line.DiagnosisCodePointer1;
                hcfaLine.DiagnosisPointer2 = line.DiagnosisCodePointer2;
                hcfaLine.DiagnosisPointer3 = line.DiagnosisCodePointer3;
                hcfaLine.DiagnosisPointer4 = line.DiagnosisCodePointer4;

                hcfaLine.Charges     = line.ChargeAmount;
                hcfaLine.DaysOrUnits = line.Quantity;
                hcfaLine.EarlyPeriodicScreeningDiagnosisAndTreatment = line.EpsdtIndicator;

                if (line.RenderingProvider != null && !string.IsNullOrWhiteSpace(line.RenderingProvider.Npi))
                {
                    hcfaLine.RenderingProviderNpi = line.RenderingProvider.Npi;
                }
                else if (claim.RenderingProvider != null && !string.IsNullOrWhiteSpace(claim.RenderingProvider.Npi))
                {
                    hcfaLine.RenderingProviderNpi = claim.RenderingProvider.Npi;
                }

                if (line.RenderingProvider != null && line.RenderingProvider.Identifications.Count > 0)
                {
                    hcfaLine.RenderingProviderIdQualifier = line.RenderingProvider.Identifications[0].Qualifier;
                    hcfaLine.RenderingProviderId          = line.RenderingProvider.Identifications[0].Id;
                }
                else if (line.RenderingProvider != null && line.RenderingProvider.ProviderInfo != null)
                {
                    hcfaLine.RenderingProviderIdQualifier = line.RenderingProvider.ProviderInfo.Qualifier;
                    hcfaLine.RenderingProviderId          = line.RenderingProvider.ProviderInfo.Id;
                }
                else if (claim.RenderingProvider != null && claim.RenderingProvider.Identifications.Count > 0)
                {
                    hcfaLine.RenderingProviderIdQualifier = claim.RenderingProvider.Identifications[0].Qualifier;
                    hcfaLine.RenderingProviderId          = claim.RenderingProvider.Identifications[0].Id;
                }
                else if (claim.RenderingProvider != null && claim.RenderingProvider.ProviderInfo != null)
                {
                    hcfaLine.RenderingProviderIdQualifier = claim.RenderingProvider.ProviderInfo.Qualifier;
                    hcfaLine.RenderingProviderId          = claim.RenderingProvider.ProviderInfo.Id;
                }


                hcfaServiceLines.Add(hcfaLine);
            }
            hcfa.Field24_ServiceLines = hcfaServiceLines;


            // Federal Tax Number
            if (claim.PayToProvider != null && !string.IsNullOrWhiteSpace(claim.PayToProvider.TaxId))
            {
                hcfa.Field25_FederalTaxIDNumber = claim.PayToProvider.TaxId;
                if (claim.PayToProvider.Identifications.Exists(id => id.Qualifier == "EI"))
                {
                    hcfa.Field25_IsEIN = true;
                }
                if (claim.PayToProvider.Identifications.Exists(id => id.Qualifier == "SY"))
                {
                    hcfa.Field25_IsSSN = true;
                }
            }
            else
            {
                if (claim.BillingProvider != null)
                {
                    hcfa.Field25_FederalTaxIDNumber = claim.BillingProvider.TaxId;
                    if (claim.BillingProvider.Identifications.Exists(id => id.Qualifier == "EI"))
                    {
                        hcfa.Field25_IsEIN = true;
                    }
                    if (claim.BillingProvider.Identifications.Exists(id => id.Qualifier == "SY"))
                    {
                        hcfa.Field25_IsSSN = true;
                    }
                }
            }

            // shouldnt we represent hcfa.Field25_IsSSN and Field25_IsEIN to know which type TaxID?
            hcfa.Field26_PatientAccountNumber = claim.PatientControlNumber;

            if (claim.ProviderAcceptAssignmentCode == "A" || claim.ProviderAcceptAssignmentCode == "B")
            {
                hcfa.Field27_AcceptAssignment = true;
            }
            else if (claim.ProviderAcceptAssignmentCode == "C")
            {
                hcfa.Field27_AcceptAssignment = false;
            }

            hcfa.Field28_TotalCharge = claim.TotalClaimChargeAmount;
            hcfa.Field29_AmountPaid  = claim.PatientAmountPaid ?? 0;
            foreach (var otherSubscriberObj in claim.OtherSubscriberInformations)
            {
                if (otherSubscriberObj.Amounts.Count > 0)
                {
                    hcfa.Field29_AmountPaid += otherSubscriberObj.Amounts[0].Amount;
                }
            }


            hcfa.Field30_BalanceDue = hcfa.Field28_TotalCharge - hcfa.Field29_AmountPaid;     // does not exist on 837P

            if (claim.ProviderSignatureOnFile == "Y")
            {
                hcfa.Field31_PhysicianOrSupplierSignatureIsOnFile = true;
            }
            else if (claim.ProviderSignatureOnFile == "N")
            {
                hcfa.Field31_PhysicianOrSupplierSignatureIsOnFile = false;
            }

            // Service Location
            var serviceLocation = claim.ServiceLocation;

            if (serviceLocation != null)
            {
                if (serviceLocation.Name != null)
                {
                    hcfa.Field32_ServiceFacilityLocation_Name = serviceLocation.Name.LastName;
                }
                else
                {
                    hcfa.Field32_ServiceFacilityLocation_Name = null;
                }

                if (serviceLocation.Address != null)
                {
                    hcfa.Field32_ServiceFacilityLocation_Street = serviceLocation.Address.Line1;
                    hcfa.Field32_ServiceFacilityLocation_City   = serviceLocation.Address.City;
                    hcfa.Field32_ServiceFacilityLocation_State  = serviceLocation.Address.StateCode;
                    hcfa.Field32_ServiceFacilityLocation_Zip    = serviceLocation.Address.PostalCode;
                }
                else
                {
                    hcfa.Field32_ServiceFacilityLocation_Street = string.Empty;
                    hcfa.Field32_ServiceFacilityLocation_City   = string.Empty;
                    hcfa.Field32_ServiceFacilityLocation_State  = string.Empty;
                    hcfa.Field32_ServiceFacilityLocation_Zip    = string.Empty;
                }

                hcfa.Field32a_ServiceFacilityLocation_Npi = serviceLocation.Npi;
                if (serviceLocation.Identifications != null && serviceLocation.Identifications.Count > 0)
                {
                    hcfa.Field32b_ServiceFacilityLocation_OtherID = serviceLocation.Identifications.First().Id;
                }
                else
                {
                    hcfa.Field32b_ServiceFacilityLocation_OtherID = null;
                }
            }
            // Pay To Provider
            if (claim.BillingProvider != null)
            {
                if (claim.BillingProvider.Name != null)
                {
                    hcfa.Field33_BillingProvider_Name = claim.BillingProvider.Name.LastName;
                }
                else
                {
                    hcfa.Field33_BillingProvider_Name = null;
                }

                if (claim.BillingProvider.Address != null)
                {
                    hcfa.Field33_BillingProvider_Street = claim.BillingProvider.Address.Line1;
                    hcfa.Field33_BillingProvider_City   = claim.BillingProvider.Address.City;
                    hcfa.Field33_BillingProvider_State  = claim.BillingProvider.Address.StateCode;
                    hcfa.Field33_BillingProvider_Zip    = claim.BillingProvider.Address.PostalCode;
                }
                else
                {
                    hcfa.Field33_BillingProvider_Street = string.Empty;
                    hcfa.Field33_BillingProvider_City   = string.Empty;
                    hcfa.Field33_BillingProvider_State  = string.Empty;
                    hcfa.Field33_BillingProvider_Zip    = string.Empty;
                }

                hcfa.Field33a_BillingProvider_Npi = claim.BillingProvider.Npi;
            }

            LimitFieldWidths(hcfa);

            return(hcfa);
        }
Example #3
0
        public void TransformToInstitutionalClaim5010Test()
        {
            var service = new ClaimTransformationService();

            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("OopFactory.X12.Hipaa.Tests.Unit.Claims.TestData.InstitutionalClaim5010.txt");

            var document = service.Transform837ToClaimDocument(stream);

            string xml = document.Serialize();

            Assert.AreEqual(1, document.Claims.Count, "Expected one claim");

            Claim claim = document.Claims.First();

            Trace.Write(claim.Serialize());
            Assert.AreEqual(ClaimTypeEnum.Institutional, claim.Type);
            // Box 1 - Service Location
            Assert.AreEqual("JONES HOSPITAL", claim.ServiceLocation.Name.LastName, "Unexpected Billing Provider Last Name");
            Assert.AreEqual("225 MAIN STREET BARKLEY BUILDING", claim.ServiceLocation.Address.Line1, "Unexpected Billing Provider Adddress Line 1");
            Assert.AreEqual("CENTERVILLE", claim.ServiceLocation.Address.City, "Unexpected Billing Provider Address City");
            Assert.AreEqual("PA", claim.ServiceLocation.Address.StateCode, "Unexpected Billing Provider Address State Code");
            Assert.AreEqual("17111", claim.ServiceLocation.Address.PostalCode, "Unexpected Billing Provider Address Postal Code");
            // Box 2 - Pay To Provider
            Assert.AreEqual("JONES HOSPITAL", claim.PayToProvider.Name.LastName, "Unexpected Billing Provider Last Name");
            Assert.AreEqual("225 MAIN STREET BARKLEY BUILDING", claim.PayToProvider.Address.Line1, "Unexpected Billing Provider Adddress Line 1");
            Assert.AreEqual("CENTERVILLE", claim.PayToProvider.Address.City, "Unexpected Billing Provider Address City");
            Assert.AreEqual("PA", claim.PayToProvider.Address.StateCode, "Unexpected Billing Provider Address State Code");
            Assert.AreEqual("17111", claim.PayToProvider.Address.PostalCode, "Unexpected Billing Provider Address Postal Code");
            // Box 3a - Patient Control Number
            Assert.AreEqual("756048Q", claim.PatientControlNumber, "Unexpected PatientControlNumber");
            // Box 3b - Type of Bill
            Assert.AreEqual("TEST MEDICAL RECORD NUMBER", claim.MedicalRecordNumber, "Unexpected MedicalRecordNumber");
            // Box 4 - Type of Bill
            Assert.AreEqual("14", claim.ServiceLocationInfo.FacilityCode, "Unexpected facility code");
            Assert.AreEqual("A", claim.ServiceLocationInfo.Qualifier, "Unexpected facility code qualifier");
            Assert.AreEqual("1", claim.ServiceLocationInfo.FrequencyTypeCode, "Unexpected frequency type code");
            // Box 5 - Federal Tax Number
            Assert.AreEqual("567891234", claim.PayToProvider.TaxId, "Unexpected Federal Tax ID");
            // Box 6 Statement Covers Period
            Assert.AreEqual(DateTime.Parse("1996-9-11"), claim.StatementFromDate, "Unexpected statement from date");
            Assert.AreEqual(DateTime.Parse("1996-9-11"), claim.StatementToDate, "Unexpected statement through date");
            // Box 7 - Filler

            ClaimMember patient = claim.Patient ?? claim.Subscriber;

            // Box 8 - Patient Name
            Assert.AreEqual("DOE", patient.Name.LastName, "Unexpected patient last name");
            Assert.AreEqual("JOHN", patient.Name.FirstName, "Unexpected patient first name");
            Assert.AreEqual("T", patient.Name.MiddleName, "Unexpected patient middle name");
            Assert.AreEqual("030005074A", patient.MemberId);
            // Box 9 Patient Address
            Assert.AreEqual("125 CITY AVENUE", patient.Address.Line1, "Unexpected patient address line 1");
            Assert.AreEqual("CENTERVILLE", patient.Address.City, "Unexpected patient address city");
            Assert.AreEqual("PA", patient.Address.StateCode, "Unexpected patient address state code");
            Assert.AreEqual("17111", patient.Address.PostalCode, "Unexpected patient address postal code");
            // Box 10 Birthdate
            Assert.AreEqual(DateTime.Parse("1926-11-11"), patient.DateOfBirth);
            // Box 11 Sex
            Assert.AreEqual(GenderEnum.Male, patient.Gender);
            // Box 12 & 13 Admission Date and Hour
            Assert.AreEqual(DateTime.Parse("1996-09-11 2:02 PM"), claim.AdmissionDate);
            // Box 14 Admission Type

            // Box 15 Admission Source

            // Box 16 Discharge Hour

            // Box 17 Discharge Status

            // Box 18 through 28 Condition Codes
            Assert.AreEqual(14, claim.Conditions.Count);
            Assert.AreEqual("01", claim.Conditions[0].Code);
            Assert.AreEqual("02", claim.Conditions[1].Code);
            Assert.AreEqual("03", claim.Conditions[2].Code);
            Assert.AreEqual("04", claim.Conditions[3].Code);
            Assert.AreEqual("05", claim.Conditions[4].Code);
            Assert.AreEqual("06", claim.Conditions[5].Code);
            Assert.AreEqual("07", claim.Conditions[6].Code);
            Assert.AreEqual("08", claim.Conditions[7].Code);
            Assert.AreEqual("09", claim.Conditions[8].Code);
            Assert.AreEqual("10", claim.Conditions[9].Code);
            Assert.AreEqual("11", claim.Conditions[10].Code);

            // Box 29

            // Box 30

            // Box 31 through 34 - Occurrences
            Assert.AreEqual(8, claim.Occurrences.Count);
            Assert.AreEqual("A1", claim.Occurrences[0].Code);
            Assert.AreEqual(DateTime.Parse("1926-11-11"), claim.Occurrences[0].Date);
            Assert.AreEqual("A2", claim.Occurrences[1].Code);
            Assert.AreEqual(DateTime.Parse("1991-11-01"), claim.Occurrences[1].Date);
            Assert.AreEqual("B1", claim.Occurrences[2].Code);
            Assert.AreEqual(DateTime.Parse("1926-11-11"), claim.Occurrences[2].Date);
            Assert.AreEqual("B2", claim.Occurrences[3].Code);
            Assert.AreEqual(DateTime.Parse("1987-1-1"), claim.Occurrences[3].Date);
            Assert.AreEqual("C1", claim.Occurrences[4].Code);
            Assert.AreEqual(DateTime.Parse("1926-11-11"), claim.Occurrences[4].Date);
            Assert.AreEqual("C2", claim.Occurrences[5].Code);
            Assert.AreEqual(DateTime.Parse("1991-11-1"), claim.Occurrences[5].Date);
            Assert.AreEqual("D1", claim.Occurrences[6].Code);
            Assert.AreEqual(DateTime.Parse("1926-11-11"), claim.Occurrences[6].Date);
            Assert.AreEqual("D2", claim.Occurrences[7].Code);
            Assert.AreEqual(DateTime.Parse("1987-1-1"), claim.Occurrences[7].Date);

            // Box 35 through 36 - Occurrence Spans
            Assert.AreEqual(4, claim.OccurrenceSpans.Count);
            Assert.AreEqual("A1", claim.OccurrenceSpans[0].Code);
            Assert.AreEqual(DateTime.Parse("1926-11-11"), claim.OccurrenceSpans[0].FromDate);
            Assert.AreEqual(DateTime.Parse("1927-12-31"), claim.OccurrenceSpans[0].ThroughDate);

            // Box 37 - Filler

            // Box 38 - Responsible Party

            // Box 39 through 41 - Value Codes
            Assert.AreEqual(14, claim.Values.Count);
            Assert.AreEqual("A2", claim.Values[0].Code);
            Assert.AreEqual(15.31m, claim.Values[0].Amount);
            Assert.AreEqual("N2", claim.Values[13].Code);
            Assert.AreEqual(28.31m, claim.Values[13].Amount);

            // Box 42 through 49 - Service Lines

            Assert.AreEqual(2, claim.ServiceLines.Count, "Unexpected number of service lines.");

            ServiceLine line = claim.ServiceLines[0];

            Assert.AreEqual("0305", line.RevenueCode);
            Assert.AreEqual("85025", line.Procedure.ProcedureCode);
            Assert.AreEqual(13.39m, line.ChargeAmount);
            Assert.AreEqual(1, line.Quantity);
            Assert.AreEqual(DateTime.Parse("1996-9-11"), line.ServiceDateFrom);
            Assert.IsNull(line.OperatingPhysician);

            line = claim.ServiceLines[1];
            Assert.AreEqual("0730", line.RevenueCode);
            Assert.AreEqual("93005", line.Procedure.ProcedureCode);
            Assert.AreEqual("AA", line.Procedure.Modifier1);
            Assert.AreEqual("BB", line.Procedure.Modifier2);
            Assert.AreEqual("CC", line.Procedure.Modifier3);
            Assert.AreEqual("DD", line.Procedure.Modifier4);
            Assert.AreEqual("Test Procedure", line.Procedure.Description);
            Assert.AreEqual(76.54m, line.ChargeAmount);
            Assert.AreEqual(3, line.Quantity);
            Assert.AreEqual(11.15m, line.NonCoveredChargeAmount);
            Assert.AreEqual(DateTime.Parse("1996-9-11"), line.ServiceDateFrom);
            Assert.AreEqual(1, line.Notes.Count);
            Assert.AreEqual("TPO", line.Notes[0].Code);

            Assert.IsNotNull(line.OperatingPhysician);
            Assert.AreEqual("JONES", line.OperatingPhysician.Name.LastName);
            Assert.AreEqual("JOHN", line.OperatingPhysician.Name.FirstName);
            Assert.AreEqual("B99937", line.OperatingPhysician.Npi);
            Assert.AreEqual("363LP0200N", line.OperatingPhysician.ProviderInfo.Id);

            // Box 50 through 55 - Payers

            // Box 56 - NPI

            // Box 57 - Other Provider ID

            // Box 68 through 62 - Insured

            // Box 63 through 65 - Authorizations

            // Box 66 - Diagnosis Version

            // Box 67 - Diagnosis
            Assert.AreEqual("3669", claim.Diagnoses.First(d => d.DiagnosisType == DiagnosisTypeEnum.Principal).Code);
            // Box 68

            // Box 69 - Admitting Diagnosis

            // Box 70 - Patient Reason Diagnosis

            // Box 71 - PPS Code

            // Box 72 - ECI

            // Box 73

            // Box 74 - Procedures
            Assert.AreEqual(3, claim.Procedures.Count);
            var principal = claim.Procedures.FirstOrDefault(p => p.IsPrincipal);

            Assert.IsNotNull(principal);
            Assert.AreEqual("BBR", principal.Qualifier);
            Assert.AreEqual("0B110F5", principal.Code);
            Assert.AreEqual(DateTime.Parse("2005-3-21"), principal.Date);

            // Box 75 - Blank

            // Box 76 - Attending Physician
            Assert.IsNotNull(claim.AttendingProvider);
            Assert.AreEqual("JOHN", claim.AttendingProvider.Name.FirstName);
            Assert.AreEqual("1G", claim.AttendingProvider.Identifications[0].Qualifier);
            Assert.AreEqual("B99937A", claim.AttendingProvider.Identifications[0].Id);

            // Box 77 - Operating Physician
            Assert.IsNotNull(claim.OperatingPhysician);
            Assert.AreEqual("JANE", claim.OperatingPhysician.Name.FirstName);

            // Box 78 - Other
            Assert.IsNotNull(claim.OtherOperatingPhysician);
            Assert.AreEqual("JOE", claim.OtherOperatingPhysician.Name.FirstName);

            // Box 79 - Other

            // Box 80 - Remarks

            // Box 81CC
        }
Example #4
0
 private static void TransformLoop2010BATo837(XmlNode loop2010BA, ClaimMember subscriber)
 {
     var gender = loop2010BA.SelectSingleNode("DMG/DMG03");
     switch (subscriber.Gender)
     {
         case OopFactory.X12.Hipaa.Common.GenderEnum.Unknown:
             gender.InnerText = "";
             break;
         case OopFactory.X12.Hipaa.Common.GenderEnum.Male:
             gender.InnerText = "M";
             break;
         case OopFactory.X12.Hipaa.Common.GenderEnum.Female:
             gender.InnerText= "F";
             break;
         default:
             break;
     }
     var dob= loop2010BA.SelectSingleNode("DMG/DMG02");
     if (subscriber.DateOfBirth.HasValue)
         dob.InnerText= subscriber.DateOfBirth.Value.ToString("yyyyMMdd");
 }