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

PSOERXU2.m

Go to the documentation of this file.
PSOERXU2 ;ALB/BWF - eRx utilities ; 5/26/2017 9:57am
 ;;7.0;OUTPATIENT PHARMACY;**508,598,581,631,617,746**;DEC 1997;Build 106
 ;
 Q
 ; look for existing patient
 ; NAME - PATIENT FULL NAME
 ; IDOB - INCOMING PATIENT DOB
 ; IDGEN - INCOMING PATIENT GENDER
 ; SSN - INCOMING PATIENT SSN
 ; AL1 - INCOMING PATIENT ADDRESS LINE 1
FINDPAT(NAME,IDOB,IGEN,SSN,AL1) ;
 N MPAT,MTCHCNT,PIEN,MATCH,PDOB,PGEN,PSSN,PAL1
 ; for now, quit if name match does not occur.
 I '$D(^PS(52.46,"BN",NAME)) Q ""
 S MTCHCNT=0
 S PIEN=0 F  S PIEN=$O(^PS(52.46,"BN",NAME,PIEN)) Q:'PIEN  D
 .S PDOB=$$GET1^DIQ(52.46,PIEN,.08,"I"),PGEN=$$GET1^DIQ(52.46,PIEN,.07,"I")
 .S PSSN=$$GET1^DIQ(52.46,PIEN,1.4),PAL1=$$GET1^DIQ(52.46,PIEN,3.1,"E")
 .; if the ssn exists, and does not match, quit
 .I $L(SSN),SSN'=PSSN Q
 .I PDOB=IDOB,PGEN=IGEN,AL1=PAL1 S MTCHCNT=MTCHCNT+1,MATCH(PIEN)=""
 I MTCHCNT'=1 Q ""
 S MPAT=$O(MATCH(0))
 I MPAT Q MPAT
 Q ""
 ; 
