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

BMCRPC3.m

Go to the documentation of this file.
BMCRPC3 ;  IHS/CAS/AU - GUI-REFERRED CARE INFO SYSTEM (3/4);     
 ;;4.0;REFERRED CARE INFO SYSTEM;**7,8,12,13**;JAN 09, 2006;Build 101
 ;
 ;GDIT/HS/BEE 10/19/17 - p12 CR#8528: Alphabetize the Referral-to-SNOMED terms
 ;GDIT/HS/BEE 10/19/17 - p12 - Address XINDEX/SAC issues
 ;GDIT/HS/BEE 05/08/2018 - BMC*4.0*13 - Consult review - Time is now passed in and required
 ;
 ; RPC code for RCIS GUI Application
 ; Routines contains code for Fetching Referral Templates
GTTMPLST(RSLT) ;; Get RCIS Template List from RCIS ROUTINE REFERRAL DEF
 N INDEX,OUT
 S RSLT="~`"
 D LIST^DIC(90001.32,"","@;.01","P","*",,,,,"","OUT")
 S INDEX=$O(OUT("DILIST",0))
 I +INDEX>0 F  D  Q:(+INDEX'>0)
 .S RSLT=RSLT_$G(OUT("DILIST",INDEX,0))_"~"
 .S INDEX=$O(OUT("DILIST",INDEX))
 S RSLT=$E(RSLT,1,$L(RSLT)-1)
 Q RSLT
GETTMPLT(RSLT,TMPLTIEN) ;; Get Template Detail
 ; D GETTMPLT^BMCRPC3(.R,8) W R
 N INDEX,OUT,TYPE,INOROUT,ICDCAT,CPTCAT,PURPOSE,PRIORITY,TYPEEXT,FCLTYRFT,VISITS,NOTESCHD,HXCMNTS,OTHERTYPE,OTHERTYPETEXT,VREFSNOMED
 ;GDIT/HS/BEE 10/19/17 - p12 - Address XINDEX/SAC issues
 NEW BCMNTS
 S TYPEEXT="",HXCMNTS="",FCLTYRFT=""
 D GETS^DIQ(90001.32,TMPLTIEN_",","@;.04;.07;.08;.09;.11;.12;.13;.14;.32;1;2;1111;1201;1301;1303","I","OUT")
 Q:'$D(OUT)
 S TYPE=$G(OUT(90001.32,TMPLTIEN_",",.04,"I"))
 ;; CHS - Vendor
 I TYPE="C" S TYPEEXT=$G(OUT(90001.32,TMPLTIEN_",",.07,"I")) S FCLTYRFT=$$GET1^DIQ(9999999.11,TYPEEXT_",",.01,"") S OTHERTYPE=$G(OUT(90001.32,TMPLTIEN_",",.09,"I")) S OTHERTYPETEXT=$$GET1^DIQ(90001.53,OTHERTYPE_",",.01,"")
 ;; OTHER - RCIS Specific provider
 I TYPE="O" S TYPEEXT=$G(OUT(90001.32,TMPLTIEN_",",.07,"I")) S FCLTYRFT=$$GET1^DIQ(9999999.11,TYPEEXT_",",.01,"") S OTHERTYPE=$G(OUT(90001.32,TMPLTIEN_",",.09,"I")) S OTHERTYPETEXT=$$GET1^DIQ(90001.53,OTHERTYPE_",",.01,"")
 I TYPE="N" S TYPEEXT="",FCLTYRFT="" ;; no field available in file (90001.32) for - IN-HOUSE - Clinic Stop
 I TYPE="I" S TYPEEXT=$G(OUT(90001.32,TMPLTIEN_",",.08,"I")) S FCLTYRFT=$$GET1^DIQ(9999999.06,TYPEEXT_",",.01,"") ;; IHS (Another facility) - Location (TO IHS FACILITY)
 S INOROUT=$G(OUT(90001.32,TMPLTIEN_",",.14,"I"))
 S ICDCAT=$G(OUT(90001.32,TMPLTIEN_",",.12,"I"))
 S CPTCAT=$G(OUT(90001.32,TMPLTIEN_",",.13,"I"))
 S PURPOSE=$G(OUT(90001.32,TMPLTIEN_",",1201,"I"))
 S PRIORITY=$G(OUT(90001.32,TMPLTIEN_",",.32,"I"))
 S VISITS=$G(OUT(90001.32,TMPLTIEN_",",1111,"I"))
 S NOTESCHD=$G(OUT(90001.32,TMPLTIEN_",",1301,"I"))
 S HXCMNTS=""
 S INDEX=$O(OUT(90001.32,TMPLTIEN_",",1,0))
 I +INDEX>0 F  D  Q:(+INDEX'>0)
 .S HXCMNTS=HXCMNTS_$G(OUT(90001.32,TMPLTIEN_",",1,INDEX))_"~"
 .S INDEX=$O(OUT(90001.32,TMPLTIEN_",",1,INDEX))
 S HXCMNTS=$E(HXCMNTS,1,$L(HXCMNTS)-1)
 S BCMNTS=""
 S INDEX=$O(OUT(90001.32,TMPLTIEN_",",2,0))
 I +INDEX>0 F  D  Q:(+INDEX'>0)
 .S BCMNTS=BCMNTS_$G(OUT(90001.32,TMPLTIEN_",",2,INDEX))_"~"
 .S INDEX=$O(OUT(90001.32,TMPLTIEN_",",2,INDEX))
 S BCMNTS=$E(BCMNTS,1,$L(BCMNTS)-1)
 S VREFSNOMED=$G(OUT(90001.32,TMPLTIEN_",",1303,"I"))
 S RSLT="~`"_TYPE_"^"_INOROUT_"^"_ICDCAT_"^"_CPTCAT_"^"_PURPOSE_"^"_PRIORITY_"^"_TYPEEXT_"^"_FCLTYRFT_"^"_VISITS_"^"_NOTESCHD_"^"_HXCMNTS_"^"_$G(BCMNTS)_"^"_$G(OTHERTYPE)_"^"_$G(OTHERTYPETEXT)_"^"_$G(VREFSNOMED)
 Q RSLT
ADDC32LG(RSLT,REFIEN,USERIEN,RRINTDT) ;;Add log entry for C32 print in 600 (C32 PRINTED) multiple of 90001(RCIS REFERRAL) file
 I '$D(REFIEN) S RSLT="~`0^Referral IEN is not present" Q RSLT
 N FDA,FDAIEN,ERR1
 I '$D(USERIEN) S USERIEN=DUZ
 I USERIEN="" S USERIEN=DUZ
 I 'USERIEN S RSLT="~`0^USERIEN(DUZ) is not present" Q RSLT
 I $D(RRINTDT) D DT^DILF("RS",RRINTDT,.RRINTDT,,"") I RRINTDT="-1" S RSLT="~`0^Date/Time format is MM/DD/YYYY@HHMM" Q RSLT
 D NOW^%DTC
 I (('$D(RRINTDT))!(RRINTDT="")!(RRINTDT>%)) S RRINTDT=%  ;;if date/time not provided, assume current date/time
 S FDA(90001.6,"+1,"_REFIEN_",",.01)=RRINTDT
 S FDA(90001.6,"+1,"_REFIEN_",",.02)=USERIEN
 D UPDATE^DIE("","FDA","FDAIEN","ERR1")
 I $D(ERR1("DIERR")) S RSLT="~`0^Error adding C32 printed log: "_$G(ERR1("DIERR","1","TEXT",1)) Q RSLT
 S RSLT="~`1^"_FDAIEN(1) Q RSLT
 Q
SENDALRT(BMCRIEN)  ;;EP-ALERT FOR PHYS
 ;GDIT/HS/BEE 10/19/17 - p12 - Address XINDEX/SAC issues
 NEW BMCRHDR,XQADATA
 Q:$G(BMCRIEN)=""
 S BMCDFN=$$GET1^DIQ(90001,BMCRIEN_",",.03,"I")
 S:$G(BMCDFN) BMCREC("PAT NAME")=$P(^DPT(BMCDFN,0),U)
 N XQA
 S BMCRHDR="New"
 S XQADATA=BMCRIEN
 I ($P($G(^BMCPARM(DUZ(2),4100)),U,9)="Y")!($P($G(^BMCPARM(DUZ(2),4100)),U,10)="Y") D PALRT1^BMCALERT
 Q
SENDXM(BMCRIEN,BMCMODE)  ;;Send mailman message for add/update referral
 ;GDIT/HS/BEE 10/19/17 - p12 - Address XINDEX/SAC issues
 NEW BMCGRP,BMCGRP1,BMCGRPS,I
 S BMCDFN=$$GET1^DIQ(90001,BMCRIEN_",",.03,"I"),BMCRDATE=$$GET1^DIQ(90001,BMCRIEN_",",.01,"I")
 S:$G(BMCDFN) BMCREC("PAT NAME")=$P(^DPT(BMCDFN,0),U)
 S BMCREC("REF DATE")=$$GET1^DIQ(90001,BMCRIEN_",",.01,"E"),BMCRNUMB=$$GET1^DIQ(90001,BMCRIEN_",",.02,"E"),BMCDTYPE=15
 I BMCMODE="A" D
 .I $D(^BMCMSG("C",BMCRIEN)) K BMCRIEN,BMCDFN,BMCRDATE,BMCMODE,BMCREC,BMCRNUMB,BMCDTYPE Q
 .S BMCGRP="BMC",Y=0
 .F  S BMCGRP=$O(^XMB(3.8,"B",BMCGRP)) Q:$E(BMCGRP,1,3)'="BMC"  D
 ..S BMCGRP1=0 S BMCGRP1=$O(^XMB(3.8,"B",BMCGRP,BMCGRP1))
 ..S Y=Y+1,BMCGRP(Y)=BMCGRP_U_BMCGRP1
 .K XMB,XMY
 .F I=1:1 Q:$P(Y,",",I)'?1N.N  S XMY("G."_$P(BMCGRP($P(Y,",",I)),U))="",BMCGRPS($P(BMCGRP($P(Y,",",I)),U,2))=""
 .D MSGGRP^BMCMM
 I BMCMODE="M" D
 .D MPER^BMCMM,MSGPRV^BMCMM
 D SND^BMCMM
 D EXT^BMCMM
 K BMCRIEN,BMCDFN,BMCRDATE,BMCMODE,BMCREC,BMCRNUMB,BMCDTYPE
 Q
STATIC(PATIEN,REFIEN) ;;EP - STORE STATIC DATA OF REFERRAL
 N BMCREC,Y,%
 S BMCREC=^BMCREF(REFIEN,0)
 S Y=^DPT(PATIEN,0)
 S DR="5101///"_$P(Y,U) ; name
 S DR=DR_";5103///"_$P(Y,U,3) ;dob
 S DR=DR_";5104///"_$P(Y,U,9) ;ssn
 S DR=DR_";5107///"_$P(Y,U,2) ;sex
 S %=$P(BMCREC,U,5)
 I % D
 .S DR=DR_";5102///"_$P($G(^AUPNPAT(PATIEN,41,%,0)),U,2) ;chart #
 .S DR=DR_";5113///"_$P($G(^DIC(4,%,0)),U) ;facility
 .S DR=DR_";5114///"_$P($G(^AUTTLOC(%,0)),U,10) ;asufac
 S Y=$G(^AUPNPAT(PATIEN,51))
 I $P(Y,U,18)'="" S DR=DR_";5105///"_$P(Y,U,18) ;comm
 I $P(Y,U,8) S DR=DR_";5106///"_$P($G(^AUTTTRI($P(Y,U,8),0)),U,2) ;tribe
 S %=$P(BMCREC,U,7)
 I % D
 .S DR=DR_";5108///"_$P($G(^AUTTVNDR(%,0)),U) ;vendor
 .S DR=DR_";5109///"_$P($G(^AUTTVNDR(%,51)),U)  ;ein
 S %=$P(BMCREC,U)
 S DR=DR_";5110///"_$$MCR^AUPNPAT(PATIEN,%)  ;medicare
 S DR=DR_";5111///"_$$MCD^AUPNPAT(PATIEN,%) ;medicaid
 S DR=DR_";5112///"_$$PI^AUPNPAT(PATIEN,%) ;private insurance
 S DIE="^BMCREF(",DA=REFIEN
 D DIE^BMCFMC
 K DA,DIE,DR
 Q
SETMEDHX(RSLT,CMNTSX,PATIEN,REFIEN,TYPE)  ;;Add Medical History comments into RCIS COMMENTS file
 ;S BMCDFN=PATIEN,BMCRIEN=REFIEN,BMCCTYP=$G(TYPE)
 ;D COMMENTS^BMCADD1
 I (('$D(REFIEN))!('$D(PATIEN))!('$D(CMNTSX))) S RSLT="~`0^Required data not provided" Q RSLT
 N INDEX,FDA,FDAIENP,ERR1,WP,ERR2,RET
 S INDEX=1
 S FDA(90001.03,"+1,",.01)=DT
 S FDA(90001.03,"+1,",.02)=PATIEN
 S FDA(90001.03,"+1,",.03)=REFIEN
 S FDA(90001.03,"+1,",.04)=DUZ
 S FDA(90001.03,"+1,",.05)=$G(TYPE)
 D UPDATE^DIE("","FDA","FDAIENP","ERR1")
 I $D(ERR1("DIERR")) S RSLT="~`0^Error adding Med Hx/Business Comments: "_$G(ERR1("DIERR","1","TEXT",1)) Q RSLT
 ;I $P(CMNTSX,"~",INDEX)'="" F  D  Q:($P(CMNTSX,"~",INDEX)="")
 ;.;S WP(INDEX)=$P(CMNTSX,"~",INDEX)
 ;.;S INDEX=INDEX+1 
 ;I (($D(WP))&(FDAIENP(1)>0)) D WP^DIE(90001.03,FDAIENP(1)_",",1,"","WP","ERR2")
 ;I $D(ERR2("DIERR")) N FDAK S FDAK(90001.03,FDAIENP(1)_",",.01)="@" D UPDATE^DIE("","FDAK","FDAIENP","ERR1") S RSLT="~`0^Error adding Med Hx/Business Comments text: "_$G(ERR2("DIERR","1","TEXT",1)) Q RSLT
 I (($D(CMNTSX))&(FDAIENP(1)>0)) S RET=$$SETWP^BMCRPC5(90001.03,1,FDAIENP(1),CMNTSX,1,0)
 I $G(RET)'=1 S RSLT="~`0^Error adding Med Hx/Business Comments text: "_$G(RET) Q RSLT
 S RSLT="~`1^"_FDAIENP(1)
 Q RSLT
 ;
GTREFTYP(RSLT) ;;Get Purpose Of Referrals
 ;BMC GET PURPOSE OF REF API
 ;D GTREFTYP^BMCRPC3(.R) ZW @R
 K ^TMP($J,"REFPURPOSE")
 ;GDIT/HS/BEE 10/19/17 - p12 CR#8528: Reworked next section of code to sort results
 ;N OUT,INDEX
 ;S OUT="VAR"
 ;D SUBLST^BSTSAPI(OUT,"EHR REFERRAL TYPE^^1")
 ;S INDEX=$O(VAR(""))
 ;I +INDEX>0 F  D  Q:(+INDEX'>0)
 ;.S ^TMP($J,"REFPURPOSE",1)=$G(^TMP($J,"REFPURPOSE",1))_$G(VAR(INDEX))_"~"
 ;.S INDEX=$O(VAR(INDEX)) 
 N INDEX,VAR,TMP,ND,TRM
 D SUBLST^BSTSAPI("VAR","EHR REFERRAL TYPE^^1")
 S INDEX="" F  S INDEX=$O(VAR(INDEX)) Q:'INDEX  S ND=$G(VAR(INDEX)),TRM=$P(ND,U,3) I TRM]"" S TMP(TRM)=ND
 S (INDEX,TMP)="" F  S INDEX=$O(TMP(INDEX)) Q:INDEX=""  S TMP=TMP_$S(TMP]"":"~",1:"")_TMP(INDEX)
 I TMP]"" S ^TMP($J,"REFPURPOSE",1)=TMP
 ;End of CR#8528 Changes
 S ^TMP($J,"REFPURPOSE",2)=""
 S RSLT=$NA(^TMP($J,"REFPURPOSE"))
 Q
UPDTSTRF(RSLT,REFIEN,STATUS) ;;Update Status Of Referral against Ref IEN return 0 or 1
 ; Not in Use
 ;TUS)  ADTLINFO=0 ;;ADDITIONAL INFO flag
 I '$D(REFIEN) S RSLT="~`0^Referral Ien is not provided" Q RSLT
 I '$D(STATUS) S RSLT="~`0^Referral Status is not provided" Q RSLT
 I REFIEN'>0 S RSLT="~`0^Referral Ien is not provided" Q RSLT
 S FDA(90001,REFIEN_",",.15)=$G(STATUS)
 D FILE^DIE("","FDA","ERR1")
 I $D(ERR1("DIERR")) S RSLT="~`0^Error updating referral:"_$G(ERR1("DIERR","1","TEXT",1)) Q RSLT
 ;D SENDXM^BMCRPC3(REFIEN,"M") ;;Send mailman message
 S RSLT="1"
 Q
 ;
UPCNRINF(RSLT,REFIEN,CONSULTBY,CONSULTDT,CONSULTSTATUS) ;;Updates new Multiple Consulted By
 ; S REFIEN="113248"
 ; S CONSULTBY="3039"
 ; GDIT/HS/BEE 05/08/2018 - BMC*4.0*13 - Time is passed in and required
 ; OLD: S CONSULTDT="8/12/2013"
 ; S CONSULTDT="8/12/2013@10:30"
 ; S CONSULTSTATUS="R"
 ; D UPCNRINF^BMCRPC3(.R,REFIEN,CONSULTBY,CONSULTDT,CONSULTSTATUS) W R
 ; S ^TMP("FAR",12)=$G(REFIEN)_"^"_$G(CONSULTBY)_"^"_$G(CONSULTDT)_"^"_$G(CONSULTSTATUS)
 N OUT,FDA,ERR1,PATIEN,ADTLINFO,MSG
 I '$D(REFIEN) S RSLT="~`0^Referral Ien is not provided" Q RSLT
 I REFIEN'>0 S RSLT="~`0^Referral Ien is not provided" Q RSLT
 I $$GET1^DIQ(90001,REFIEN_",",1308,"")'=""  D
 . I $$GET1^DIQ(90001,REFIEN_",",1307,"")'=""  D
 . . I $$GET1^DIQ(90001,REFIEN_",",1306,"I")=$G(CONSULTSTATUS)  D
 . . . S MSG=$$GET1^DIQ(90001,REFIEN_",",.03,"")_" has already been reviewed by "_$$GET1^DIQ(90001,REFIEN_",",1308,"")_" on "_$$GET1^DIQ(90001,REFIEN_",",1307,"")_"."
 I $G(MSG)'="" S RSLT="~`1^"_$G(MSG) Q RSLT
 ; GDIT/HS/BEE 05/08/2018 - BMC*4.0*13 - Time is passed in and required
 ;D DT^DILF("",CONSULTDT,.CONSULTDT) I CONSULTDT="-1" S RSLT="~`0^Review Date is not in mm/dd/yyyy fromat" Q RSLT
 D DT^DILF("RT",CONSULTDT,.CONSULTDT) I CONSULTDT="-1" S RSLT="~`0^Review Date is not in mm/dd/yyyy format" Q RSLT
 S FDA(90001,REFIEN_",",1308)=$G(CONSULTBY)
 S FDA(90001,REFIEN_",",1307)=$G(CONSULTDT)
 S FDA(90001,REFIEN_",",1306)=$G(CONSULTSTATUS)
 D FILE^DIE("","FDA","ERR1")
 I $D(ERR1("DIERR")) S RSLT="~`0^Error updating referral:"_$G(ERR1("DIERR","1","TEXT",1)) Q RSLT
 D CRENSCCT^BMCRPC3("",REFIEN,"371530004")
 S RSLT="~`1^"
 Q
 ;
CRENSCCT(RSLT,RRIEN,TERM) ; Create entry in 2300 (SNOMED CLOSED CLINICAL TERM) multiple of RCIS REFERRAL (90001) file
 ; D CRENSCCT^BMCRPC3(.R,"113255","371530004") W @R
 ; RRIEN = RCIS Feferral IEN
 ; TERM = Free text
 ; RSLT=IEN of entry created in  2300 (SNOMED CLOSED CLINICAL TERM) multiple
 K FDA,FDAMSG,FDAIEN
 N FDADA
 ;
 S FDA(42,90001.23,"+1,"_RRIEN_",",.01)=$G(TERM)
 D UPDATE^DIE("","FDA(42)","FDAIEN","FDAMSG")
 S FDADA=+$G(FDAIEN(1))
 I $D(FDAMSG) D
 . W !!,"The following error message was returned:",!!
 . S FDAMSG="" F  S FDAMSG=$O(FDAMSG("DIERR",1,"TEXT",FDAMSG)) Q:FDAMSG=""  W FDAMSG("DIERR",1,"TEXT",FDAMSG),!
 I $G(FDADA)=""  S RSLT=$G(FDAMSG) Q
 S RSLT=$G(FDADA)
 Q
 ;
CRENSCT(RSLT,RRIEN,TERM) ; Create entry in 2200 (SNOMED CLINICAL TERM) multiple of RCIS REFERRAL (90001) file
 ; D CRENSCT^BMCRPC3(.R,"113255","371530004") W @R
 ; RRIEN = RCIS Feferral IEN
 ; TERM = Free text
 ; RSLT=IEN of entry created in  2200 (SNOMED CLINICAL TERM) multiple
 K FDA,FDAMSG,FDAIEN
 N FDADA
 ;
 S FDA(42,90001.22,"+1,"_RRIEN_",",.01)=$G(TERM)
 D UPDATE^DIE("","FDA(42)","FDAIEN","FDAMSG")
 S FDADA=+$G(FDAIEN(1))
 I $D(FDAMSG) D
 . W !!,"The following error message was returned:",!!
 . S FDAMSG="" F  S FDAMSG=$O(FDAMSG("DIERR",1,"TEXT",FDAMSG)) Q:FDAMSG=""  W FDAMSG("DIERR",1,"TEXT",FDAMSG),!
 I $G(FDADA)=""  S RSLT=$G(FDAMSG) Q
 S RSLT=$G(FDADA)
 Q
 ;