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

BQIDCAH7.m

Go to the documentation of this file.
BQIDCAH7 ;GDHD/HCD/ALA-Ad Hoc Logic ; 17 Jan 2017  3:44 PM
 ;;2.6;ICARE MANAGEMENT SYSTEM;;Jul 07, 2017;Build 72
 ;
MEAS(FGLOB,TGLOB,MEAS,FDT,TDT,MSNOT,MPARMS) ;EP - Measurement search
 NEW NGLOB,LCT,CT,IEN,LOK,MSRES,MSRSN,MSURNP,MURES,RES,ROK,RVAL,LB,LIEN
 NEW CMEAS,BBOTH,ABOTH,BMEAS,BPARMS,CPAR,BQMEAS,CPARMS,PPARMS,BNUMMEAS,FLG
 NEW BPRES,COD,NUMMEAS,SETMEAS,SRES,TCT
 S NGLOB=$NA(^TMP("BQIDCMEAS",$J)) K @NGLOB
 S MSGLOB=$NA(^TMP("BQIMSOP",$J)) K @MSGLOB
 I $G(TGLOB)="" Q
 ;
 S BBOTH=0,ABOTH=0,TCT=0
 ;
 I $G(MEAS)'="" D
 . NEW BMEAS
 . S COD=$P(^BQI(90507.2,MEAS,0),"^",2),CMEAS=$P(^(0),"^",3),BMEAS=MEAS
 . I $D(APARMS) D
 .. I COD="SYS" S BBOTH=BBOTH+1 D VL Q
 .. I COD="DIA" S BBOTH=BBOTH+1 D VL Q
 .. I COD="ASYS" S ABOTH=ABOTH+1 D VL Q
 .. I COD="ADIA" S ABOTH=ABOTH+1 D VL Q
 .. S RVAL=$O(APARMS("MEAS",MEAS,""))
 .. I RVAL="NUMMEAS" S NUMMEAS=APARMS("MEAS",MEAS,"NUMMEAS"),CPARMS("MEAS",CMEAS,"NUMMEAS")=NUMMEAS
 .. I RVAL="SETMEAS" S SETMEAS=APARMS("MEAS",MEAS,"SETMEAS"),CPARMS("MEAS",CMEAS,"SETMEAS")=SETMEAS
 . I $D(MAPARMS) D
 .. S RVAL=$O(MAPARMS("MEAS",MEAS,""))
 .. I RVAL="SETMEAS" S PPARMS("MEAS",CMEAS)=RVAL D
 ... S RV="" F  S RV=$O(MAPARMS("MEAS",MEAS,RVAL,RV)) Q:RV=""  S CPARMS("MEAS",CMEAS,"SETMEAS",RV)=""
 ... K MAPARMS
 ... M MAPARMS=CPARMS
 ... K CPARMS
 . I '$D(APARMS),'$D(MAPARMS) S PPARMS("MEAS",CMEAS)=""
 ;
 D
 . S BMEAS="" F  S BMEAS=$O(MPARMS("MEAS",BMEAS)) Q:BMEAS=""  D
 .. S COD=$P(^BQI(90507.2,BMEAS,0),"^",2),CMEAS=$P(^(0),"^",3)
 .. I $D(APARMS("MEAS",BMEAS)) D  Q
 ... I COD="SYS" S BBOTH=BBOTH+1 D VL Q
 ... I COD="DIA" S BBOTH=BBOTH+1 D VL Q
 ... I COD="ASYS" S ABOTH=ABOTH+1 D VL Q
 ... I COD="ADIA" S ABOTH=ABOTH+1 D VL Q
 ... S RVAL=$O(APARMS("MEAS",BMEAS,""))
 ... I RVAL="NUMMEAS" S NUMMEAS=APARMS("MEAS",BMEAS,"NUMMEAS"),CPARMS("MEAS",CMEAS,"NUMMEAS")=NUMMEAS
 ... I RVAL="SETMEAS" S SETMEAS=APARMS("MEAS",BMEAS,"SETMEAS"),CPARMS("MEAS",CMEAS,"SETMEAS")=SETMEAS
 .. S PPARMS("MEAS",CMEAS)=""
 ;
 S BMEAS="" F  S BMEAS=$O(CPARMS("MEAS",BMEAS)) Q:BMEAS=""  D
 . K RVAL,NUMMEAS,SETMEAS
 . S RVAL=$O(CPARMS("MEAS",BMEAS,"")),TCT=TCT+1
 . I RVAL="NUMMEAS" S NUMMEAS=CPARMS("MEAS",BMEAS,"NUMMEAS")
 . I RVAL="SETMEAS" S SETMEAS=CPARMS("MEAS",BMEAS,"SETMEAS")
 . D MS(BMEAS,1)
 . K RVAL,NUMMEAS,SETMEAS
 ;
 S BMEAS="" F  S BMEAS=$O(PPARMS("MEAS",BMEAS)) Q:BMEAS=""  D
 . S RVAL=PPARMS("MEAS",BMEAS),TCT=TCT+1
 . I RVAL="NUMMEAS" S NUMMEAS=1
 . I RVAL="SETMEAS" S SETMEAS=1
 . D MS(BMEAS,0)
 ;
 I MSOP="!" D
 . S IEN=""
 . F  S IEN=$O(@MSGLOB@(IEN)) Q:IEN=""  S @TGLOB@(IEN)=""
 I MSOP="&" D
 . S IEN=""
 . F  S IEN=$O(@MSGLOB@(IEN)) Q:IEN=""  D
 .. S LCT=0,LB=""
 .. F  S LB=$O(@MSGLOB@(IEN,LB)) Q:LB=""  S LCT=LCT+1
 .. I LCT'=TCT K @CRIT@("MEAS",IEN) Q
 .. I LCT=TCT,'MSNOT D
 ... S @TGLOB@(IEN)="",LB=""
 ... F  S LB=$O(@MSGLOB@(IEN,LB)) Q:LB=""  D
 .... S LIEN=""
 .... F  S LIEN=$O(@MSGLOB@(IEN,LB,LIEN)) Q:LIEN=""  S @CRIT@("MEAS",IEN,LIEN)=""
 .. I LCT=TCT,MSNOT S @NGLOB@(IEN)="" K @CRIT@("MEAS",IEN)
 ;
 I MSNOT,$G(FGLOB)'="" D
 . S IEN="" F  S IEN=$O(@FGLOB@(IEN)) Q:IEN=""  D
 .. I '$D(@NGLOB@(IEN)) S @TGLOB@(IEN)=""
 I MSNOT,$G(FGLOB)="" D
 . S IEN=0 F  S IEN=$O(^AUPNPAT(IEN)) Q:'IEN  I '$D(@NGLOB@(IEN)) S @TGLOB@(IEN)=""
 K @NGLOB,@MSGLOB
 Q
 ;