FINDPRE(NAME,NPI,DEA) ; Try to find an existing prescriber record in #52.48
 ; Input: NAME - Prescriber Name
 ;        NPI  - Prescriber NPI Number
 ;        DEA  - Prescriber DEA Number
 ;Output: 0 - Prescriber not Found | NNN - Pointer to ERX EXTERNAL PERSON file (#52.48) for the matching Prescriber
 N PREMTCH,FOUND
 ;
 S NAME=$$UP^XLFSTR($G(NAME)),NPI=$G(NPI),DEA=$$UP^XLFSTR($G(DEA))
 ; If Name, NPI and DEA Number are present, entry must match all 3
 I NAME'="",NPI'="",DEA'="" D  Q +PREMTCH
 .S (FOUND,PREMTCH)=0 F  S PREMTCH=$O(^PS(52.48,"C",NPI,PREMTCH)) Q:'PREMTCH  D  I FOUND Q
 ..I NAME=$$GET1^DIQ(52.48,PREMTCH,.01),$D(^PS(52.48,"D",DEA,PREMTCH)) S FOUND=1
 ;
 ; If NPI and DEA Number are present, entry must match both
 I NPI'="",DEA'="" D  Q +PREMTCH
 .S (FOUND,PREMTCH)=0 F  S PREMTCH=$O(^PS(52.48,"C",NPI,PREMTCH)) Q:'PREMTCH  D  I FOUND Q
 ..I $D(^PS(52.48,"D",DEA,PREMTCH)) S FOUND=1
 ;
 ; If Name and NPI are present and DEA is missing, entry must match both (DEA must be blank)
 I NAME'="",NPI'="",DEA="" D  Q +PREMTCH
 .S (FOUND,PREMTCH)=0 F  S PREMTCH=$O(^PS(52.48,"C",NPI,PREMTCH)) Q:'PREMTCH  D  I FOUND Q
 ..I NAME=$$GET1^DIQ(52.48,PREMTCH,.01),$$GET1^DIQ(52.48,PREMTCH,1.6)="" S FOUND=1
 ;
 ; If Name and DEA are present and NPI is missing, entry must match both
 I NAME'="",NPI="",DEA'="" D  Q +PREMTCH
 .S (FOUND,PREMTCH)=0 F  S PREMTCH=$O(^PS(52.48,"C",NPI,PREMTCH)) Q:'PREMTCH  D  I FOUND Q
 ..I NAME=$$GET1^DIQ(52.48,PREMTCH,.01),$$GET1^DIQ(52.48,PREMTCH,1.6)=DEA S FOUND=1
 ;
 ; If only Name is present
 I NAME'="",$O(^PS(52.48,"BN",NAME,0)) Q +$O(^PS(52.48,"BN",NAME,0))
 ;
 Q 0
 ;
ERR(ERXIEN,MTYPE) ;
 N GL,ECODE,DESCODE,ERRTEXT,DONE,I,REQIEN,REQTYP,ERXTYP,NWRXIEN
 S GL=$NA(^TMP($J,"PSOERXO1","Message",0,"Body",0,MTYPE,0))
 S ECODE=$G(@GL@("Code",0))
 S ERRTEXT=$G(@GL@("Description",0))
 S FDA(52.49,ERXIEN_",",60.1)=ECODE
 S FDA(52.49,ERXIEN_",",60)=ERRTEXT
 D FILE^DIE(,"FDA") K FDA
 S DONE=0
 F I=0:1 D  Q:DONE  D
 .I '$D(@GL@("DescriptionCode",I)) S DONE=1 Q
 .S DESCODE=$G(@GL@("DescriptionCode",I))
 .S DESCODE=$$PRESOLV^PSOERXA1(DESCODE,"ERR") Q:'DESCODE
 .Q:$D(^PS(52.49,ERXIEN,61,"B",DESCODE))
 .S FDA(52.4961,"+1,"_ERXIEN_",",.01)=DESCODE D UPDATE^DIE(,"FDA") K FDA
 S ERXTYP=$$GET1^DIQ(52.49,ERXIEN,.08,"I")
 S REQIEN=$$RESOLV(ERXIEN)
 I REQIEN D  Q
 .S REQTYP=$$GET1^DIQ(52.49,REQIEN,.08,"I")
 .I REQTYP="CR" D UPDSTAT^PSOERXU1(ERXIEN,"CRE")
 .I REQTYP="RR" D UPDSTAT^PSOERXU1(REQIEN,"RRE"),UPDSTAT^PSOERXU1(ERXIEN,"RRE")
 .I REQTYP="CN" D UPDSTAT^PSOERXU1(REQIEN,"CNE"),UPDSTAT^PSOERXU1(ERXIEN,"CNE")
 D UPDSTAT^PSOERXU1(ERXIEN,"E")
 Q
GETSTAT(MTYPE,RTHID,RTMID) ;
 N ESTAT,RTMTYPE,STFDA,RTMIEN,RESTAT
 ; if this is a cancel request, set the initial status to CAR - cancel request received
 I MTYPE="CR" Q $$PRESOLV^PSOERXA1("CRN","ERX")
 I MTYPE="CA" Q $$PRESOLV^PSOERXA1("CAR","ERX")
 I 'RTHID,'RTMID S ESTAT=$S(MTYPE="RR":"RRN",MTYPE="RE":"RXR",MTYPE="N":"N",MTYPE="IE":"E",1:"N") Q $$PRESOLV^PSOERXA1(ESTAT,"ERX")
 S RTMIEN=RTHID
 I MTYPE="IE",'$L(RTMIEN) S ESTAT="E" Q $$PRESOLV^PSOERXA1(ESTAT,"ERX")
 I MTYPE="IE",$L(RTMIEN) D
 .S RTMTYPE=$$GET1^DIQ(52.49,RTMIEN,.08,"I")
 .I RTMTYPE="CR" D UPDSTAT^PSOERXU1(RTMIEN,"CRE")
 .I RTMTYPE="RR" S RESTAT=$$PRESOLV^PSOERXA1("RRE","ERX"),STFDA(52.49,RTMIEN_",",1)=RESTAT D UPDATE^DIE(,"STFDA") K STFDA Q
 .S RESTAT=$$PRESOLV^PSOERXA1("E","ERX")
 I MTYPE="RE",$L(RTMIEN) D
 .S RTMTYPE=$$GET1^DIQ(52.49,RTMIEN,.08,"I")
 .I RTMTYPE="RR"  D UPDSTAT^PSOERXU1(RTMIEN,"RRR")
 I MTYPE="CX",$L(RTMIEN) D
 .S RTMTYPE=$$GET1^DIQ(52.49,RTMIEN,.08,"I")
 .I RTMTYPE="CR",$$GET1^DIQ(52.49,RTMIEN,1,"E")'="CRR" D UPDSTAT^PSOERXU1(RTMIEN,"CRR")
 I $G(ESTAT) Q ESTAT
 S ESTAT=$S(MTYPE="CX":"CXN",MTYPE="RR":"RRN",MTYPE="RE":"RXN",MTYPE="N":"N",1:"N")
 I ESTAT="" Q ""
 I '$D(^PS(52.45,"C","ERX",ESTAT)) Q ""
 Q $$PRESOLV^PSOERXA1(ESTAT,"ERX")
ADDCOMM(ERXIEN) ;
 N DIR,Y,FDA,MTYPE,DA
 D FULL^VALM1
 S VALMBCK="R"
 I $D(^XUSEC("PSO ERX VIEW",DUZ)) W !,">>>  Add Comments may not be selected at this point." D DIRE^PSOERXX1 Q
 S MTYPE=$$GET1^DIQ(52.49,ERXIEN,.08,"I")
 I "RR,RE,CA,CN,CR,CX"'[MTYPE!(MTYPE="N") S DIR(0)="E" W !!,"This option can only be used to add comments to request and response message",!,"types." D ^DIR K DIR Q
 K DA S DIR(0)="52.49,50",DIR("B")=$$GET1^DIQ(52.49,ERXIEN,50,"E") D ^DIR
 Q:Y="^"!(Y="")
 S FDA(52.49,ERXIEN_",",50)=Y
 S FDA(52.49,ERXIEN_",",50.1)=DUZ
 S FDA(52.49,ERXIEN_",",50.2)=$$NOW^XLFDT()
 D FILE^DIE(,"FDA")
 D REF^PSOERSE1
 Q
RESOLV(IEN) ;
 N RTHID,RTHIEN,RES
 S RTHID=$$GET1^DIQ(52.49,IEN,.14,"E")
 S RTHIEN=$$FIND1^DIC(52.49,,"O",RTHID,"FMID",,"RES")
 I 'RTHIEN,$D(RES) Q "0^Could not find related message."
 Q RTHIEN
GETREQ(IEN) ;
 N RTMID,RTHIEN
 S RTMID=$$GET1^DIQ(52.49,IEN,.02,"E")
 S RTHIEN=$$FIND1^DIC(52.49,,"O",RTMID,"CHVID",,"RES")
 I 'RTHIEN,$D(RES) Q "0^Could not find related message."
 Q RTHIEN
GETRESP(IEN) ;
 N MID,RTHIEN
 S MID=$$GET1^DIQ(52.49,IEN,.01,"E")
 S RTHIEN=$$FIND1^DIC(52.49,,"O",MID,"RTHID",,"RES")
 I 'RTHIEN,$D(RES) Q "0^Could not find related message."
 Q RTHIEN
MSGHIST(RES,IEN) ;
 N SIEN,RELIEN
 S SIEN=0
 F  S SIEN=$O(^PS(52.49,IEN,201,SIEN)) Q:'SIEN  D
 .S RELIEN=$$GET1^DIQ(52.49201,SIEN_","_IEN_",",.01,"I")
 .S RES(RELIEN)=""
 Q
 ; REFREQ - erx refill request IEN
 ; REFRES - erx refill response IEN
 ; Determine deltas between refill request and response.
RRDELTA(DELTAS,REFREQ,REFRES) ;
 N FLDS,DONE,I,REQARY,RESARY,FLDNM,SFLDS,REQSIEN,FOUND,REQIENS,RESIENS,REQTYP,RESTYP,SFLD,SFLDS,FLDNM,SFLDNM,SREQVAL,SRESVAL
 N REQDAT,RESDAT,FIELD,SFIELD,FLD,REQVAL,RESVAL,RESSIEN
 ; first check the top level items
 S FLDS=".04;2.1;2.3"
 S DONE=0
 F I=1:1 D  Q:DONE
 .S FLD=$P(FLDS,";",I) I FLD="" S DONE=1 Q
 .S REQVAL=$$GET1^DIQ(52.49,REFREQ,FLD,"E")
 .S RESVAL=$$GET1^DIQ(52.49,REFRES,FLD,"E")
 .I REQVAL=RESVAL Q
 .D FIELD^DID(52.49,FLD,,"LABEL","FIELD")
 .S FLDNM=$G(FIELD("LABEL")) Q:'$L(FLDNM)
 .S DELTAS(52.49,FLDNM)=REQVAL_U_RESVAL
 S SFLDS=".06;.07;2.1"
 S (REQSIEN,FOUND)=0 F  S REQSIEN=$O(^PS(52.49,REFREQ,49,REQSIEN)) Q:'REQSIEN!(FOUND)  D
 .S REQIENS=REQSIEN_","_REFREQ_","
 .S REQTYP=$$GET1^DIQ(52.4949,REQIENS,.02,"I") I REQTYP="D" D  S FOUND=1 Q
 ..D GETS^DIQ(52.4949,REQIENS,SFLDS,"E","REQDAT")
 S (RESSIEN,FOUND)=0 F  S RESSIEN=$O(^PS(52.49,REFRES,49,RESSIEN)) Q:'RESSIEN!(FOUND)  D
 .S RESIENS=RESSIEN_","_REFRES_","
 .S RESTYP=$$GET1^DIQ(52.4949,RESIENS,.02,"I") I RESTYP="D" D  S FOUND=1 Q
 ..D GETS^DIQ(52.4949,RESIENS,SFLDS,"E","RESDAT")
 S DONE=0
 F I=1:1 D  Q:DONE
 .S SFLD=$P(SFLDS,";",I) I SFLD="" S DONE=1 Q
 .S (SREQVAL,SRESVAL)=""
 .I $D(REQIENS) S SREQVAL=$G(REQDAT(52.4949,REQIENS,SFLD,"E"))
 .I $D(RESIENS) S SRESVAL=$G(RESDAT(52.4949,RESIENS,SFLD,"E"))
 .I SREQVAL=SRESVAL Q
 .I $D(SRESVAL),SFLD=.06 S SRESVAL=$G(SRESVAL)-1
 .D FIELD^DID(52.4949,SFLD,,"LABEL","SFIELD")
 .S SFLDNM=$G(SFIELD("LABEL")) Q:'$L(SFLDNM)
 .S DELTAS(52.4949,SFLDNM)=SREQVAL_U_SRESVAL
 Q
CANREQ(ERXIEN,LINE,PMODE) ;
 N REQIEN,REQDTTM,COMM,HUBID,CANSTAT,DNB,RESTYPE,COMM,COMMARY,COMMBY,COMMDTTM,CTXT,I,REQBY
 ; - the next line of code will actually reference the related message for retrieval of the cancel request information
 ; - check that this is correct and test.
 S REQIEN=ERXIEN
 I $$GET1^DIQ(52.49,ERXIEN,.08,"I")="CN" S REQIEN=$$RESOLV^PSOERXU2(ERXIEN)
 I '$$FINDNRX^PSOERXU6(REQIEN) S DNB=1
 S HUBID=$$GET1^DIQ(52.49,REQIEN,.01,"E")
 S REQBY=$$GET1^DIQ(52.49,REQIEN,2.1,"E")
 S REQDTTM=$$GET1^DIQ(52.49,REQIEN,.03,"E")
 ;S DNB=$$GET1^DIQ(52.49,REQIEN,80.5,"I")
 S COMM=$$GET1^DIQ(52.49,REQIEN,50,"E")
 S RESTYPE=$$GET1^DIQ(52.49,REQIEN,52.1,"E")
 S CANSTAT=$$GET1^DIQ(52.49,REQIEN,1,"I")
 S CANSTAT=$$GET1^DIQ(52.45,CANSTAT,.02,"E")
 I '$G(SDERXFLG) S LINE=LINE+1 D SET^VALM10(LINE,"")
 S LINE=LINE+1 D SET^VALM10(LINE,"************************CANCEL REQUEST INFORMATION**************************")
 I $G(SDERXFLG) D SET^VALM10(LINE,"                              CANCEL REQUEST INFORMATION                          "),CNTRL^VALM10(LINE,1,80,$G(IOUON)_$G(IOINHI),$G(IOUOFF)_$G(IOINORM))
 S LINE=LINE+1 D SET^VALM10(LINE,RESTYPE),CNTRL^VALM10(LINE,1,$L(RESTYPE),$G(IORVON),$G(IORVOFF))
 S LINE=LINE+1 D SET^VALM10(LINE,"Request Status: "_CANSTAT),CNTRL^VALM10(LINE,17,$L(CANSTAT),$G(IOINHI),$G(IOINORM))
 I $L(RESTYPE) S LINE=LINE+1 D SET^VALM10(LINE,"Request/Response Type: "_RESTYPE),CNTRL^VALM10(LINE,23,$L(RESTYPE),$G(IOINHI),$G(IOINORM))
 S LINE=LINE+1 D SET^VALM10(LINE,"Requested By: "_REQBY),CNTRL^VALM10(LINE,15,$L(REQBY),$G(IOINHI),$G(IOINORM))
 S LINE=LINE+1 D SET^VALM10(LINE,"Request Date/Time: "_REQDTTM),CNTRL^VALM10(LINE,20,$L(REQDTTM),$G(IOINHI),$G(IOINORM))
 I $G(DNB) S LINE=LINE+1 D SET^VALM10(LINE,"Original eRx not found in Hub and/or in Vista."),CNTRL^VALM10(LINE,1,80,$G(IOINHI),$G(IOINORM))
 I '$G(SDERXFLG) S LINE=LINE+1 D SET^VALM10(LINE,"")
 S COMM=$$GET1^DIQ(52.49,REQIEN,50,"E")
 S COMM="Request Comments: "_COMM
 D TXT2ARY^PSOERXD1(.COMMARY,COMM," ",80)
 S I=0 F  S I=$O(COMMARY(I)) Q:'I  D
 .S CTXT=$G(COMMARY(I))
 .S LINE=LINE+1 D SET^VALM10(LINE,CTXT)
 .I I=1 D CNTRL^VALM10(LINE,19,$L(CTXT),$G(IOINHI),$G(IOINORM)) Q
 .D CNTRL^VALM10(LINE,1,$L(CTXT),$G(IOINHI),$G(IOINORM))
 S COMMBY=$$GET1^DIQ(52.49,REQIEN,50.1,"E")
 S COMMDTTM=$$GET1^DIQ(52.49,REQIEN,50.2,"E")
 S LINE=LINE+1 D SET^VALM10(LINE,"Comments By: "_COMMBY),CNTRL^VALM10(LINE,14,$L(COMMBY),$G(IOINHI),$G(IOINORM))
 S LINE=LINE+1 D SET^VALM10(LINE,"Comments Date/Time: "_COMMDTTM),CNTRL^VALM10(LINE,21,$L(COMMDTTM),$G(IOINHI),$G(IOINORM))
 I '$G(SDERXFLG) S LINE=LINE+1 D SET^VALM10(LINE,"")
 Q