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

ABSPOSFC.m

Go to the documentation of this file.
  1. ABSPOSFC ; IHS/FCS/DRS - Set up ABSP() ; [ 09/12/2002 10:09 AM ]
  1. ;;1.0;PHARMACY POINT OF SALE;**3,15,16,40,50**;JUN 21, 2001;Build 38
  1. ;----------------------------------------------------------------------
  1. ;----------------------------------------------------------------------
  1. Q
  1. ; This is a copy of routine ABSPOSCC, made on 03/20/2001.
  1. ; It has some minor changes for printing NCPDP forms.
  1. ; Try to keep the two versions in synch.
  1. ;
  1. ; Called by ABSPOSFB from ABSPOSFA.
  1. ; GETINFO gets the patient/visit-level stuff
  1. ;
  1. ;----------------------------------------------------------------------
  1. ;IHS/SD/RLT - 01/24/06 - Patch 15
  1. ; Added new code to access new Medicare D eligibility data.
  1. ;----------------------------------------------------------------------
  1. ;IHS/SD/RLT - 02/13/06 - Patch 16
  1. ; Added new code to access Group # in Medicare D eligibility data.
  1. ;----------------------------------------------------------------------
  1. ;
  1. GETINFO(DIALOUT,PATIEN,VSTIEN,PINS,INSIEN) ;EP
  1. N XDATA,NRECIEN
  1. ; PINSDA = pointer into insurance eligible file,
  1. ; PINSDA = pointer into multiple of ^AUPNPRVT where appropriate
  1. N PINSDA,PINSDA1,PINSTYPE S PINSDA=$P(PINS,",",2),PINSTYPE=$P(PINS,",")
  1. I PINSTYPE="PRVT" S PINSDA1=$P(PINS,",",3) ; else PINSDA1 undef
  1. S ABSP("VisitIEN")=VSTIEN
  1. ;
  1. ;IHS/SD/RLT - 01/24/06 - Patch 15 - begin
  1. ;New Medicare D eligibiiltiy lookup.
  1. ;Set IEN to be used in policy# and name lookup.
  1. N MDIEN
  1. S MDIEN=""
  1. S:PINSTYPE="CARE" MDIEN=$$GETMDIEN
  1. ;IHS/SD/RLT - 01/24/06 - Patch 15 - end
  1. ;
  1. ;"Site" nodes
  1. ;S ABSP("Site","IEN")=DIALOUT
  1. ;S ABSP("Site","Switch Type")=$$SWTYPE(DIALOUT)
  1. N PHARMACY
  1. D
  1. . N IEN57 S IEN57=$O(TRANSACT(""))
  1. . S PHARMACY=$P(^ABSPTL(IEN57,1),U,7)
  1. . S XDATA=^ABSP(9002313.56,PHARMACY,0)
  1. . S ABSP("Site","NABP #")=$P(XDATA,U,2)
  1. . S ABSP("Site","Default DEA #")=$P(XDATA,U,3)
  1. . S ABSP("Envoy Terminal ID")=$P(XDATA,U,6)
  1. . S ABSP("Site","Name")=$P(XDATA,U)_" PHARMACY"
  1. . S ABSP("Site","Tax ID #")=$P(XDATA,U,5)
  1. . S XDATA=$G(^ABSP(9002313.56,PHARMACY,"CAID"))
  1. . S ABSP("Site","Medicaid Pharmacy #")=$P(XDATA,U)
  1. . S ABSP("Site","Default CAID #")=$P(XDATA,U,2)
  1. . S XDATA=$G(^ABSP(9002313.56,PHARMACY,"NDC"))
  1. . S ABSP("Site","NDC ID")=$P(XDATA,U)
  1. . ; These additional nodes for paper forms only:
  1. . N ADDR S ADDR=$G(^ABSP(9002313.56,PHARMACY,"ADDR"))
  1. . S ABSP("Site","Addr")=$P(ADDR,U) I $P(ADDR,U,2)]"" D
  1. . . S ABSP("Site","Addr")=ABSP("Site","Addr")_"/"_$P(ADDR,U,2)
  1. . S ABSP("Site","City")=$P(ADDR,U,3)
  1. . S ABSP("Site","State")=$P(ADDR,U,4)
  1. . S ABSP("Site","Zip")=$P(ADDR,U,5)
  1. . S ABSP("Site","Phone")=$P(ADDR,U,6)
  1. . S ABSP("Site","Fax")=$P(ADDR,U,7)
  1. . S ABSP("Site","Contact")="" ; contact name
  1. . ; May have special list of contact names and phone #s
  1. . ; (the old NCPDP form had a line for Contact name as well as phone #)
  1. . N X S X=$G(^ABSP(9002313.56,PHARMACY,"REP"))
  1. . Q:$P(X,U,2)=""
  1. . N N S N=$L($P(X,U,2),",") ; how many contact names/phone #s
  1. . S N=$R(N)+1 ; pick one at random
  1. . S ABSP("Site","Phone")=$P($P(X,U,2),",",N)
  1. . S ABSP("Site","Contact")=$P($P(X,U),",",N)
  1. ;
  1. S XDATA=^DPT(PATIEN,0)
  1. S ABSP("Patient","IEN")=PATIEN
  1. D ; Patient,Name
  1. . N % I PINSTYPE="CAID" D
  1. . . S %=$$CAIDNAME
  1. . E I PINSTYPE="CARE" D
  1. . . S %=$$CARENAME
  1. . E S %=""
  1. . I %="" S %=$P(XDATA,U)
  1. . S ABSP("Patient","Name")=%
  1. S ABSP("Patient","Sex")=$P(XDATA,U,2)
  1. S ABSP("Patient","DOB")=$P(XDATA,U,3)
  1. S ABSP("Patient","SSN")=$P(XDATA,U,9)
  1. ;
  1. ;"RX" mode containing date filled
  1. ; (All of the prescriptions are the same date filled
  1. ; because they're all for the same visit. We assume.)
  1. ;IHS/OIT/CNI/RAN Patch 40 This is not the correct date
  1. ;S ABSP("RX","Date Filled")=$P($G(^AUPNVSIT(VSTIEN,0)),U,1)
  1. ;
  1. ;"Insurer" nodes
  1. S (INSIEN,ABSP("Insurer","IEN"))=INSIEN ;$$INSIEN
  1. S ABSP("Cardholder","Last Name")=$$INSDNAME(2)
  1. S ABSP("Cardholder","First Name")=$$INSDNAME(1)
  1. S ABSP("Insurer","Relationship")=$$INSREL
  1. S ABSP("Insurer","Person Code")=$$PERSON
  1. ;ABSP("Eligibility Clarification code")=$$ELGCLAR
  1. S ABSP("Insurer","Group #")=$$INSGRP
  1. S ABSP("Insurer","Policy #")=$$INSPOL
  1. ;IHS/OIT/SCR 01/15/09 patch 29
  1. S ABSP("Insurer","Member #")=$$INSMBRNM
  1. ;
  1. ; Pharmacy number: usually NABP #, but sometimes the insurer demands
  1. ; their own insurer-assigned pharmacy number. Especially with Medicaid
  1. S ABSP("Site","Pharmacy #")=ABSP("Site","NABP #")
  1. I $D(^ABSP(9002313.56,PHARMACY,"INSURER-ASSIGNED #","B",INSIEN)) D
  1. . N X S X=$O(^ABSP(9002313.56,PHARMACY,"INSURER-ASSIGNED #","B",INSIEN,0))
  1. . S ABSP("Site","Pharmacy #")=$P(^ABSP(9002313.56,PHARMACY,"INSURER-ASSIGNED #",X,0),U,2)
  1. ; Anachronism: Medicaid Pharmacy # is a special field,
  1. ; properly, it belongs in the INSURER-ASSIGNED #
  1. ; But that Medicaid Pharmacy # will overwrite the in INS.-ASSIGNED #
  1. I PINSTYPE="CAID",ABSP("Site","Medicaid Pharmacy #")]"" D
  1. . S ABSP("Site","Pharmacy #")=ABSP("Site","Medicaid Pharmacy #")
  1. ;"NCPDP" nodes
  1. S NRECIEN=$P($G(^ABSPEI(INSIEN,100)),U,1)
  1. D ; most of this is electronic only but retained anyhow
  1. .S ABSP("NCPDP","IEN")=NRECIEN
  1. .I NRECIEN S XDATA=$G(^ABSPF(9002313.92,NRECIEN,1))
  1. .E S XDATA="" ;
  1. .S $P(XDATA,U,8)=0 ; do not add disp fee to ingr cost on paper forms
  1. .S ABSP("NCPDP","BIN Number")=$P(XDATA,U,1)
  1. .S ABSP("NCPDP","Version")=$P(XDATA,U,2)
  1. .S ABSP("NCPDP","# Meds/Claim")=$P(XDATA,U,3)
  1. .S ABSP("NCPDP","Envoy Plan Number")=$P(XDATA,U,4)
  1. .I $P(XDATA,U,8)="" S $P(XDATA,U,8)=1
  1. .S ABSP("NCPDP","Add Disp. Fee to Ingr. Cost")=$P(XDATA,U,8)
  1. I $$WORKREL D ; extra info for workers comp claims
  1. . D INSWORK
  1. . S ABSP("Date of Injury")=$P(^AUPNVPOV($$WORKREL,0),U,8)
  1. ;IHS/OIT/SCR 01/15/09 - added 'SPECIAL' node info
  1. ;"SPECIAL" node
  1. S ABSP("SPECIAL","SUBSCRIBER ID")=$P($G(^ABSP(9002313.99,1,"SPECIAL")),U,4)
  1. Q
  1. WORKREL() ; this is copied from ABSPOS26+/- ; changed ABSBVISI to VSTIEN
  1. ; is VSTIEN a worker's comp visit?
  1. ; If so, return value is true = pointer to ^AUPNVPOV which has
  1. ; the CAUSE OF DX listed as EMPLOYMENT RELATED
  1. N A,RET S (A,RET)=0
  1. F S A=$O(^AUPNVPOV("AD",VSTIEN,A)) Q:'A D Q:RET
  1. . I $P($G(^AUPNVPOV(A,0)),U,7)=4 D
  1. . . S RET=A
  1. Q RET
  1. ; $$INSxxx functions - given PINSTYPE, PINSDA, PINSDA1
  1. INSIEN() ; get pointer to ^AUTNINS
  1. ; (But shouldn't we directly get this from the IEN59?)
  1. I PINSTYPE="CAID" Q $P($G(^AUPNMCD(PINSDA,0)),U,2)
  1. I PINSTYPE="PRVT" Q $P($G(^AUPNPRVT(PINSDA,11,PINSDA1,0)),U)
  1. I PINSTYPE="CARE" Q $P($G(^AUPNMCR(PINSDA,0)),U,2)
  1. I PINSTYPE="RR" Q $P($G(^AUPNRRE(PINSDA,0)),U,2)
  1. I PINSTYPE="SELF" Q ""
  1. D IMPOSS^ABSPOSUE("P","TI","bad PINSTYPE="_PINSTYPE,,"INSIEN",$T(+0))
  1. Q ""
  1. INSREL() ; a single digit, 1, 2, 3, 4 = self,spouse,child,other
  1. N X S X=+$$AUTTRLSH Q:'X 4 ; X points to ^AUTTRLSH(
  1. ; Translate it using our own file, 9002313.81
  1. S X=$P($G(^AUTTRLSH(X,0)),U) Q:X="" 4 ; translate to name
  1. S X=$O(^ABSPF(9002313.81,"B",X,0)) Q:'X 4 ; point into 9002313.81
  1. S X=$P(^ABSPF(9002313.81,X,0),U,2)
  1. Q $S(X:X,1:4)
  1. AUTTRLSH() ; relationship - pointer to ^AUTTRLSH
  1. I PINSTYPE="PRVT" Q $P($G(^AUPNPRVT(PINSDA,11,PINSDA1,0)),U,5)
  1. N X S X=$O(^AUTTRLSH("B","SELF",0)) I 'X D IMPOSS^ABSPOSUE("DB","TI","RELATIONSHIP file is missing SELF entry",,"AUTTRLSH",$T(+0))
  1. ELGCLAR() ; Eligibility clarification code
  1. ; From Paid Presc. documentation:
  1. ; 3=Full-time student; 4=Disabled dependent; 5=Dependent parent
  1. ; 6=Significant other. Required if relationship code=3 or 4 and
  1. ; patient is age 18 or over.
  1. Q ""
  1. PERSON() ; Person Code
  1. ; For now, it's a simple translation from relationship code:
  1. ; 1->"01", 2->"02", etc.
  1. Q "0"_$$INSREL
  1. INSGRP() ; Insurer Group #
  1. ;RLT - 2/13/06 - Patch 16
  1. ;Get Medicare D group #
  1. N GRPIEN
  1. S GRPIEN=""
  1. S:PINSTYPE="CARE"&(MDIEN) GRPIEN=$P($G(^AUPNMCR(PINSDA,11,MDIEN,0)),U,11)
  1. Q:GRPIEN $P($G(^AUTNEGRP(GRPIEN,0)),U,2)
  1. ;RLT - 2/13/06 - Patch 16
  1. I PINSTYPE'="PRVT" Q ""
  1. N X S X=$$INS3PPH Q:'X ""
  1. N Y S Y=$P($G(^AUPN3PPH(X,0)),U,6) Q:'Y ""
  1. N Z S Z=$P($G(^AUTNEGRP(Y,11,111,0)),U,2) ; OUTPATIENT group # if poss
  1. I Z="" S Z=$P($G(^AUTNEGRP(Y,0)),U,2) ; else take the general one
  1. Q Z
  1. INSDNAME(N) ; Insured's name
  1. N X
  1. I PINSTYPE="CAID" S X=$$CAIDNAME
  1. E I PINSTYPE="CARE" S X=$$CARENAME
  1. E I PINSTYPE="SELF"!(PINSTYPE="RR") S X=ABSP("Patient","Name")
  1. E I PINSTYPE="PRVT" D
  1. . N T S T=$$INS3PPH
  1. . I 'T S X="" Q ; no 3PPH?
  1. . S X=$P(^AUPN3PPH(T,0),U) ; Policy holder
  1. E D IMPOSS^ABSPOSUE("P","TI","Bad PINSTYPE="_PINSTYPE,,"INSDNAME",$T(+0))
  1. I X="" S X=ABSP("Patient","Name")
  1. I N=1 Q $P(X,",",2) ; first name
  1. E I N=2 Q $P(X,",",1) ; last name
  1. E Q X ; entire name
  1. INSWORK ; get worker's comp-related info
  1. Q:PINSTYPE'="PRVT"
  1. N P S P=$$INS3PPH Q:'P
  1. N X S X=$P($G(^AUPN3PPH(P,0)),U,16) Q:'X
  1. S X=$G(^AUTNEMPL(X,0)) Q:X=""
  1. S ABSP("Employer","Name")=$P(X,U)
  1. S ABSP("Employer","Address")=$P(X,U,2)
  1. S ABSP("Employer","City")=$P(X,U,3)
  1. D
  1. . N ST
  1. . S ABSP("Employer","State")=$P(^DIC(5,ST,0),U,2)
  1. S ABSP("Employer","Zip Code")=$P(X,U,5)
  1. S ABSP("Employer","Phone")=$P(X,U,6)
  1. Q
  1. INS3PPH() Q $P($G(^AUPNPRVT(PINSDA,11,PINSDA1,0)),U,8)
  1. INSPOL() ; /IHS/OIT/RAM ; 15 DEC 17 - IT APPEARS THAT THIS ROUTINE HAS NOT BEEN KEPT UP
  1. ; I WONDER IF IT'S EVEN IN USE...
  1. I PINSTYPE="CAID" Q $P($G(^AUPNMCD(PINSDA,0)),U,3)
  1. ;IHS/SD/RLT - 01/24/06 - Patch 15 - begin
  1. ;I PINSTYPE="CARE" Q $P($G(^AUPNMCR(PINSDA,0)),U,3) ; no suffix?
  1. I PINSTYPE="CARE" Q $$GETMDPOL
  1. ;IHS/SD/RLT - 01/24/06 - Patch 15 - end
  1. ; I PINSTYPE="RR" Q $P($G(^AUPNRRE(PINSDA,0)),U,4) ; no prefix?
  1. I PINSTYPE="RR" Q $$GETRRE^AGUTL(PINSDA) ; /IHS/OIT/RAM ; 18 DEC 17 - New method for retrieving the RR Policy Number.
  1. I PINSTYPE="SELF" Q ""
  1. I PINSTYPE'="PRVT" D IMPOSS^ABSPOSUE("P","TI","Bad PINSTYPE="_PINSTYPE,,"INSPOL",$T(+0))
  1. N X S X=$$INS3PPH
  1. I X N Y S Y=$P($G(^AUPN3PPH(X,0)),U,4) I Y]"" Q Y ; 3PPH version first
  1. Q $P($G(^AUPNPRVT(PINSDA,11,PINSDA1,0)),U,2) ; else PRVT version
  1. INSMBRNM() ; Member #
  1. ;IHS/OIT/SCR 01/15/09 - Patch 29
  1. N ABSPMNUM
  1. S ABSPMNUM=""
  1. S:PINSTYPE="PRVT" ABSPMNUM=$G(^AUPNPRVT(PINSDA,11,PINSDA1,2))
  1. Q ABSPMNUM
  1. OLDGETMDPOL() ;Updated policy number lookup for Medicare D elig.
  1. ;IHS/SD/RLT - 01/24/06 - Patch 15 - begin
  1. N POL,MDPOL
  1. S POL=$P($G(^AUPNMCR(PINSDA,0)),U,3) ;original Medicare policy#
  1. S MDPOL=""
  1. S:MDIEN'="" MDPOL=$P($G(^AUPNMCR(PINSDA,11,MDIEN,0)),U,6)
  1. S:MDPOL'="" POL=MDPOL ;use Medicare D policy# if elig found
  1. Q POL
  1. ;IHS/SD/RLT - 01/24/06 - Patch 15 - end
  1. GETMDPOL() ;EP ; /IHS/OIT/RAM ; 15 DEC 2017 ; Total rewrite to account for Medicare Bendficiary Identifier, or MBI.
  1. ; /IHS/OIT/RAM ; 21 MAR 18 ; update to # logic - scan for Medicare Part D first, return that from the original area if it exists.
  1. ; Does the individual have a new MBI? If so, get it and return.... Do we care? This isn't date specific, so everything is 'Today'... just get the info...
  1. N POL,MDPOL S (POL,MDPOL)=""
  1. ; MDFLAG has already been called and correct flags set - let's use them to see if it's Medicare Part D & retrieve.
  1. S:MDFLG&(MDIEN) MDPOL=$P($G(^AUPNMCR(PINSDA,11,MDIEN,0)),U,6)
  1. ; If the retrieve was successful, let's return that policy #.
  1. I MDPOL'="" Q MDPOL
  1. ; If not, then let's go snag the individual's MBI if it exists...
  1. S POL=$$GETMCR^AGUTL(PINSDA)
  1. ; if MBI exists, let's default to that & return.
  1. I POL'="" Q POL
  1. ; OK... the "new way" & Medicare D resulted in nothing. Let's fall back to the original code as a 'Plan B.'
  1. S POL=$P($G(^AUPNMCR(PINSDA,0)),U,3) ;original
  1. ;
  1. Q POL
  1. ;
  1. CAIDNAME() Q $P($G(^AUPNMCD(PINSDA,21)),U)
  1. CARENAME() ;Q $P($G(^AUPNMCR(PINSDA,21)),U)
  1. ;IHS/SD/RLT - 01/24/06 - Patch 15 - begin
  1. ;Updated name lookup for new Medicare D elig.
  1. N NAME,MDNAME
  1. S NAME=$P($G(^AUPNMCR(PINSDA,21)),U) ;original Medicare name
  1. S MDNAME=""
  1. S:MDIEN'="" MDNAME=$P($G(^AUPNMCR(PINSDA,11,MDIEN,0)),U,5)
  1. S NAME=MDNAME ;use Medicare D name if elig found
  1. Q NAME
  1. ;IHS/SD/RLT - 01/24/06 - Patch 15 - end
  1. GETMDIEN() ;Get IEN for Medicare D elig record lookup.
  1. ;IHS/SD/RLT - 01/24/06 - Patch 15 - begin
  1. ;New Medicare D eligibiiltiy lookup.
  1. N MDFND,D1
  1. S MDFND=""
  1. S D1="A"
  1. F S D1=$O(^AUPNMCR(PINSDA,11,D1),-1) Q:'D1!(MDFND) D
  1. . Q:$P($G(^AUPNMCR(PINSDA,11,D1,0)),U,3)'="D" ;coverage type
  1. . S MDFND=1
  1. . S MDIEN=D1
  1. Q:'MDFND ""
  1. Q MDIEN
  1. ;IHS/SD/RLT - 01/24/06 - Patch 15 - end