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

BLRAG05C.m

Go to the documentation of this file.
BLRAG05C ; IHS/MSC/SAT - SUPPORT FOR LABORATORY ACCESSION GUI RPCS ; 17-Oct-2014 09:22 ; MKK
 ;;5.2;IHS LABORATORY;**1031,1034,1039**;NOV 01, 1997;Build 38
 Q
 ;
BILL ;-- this is where we ask billing type
 Q:$G(BLRRL("BILL TYPE"))'="T"
 D SETINS
 F BLRJK=1:1:$L(BLRAGDX,":") D
 .S BLRADX=0
 .; S BLRDXS=$$ICDDX^ICDCODE($P(BLRAGDX,":",BLRJK))
 .S BLRDXS=$$ICDDX^ICDEX($P(BLRAGDX,":",BLRJK),,,"I")     ; IHS/MSC/MKK - LR*5.2*1034
 .D SETDX
 Q
 ;
DX(PAT) ;-- get the diagnosis for billing
 K DIC,BLRDXS,BLRADX,BLRDXA
 ;
 S BLRADX=1
 ;
 ; S DIC="^ICD9("
 ; S DIC("S")="I '$P($G(^(0)),U,9)"
 ; S DIC(0)="AEMQZ",DIC("A")="What is the ICD Diagnosis code for billing: "
 ; D ^DIC
 ;
 ; ----- BEGIN IHS/MSC/MKK - LR*5.2*1034
 ; AICD 4.0 re-structured File 80.  There is no longer an INACTIVE FLAG.
 ; STATUS is now a multiple.  Note that STATUS=1 is ACTIVE; STATUS=0 is INACTIVE.
 ; This means the D ^DIC call will no longer work: have to use D ^DIR.
 NEW ICD10DT,ICD10PTR
 ;
 D ^XBFMK
 ;
 ; Try to use 80.4 to determine ICD-10 Date
 S ICD10PTR=+$$FIND1^DIC(80.4,,,"ICD-10-CM")
 S ICD10DT=+$P($$GET1^DIQ(80.4,ICD10PTR,"IMPLEMENTATION DATE","I"),".")
 S:ICD10DT<1 ICD10DT=3151001   ; If no ICD10DT, hard set to 10/1/2015.
 ;
 ; If Date >= ICD-10 date, just return ACTIVE ICD-9 & ICD-10 entries
 I $$DT^XLFDT>=ICD10DT S DIR("S")="I $P($G(^ICD9(+Y,66,+$O(^ICD9(+Y,66,""A""),-1),0)),""^"",2)"
 ;
 ; If Date < ICD-10 date, only ICD-9 AND ACTIVE entries are returned
 I $$DT^XLFDT<ICD10DT S DIR("S")="I +$G(^ICD9(+Y,1))<30&($P($G(^ICD9(+Y,66,+$O(^ICD9(+Y,66,""A""),-1),0)),""^"",2))"
 ;
 S DIR(0)="PO^80:AEMQZ"
 S DIR("A")="What is the ICD Diagnosis code for billing: "
 D ^DIR
 ; ----- END IHS/MSC/MKK - LR*5.2*1034
 ;
 I Y<0 D  Q
 . D ADDDX(BLRTSTDA)
 . K BLRADX
 ;
 ; S BLRDXS=$$ICDDX^ICDCODE(+Y)
 S BLRDXS=$$ICDDX^ICDEX(+Y,,,"I")       ; IHS/MSC/MKK - LR*5.2*1034
 I $G(BLRDXA(+Y)) D  G ENDDX
 . W !,"You have already selected this Diagnosis"
 S BLRDXA(+Y)=1
 S BLRDX(DXCNT)=BLRDXS
SETDX I '$G(BLRADX) D ADDDX(BLRTSTDA) Q
 ;S BLRRL(BLRTSTDA,"DX",DXCNT)=$P(BLRDXS,U,2)
 S BLRRL("DX",DXCNT)=$P(BLRDXS,U,2)
 S BLRRL("DX")=$P(BLRDXS,U,2)
 ;S BLRRL(BLRTSTDA,"DXE",DXCNT)=$P(BLRDXS,U,4)
 S DXCNT=DXCNT+1
ENDDX D DX(BLRRL("PAT"))
 Q
 ;
ADDDX(TSTDA) ;-- add the diagnosis to the test since it is not there, this happens when they want all dx for mult accessions
 N TDA
 S TDA=0 F  S TDA=$O(BLRDX(TDA)) Q:'TDA  D
 . N DXS
 . S DXS=$G(BLRDX(TDA))
 . S BLRRL(TSTDA,"DX",TDA)=$P(DXS,U,2)
 . S BLRRL(TSTDA,"DXE",TDA)=$P(DXS,U,4)
 . S BLRRL(TSTDA,"DX")=$P(DXS,U,2)  ;cmi/maw 01/20/2010
 . S BLRRL(TSTDA,"DXE")=$P(DXS,U,4)  ;cmi/maw 01/20/2010
 Q
 ;
