BGP7D3C ; IHS/CMI/LAB - VARIOUS UTILS
;;17.1;IHS CLINICAL REPORTING;;MAY 10, 2017;Build 29
;
FIRSTPDX(P,BDATE,EDATE) ;EP
NEW BGPG,G,Y,X,T,E,BGPR
K BGPG
S Y="BGPG("
S BDATE=$G(BDATE)
I BDATE="" S BDATE=$P(^DPT(P,0),U,3)
S BGPR=""
S X=P_"^FIRST DX [BGP PREGNANCY DIAGNOSES 2;DURING "_BDATE_"-"_EDATE S E=$$START1^APCLDF(X,Y)
I $D(BGPG(1)) S BGPR=$P(BGPG(1),U)
K BGPG
S BGPG=$$FIRSTPRC^BGP7UTL1(P,"BGP PREGNANCY ICD PROCEDURES",BDATE,EDATE)
I BGPG]"",$P(BGPG,U,3)<BGPR S BGPR=$P(BGPG,U,3)
S X=$$FIRSTCPT^BGP7UTL1(P,"BGP PREGNANCY CPT CODES",BDATE,EDATE)
I X,$P(X,U,1)<BGPR S BGPR=$P(X,U,1)
Q BGPR
LASTVD(P,BDATE,EDATE) ;EP
I '$D(^AUPNVSIT("AC",P)) Q ""
NEW VISIT
S A="VISIT(",B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(B,A)
I '$D(VISIT(1)) Q ""
S (X,G)=0 F S X=$O(VISIT(X)) Q:X'=+X!(G) S V=$P(VISIT(X),U,5) D
.Q:'$D(^AUPNVSIT(V,0))
.Q:'$P(^AUPNVSIT(V,0),U,9)
.Q:$P(^AUPNVSIT(V,0),U,11)
.Q:'$D(^AUPNVPRV("AD",V))
.Q:"SAHO"'[$P(^AUPNVSIT(V,0),U,7)
.Q:"V"[$P(^AUPNVSIT(V,0),U,3)
.Q:$P(^AUPNVSIT(V,0),U,6)=""
.S G=1
.Q
Q G
BGP7D3C ; IHS/CMI/LAB - VARIOUS UTILS
+1 ;;17.1;IHS CLINICAL REPORTING;;MAY 10, 2017;Build 29
+2 ;
FIRSTPDX(P,BDATE,EDATE) ;EP
+1 NEW BGPG,G,Y,X,T,E,BGPR
+2 KILL BGPG
+3 SET Y="BGPG("
+4 SET BDATE=$GET(BDATE)
+5 IF BDATE=""
SET BDATE=$PIECE(^DPT(P,0),U,3)
+6 SET BGPR=""
+7 SET X=P_"^FIRST DX [BGP PREGNANCY DIAGNOSES 2;DURING "_BDATE_"-"_EDATE
SET E=$$START1^APCLDF(X,Y)
+8 IF $DATA(BGPG(1))
SET BGPR=$PIECE(BGPG(1),U)
+9 KILL BGPG
+10 SET BGPG=$$FIRSTPRC^BGP7UTL1(P,"BGP PREGNANCY ICD PROCEDURES",BDATE,EDATE)
+11 IF BGPG]""
IF $PIECE(BGPG,U,3)<BGPR
SET BGPR=$PIECE(BGPG,U,3)
+12 SET X=$$FIRSTCPT^BGP7UTL1(P,"BGP PREGNANCY CPT CODES",BDATE,EDATE)
+13 IF X
IF $PIECE(X,U,1)<BGPR
SET BGPR=$PIECE(X,U,1)
+14 QUIT BGPR
LASTVD(P,BDATE,EDATE) ;EP
+1 IF '$DATA(^AUPNVSIT("AC",P))
QUIT ""
+2 NEW VISIT
+3 SET A="VISIT("
SET B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(B,A)
+4 IF '$DATA(VISIT(1))
QUIT ""
+5 SET (X,G)=0
FOR
SET X=$ORDER(VISIT(X))
IF X'=+X!(G)
QUIT
SET V=$PIECE(VISIT(X),U,5)
Begin DoDot:1
+6 IF '$DATA(^AUPNVSIT(V,0))
QUIT
+7 IF '$PIECE(^AUPNVSIT(V,0),U,9)
QUIT
+8 IF $PIECE(^AUPNVSIT(V,0),U,11)
QUIT
+9 IF '$DATA(^AUPNVPRV("AD",V))
QUIT
+10 IF "SAHO"'[$PIECE(^AUPNVSIT(V,0),U,7)
QUIT
+11 IF "V"[$PIECE(^AUPNVSIT(V,0),U,3)
QUIT
+12 IF $PIECE(^AUPNVSIT(V,0),U,6)=""
QUIT
+13 SET G=1
+14 QUIT
End DoDot:1
+15 QUIT G