Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: BLRRLHL

BLRRLHL.m

Go to the documentation of this file.
BLRRLHL ;cmi/anch/maw - BLR HL7 Utilities for Reference Lab ;27-Jul-2015 06:10;MKK
 ;;5.2;IHS LABORATORY;**1027,1028,1031,1034,1036**;NOV 01, 1997;Build 10
 Q
 ;
CLIENT N BLRCLCNT
 I +$G(BLRAGUI) Q $$CLIENTG^BLRRLEDI(LRORD,LRUID)
 S BLRCLCNT=$$CLCNT(DUZ(2))
 I $G(BLRCLCNT)=1 D
 . S BLRRL("CLIENT")=$O(^BLRSITE($S($G(BLRALTDZ):BLRALTDZ,1:DUZ(2)),"RLCA","B",""))
 . I $G(BLRRL("CLIENT"))="" S BLRRL("CLIENT")=$P($G(^BLRRL(BLRRL("RL"),0)),U,13)
 I $G(BLRCLCNT)>1 D
 . W !,"Please select the appropriate account number for this accession"
 . N BLRRLD
 . S BLRRLD=0 F  S BLRRLD=$O(BLRCLA(BLRRLD)) Q:'BLRRLD  D
 .. W !,BLRRLD_") "_$G(BLRCLA(BLRRLD))
 . K DIR
 . S DIR(0)="N^1:"_$G(BLRCLCNT),DIR("A")="Which account number for this accession "
 . D ^DIR
 . Q:$D(DIRUT)
 . S BLRRL("CLIENT")=$G(BLRCLA(+Y))
 S BLRRLCLT=BLRRL("CLIENT")
 I $G(BLRRL("CLIENT"))="" G CLIENT
 S BLRRLCLA=BLRRLCLT
 ;cmi/maw 2/25/2008 end of mods for multiple account numbers
 ;cmi/maw 10/31/07 ask what type of billing here
 ;cmi/maw 10/31/07 end of mods
 Q
 ;
CLCNT(DZ2) ;-- get the number of client account numbers to see if we need to prompt
 N BLRRLDA,BLRCLC
 S BLRCLC=0
 S BLRRLDA=0 F  S BLRRLDA=$O(^BLRSITE($S($G(BLRALTDZ):BLRALTDZ,1:DZ2),"RLCA","B",BLRRLDA)) Q:BLRRLDA=""  D
 . S BLRCLC=BLRCLC+1
 . S BLRCLA(BLRCLC)=BLRRLDA
 Q +$G(BLRCLC)
 ;
BILL ;-- this is where we ask billing type
 I '$G(BLRRLASK),BLRRLCNT>0 D  Q
 . I $E($G(BLRRLBTP),1,1)="P" D PATBILL(BLRTSTDA) Q
 . Q:$E($G(BLRRLBTP),1,1)'="T"
 . S BLRRL("BILL TYPE")="T"
 . D SETINS
 . ;D SETDX^BLRRLHL2  ;ihs/cmi/maw p1034
 S DIR(0)="S^C:Client;T:Third Party;P:Patient"
 S DIR("A")="Which Party is Responsible for Billing: "
 S DIR("B")=$P($G(^BLRSITE($S($G(BLRALTDZ):BLRALTDZ,1:DUZ(2)),"RL")),U,15)
 D ^DIR
 ; S BLRRL("BILL TYPE")=Y(0)
 ; I $D(DIRUT) S BLRRL("BILL TYPE")="Client"
 ; ----- BEGIN IHS/MSC/MKK - LR*5.2*1036
 I $D(DIRUT) S BLRRL("BILL TYPE")="Client"
 E  S BLRRL("BILL TYPE")=$G(Y(0))
 ; ----- END IHS/MSC/MKK - LR*5.2*1036
 K DIR
 I $E(BLRRL("BILL TYPE"),1,1)="T" D
 . K DXCNT,INSCNT
 . S DXCNT=1
 . S INSCNT=1
 . ;D DX^BLRRLEDI(LRORD)  ;ihs/cmi/maw - LR*5.2*1034
 . ;D DX2^BLRRLHL2(BLRRL("PAT"))  ;ihs/cmi/maw - LR*5.2*1034
 . D INS(BLRRL("PAT"),0)
 ;I $E(BLRRL("BILL TYPE"),1,1)="T",$G(BLRRL("DX"))="" D  G BILL
 I $E(BLRRL("BILL TYPE"),1,1)="T",'$O(^BLRRLO(BLRO,1,"B",0)) D  G BILL  ;ihs/cmi/maw p1034
 . W !,"You must select an ICD Diagnosis if Bill Type is Third Party"
 . D DX^BLRRLEDI(LRORD)
 I $E(BLRRL("BILL TYPE"),1,1)="T",$G(BLRRL("INSE"))="" D  G BILL
 . W !,"You must select an Insurer if Bill Type is Third Party"
 I $E(BLRRL("BILL TYPE"),1,1)="P" D PATBILL(BLRTSTDA)
 S BLRRLCNT=BLRRLCNT+1
 S BLRRLBTP=BLRRL("BILL TYPE")
 Q
 ;
