Skip to content

Commit

Permalink
Merge pull request #6 from databricks-industry-solutions/raven-claim-…
Browse files Browse the repository at this point in the history
…build

updated submitter and receiver claim lines, authors, notebook
  • Loading branch information
ritwikamukherjee authored May 31, 2024
2 parents 88f488d + c6f2c5c commit 149e6bf
Show file tree
Hide file tree
Showing 4 changed files with 10,557 additions and 3,630 deletions.
43 changes: 25 additions & 18 deletions databricksx12/hls/claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ def _populate_diagnosis(self):
return DiagnosisIdentity([x for x in self.claim_loop if x.segment_name() == "HI"])

def _populate_submitter_loop(self) -> Dict[str, str]:
return SubmitterIdentity(self.sender_receiver_loop)
return Submitter_Receiver_Identity(nm1=self._first([x for x in self.sender_receiver_loop if x.element(1) == "41"],"NM1"),
per=self._first(self.sender_receiver_loop, "PER"))

def _populate_receiver_loop(self) -> Dict[str, str]:
return ReceiverIdentity(self.sender_receiver_loop)
return Submitter_Receiver_Identity(nm1=self._first([x for x in self.sender_receiver_loop if x.element(1) == "40"],"NM1"))

def _populate_subscriber_loop(self):
l = self.subscriber_loop[0:min(filter(lambda x: x!= -1, [self.index_of_segment(self.subscriber_loop, "CLM"), len(self.subscriber_loop)]))] #subset the subscriber loop before the CLM segment
Expand All @@ -64,7 +65,7 @@ def _populate_subscriber_loop(self):
)

def _populate_patient_loop(self) -> Dict[str, str]:
# Note - if this doesn't exist then its the same as subscriber loop
# Note - if this doesn't exist then it's the same as subscriber loop
# 01 = Spouse; 18 = Self; 19 = Child; G8 = Other
return self._populate_subscriber_loop() if self._first(self.subscriber_loop, "SBR").element(1) == "18" else PatientIdentity(
nm1 = self._first(self.patient_loop, "NM1"),
Expand Down Expand Up @@ -122,19 +123,23 @@ class Claim837i(MedicalClaim):

NAME = "837I"

# Format of 837P https://www.dhs.wisconsin.gov/publications/p0/p00265.pdf

# Format for 837I https://www.dhs.wisconsin.gov/publications/p0/p00266.pdf
def _attending_provider(self):
return ProviderIdentity(Segment.empty(), Segment.empty()) #TODO
return ProviderIdentity(nm1=self._first([x for x in self.claim_loop if x.element(1) == "71"],"NM1"),
prv=self._first([x for x in self.claim_loop if x.element(1) == "AT"],"PRV"),
ref=self._first(self.claim_loop, "REF")) # only occurs once post CLM loop providers

def _operating_provider(self):
return ProviderIdentity(Segment.empty(), Segment.empty()) #TODO
return ProviderIdentity(nm1=self._first([x for x in self.claim_loop if x.element(1) == "72"],"NM1"),
prv=self._first([x for x in self.claim_loop if x.element(1) == "OP"],"PRV"))

def _other_provider(self):
return ProviderIdentity(Segment.empty(), Segment.empty()) #TODO
return ProviderIdentity(nm1=self._first([x for x in self.claim_loop if x.element(1) == "73"],"NM1"),
prv=self._first([x for x in self.claim_loop if x.element(1) == "OT"],"PRV"))

def _facility_provider(self):
return ProviderIdentity(Segment.empty(), Segment.empty()) #TODO
return ProviderIdentity(nm1=self._first([x for x in self.claim_loop if x.element(1) == "FA"],"NM1")) # also in 837P but rare

def _populate_providers(self):
return {"billing": self._billing_provider(),
Expand All @@ -158,23 +163,28 @@ def _populate_sl_loop(self, missing=""):
dtp = self._first(s, "DTP")
),self.claim_lines()))

def __populate_patient_loop(self):
# Note - if this doesn't exist then its the same as subscriber loop
# Note to include in loop: information about subscriber/dependent relationship is marked by Element 2
# 01 = Spouse; 18 = Self; 19 = Child; G8 = Other
pass

class Claim837p(MedicalClaim):

NAME = "837P"
# Format of 837P https://www.dhs.wisconsin.gov/publications/p0/p00265.pdf