VL ;EP
 S RVAL=$O(APARMS("MEAS",BMEAS,"")),BPARMS("MEAS",COD,RVAL)=APARMS("MEAS",BMEAS,RVAL),CPAR(COD)=CMEAS
 S PPARMS("MEAS",CMEAS)=RVAL
 Q
 ;
MS(MEAS,FLG) ;EP
 NEW DFN,IEN,BGT,BDT,ENT,VIS,VSDTM
 S TDT=$S(TDT'="":TDT,1:DT)
 I $G(FGLOB)'="" D  Q
 . NEW IEN
 . S IEN=""
 . F  S IEN=$O(@FGLOB@(IEN)) Q:'IEN  D
 .. I FDT="" D
 ... S BDT=""
 ... F  S BDT=$O(^AUPNVMSR("AA",IEN,MEAS,BDT)) Q:BDT=""  D MSDT
 .. I FDT'="" D
 ... S BGT=9999999-FDT,ENT=9999999-TDT,BDT=ENT-1
 ... F  S BDT=$O(^AUPNVMSR("AA",IEN,MEAS,BDT)) Q:BDT=""!(BDT>BGT)  D MSDT
 ;
 S IEN=""
 F  S IEN=$O(^AUPNVMSR("B",MEAS,IEN),-1) Q:IEN=""  D
 . I $G(^AUPNVMSR(IEN,0))="" Q
 . ; if the new ENTERED IN ERROR field exists, exclude the record if it is marked as an error
 . I $$VFIELD^DILFD(9000010.01,2) Q:$$GET1^DIQ(9000010.01,IEN_",",2,"I")=1
 . S DFN=$P($G(^AUPNVMSR(IEN,0)),U,2),VIS=$P(^AUPNVMSR(IEN,0),U,3) I VIS="" Q
 . I $G(^AUPNVSIT(VIS,0))="" Q
 . Q:"DXCT"[$P(^AUPNVSIT(VIS,0),U,7)
 . S VSDTM=$P(^AUPNVSIT(VIS,0),U,1)\1
 . I FDT'="",VSDTM<FDT!(VSDTM>TDT) Q
 . ;B:MEAS=2
 . S MSRES=$P($G(^AUPNVMSR(IEN,0)),U,4),MURES=$$UP^XLFSTR(MSRES)
 . S MSRSN=$$PUNC^BQIUL3(MSRES),MSURNP=$$PUNC^BQIUL3(MURES)
 . ;
 . ; If looking for a MEAS result
 . S RES=0
 . I $G(SETMEAS)="",$G(NUMMEAS)="" S ROK=1,RES=1,LOK=1
 . I $G(SETMEAS)'=""!($G(NUMMEAS)'="") S ROK=1,LOK=0 D MSR
 . ;I $G(SETMEAS)'=""!($G(NUMMEAS)'="")!($D(BPARMS("MEAS"))) S ROK=1,LOK=0 D MSR
 . I 'MSNOT D  Q
 .. I ROK,'RES Q
 .. S @MSGLOB@(DFN,MEAS,IEN)=MSRES
 .. I LOK S @CRIT@("MEAS",DFN,IEN)=""
 . I MSNOT D  Q
 .. I ROK,'RES Q
 .. S @NGLOB@(DFN)=""
 .. I LOK S @CRIT@("MEAS",DFN,IEN)=""
 Q
 ;