DX(PAT) ;-- get the diagnosis for billing
 D DX2^BLRRLHL2(PAT)    ; IHS/MSC/MKK - LR*5.2*1034
 Q
 ;
INS(PAT,FLG) ;-- lets get a list of selectable insurances for the patient and if set for auto select pick the first one in sequence
 ;we must also setup the BLRRL insurance array and diagnosis array for GIS
 S DFN=PAT
 D ^AGINS
 I '$D(AGINS(1)),$E($G(BLRRL("BILL TYPE")),1,1)="T" D  Q  ;p1034
 . W !,"Patient has No Insurance on file, changing Bill Type to Client"
 . S BLRRL("BILL TYPE")="Client"
 . S BLRRL("INSCOV")=BLRRL("BILL TYPE")
 ;W !,"Now Applying Sequenced Insurer to Accession"
 ;cmi/maw 1/22/2010 readded ask of insurance if flag set for no sequencing
 I $P($G(^BLRSITE($S($G(BLRALTDZ):BLRALTDZ,1:DUZ(2)),"RL")),U,21) D  Q  ;get flag for insurance
 . I '$G(FLG) W !,"Now applying Sequenced Insurer to Accession"
 . S BLRINS=1
 . D SETINS
 I $G(FLG) S BLRINS=1 G SETINS
 N BLRRLDA,BLRRLCN
 S BLRRLCN=0
 S BLRRLDA=0 F  S BLRRLDA=$O(AGINS(BLRRLDA)) Q:'BLRRLDA  D
 . S BLRRLCN=BLRRLCN+1
 . W !,BLRRLCN_")"_$P(AGINS(BLRRLDA),U)
 . W ?30,"Policy #: "_$P(AGINS(BLRRLDA),U,9)
 . W ?50,"Elg/Exp Date: "_$S($P(AGINS(BLRRLDA),U,5)>0:$$FMTE^XLFDT($P(AGINS(BLRRLDA),U,5)),1:"")_"/"_$S($P(AGINS(BLRRLDA),U,6)>0:$$FMTE^XLFDT($P(AGINS(BLRRLDA),U,6)),1:"")
 S DIR(0)="N^1:"_$G(BLRRLCN),DIR("A")="Select the insurer for this accession: "
 D ^DIR
 Q:$D(DIRUT)
 Q:Y<0
 S BLRINS=+Y
 ;cmi/maw 1/22/2010 end of add of ask of insurer