def _rendering_provider(self):
return ProviderIdentity(nm1=self._first([x for x in self.claim_loop if x.element(1) == "82"],"NM1"),
prv=self._first([x for x in self.claim_loop if x.element(1) == "PE"],"PRV"))

def _referring_provider(self):
return ProviderIdentity(nm1=self._first([x for x in self.claim_loop if x.element(1) == "DN"],"NM1"),
prv=self._first([x for x in self.claim_loop if x.element(1) == "RF"],"PRV"))

def _service_facility_provider(self):
return ProviderIdentity(nm1=self._first([x for x in self.claim_loop if x.element(1) == "77"],"NM1"))

def _populate_providers(self):
return {"billing": self._billing_provider(),
"servicing": (self._billing_provider() if self._rendering_provider() is None else self._rendering_provider())
"referring": self._referring_provider(),
"servicing": (self._billing_provider() if self._rendering_provider() is None else self._rendering_provider()),
"service_facility": self._service_facility_provider()
}


Expand All @@ -188,9 +198,6 @@ def _populate_sl_loop(self, missing=""):
), self.claim_lines()))

def _populate_patient_loop(self):
# Note - if this doesn't exist then its the same as subscriber loop
# Note to include in loop: information about subscriber/dependent relationship is marked by Element 2
# 01 = Spouse; 18 = Self; 19 = Child; G8 = Other
pass
#
# Base claim builder (transaction -> 1 or more claims)
Expand Down
56 changes: 8 additions & 48 deletions databricksx12/hls/identities.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,54 +70,14 @@ def __init__(self, hi_segments):
self.external_injury_dx_cd = "" if [s.element(1,1) for s in hi_segments if s.element(1, 0) == "ABN"] == [] else [s.element(1,1) for s in hi_segments if s.element(1, 0) == "ABN"][0]
self.other_dx_cds = ",".join([s.element(1,1) for s in hi_segments if s.element(1, 0) == "ABF"])

class SubmitterIdentity(Identity):
def __init__(self, submitter_segments: List[Segment]):
self.contact_name = None
self.contacts = None
#super().__init__(submitter_segments)
#self.build_submitter_lines(submitter_segments)

def build_submitter_lines(self, submitter_loop: List[Segment]):
nm1_segments = filter(lambda segment: segment.element(0) == 'NM1' and segment.element(1) == '41', submitter_loop)
per_segments = filter(lambda segment: segment.element(0) == 'PER', submitter_loop)

list(map(self.process_nm1_segment, nm1_segments))
list(map(self.process_per_segment, per_segments))

def process_per_segment(self, segment):
self.contact_name = segment.element(2)
contact_methods = {
'EM': 'Email',
'TE': 'Telephone',
'FX': 'Fax'
}
contact = {
'contact_method': contact_methods.get(segment.element(3), 'Unknown method'),
'contact_number': segment.element(4)
}
# Add additional contact details if present
if segment.element(5) in contact_methods:
contact['contact_method_2'] = contact_methods.get(segment.element(5), 'Unknown method')
contact['contact_number_2'] = segment.element(6)

if segment.element(7) in contact_methods:
contact['contact_method_3'] = contact_methods.get(segment.element(7), 'Unknown method')
contact['contact_number_3'] = segment.element(8)

self.contacts['primary'].append(contact)



class ReceiverIdentity(Identity):
def __init__(self, receiver_segments: List[Segment]):
pass
#super().__init__(receiver_segments)
#self.build_receiver_lines(receiver_segments)

def build_receiver_lines(self, receiver_loop: List[Segment]):
nm1_segments = filter(lambda segment: segment.element(0) == 'NM1' and segment.element(1) == '40', receiver_loop)
return list(map(self.process_nm1_segment, nm1_segments))

class Submitter_Receiver_Identity(Identity):
def __init__(self, nm1=Segment.empty(), per= Segment.empty()):
self.type = 'Organization' if nm1.element(2) == '2' else 'Individual'
self.name = nm1.element(3) if self.type == 'Organization' else ' '.join([nm1.element(3), nm1.element(4,dne=""), nm1.element(5)])
if per.element(0):
self.sbmtter_contact_name = "" if per.element(2) == '' else per.element(2)
self.sbmtter_contacts = "" if (per.element(3), per.element(4)) == [] else [(per.element(3), per.element(4)), #telephone
(per.element(5), per.element(6))] # usually fax/email


class ServiceLine(Identity):
Expand Down
Loading

0 comments on commit 149e6bf

Please sign in to comment.