MSDT ;EP
 S LIEN=""
 F  S LIEN=$O(^AUPNVMSR("AA",IEN,MEAS,BDT,LIEN)) Q:LIEN=""  D
 . S VIS=$P($G(^AUPNVMSR(LIEN,0)),U,3) I VIS="" Q
 . I $G(^AUPNVSIT(VIS,0))="" Q
 . ; if the new ENTERED IN ERROR field exists, exclude the record if it is marked as an error
 . I $$VFIELD^DILFD(9000010.01,2) Q:$$GET1^DIQ(9000010.01,LIEN_",",2,"I")=1
 . Q:"DXCT"[$P(^AUPNVSIT(VIS,0),U,7)
 . S MSRES=$P($G(^AUPNVMSR(LIEN,0)),U,4),MURES=$$UP^XLFSTR(MSRES)
 . S MSRSN=$$PUNC^BQIUL3(MSRES),MSURNP=$$PUNC^BQIUL3(MURES)
 . ; If looking for a MEAS result
 . S RES=0
 . I $G(SETMEAS)="",$G(NUMMEAS)="" S ROK=1,RES=1,LOK=1
 . I $G(SETMEAS)'=""!($G(NUMMEAS)'="") S ROK=1,LOK=0 D MSR
 . ;I $G(SETMEAS)'=""!($G(NUMMEAS)'="")!($D(BPARMS("MEAS"))) S ROK=1,LOK=0 D MSR
 . I 'MSNOT D  Q
 .. I ROK,'RES Q
 .. S @MSGLOB@(IEN,MEAS,LIEN)=MSRES
 .. I LOK S @CRIT@("MEAS",IEN,LIEN)=""
 . I MSNOT D  Q
 .. I ROK,'RES Q
 .. S @NGLOB@(IEN)=""
 .. I LOK S @CRIT@("MEAS",IEN,LIEN)=""
 Q
 ;
