class Relationship(X12SegmentBridge): is_insured = ElementAccess("INS", 1, x12type=boolean('Y')) relationship = ElementAccess("INS", 2, x12type=enum( { "01": "Spouse", "18": "Self", "19": "Child", "21": "Unknown", "34": "Other Adult" }, raw_unknowns=True)) maintenance_type = ElementAccess("INS", 3, x12type=enum({"001": "Change"}, raw_unknowns=True)) maintenance_reason = ElementAccess( "INS", 4, x12type=enum({"25": "Change in Identifying Data Elements"}, raw_unknowns=True)) student_status = ElementAccess("INS", 9, x12type=enum({ "F": "Full-time", "N": "Not a Student", "P": "Part-time" })) handicapped = ElementAccess("INS", 10, x12type=boolean("Y")) birth_sequence_number = ElementAccess("INS", 17)
class RequestValidation(X12SegmentBridge): valid_request = ElementAccess("AAA", 1, x12type=boolean("Y")) reject_reason = ElementAccess("AAA", 3, x12type=enum(reject_reason_code)) follow_up_action_code = ElementAccess( "AAA", 4, x12type=enum({ "C": "Please Correct and Resubmit", "N": "Resubmission Not Allowed", "P": "Please Resubmit Original Transaction", "R": "Resubmission Allowed", "S": "Do Not Resubmit; Inquiry Initiated to a Third Party", "W": "Please Wait 30 Days and Resubmit", "X": "Please Wait 10 Days and Resubmit", "Y": "Do Not Resubmit; We Will Hold Your Request and Respond Again " "Shortly" }))
class _HierarchicalTransaction(X12SegmentBridge): """Use this to start the transaction set. This also indicates the sequence of hierarchical levels of information that will follow, though that information is not used at this time.""" structure = ElementAccess( "BHT", 1, x12type=enum({ "0022": "Information Source, Information Receiver, Subscriber, " "or Dependent." }, raw_unknowns=True)) purpose = ElementAccess( "BHT", 2, x12type=enum({ "01": "Cancellation", "11": "Response", "13": "Request", "36": "Authority to Dedduct (Reply)" }, raw_unknowns=True)) transaction_id = ElementAccess("BHT", 3) creation_date = ElementAccess("BHT", 4, x12type=D8) creation_time = ElementAccess("BHT", 5, x12type=TM) type = ElementAccess( "BHT", 6, x12type=enum({ "RT": "Spend Down", "RU": "Medical Services Reservation" }, raw_unknowns=True))
class _ClaimPaymentInfo(X12LoopBridge): patient_control_number = ElementAccess("CLP", 1) status_code = ElementAccess("CLP", 2, x12type=enum({ "1": "Processed as Primary", "2": "Processed as Secondary", "3": "Processed as Tertiary", "4": "Denied", "19": "Processed as Primary, Forwarded to Additional Payer(s)", "20": "Processed as Secondary, Forwarded to Additional Payer(s)", "21": "Processed as Tertiary, Forwarded to Additional Payer(s)", "22": "Reversal of Previous Payment", "23": "Not Our Claim, Forwarded to Additional Payer(s)", "25": "Predetermination Pricing Only - No Payment"})) total_charge = ElementAccess("CLP", 3, x12type=Money) payment = ElementAccess("CLP", 4, x12type=Money) patient_responsibility = ElementAccess("CLP", 5, x12type=Money) claim_type = ElementAccess("CLP", 6, x12type=enum({ "12": "Preferred Provider Organization (PPO)", "13": "Point of Service (POS)", "14": "Exclusive Provider Organization (EPO)", "15": "Indemnity Insurance", "16": "Health Maintenance Organization (HMO) Medicare Risk", "AM": "Automobile Medical", "CH": "Champus", "DS": "Disability", "HM": "Health Maintenance Organization", "LM": "Liability Medical", "MA": "Medicare Part A", "MB": "Medicare Part B", "MC": "Medicaid", "OF": "Other Federal Program", "TV": "Title V", "VA": "Veteran Administration Plan", "WC": "Workers Compensation Health Claim"})) payer_claim_control_number = ElementAccess("CLP", 7) facility_type = ElementAccess("CLP", 8) frequency_code = ElementAccess("CLP", 9) diagnosis_related_group_weight = ElementAccess("CLP", 11) discharge_fraction = ElementAccess("CLP", 12) # TODO: Medicare inpatient/outpatient adjudication? total_covered_charge = ElementAccess( "AMT", 2, qualifier=(1, "AU"), x12type=Money) discount_amount = ElementAccess( "AMT", 2, qualifier=(1, "D8"), x12type=Money) per_day_limit = ElementAccess( "AMT", 2, qualifier=(1, "DY"), x12type=Money) patient_amount_paid = ElementAccess( "AMT", 2, qualifier=(1, "F5"), x12type=Money) interest = ElementAccess( "AMT", 2, qualifier=(1, "I"), x12type=Money) negative_ledger = ElementAccess( "AMT", 2, qualifier=(1, "NL"), x12type=Money) tax_amount = ElementAccess( "AMT", 2, qualifier=(1, "T"), x12type=Money) total_claim_before_taxes = ElementAccess( "AMT", 2, qualifier=(1, "T2"), x12type=Money)
class EligibilityOrBenefitInquiry(X12SegmentBridge): service_type = ElementAccess("EQ", 1, x12type=enum(service_type_codes)) ada_code = CompositeAccess("EQ", "AD", 2) cpt_code = CompositeAccess("EQ", "CJ", 2) hcpcs_code = CompositeAccess("EQ", "HC", 2) icd_9_cm_code = CompositeAccess("EQ", "ID", 2) hiec_code = CompositeAccess("EQ", "IV", 2) ndc_code = CompositeAccess("EQ", "ND", 2) zz_code = CompositeAccess("EQ", "ZZ", 2) coverage_level = ElementAccess("EQ", 3, x12type=enum(coverage_level)) insurance_type = ElementAccess("EQ", 4, x12type=enum(insurance_type))
class NamedEntity(X12SegmentBridge): entity_identifier = ElementAccess( "NM1", 1, x12type=enum( { "03": "Dependent", "13": "Contracted Service Provider", "1P": "Provider", "2B": "Third-Party Administrator", "36": "Employer", "73": "Other Physician", "80": "Hospital", "FA": "Facility", "GP": "Gateway Provider", "IL": "Insured", "LR": "Legal Representative", "P3": "Primary Care Provider", "P4": "Prior Insurance Carrier", "P5": "Plan Sponsor", "PR": "Payer", "PRP": "Primary Payer", "QC": "Patient", "SEP": "Secondary Payer", "TTP": "Tertiary Payer", "VN": "Vendor", "X3": "Utilization Management Organization" }, raw_unknowns=True)) entity_type = ElementAccess("NM1", 2, x12type=enum({ "1": "Person", "2": "Non-Person Entity" })) last_name = ElementAccess("NM1", 3) org_name = ElementAccess("NM1", 3) first_name = ElementAccess("NM1", 4) middle_initial = ElementAccess("NM1", 5) suffix = ElementAccess("NM1", 7) id_code = ElementAccess("NM1", 9) id_code_qual = ElementAccess("NM1", 8, x12type=enum(id_code_qualifier)) @property def is_person(self): return self.entity_type[0] == "1" @property def is_organization(self): return self.entity_type[0] == "2"
class ContactDetails(X12LoopBridge): name = ElementAccess("N1", 2) id_qualifier = ElementAccess( "N1", 3, x12type=enum({ "XV": "Health Care Financing Administration National Plan ID", "FI": "Federal Taxpayer Identification Number", "XX": "Health Care Financing Administration National Provider ID" })) id = ElementAccess("N1", 4) addr1 = ElementAccess("N3", 1) addr2 = ElementAccess("N3", 2) city = ElementAccess("N4", 1) state = ElementAccess("N4", 2) zip = ElementAccess("N4", 3) country_code = ElementAccess("N4", 4) location_type = ElementAccess( "N4", 5, x12type=enum( { "CY": "County/Parish", "FI": "Federal Information Processing Standards (FIPS) 55 (Named " "Populated Places)" }, raw_unknowns=True)) location_id = ElementAccess("N4", 6) contact_code = ElementAccess("PER", 1, x12type=enum({"IC": "Information Contact"}, raw_unknowns=True)) contact_name = ElementAccess("PER", 2) contact_edi = ElementAccess("PER", oneOf=("ED", (3, 4), (5, 6), (7, 8))) contact_email = ElementAccess("PER", oneOf=("EM", (3, 4), (5, 6), (7, 8))) contact_fax = ElementAccess("PER", oneOf=("FX", (3, 4), (5, 6), (7, 8))) contact_home_phone = ElementAccess("PER", oneOf=("HP", (3, 4), (5, 6), (7, 8))) contact_work_phone = ElementAccess("PER", oneOf=("WP", (3, 4), (5, 6), (7, 8))) contact_phone = ElementAccess("PER", oneOf=("TE", (3, 4), (5, 6), (7, 8))) contact_phone_ext = ElementAccess("PER", oneOf=("EX", (3, 4), (5, 6), (7, 8)))
class Diagnosis(X12SegmentBridge): principal_diagnosis_icd9_code = ElementAccess("III", 2, qualifier=(1, "BK")) diagnosis_icd9_code = ElementAccess("III", 2, qualifier=(1, "BF")) diagnosis_ncci_code = ElementAccess("III", 2, qualifier=(1, "GR")) diagnosis_injury_code = ElementAccess("III", 2, qualifier=(1, "NI")) other_code = ElementAccess( "III", 2, qualifier=(1, "ZZ"), x12type=enum({ "11": "Office", "12": "Home", "21": "Inpatient Hospital", "22": "Outpatient Hospital", "23": "Emergency Room - Hospital", "24": "Ambulatory Surgical Center", "25": "Birthing Center", "26": "Military Treatment Facility", "31": "Skilled Nursing Facility", "32": "Nursing Facility", "33": "Custodial Care Facility", "34": "Hospice", "41": "Ambulance - Land", "42": "Ambulance - Air or Water", "50": "Federally Qualified Health Center", "51": "Inpatient Psychiatric Facility", "52": "Psychiatric Facility Partial Hospitalization", "53": "Community Mental Health Center", "54": "Intermediate Care Facility/Mentally Retarded", "55": "Residential Substance Abuse Treatment Facility", "56": "Psychiatric Residential Treatment Center", "60": "Mass Immunization Center", "61": "Comprehensive Inpatient Rehabilitation Facility", "62": "Comprehensive Outpatient Rehabilitation Facility", "65": "End-Stage Renal Disease Treatment Facility", "71": "State or Local Public Health Clinic", "72": "Rural Health Clinic", "81": "Independent Laboratory 99 Other Unlisted Facility" }, raw_unknowns=True)) code_category = ElementAccess( "III", 3, x12type=enum({ "44": "Nature of Injury" }))
class DemographicInformation(X12SegmentBridge): birth_date = ElementAccess("DMG", 2, x12type=D8, qualifier=(1, "D8")) gender = ElementAccess("DMB", 3, x12type=enum({ "F": "Female", "M": "Male", "U": "Unknown" }))
class HealthCareServicesDelivery(X12LoopBridge): benefit_quantity_type = ElementAccess("HSD", 1, x12type=enum(quantity_qualifier)) benefit_quantity = ElementAccess("HSD", 2) unit_or_basis_for_measurement = ElementAccess("HSD", 3, x12type=enum({ "DA": "Days", "MO": "Months", "VS": "Visit", "WK": "Week", "YR": "Years"})) sample_selection_modulus = ElementAccess("HSD", 4) time_period_type = ElementAccess("HSD", 5, x12type=enum(time_period_qualifier)) period_count = ElementAccess("HSD", 6) delivery_frequency = ElementAccess("HSD", 7, x12type=enum(delivery_or_calendar_pattern_code)) delivery_time = ElementAccess("HSD", 8, x12type=enum(delivery_time_pattern_code))
class NamedEntity(X12LoopBridge): entity_identifier = ElementAccess("NM1", 1, x12type=enum({ "03": "Dependent", "1P": "Provider", "2B": "Third-Party Administrator", "36": "Employer", "80": "Hospital", "FA": "Facility", "GP": "Gateway Provider", "IL": "Insured", "P5": "Plan Sponsor", "PR": "Payer", "QC": "Patient" })) entity_type = ElementAccess("NM1", 2, x12type=enum({ "1": "Person", "2": "Non-Person Entity" })) last_name = ElementAccess("NM1", 3) org_name = ElementAccess("NM1", 3) first_name = ElementAccess("NM1", 4) middle_initial = ElementAccess("NM1", 5) suffix = ElementAccess("NM1", 7) id_code = ElementAccess("NM1", 9) id_code_qual = ElementAccess("NM1", 8, x12type=enum(id_code_qualifier)) def is_person(self): return self.entity_type[0] == "1" def is_organization(self): return self.entity_type[0] == "2" def __init__(self, aLoop, qualifier=None, *args, **kwargs): if qualifier: self.qualifier = qualifier super(NamedEntity, self).__init__(aLoop) #NOTE: Sometimes this can be multiple Elements... self.contact_details = ContactDetails(aLoop, *args, **kwargs)
class _ReassociationTraceNumber(X12LoopBridge): """ Uniquely identify this transaction set. Also aid in reassociating payments and remittances that have been separated. """ trace_type = ElementAccess( "TRN", 1, x12type=enum({"1": "Current Transaction Trace Numbers"})) check_or_eft_trace_number = ElementAccess("TRN", 2) payer_id = ElementAccess("TRN", 3) originating_company_supplemental_code = ElementAccess("TRN", 4)
class Hierarchy(X12SegmentBridge): id = ElementAccess("HL", 1) parent_id = ElementAccess("HL", 2) level = ElementAccess("HL", 3, x12type=enum({ "20": "Information Source", "21": "Information Receiver", "22": "Subscriber", "23": "Dependent", })) has_children = ElementAccess("HL", 4, x12type=boolean("1"))
class EligibilityOrBenefitInformation(X12SegmentBridge): """Eligibility Information.""" information_type = ElementAccess("EB", 1, x12type=enum( eligibility_or_benefit_code)) coverage_level = ElementAccess("EB", 2, x12type=enum( coverage_level)) service_type = ElementAccess("EB", 3, x12type=enum( service_type_codes)) insurance_type = ElementAccess("EB", 4, x12type=enum( insurance_type)) description = ElementAccess("EB", 5) time_period_type = ElementAccess("EB", 6, x12type=enum(time_period_qualifier)) benefit_amount = ElementAccess("EB", 7, x12type=Money) benefit_percent = ElementAccess("EB", 8, x12type=XDecimal) quantity_type = ElementAccess("EB", 9, x12type=enum(quantity_qualifier)) quantity = ElementAccess("EB", 10) authorization_or_certification = ElementAccess("EB", 11, x12type=boolean("Y")) in_plan_network = ElementAccess("EB", 12, x12type=boolean("Y")) both_in_out_network = ElementAccess("EB", 12, x12type=boolean("W")) ada_code = CompositeAccess("EB", "AD", 13) cpt_code = CompositeAccess("EB", "CJ", 13) hcpcs_code = CompositeAccess("EB", "HC", 13) icd_9_cm_code = CompositeAccess("EB", "ID", 13) ndc_code = CompositeAccess("EB", "ND", 13) zz_code = CompositeAccess("EB", "ZZ", 13)
class ProviderInformation(X12SegmentBridge): provider_code = ElementAccess("PRV", 1, x12type=enum({ "AD": "Admitting", "AT": "Attending", "BI": "Billing", "CO": "Consulting", "CV": "Covering", "H": "Hospital", "HH": "Home Health Care", "LA": "Laboratory", "OT": "Other Physician", "P1": "Pharmacist", "P2": "Pharmacy", "PC": "Primary Care Physician", "PE": "Performing", "R": "Rural Health Clinic", "RF": "Referring", "SB": "Submitting", "SK": "Skilled Nursing Facility", "SU": "Supervising" })) reference_id_qualifier = ElementAccess( "PRV", 2, x12type=enum( { "9K": "Servicer", "D3": "National Association of Boards of Pharmacy Number", "EI": "Employer's Identification Number", "HPI": "Healthcare Financing Administration National Provider ID", "SY": "Social Security Number", "TJ": "Federal Taxpayer's Identification Number", "ZZ": "Mutually Defined" }, raw_unknowns=True)) reference_id = ElementAccess("PRV", 3)
class ContactInformation(X12SegmentBridge): contact_code = ElementAccess( "PER", 1, x12type=enum({ "IC": "Information Contact" }, raw_unknowns=True)) contact_name = ElementAccess("PER", 2) contact_edi = ElementAccess("PER", oneOf=("ED", (3, 4), (5, 6), (7, 8))) contact_email = ElementAccess("PER", oneOf=("EM", (3, 4), (5, 6), (7, 8))) contact_fax = ElementAccess("PER", oneOf=("FX", (3, 4), (5, 6), (7, 8))) contact_home_phone = ElementAccess("PER", oneOf=("HP", (3, 4), (5, 6), (7, 8))) contact_work_phone = ElementAccess("PER", oneOf=("WP", (3, 4), (5, 6), (7, 8))) contact_phone = ElementAccess("PER", oneOf=("TE", (3, 4), (5, 6), (7, 8))) contact_phone_ext = ElementAccess("PER", oneOf=("EX", (3, 4), (5, 6), (7, 8))) contact_url = ElementAccess("PER", oneOf=("UR", (3, 4), (5, 6), (7, 8)))
class Location(X12SegmentBridge): city = ElementAccess("N4", 1) state = ElementAccess("N4", 2) zip = ElementAccess("N4", 3) country_code = ElementAccess("N4", 4) location_type = ElementAccess( "N4", 5, x12type=enum({ "CY": "County/Parish", "FI": "Federal Information Processing Standards (FIPS) 55 (Named " "Populated Places)" }, raw_unknowns=True)) location_id = ElementAccess("N4", 6)
class TraceNumber(X12SegmentBridge): """ Uniquely identify this transaction set. Also aid in reassociating payments and remittances that have been separated. """ trace_type = ElementAccess( "TRN", 1, x12type=enum({ "1": "Current Transaction Trace Numbers", "2": "Referenced Transaction Trace Numbers (Value from 270)" })) trace_number = ElementAccess("TRN", 2) entity_id = ElementAccess("TRN", 3) entity_additional_id = ElementAccess("TRN", 4)
class _EligibilityOrBenefitInformation(Facade, X12LoopBridge): loopName = "2110D" coverage_information = SegmentAccess("EB", x12type=SegmentConversion(EligibilityOrBenefitInformation)) services_deliveries = SegmentSequenceAccess("HSD", x12type=SegmentConversion(HealthCareServicesDelivery)) reference_ids = SegmentSequenceAccess("REF", x12type=SegmentConversion(ReferenceID)) dates = SegmentSequenceAccess("DTP", x12type=SegmentConversion(DateOrTimePeriod)) request_validations = SegmentSequenceAccess("AAA", x12type=SegmentConversion(RequestValidation)) messages = ElementSequenceAccess("MSG", 1) additional_information = ElementSequenceAccess("III", 2, x12type=enum(place_of_service)) class _AdditionalInformation(X12LoopBridge): loopName = "2115C" diagnosis = SegmentAccess("III", x12type=SegmentConversion(Diagnosis)) class _RelatedEntityInformation(X12LoopBridge): loopName = "2120D" name = SegmentAccess("NM1", x12type=SegmentConversion(NamedEntity)) address_street = SegmentAccess("N3", x12type=SegmentConversion(Address)) address_location = SegmentAccess("N4", x12type=SegmentConversion(Location)) contact_information = SegmentSequenceAccess("PER", x12type=SegmentConversion(ContactInformation)) provider_information = SegmentAccess("PRV", x12type=SegmentConversion(ProviderInformation)) def __init__(self, anX12Message, *args, **kwargs): super(Dependent._EligibilityOrBenefitInformation, self).__init__( anX12Message, *args, **kwargs) self.additional_information = self.loops( self._AdditionalInformation, anX12Message) self.benefit_related_entity = first(self.loops( self._RelatedEntityInformation, anX12Message))
class _FinancialInformation(X12LoopBridge): """ Use this to address a single payment to a single payee. A payee may represent a single provider, a provider group, or multiple providers in a chain. The BPR contains mandatory information, even when it is not being used to move funds electronically. """ transaction_type = ElementAccess("BPR", 1, x12type=enum({ "C": "Payment Accompanies Remittance Advice", "D": "Make Payment Only", "H": "Notification Only", "I": "Remittance Information Only", "P": "Prenotification of Ruture Transfers", "U": "Split Payment and Remittance", "X": "Handling Party's Option to Split Payment and Remittance."})) amount = ElementAccess("BPR", 2, x12type=Money) credit_or_debit = ElementAccess("BPR", 3, x12type=enum({ "C": "Credit", "D": "Debit"})) payment_method = ElementAccess("BPR", 4, x12type=enum({ "ACH": "Automated Clearing House (ACH)", "BOP": "Financial Institution Option", "CHK": "Check", "FWT": "Federal Reserve Funds/Wire Transfer - Nonrepetitive", "NON": "Non-payment Data (only for transaction-type=H)"})) payment_format = ElementAccess("BPR", 5, x12type=enum({ "CCP": "Cash Concentration/Disbursement Plus Addenda", "CTX": "Coporate Trade Exchange"})) sender_aba_transit_routing_number = ElementAccess( "BPR", 7, qualifier=(6, "01")) sender_canadian_bank_branch_and_institution_number = ElementAccess( "BPR", 7, qualifier=(6, "04")) sender_account_type = ElementAccess("BPR", 8, x12type=enum({ "DA": "Demand Deposit"})) sender_bank_account_number = ElementAccess("BPR", 9) sender_id = ElementAccess("BPR", 10) sender_supplemental_id = ElementAccess("BPR", 11) receiver_aba_transit_routing_number = ElementAccess( "BPR", 13, qualifier=(12, "01")) receiver_canadian_bank_branch_and_institution_number = ElementAccess( "BPR", 13, qualifier=(12, "04")) receiver_account_type = ElementAccess("BPR", 14, x12type=enum({ "DA": "Demand Deposit", "SG": "Savings"})) receiver_bank_account_number = ElementAccess("BPR", 15) issue_date = ElementAccess("BPR", 16, x12type=D8)
class EligibilityOrBenefitAdditionalInformation(X12LoopBridge): additional_information = CompositeAccess("III", "ZZ", 2, x12type=enum(place_of_service))
class _ServiceInfo(X12LoopBridge): """ Oh jeez, I'm so sorry about this mess. Each claim has several nested 2110 loops that have additional information pertaining to a claim. This is usually when the insurance company doesn't want to pay the whole amount billed. The only way I could think of to implement this is to do this mess of multiple inheritance. Rest assured I did not come to this decision lightly.""" loopName = "2110" hcpcs_code = CompositeAccess("SVC", "HC", 1) charge = ElementAccess("SVC", 2, x12type=Money) payment = ElementAccess("SVC", 3, x12type=Money) quantity = ElementAccess("SVC", 5) start_date = ElementAccess("DTM", 2, qualifier=(1, "150"), x12type=D8) end_date = ElementAccess("DTM", 2, qualifier=(1, "151"), x12type=D8) service_date = ElementAccess("DTM", 2, qualifier=(1, "472"), x12type=D8) # Identification apg_number = ElementAccess("REF", 2, qualifier=(1, "1S")) provider_control_number = ElementAccess("REF", 2, qualifier=(1, "6R")) authorization_number = ElementAccess("REF", 2, qualifier=(1, "BB")) attachment_code = ElementAccess("REF", 2, qualifier=(1, "E9")) prior_authorization_number = ElementAccess("REF", 2, qualifier=(1, "G1")) predetermination_of_benefits_id = ElementAccess("REF", 2, qualifier=(1, "G3")) location_number = ElementAccess("REF", 2, qualifier=(1, "LU")) rate_code_number = ElementAccess("REF", 2, qualifier=(1, "RB")) # TODO: Rendering provider info? # Line-item claim amounts allowed_amount = ElementAccess("AMT", 2, qualifier=(1, "B6"), x12type=Money) per_day_limit = ElementAccess("AMT", 2, qualifier=(1, "DY"), x12type=Money) deduction_amount = ElementAccess("AMT", 2, qualifier=(1, "KH"), x12type=Money) tax_amount = ElementAccess("AMT", 2, qualifier=(1, "T"), x12type=Money) total_claim_before_taxes = ElementAccess("AMT", 2, qualifier=(1, "T2"), x12type=Money) not_covered_quantity = ElementAccess("QTY", 2, qualifier=(1, "NE")) notes = ElementSequenceAccess("LQ", 2, qualPos=1, inList=("HE", ), x12type=enum(remittance_advice_codes, raw_unknowns=True)) def __init__(self, anX12Message, *args, **kwargs): super(Claim._ServiceInfo, self).__init__(anX12Message, *args, **kwargs) self.claim_adjustments = Claim._ClaimAdjustments(anX12Message) def get_actual_allowed_amount(self): if self.allowed_amount == Decimal('0.00'): # Actually means that the allowed amount is the full billed amt return self.charge return self.allowed_amount def get_actual_deductible(self): return (self.claim_adjustments.patient_responsibility.total_amount( '1')) def get_actual_coinsurance(self): return (self.claim_adjustments.patient_responsibility.total_amount( '2')) def get_actual_copayment(self): return (self.claim_adjustments.patient_responsibility.total_amount( '3'))
class NamedEntity(X12SegmentBridge): entity_identifier = ElementAccess( "NM1", 1, x12type=enum({ "03": "Dependent", "13": "Contracted Service Provider", "1I": "Preferred Provider Organization (PPO)", "1P": "Provider", "2B": "Third-Party Administrator", "36": "Employer", "73": "Other Physician", "80": "Hospital", "FA": "Facility", "GP": "Gateway Provider", "GW": "Group", "IL": "Insured", "I3": "Independent Physicians Association (IPA)", "LR": "Legal Representative", "P3": "Primary Care Provider", "P4": "Prior Insurance Carrier", "P5": "Plan Sponsor", "PR": "Payer", "PRP": "Primary Payer", "OC": "Origin Carrier", "QC": "Patient", "SEP": "Secondary Payer", "TTP": "Tertiary Payer", "VER": "Party Performing Verification", "VN": "Vendor", "VY": "Organization Completing Configuration Change", "X3": "Utilization Management Organization", "Y2": "Managed Care Organization" }, raw_unknowns=True)) entity_type = ElementAccess("NM1", 2, x12type=enum({"1": "Person", "2": "Non-Person Entity"})) last_name = ElementAccess("NM1", 3) org_name = ElementAccess("NM1", 3) first_name = ElementAccess("NM1", 4) middle_initial = ElementAccess("NM1", 5) suffix = ElementAccess("NM1", 7) id_code = ElementAccess("NM1", 9) id_code_qual = ElementAccess("NM1", 8, x12type=enum(id_code_qualifier)) benefit_relationship = ElementAccess("NM1", 10, x12type=enum({ "01": "Parent", "02": "Child", "27": "Domestic Partner", "41": "Spouse", "48": "Employee", "65": "Other", "72": "Unknown" })) @property def is_person(self): return self.entity_type[0] == "1" @property def is_organization(self): return self.entity_type[0] == "2"
class ReferenceID(Facade, X12LoopBridge): reference_id_qualifier = ElementAccess( "REF", 1, x12type=enum(reference_id_qualifier)) reference_id = ElementAccess("REF", 2) description = ElementAccess("REF", 3)
class DateOrTimePeriod(X12SegmentBridge): type = ElementAccess("DTP", 1, x12type=enum(date_or_time_qualifier)) time = ElementAccess("DTP", 3, x12type=D8, qualifier=(2, "D8")) time_range = ElementAccess("DTP", 3, x12type=DR, qualifier=(2, "RD8"))
class ClaimAdjustment(X12LoopBridge): group = ElementAccess("CAS", 1, x12type=enum({ "CO": "Contractual Obligation", "CR": "Correction and/or reversal", "OA": "Other Adjustment", "PI": "Payor initiated adjustment", "PR": "Patient Responsibility" })) reason_1 = ElementAccess("CAS", 2, x12type=enum(claim_adjustment_reasons, raw_unknowns=True)) amount_1 = ElementAccess("CAS", 3, x12type=Money) quantity_1 = ElementAccess("CAS", 4) reason_2 = ElementAccess("CAS", 5, x12type=enum(claim_adjustment_reasons, raw_unknowns=True)) amount_2 = ElementAccess("CAS", 6, x12type=Money) quantity_2 = ElementAccess("CAS", 7) reason_3 = ElementAccess("CAS", 8, x12type=enum(claim_adjustment_reasons, raw_unknowns=True)) amount_3 = ElementAccess("CAS", 9, x12type=Money) quantity_3 = ElementAccess("CAS", 10) reason_4 = ElementAccess("CAS", 11, x12type=enum(claim_adjustment_reasons, raw_unknowns=True)) amount_4 = ElementAccess("CAS", 12, x12type=Money) quantity_4 = ElementAccess("CAS", 13) reason_5 = ElementAccess("CAS", 14, x12type=enum(claim_adjustment_reasons, raw_unknowns=True)) amount_5 = ElementAccess("CAS", 15, x12type=Money) quantity_5 = ElementAccess("CAS", 16) reason_6 = ElementAccess("CAS", 17, x12type=enum(claim_adjustment_reasons, raw_unknowns=True)) amount_6 = ElementAccess("CAS", 18, x12type=Money) quantity_6 = ElementAccess("CAS", 19) def total_amount(self, reason=None): s = Decimal('0.0') for i in range(1, 7): val = self.__getattribute__("amount_%s" % i) reason_tuple = self.__getattribute__("reason_%s" % i) if reason is None or (reason_tuple is not None and reason_tuple[0] is not None and reason_tuple[0] == reason): s += val return s def total_quantity(self, reason=None): s = 0.0 for i in range(1, 7): a = self.__getattribute__("quantity_%s" % i) if a is not None: try: s += float(a) except: pass return s def all_reasons_iter(self): for i in range(1, 7): reason_tuple = self.__getattribute__("reason_%s" % i) if reason_tuple is not None: yield reason_tuple def __init__(self, aLoop, qualifier, *args, **kwargs): self.qualifier = qualifier super(ClaimAdjustment, self).__init__(aLoop, *args, **kwargs)