SETINS I '$G(PAT) S PAT=DFN
 I $G(BLRRL(BLRTSTDA,"CDT")) S BLRRLCDT=BLRRL(BLRTSTDA,"CDT")
 ;D SEQINS(.AGINS,PAT,$G(BLRRLCDT))
 I 0&'$D(BLRSEQ(1)) D  Q
 . ; W !,"Patient Insurance has not been Sequenced, changing Bill Type to Patient"
 . S BLRRL("BILL TYPE")="Patient"
 . S BLRRL("INSCOV")=BLRRL("BILL TYPE")
 ;K AGINS
 ;M AGINS=BLRSEQ
 ;K BLRSEQ
 S BLRINS=1
 S BLRRL(BLRTSTDA,"INSE")=$P(BLRAGINS,U)
 S BLRRL("INSE")=$P(BLRAGINS,U)
 S BLRRL(BLRTSTDA,"INSI")=$P(BLRAGINS,U,2)
 I 0&'$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(BLRAGINS,U,7)
 S BLRRL(BLRTSTDA,"INSGRP")=$P(BLRAGINS,U,20)
 S BLRRL(BLRTSTDA,"INSREL")=$S($P(BLRAGINS,U,16):$P($G(^AUTTRLSH($P(BLRAGINS,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(BLRAGINS,U,9)
 S BLRRL(BLRTSTDA,"INSELG")=$P(BLRAGINS,U,5)
 S BLRRL(BLRTSTDA,"INSEXP")=$P(BLRAGINS,U,6)
 ; S BLRRL(BLRTSTDA,"INSPLN")=$S(BLRRL(BLRTSTDA,"INSE")["MEDICARE":"MC",BLRRL(BLRTSTDA,"INSE")["MEDICAID":"MD",1:"PI")
 S BLRRL(BLRTSTDA,"INSPLN")=$S($G(BLRRL(BLRTSTDA,"INSE"))["MEDICARE":"MC",$G(BLRRL(BLRTSTDA,"INSE"))["MEDICAID":"MD",1:"PI")     ; IHS/MSC/MKK - LR*5.2*1039
 ; S BLRRL(BLRTSTDA,"INSTYP")=$P($G(^AUTNINS(BLRRL(BLRTSTDA,"INSI"),2)),U)
 S BLRRL(BLRTSTDA,"INSTYP")=$P($G(^AUTNINS(+$G(BLRRL(BLRTSTDA,"INSI")),2)),U)  ; IHS/MSC/MKK - LR*5.2*1039
 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(BLRRL("PAT")),U),U," ")_"~"_$TR($P($$PATADD(BLRRL("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(BLRAGINS,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
 ;
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)
 Q
 ;
HLSET(BLRINS) ;-- setup hl7 variables
 S INSCNT=BLRINS
 S BLRRL(BLRTSTDA,"INSE",INSCNT)=$P(BLRAGINS,U)
 S BLRRL("INSE",INSCNT)=$P(BLRAGINS,U)
 S BLRRL(BLRTSTDA,"INSI",INSCNT)=$P(BLRAGINS,U,2)
 ;S BLRRL(BLRTSTDA,"INSCOV")=$P(BLRAGINS,U,4)
 S BLRRL(BLRTSTDA,"INSCOV",INSCNT)=$E($G(BLRRL("BILL TYPE")),1,1)
 S BLRRL(BLRTSTDA,"INSPH",INSCNT)=$P(BLRAGINS,U,7)
 S BLRRL(BLRTSTDA,"INSGRP",INSCNT)=$P(BLRAGINS,U,20)
 S BLRRL(BLRTSTDA,"INSREL",INSCNT)=$S($P(BLRAGINS,U,16):$P($G(^AUTTRLSH($P(BLRAGINS,U,16),0)),U),1:"")
 S BLRRL(BLRTSTDA,"INSRELE",INSCNT)=BLRRL(BLRTSTDA,"INSREL",INSCNT)
 I $G(BLRRL(BLRTSTDA,"INSREL",INSCNT))]"" D
 . I BLRRL(BLRTSTDA,"INSREL",INSCNT)="SELF" S BLRRL(BLRTSTDA,"INSREL",INSCNT)=$S(BLRRL("RLE")["QUEST":2,1:1) Q
 . I BLRRL(BLRTSTDA,"INSREL",INSCNT)="SPOUSE" S BLRRL(BLRTSTDA,"INSREL",INSCNT)=$S(BLRRL("RLE")["QUEST":2,1:2),BLRRL(BLRTSTDA,"INSRELE",INSCNT)="SPOUSE" Q
 . I BLRRL(BLRTSTDA,"INSREL",INSCNT)="HUSBAND" S BLRRL(BLRTSTDA,"INSREL",INSCNT)=$S(BLRRL("RLE")["QUEST":2,1:2),BLRRL(BLRTSTDA,"INSRELE",INSCNT)="SPOUSE" Q
 . I BLRRL(BLRTSTDA,"INSREL",INSCNT)="WIFE" S BLRRL(BLRTSTDA,"INSREL",INSCNT)=$S(BLRRL("RLE")["QUEST":2,1:2),BLRRL(BLRTSTDA,"INSRELE",INSCNT)="SPOUSE" Q
 . S BLRRL(BLRTSTDA,"INSREL",INSCNT)=$S(BLRRL("RLE")["QUEST":8,1:3),BLRRL(BLRTSTDA,"INSRELE",INSCNT)="OTHER" Q
 I $G(BLRRL(BLRTSTDA,"INSREL",INSCNT))="" S BLRRL(BLRTSTDA,"INSREL",INSCNT)=$S(BLRRL("RLE")["QUEST":1,1:1),BLRRL(BLRTSTDA,"INSRELE",INSCNT)="SELF"
 S BLRRL(BLRTSTDA,"INSPOL",INSCNT)=$P(BLRAGINS,U,9)
 S BLRRL(BLRTSTDA,"INSELG",INSCNT)=$P(BLRAGINS,U,5)
 S BLRRL(BLRTSTDA,"INSEXP",INSCNT)=$P(BLRAGINS,U,6)
 S BLRRL(BLRTSTDA,"INSPLN",INSCNT)=$S(BLRRL(BLRTSTDA,"INSE",INSCNT)["MEDICARE":"MC",BLRRL(BLRTSTDA,"INSE",INSCNT)["MEDICAID":"MD",1:"PI")
 ; S BLRRL(BLRTSTDA,"INSTYP",INSCNT)=$P($G(^AUTNINS(BLRRL(BLRTSTDA,"INSI",INSCNT),2)),U)
 S BLRRL(BLRTSTDA,"INSTYP",INSCNT)=$P($G(^AUTNINS(+$G(BLRRL(BLRTSTDA,"INSI",INSCNT)),2)),U)   ; IHS/MSC/MKK - LR*5.2*1039
 ; I BLRRL(BLRTSTDA,"INSI",INSCNT)]"" D
 I $G(BLRRL(BLRTSTDA,"INSI",INSCNT))]"" D   ; IHS/MSC/MKK - LR*5.2*1039
 . S BLRRL(BLRTSTDA,"INSID",INSCNT)=$TR($P($G(^AUTNINS(BLRRL(BLRTSTDA,"INSI",INSCNT),2)),U,19),"~")  ;cmi/maw 2/17/2009 changed to piece 10 external group name from external id 2
 . S BLRRL(BLRTSTDA,"INSCNME",INSCNT)=$P($G(^AUTNINS(BLRRL(BLRTSTDA,"INSI",INSCNT),0)),U)  ;insurance company name
 . S BLRRL(BLRTSTDA,"INSADD",INSCNT)=$$INSADD(BLRRL(BLRTSTDA,"INSI",INSCNT))
 . S BLRRL(BLRTSTDA,"INSADDE",INSCNT)=$TR($P(BLRRL(BLRTSTDA,"INSADD",INSCNT),U),U," ")_"~"_$TR($P(BLRRL(BLRTSTDA,"INSADD",INSCNT),U,3,99),U," ")
 . S BLRRL(BLRTSTDA,"INSPHO",INSCNT)=$P($G(^AUTNINS(BLRRL(BLRTSTDA,"INSI"),0)),U,6)
 . S BLRRL(BLRTSTDA,"INSTYP",INSCNT)=$P($G(^AUTNINS(BLRRL(BLRTSTDA,"INSI"),2)),U)
 S BLRRL(BLRTSTDA,"INSEMP",INSCNT)=$$GET1^DIQ(2,PAT,.3111)
 S BLRRL(BLRTSTDA,"INSNOI",INSCNT)=$$HLNAME^XLFNAME($P(^DPT(PAT,0),U))
 S BLRRL(BLRTSTDA,"INSNOIE",INSCNT)=$P(^DPT(PAT,0),U)
 S INSCNT=INSCNT+1
 ;end of hl7 lines
 Q