MSR ;EP - Measurement results
 I MSRES="" Q
 NEW MSR,VCRIT1,VCRIT2,ROPER,OPER,OPER2,RES1,RES2,SCODE,LI,MSRS,FQL,I
 I $D(MAPARMS("MEAS",MEAS,"SETMEAS")) D  Q
 . S MSR="" F  S MSR=$O(MAPARMS("MEAS",MEAS,"SETMEAS",MSR)) Q:MSR=""  D  Q:LOK
 .. I MSRES=MSR S LOK=1,RES=1 Q
 .. S SCODE=$$MSET(MEAS)
 .. NEW SETMEAS
 .. S SETMEAS=MSR D SCD
 . ;
 I $G(SETMEAS)'="",MSRES=SETMEAS S LOK=1,RES=1 Q
 I $G(SETMEAS)'="",MSRES'=SETMEAS D  Q
 . I SETMEAS=MURES S LOK=1,RES=1 Q
 . S SCODE=$$MSET(MEAS)
 . D SCD
 ;
 ;I $G(SETMEAS)'="",'$D(MAPARMS("MEAS",MEAS,"SETMEAS")),MSRES=$P(SCODE,":",1)!(MSRES=$P(SCODE,":",2)) S LOK=1,RES=1 Q
 ;
 I $G(NUMMEAS)'="",$G(FLG)=1 D  Q
 . NEW REX,SRES,DRES,BPRES,BQMEAS,BNUMMEAS
 . I $G(NUMMEAS)["~" S REX=1
 . I $G(NUMMEAS)["~",$G(NUMMEAS)["'" S REX=0
 . I MSRES?.ULP Q
 . I MSRES'?.PN,MSRES'?.N Q
 . I $E(MSRES,$L(MSRES),$L(MSRES))?.P S MSRES=$E(MSRES,1,$L(MSRES)-1)
 . ; if value starts with a punctuation e.g. < or >
 . I $E(MSRES,1,1)?.P S ROPER=$E(MSRES,1,1),MSRES=$E(MSRES,2,$L(MSRES))
 . I $P(^AUTTMSR(MEAS,0),"^",1)="EGA" D
 .. I MSRES["/" S MSRES=$P(MSRES," ",1)
 . D NCHK(NUMMEAS)
 ;
 I $G(NUMMEAS)'="",$G(FLG)=0 D  Q
 . I $G(BBOTH)!($G(ABOTH)) D  Q
 .. S BPRES=MSRES,SRES=0,DRES=0
 .. I $G(BBOTH)'=0 F BQMEAS="DIA","SYS" S LOK=0,RES=0 D
 ... I $G(CPAR(BQMEAS))'=MEAS Q
 ... S BNUMMEAS=$G(BPARMS("MEAS",BQMEAS,"NUMMEAS"))
 ... I BNUMMEAS="" Q
 ... I BNUMMEAS["~" S REX=1
 ... I BNUMMEAS["~",BNUMMEAS["'" S REX=0
 ... I $G(BQMEAS)["SYS" S MSRES=$P(MSRES,"/",1) D NCHK(BNUMMEAS) S SRES=RES,MSRES=BPRES
 ... I $G(BQMEAS)["DIA" S MSRES=$P(MSRES,"/",2) D NCHK(BNUMMEAS) S DRES=RES,MSRES=BPRES
 .. I $G(ABOTH)'=0 F BQMEAS="ADIA","ASYS" S LOK=0,RES=0 D
 ... I $G(CPAR(BQMEAS))'=MEAS Q
 ... S BNUMMEAS=$G(BPARMS("MEAS",BQMEAS,"NUMMEAS"))
 ... I BNUMMEAS="" Q
 ... I BNUMMEAS["~" S REX=1
 ... I BNUMMEAS["~",BNUMMEAS["'" S REX=0
 ... I $G(BQMEAS)["SYS" S MSRES=$P(MSRES,"/",1) D NCHK(BNUMMEAS) S SRES=RES,MSRES=BPRES
 ... I $G(BQMEAS)["DIA" S MSRES=$P(MSRES,"/",2) D NCHK(BNUMMEAS) S DRES=RES,MSRES=BPRES
 .. S LOK=0,RES=0
 .. I $G(BBOTH)'=0,BPOP="&" D  Q
 ... I SRES=1,DRES=1 S LOK=1,RES=1
 .. I $G(ABOTH)'=0,ABPOP="&" D  Q
 ... I SRES=1,DRES=1 S LOK=1,RES=1
 .. I BPOP="!"!(ABPOP="!") D
 ... I SRES=1!(DRES=1) S LOK=1,RES=1
 Q
 ;
NCHK(NUMMEAS) ;
 I NUMMEAS["~" S VCRIT1=$P(NUMMEAS,"~",1),VCRIT2=$P(NUMMEAS,"~",2)
 E  S VCRIT1=NUMMEAS,VCRIT2=""
 F I=1:1:$L(VCRIT1) Q:$E(VCRIT1,I,I)'?.P
 S OPER=$E(VCRIT1,1,I-1),RES1=$E(VCRIT1,I,$L(VCRIT1))
 I $E(OPER,$L(OPER),$L(OPER))="." D
 . S OPER=$E(OPER,1,$L(OPER)-1),RES1="."_RES1
 I $G(VCRIT2)'="" D
 . F I=1:1:$L(VCRIT2) Q:$E(VCRIT2,I,I)'?.P
 . S OPER2=$E(VCRIT2,1,I-1),RES2=$E(VCRIT2,I,$L(VCRIT2))
 . I $E(OPER2,$L(OPER2),$L(OPER2))="." D
 .. S OPER2=$E(OPER2,1,$L(OPER2)-1),RES2="."_RES2
 I VCRIT2="" D
 . I $G(ROPER)="",@("MSRES"_OPER_"RES1") S LOK=1,RES=1 Q
 . I $G(ROPER)'="",OPER=ROPER,@("MSRES"_OPER_"RES1") S LOK=1,RES=1 Q
 . I $G(ROPER)'="",OPER'=ROPER Q
 I VCRIT2'="" D
 . I @("MSRES"_OPER_"RES1"),@("MSRES"_OPER2_"RES2") S LOK=1,RES=1
 . I REX D
 .. I @("MSRES"_OPER_"RES1") S LOK=1,RES=1
 .. I @("MSRES"_OPER2_"RES2") S LOK=1,RES=1
 Q
 ;
SCD ;EP
 NEW LCOD,LCODU,LCODP,LVAL,LVALU,LVALP
 F LI=1:1:$L(SCODE,";") S FQL=0 D  Q:FQL
 . S MSRS=$P(SCODE,";",LI),ROK=1,RES=0
 . NEW LCOD,LCODU,LCODP
 . ; Set code exactly, set code uppercase, set code no punctuation
 . S LCOD=$P(MSRS,":",1),LCODU=$$UP^XLFSTR(LCOD),LCODP=$$PUNC^BQIUL3(LCOD)
 . ; Set value exactly, set value uppercase, set value no punctuation
 . S LVAL=$P(MSRS,":",2),LVALU=$$UP^XLFSTR(LVAL),LVALP=$$PUNC^BQIUL3(LVAL)
 . ;
 . ; If the set code matches the actual MEAS result
 . I SETMEAS=LCOD D  Q
 .. I MSRES=LCOD S LOK=1,RES=1,FQL=1 Q
 .. I MURES=LCODU S LOK=1,RES=1,FQL=1 Q
 .. I MSURNP=LCODP S LOK=1,RES=1,FQL=1 Q
 .. I MSRES=LVAL S LOK=1,RES=1,FQL=1 Q
 .. I MURES=LVALU S LOK=1,RES=1,FQL=1 Q
 .. I MSURNP=LVALP S LOK=1,RES=1,FQL=1 Q
 Q
 ;
MSET(LN) ;EP - Set of codes
 NEW COD,IEN,VALUE,TYPE
 S VALUE=""
 S COD=$P(^AUTTMSR(LN,0),U,1),IEN=$O(^BQI(90507.2,"C",COD,"")) I IEN="" Q VALUE
 S TYPE=$$GET1^DIQ(90507.2,IEN_",",.04,"E")
 I TYPE["SET" S VALUE=$G(^BQI(90507.2,IEN,2))
 Q VALUE