SETINS I '$G(PAT) S PAT=DFN
 I $G(BLRRL(BLRTSTDA,"CDT")) S BLRRLCDT=BLRRL(BLRTSTDA,"CDT")
 D SEQINS(.AGINS,PAT,$G(BLRRLCDT))
 I '$D(BLRSEQ(1)) D  Q
 . W !,"Patient Insurance has not been Sequenced, changing Bill Type to Client"
 . S BLRRL("BILL TYPE")="Client"
 . S BLRRL("INSCOV")=BLRRL("BILL TYPE")
 K AGINS
 M AGINS=BLRSEQ
 K BLRSEQ
 S BLRINS=1
 I '$G(FLG) D UPINS^BLRRLEDI(LRORD,LRUID,PAT,$TR(AGINS(BLRINS),"^","~"))   ;ihs/cmi/maw p1034
 S BLRRL(BLRTSTDA,"INSE")=$P(AGINS(BLRINS),U)
 S BLRRL("INSE")=$P(AGINS(BLRINS),U)
 S BLRRL(BLRTSTDA,"INSI")=$P(AGINS(BLRINS),U,2)
 I '$G(BLRRL(BLRTSTDA,"INSI")) D  Q
 . W !,"The entry for "_$G(BLRRL("INSE"))_" for this patient does not have a valid pointer to the INSURER file, this needs to be fixed to proceed"
 . S BLRRL("BILL TYPE")="Patient"
 . S BLRRL("INSCOV")=BLRRL("BILL TYPE")
 S BLRRL(BLRTSTDA,"INSCOV")=$E($G(BLRRL("BILL TYPE")),1,1)
 S BLRRL(BLRTSTDA,"INSPH")=$P(AGINS(BLRINS),U,7)
 S BLRRL(BLRTSTDA,"INSGRP")=$P(AGINS(BLRINS),U,20)
 S BLRRL(BLRTSTDA,"INSREL")=$S($P(AGINS(BLRINS),U,16):$P($G(^AUTTRLSH($P(AGINS(BLRINS),U,16),0)),U),1:"")
 S BLRRL(BLRTSTDA,"INSRELE")=BLRRL(BLRTSTDA,"INSREL")
 I $G(BLRRL(BLRTSTDA,"INSREL"))]"" D
 . I BLRRL(BLRTSTDA,"INSREL")="SELF" S BLRRL(BLRTSTDA,"INSREL")=$S(BLRRL("RLE")["QUEST":2,1:1) Q
 . I BLRRL(BLRTSTDA,"INSREL")="SPOUSE" S BLRRL(BLRTSTDA,"INSREL")=$S(BLRRL("RLE")["QUEST":2,1:2),BLRRL(BLRTSTDA,"INSRELE")="SPOUSE" Q
 . I BLRRL(BLRTSTDA,"INSREL")="HUSBAND" S BLRRL(BLRTSTDA,"INSREL")=$S(BLRRL("RLE")["QUEST":2,1:2),BLRRL(BLRTSTDA,"INSRELE")="SPOUSE" Q
 . I BLRRL(BLRTSTDA,"INSREL")="WIFE" S BLRRL(BLRTSTDA,"INSREL")=$S(BLRRL("RLE")["QUEST":2,1:2),BLRRL(BLRTSTDA,"INSRELE")="SPOUSE" Q
 . S BLRRL(BLRTSTDA,"INSREL")=$S(BLRRL("RLE")["QUEST":8,1:3),BLRRL(BLRTSTDA,"INSRELE")="OTHER" Q
 I $G(BLRRL(BLRTSTDA,"INSREL"))="" S BLRRL(BLRTSTDA,"INSREL")=$S(BLRRL("RLE")["QUEST":1,1:1),BLRRL(BLRTSTDA,"INSRELE")="SELF"
 S BLRRL(BLRTSTDA,"INSPOL")=$P(AGINS(BLRINS),U,9)
 S BLRRL(BLRTSTDA,"INSELG")=$P(AGINS(BLRINS),U,5)
 S BLRRL(BLRTSTDA,"INSEXP")=$P(AGINS(BLRINS),U,6)
 S BLRRL(BLRTSTDA,"INSPLN")=$S(BLRRL(BLRTSTDA,"INSE")["MEDICARE":"MC",BLRRL(BLRTSTDA,"INSE")["MEDICAID":"MD",1:"PI")
 S BLRRL(BLRTSTDA,"INSTYP")=$P($G(^AUTNINS(BLRRL(BLRTSTDA,"INSI"),2)),U)
 I BLRRL(BLRTSTDA,"INSI")]"" D
 . ;S BLRRL(BLRTSTDA,"INSID")=$TR($P($G(^AUTNINS(BLRRL(BLRTSTDA,"INSI"),2)),U,10),"~")  ;cmi/maw 2/17/2009 changed to piece 10 external group name from external id 2
 . S BLRRL(BLRTSTDA,"INSID")=$TR($P($G(^AUTNINS(BLRRL(BLRTSTDA,"INSI"),2)),U,19),"~")  ;cmi/maw 2/17/2009 changed to piece 19 external ID 3
 . S BLRRL(BLRTSTDA,"INSCNME")=$P($G(^AUTNINS(BLRRL(BLRTSTDA,"INSI"),0)),U)  ;insurance company name
 . S BLRRL(BLRTSTDA,"INSADD")=$$INSADD(BLRRL(BLRTSTDA,"INSI"))
 . S BLRRL(BLRTSTDA,"INSADDE")=$TR($P(BLRRL(BLRTSTDA,"INSADD"),U),U," ")_"~"_$TR($P(BLRRL(BLRTSTDA,"INSADD"),U,3,99),U," ")
 . S BLRRL(BLRTSTDA,"INSPHO")=$P($G(^AUTNINS(BLRRL(BLRTSTDA,"INSI"),0)),U,6)
 . S BLRRL(BLRTSTDA,"INSTYP")=$P($G(^AUTNINS(BLRRL(BLRTSTDA,"INSI"),2)),U)
 S BLRRL(BLRTSTDA,"PATADD")=$$PATADD(PAT)
 S BLRRL(BLRTSTDA,"PATADDE")=$TR($P($$PATADD(PAT),U),U," ")_"~"_$TR($P($$PATADD(PAT),U,3,99),U," ")
 S BLRRL(BLRTSTDA,"INSEMP")=$$GET1^DIQ(2,PAT,.3111)
 S BLRRL(BLRTSTDA,"INSNOI")=$$HLNAME^XLFNAME($P(^DPT(PAT,0),U))
 S BLRRL(BLRTSTDA,"INSNOIE")=$P(^DPT(PAT,0),U)
 ;next set of lines for hl7 in1 segments
 D HL7
 S BLRRL(BLRTSTDA,"GT1PHI")=$P(AGINS(BLRINS),U,7)
 I $E(BLRRL(BLRTSTDA,"GT1PHI"),1,1)="P" D  Q
 . S BLRRL(BLRTSTDA,"GT1NM")=$$HLNAME^XLFNAME($P(^AUPN3PPH($E(BLRRL(BLRTSTDA,"GT1PHI"),2,99),0),U))
 . S BLRRL(BLRTSTDA,"GT1ADD")=$$GT1ADD($E(BLRRL(BLRTSTDA,"GT1PHI"),2,99))
 . S BLRRL(BLRTSTDA,"GT1PHO")=$P($G(^AUPN3PPH($E(BLRRL(BLRTSTDA,"GT1PHI"),2,99),0)),U,14)
 . D INSTYP(BLRTSTDA)
 . S BLRRL(BLRTSTDA,"GT1ADDE")=$TR($P($G(BLRRL(BLRTSTDA,"GT1ADD")),U),U," ")_"~"_$TR($P($G(BLRRL(BLRTSTDA,"GT1ADD")),U,3,99),U," ")
 . S BLRRL(BLRTSTDA,"GT1NME")=$TR($G(BLRRL(BLRTSTDA,"GT1NM")),U," ")
 I BLRRL(BLRTSTDA,"GT1PHI")]"" D
 . S BLRRL(BLRTSTDA,"GT1NM")=$$HLNAME^XLFNAME($P(^DPT(PAT,0),U))
 . S BLRRL(BLRTSTDA,"GT1ADD")=$$PATADD(PAT)
 . S BLRRL(BLRTSTDA,"GT1PHO")=$P($G(^DPT(PAT,.131)),U)
 I $G(BLRRL(BLRTSTDA,"GT1NM"))="" D
 . S BLRRL(BLRTSTDA,"GT1NM")=BLRRL(BLRTSTDA,"INSNOI")
 . S BLRRL(BLRTSTDA,"GT1ADD")=BLRRL(BLRTSTDA,"PATADD")
 D INSTYP(BLRTSTDA)
 S BLRRL(BLRTSTDA,"GT1ADDE")=$TR($P($G(BLRRL(BLRTSTDA,"GT1ADD")),U),U," ")_"~"_$TR($P($G(BLRRL(BLRTSTDA,"GT1ADD")),U,3,99),U," ")
 S BLRRL(BLRTSTDA,"GT1NME")=$TR($G(BLRRL(BLRTSTDA,"GT1NM")),U," ")
 Q
 ;
INSTYP(TDA) ;-- get insurance type
 I $G(BLRRL(TDA,"INSTYP"))]"" D
 . I BLRRL(TDA,"INSTYP")="H" S BLRRL(TDA,"INSTYP")="HMO"
 . I BLRRL(TDA,"INSTYP")="MD" S BLRRL(TDA,"INSTYP")="Medicare"
 . I BLRRL(TDA,"INSTYP")="M" S BLRRL(TDA,"INSTYP")="Medicare"
 . I BLRRL(TDA,"INSTYP")="P" S BLRRL(TDA,"INSTYP")="Private Insurance"
 . I BLRRL(TDA,"INSTYP")="D" S BLRRL(TDA,"INSTYP")="Medicaid"
 . I BLRRL(TDA,"INSTYP")="R" S BLRRL(TDA,"INSTYP")="Medicare"
 . I BLRRL(TDA,"INSTYP")="MH" S BLRRL(TDA,"INSTYP")="Medicaid"
 I $G(BLRRL(TDA,"INSTYP"))="" S BLRRL(TDA,"INSTYP")="Private Insurance"
 S BLRRL("INSTYP")=$G(BLRRL(TDA,"INSTYP"))
 Q
 ;
PATBILL(TSTDA) ;-- return data for the patient bill
 S BLRRL(TSTDA,"GT1NM")=$$HLNAME^XLFNAME($P(^DPT(BLRRL("PAT"),0),U))
 S BLRRL(TSTDA,"GT1NME")=$P(^DPT(BLRRL("PAT"),0),U)
 S BLRRL(TSTDA,"GT1ADD")=$$PATADD(BLRRL("PAT"))
 S BLRRL(TSTDA,"GT1ADDE")=$TR($P($$PATADD(BLRRL("PAT")),U),U," ")_"~"_$TR($P($$PATADD(BLRRL("PAT")),U,3,99),U," ")
 S BLRRL(TSTDA,"GT1PHO")=$P($G(^DPT(BLRRL("PAT"),.13)),U)
 S BLRRL(TSTDA,"INSCOV")="P"
 S BLRRL("INSE")="Patient Bill"
 Q
 ;
INSADD(INSI) ;-- return the insurance address is HL7 format
 N ADD,DATA,STR,CTY,ST,ZIP
 S DATA=$G(^AUTNINS(INSI,0))
 S STR=$P(DATA,U,2)
 S CTY=$P(DATA,U,3)
 S ST=$S($P(DATA,U,4):$P($G(^DIC(5,$P(DATA,U,4),0)),U,2),1:"")
 S ZIP=$P(DATA,U,5)
 S ADD=STR_U_U_CTY_U_ST_U_ZIP
 Q ADD
 ;
PATADD(PAT) ;-- return insured address
 N ADD,DATA,STR,CTY,ST,ZIP
 S DATA=$G(^DPT(PAT,.11))
 S STR=$P(DATA,U)
 S CTY=$P(DATA,U,4)
 S ST=$S($P(DATA,U,5):$P($G(^DIC(5,$P(DATA,U,5),0)),U,2),1:"")
 S ZIP=$P(DATA,U,6)
 S ADD=STR_U_U_CTY_U_ST_U_ZIP
 Q ADD
 ;
GT1ADD(PH) ;-- return insured address
 N ADD,DATA,STR,CTY,ST,ZIP
 S DATA=$G(^AUPN3PPH(PH,0))
 S STR=$P(DATA,U,9)
 S CTY=$P(DATA,U,11)
 S ST=$S($P(DATA,U,12):$P($G(^DIC(5,$P(DATA,U,12),0)),U,2),1:"")
 S ZIP=$P(DATA,U,13)
 S ADD=STR_U_U_CTY_U_ST_U_ZIP
 Q ADD
 ;
HL7 ;-- setup hl7 lines
 N HLDA
 S HLDA=0 F  S HLDA=$O(AGINS(HLDA)) Q:'HLDA  D
 . ; D HLSET(HLDA)
 . D HLSET^BLRRLHL2(HLDA)    ; IHS/MSC/MKK - LR*5.2*1034
 Q
 ;
 ;
SEQINS(BINS,PT,RLCDT) ;-- lets go through sequencing insurers
 Q:'$O(BINS(""))
 N BDA
 S BDA=0 F  S BDA=$O(BINS(BDA)) Q:'BDA  D
 . N BINI,SEQ,POLI
 . S BINI=$P(BINS(BDA),U,2)
 . S POLI=$P(BINS(BDA),U,9)
 . S SEQ=$$FNDSEQ(BINI,PT,POLI,RLCDT)
 . Q:'SEQ
 . S BLRSEQ(SEQ)=$G(BINS(BDA))
 Q
 ;
FNDSEQ(BN,PTI,POL,CDT) ;-- find the category prioritization
 N SQDA,EFF,SQPRI
 S EFF=$O(^AUPNICP("EFF",PTI,"M",CDT),-1)
 I '$G(EFF) Q ""
 S SQDA=0 F  S SQDA=$O(^AUPNICP("EFF",PTI,"M",EFF,SQDA)) Q:'SQDA!($G(SQPRI))  D
 . N SQDATA,SQPAT,SQPOL,SQINS
 . S SQDATA=$G(^AUPNICP(SQDA,0))
 . S SQPAT=$P(SQDATA,U,2)
 . S SQINS=$P(SQDATA,U,3)
 . S SQPOL=$P(SQDATA,U,10)
 . Q:SQPAT'=PTI
 . Q:SQINS'=BN
 . Q:SQPOL'=POL
 . S SQPRI=$P(SQDATA,U,5)
 Q $G(SQPRI)
 ;