NHINVSR ;SLC/MKB -- Surgical Procedures
;;1.0;NHIN;**1**;Oct 25, 2010;Build 11
;
; External References DBIA#
; ------------------- -----
; DIQ 2056
; STATUS^GMTSROB 3969
; ICPTCOD 1995
; ICPTMOD 1996
; SROESTV 3533
; TIUSRVR1 2944
;
; ------------ Get surgery(ies) from VistA ------------
;
EN(DFN,BEG,END,MAX,ID) ; -- find patient's surgeries
N NHI,NHICNT,NHITM,NHY
S DFN=+$G(DFN) Q:DFN<1
S BEG=$G(BEG,1410101),END=$G(END,9999998),MAX=$G(MAX,999999)
;
; get one surgery
I $G(ID) D EN1(ID,.NHITM),XML(.NHITM) Q
;
; get all surgeries
Q:'$L($T(LIST^SROESTV))
N SHOWADD S SHOWADD=1 ;to omit leading '+' with note titles
D LIST^SROESTV(.NHY,DFN,BEG,END,MAX,1)
S NHI=0 F S NHI=$O(@NHY@(NHI)) Q:NHI<1 D
. K NHITM D ONE(NHI,.NHITM)
. I $D(NHITM) D XML(.NHITM)
K @NHY
Q
;
ONE(NUM,SURG) ; -- return a surgery in SURG("attribute")=value
; Expects DFN, @NHY@(NUM) from LIST^SROESTV
N IEN,NHX,X,Y,I,NHMOD,NHOTH
S NHX=$G(@NHY@(NUM))
S IEN=+$P(NHX,U) Q:IEN<1 K SURG
S SURG("id")=IEN,SURG("name")=$P(NHX,U,2)
S SURG("dateTime")=$P(NHX,U,3)
S X=$P(NHX,U,4) S:X SURG("provider")=$TR(X,";","^")
S SURG("status")=$$STATUS(IEN,$P(NHX,U,3))
S X=$$GET1^DIQ(130,IEN_",",50,"I"),SURG("facility")=$$FAC^NHINV(X)
S SURG("encounter")=$$GET1^DIQ(130,IEN_",",.015,"I")
S X=$$GET1^DIQ(130,IEN_",",27,"I") I X D
. S SURG("type")=$$CPT(X)
. D GETS^DIQ(130,IEN_",","28*","I","NHMOD") ;CPT modifiers
. S I="" F S I=$O(NHMOD(130.028,I)) Q:I="" D
.. S X=+$G(NHMOD(130.028,I,.01,"I")),Y=$$MOD^ICPTMOD(X,"I")
.. S SURG("modifier",+I)=$P(Y,U,2,3)
D GETS^DIQ(130,IEN_",",".42*","I","NHOTH") ;other procedures
S I="" F S I=$O(NHOTH(130.16,I)) Q:I="" D
. S X=+$G(NHOTH(130.16,I,3,"I")) Q:'X
. S SURG("otherProcedure",+I)=$$CPT(X)
S I=0 F S I=$O(@NHY@(NUM,I)) Q:I<1 S X=$G(@NHY@(NUM,I)) I X D
. N LT,NT S LT=$P(X,U,2) Q:$P(LT," ")="Addendum"
. S NT=$$GET1^DIQ(8925,+X_",",".01:1501")
. S SURG("document",I)=+X_U_LT_U_NT
. I LT["OPERATION REPORT"!(LT["PROCEDURE REPORT") S SURG("opReport")=+X_U_LT_U_NT
S SURG("category")="SR"
Q
;
EN1(IEN,SURG) ; -- return a surgery in SURG("attribute")=value
N NHX,NHY,X,Y,I,NHMOD,NHOTH,SHOWADD
S SHOWADD=1 ;to omit leading '+' with note titles
D ONE^SROESTV("NHY",IEN) S NHX=$G(NHY(IEN)) Q:NHX=""
S SURG("id")=IEN,SURG("name")=$P(NHX,U,2),SURG("dateTime")=$P(NHX,U,3)
S X=$P(NHX,U,4) S:X SURG("provider")=$TR(X,";","^")
S SURG("status")=$$STATUS(IEN,$P(NHX,U,3))
S X=$$GET1^DIQ(130,IEN_",",50,"I"),SURG("facility")=$$FAC^NHINV(X)
S SURG("encounter")=$$GET1^DIQ(130,IEN_",",.015,"I")
S X=$$GET1^DIQ(130,IEN_",",27,"I") I X D
. S SURG("type")=$$CPT(X)
. D GETS^DIQ(130,IEN_",","28*","I","NHMOD") ;CPT modifiers
. S I="" F S I=$O(NHMOD(130.028,I)) Q:I="" D
.. S X=+$G(NHMOD(130.028,I,.01,"I")),Y=$$MOD^ICPTMOD(X,"I")
.. S SURG("modifier",+I)=$P(Y,U,2,3)
D GETS^DIQ(130,"28,",".42*","I","NHOTH") ;other procedures
S I="" F S I=$O(NHOTH(130.16,I)) Q:I="" D
. S X=+$G(NHOTH(130.16,I,3,"I")) Q:'X
. S SURG("otherProcedure",+I)=$$CPT(X)
S I=0 F S I=$O(NHY(IEN,I)) Q:I<1 S X=$G(NHY(IEN,I)) I X D
. N LT,NT S LT=$P(X,U,2) Q:$P(LT," ")="Addendum"
. S NT=$$GET1^DIQ(8925,+X_",",".01:1501")
. S SURG("document",I)=+X_U_LT_U_NT
. I LT["OPERATION REPORT"!(LT["PROCEDURE REPORT") S SURG("opReport")=+X_U_LT_U_NT
S SURG("category")="SR"
Q
;
CPT(IEN) ; -- return code^description for CPT code, or "^" if error
N X0,NHX,N,I,X,Y S IEN=+$G(IEN)
S X0=$$CPT^ICPTCOD(IEN) I X0<0 Q "^"
S Y=$P(X0,U,2,3) ;CPT Code^Short Name
S N=$$CPTD^ICPTCOD($P(Y,U),"NHX") ;CPT Description
I N>0,$L($G(NHX(1))) D
. S X=$G(NHX(1)),I=1
. F S I=$O(NHX(I)) Q:I<1 Q:NHX(I)=" " S X=X_" "_NHX(I)
. S $P(Y,U,2)=X
Q Y
;
STATUS(GMN,GMDT) ; -- get current STATUS of request
N STATUS S STATUS="UNKNOWN"
I $G(GMN),$G(GMDT) D STATUS^GMTSROB
I $E(STATUS)="(" S STATUS=$P($P(STATUS,"(",2),")")
Q STATUS
;
; ------------ Return data to middle tier ------------
;
XML(SURG) ; -- Return surgery as XML
N ATT,X,Y,NAMES
D ADD("<surgery>") S NHINTOTL=$G(NHINTOTL)+1
S ATT="" F S ATT=$O(SURG(ATT)) Q:ATT="" D D:$L(Y) ADD(Y)
. I $O(SURG(ATT,0)) D S Y="" Q ;multiples
.. D ADD("<"_ATT_"s>")
.. S I=0 F S I=$O(SURG(ATT,I)) Q:I<1 D
... S X=$G(SURG(ATT,I)),NAMES=""
... S NAMES=$S(ATT="document":"id^localTitle^nationalTitle^Z",1:"code^name^Z")
... S Y="<"_ATT_" "_$$LOOP_"/>" D ADD(Y)
.. D ADD("</"_ATT_"s>")
. S X=$G(SURG(ATT)),Y="" Q:'$L(X)
. I X'["^" S Y="<"_ATT_" value='"_$$ESC^NHINV(X)_"' />" Q
. S NAMES=$S(ATT="opReport":"id^localTitle^nationalTitle^Z",1:"code^name^Z")
. I $L(X)>1 S Y="<"_ATT_" "_$$LOOP_"/>"
D ADD("</surgery>")
Q
;
LOOP() ; -- build sub-items string from NAMES and X
N STR,P,TAG S STR=""
F P=1:1 S TAG=$P(NAMES,U,P) Q:TAG="Z" I $L($P(X,U,P)) S STR=STR_TAG_"='"_$$ESC^NHINV($P(X,U,P))_"' "
Q STR
;
ADD(X) ; -- Add a line @NHIN@(n)=X
S NHINI=$G(NHINI)+1
S @NHIN@(NHINI)=X
Q
;
RPT(NHY,ID) ; -- Return report in NHY(n)
S ID=+$G(ID) Q:ID<1
D TGET^TIUSRVR1(.NHY,ID)
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HNHINVSR 5272 printed Dec 13, 2024@02:17:27 Page 2
NHINVSR ;SLC/MKB -- Surgical Procedures
+1 ;;1.0;NHIN;**1**;Oct 25, 2010;Build 11
+2 ;
+3 ; External References DBIA#
+4 ; ------------------- -----
+5 ; DIQ 2056
+6 ; STATUS^GMTSROB 3969
+7 ; ICPTCOD 1995
+8 ; ICPTMOD 1996
+9 ; SROESTV 3533
+10 ; TIUSRVR1 2944
+11 ;
+12 ; ------------ Get surgery(ies) from VistA ------------
+13 ;
EN(DFN,BEG,END,MAX,ID) ; -- find patient's surgeries
+1 NEW NHI,NHICNT,NHITM,NHY
+2 SET DFN=+$GET(DFN)
if DFN<1
QUIT
+3 SET BEG=$GET(BEG,1410101)
SET END=$GET(END,9999998)
SET MAX=$GET(MAX,999999)
+4 ;
+5 ; get one surgery
+6 IF $GET(ID)
DO EN1(ID,.NHITM)
DO XML(.NHITM)
QUIT
+7 ;
+8 ; get all surgeries
+9 if '$LENGTH($TEXT(LIST^SROESTV))
QUIT
+10 ;to omit leading '+' with note titles
NEW SHOWADD
SET SHOWADD=1
+11 DO LIST^SROESTV(.NHY,DFN,BEG,END,MAX,1)
+12 SET NHI=0
FOR
SET NHI=$ORDER(@NHY@(NHI))
if NHI<1
QUIT
Begin DoDot:1
+13 KILL NHITM
DO ONE(NHI,.NHITM)
+14 IF $DATA(NHITM)
DO XML(.NHITM)
End DoDot:1
+15 KILL @NHY
+16 QUIT
+17 ;
ONE(NUM,SURG) ; -- return a surgery in SURG("attribute")=value
+1 ; Expects DFN, @NHY@(NUM) from LIST^SROESTV
+2 NEW IEN,NHX,X,Y,I,NHMOD,NHOTH
+3 SET NHX=$GET(@NHY@(NUM))
+4 SET IEN=+$PIECE(NHX,U)
if IEN<1
QUIT
KILL SURG
+5 SET SURG("id")=IEN
SET SURG("name")=$PIECE(NHX,U,2)
+6 SET SURG("dateTime")=$PIECE(NHX,U,3)
+7 SET X=$PIECE(NHX,U,4)
if X
SET SURG("provider")=$TRANSLATE(X,";","^")
+8 SET SURG("status")=$$STATUS(IEN,$PIECE(NHX,U,3))
+9 SET X=$$GET1^DIQ(130,IEN_",",50,"I")
SET SURG("facility")=$$FAC^NHINV(X)
+10 SET SURG("encounter")=$$GET1^DIQ(130,IEN_",",.015,"I")
+11 SET X=$$GET1^DIQ(130,IEN_",",27,"I")
IF X
Begin DoDot:1
+12 SET SURG("type")=$$CPT(X)
+13 ;CPT modifiers
DO GETS^DIQ(130,IEN_",","28*","I","NHMOD")
+14 SET I=""
FOR
SET I=$ORDER(NHMOD(130.028,I))
if I=""
QUIT
Begin DoDot:2
+15 SET X=+$GET(NHMOD(130.028,I,.01,"I"))
SET Y=$$MOD^ICPTMOD(X,"I")
+16 SET SURG("modifier",+I)=$PIECE(Y,U,2,3)
End DoDot:2
End DoDot:1
+17 ;other procedures
DO GETS^DIQ(130,IEN_",",".42*","I","NHOTH")
+18 SET I=""
FOR
SET I=$ORDER(NHOTH(130.16,I))
if I=""
QUIT
Begin DoDot:1
+19 SET X=+$GET(NHOTH(130.16,I,3,"I"))
if 'X
QUIT
+20 SET SURG("otherProcedure",+I)=$$CPT(X)
End DoDot:1
+21 SET I=0
FOR
SET I=$ORDER(@NHY@(NUM,I))
if I<1
QUIT
SET X=$GET(@NHY@(NUM,I))
IF X
Begin DoDot:1
+22 NEW LT,NT
SET LT=$PIECE(X,U,2)
if $PIECE(LT," ")="Addendum"
QUIT
+23 SET NT=$$GET1^DIQ(8925,+X_",",".01:1501")
+24 SET SURG("document",I)=+X_U_LT_U_NT
+25 IF LT["OPERATION REPORT"!(LT["PROCEDURE REPORT")
SET SURG("opReport")=+X_U_LT_U_NT
End DoDot:1
+26 SET SURG("category")="SR"
+27 QUIT
+28 ;
EN1(IEN,SURG) ; -- return a surgery in SURG("attribute")=value
+1 NEW NHX,NHY,X,Y,I,NHMOD,NHOTH,SHOWADD
+2 ;to omit leading '+' with note titles
SET SHOWADD=1
+3 DO ONE^SROESTV("NHY",IEN)
SET NHX=$GET(NHY(IEN))
if NHX=""
QUIT
+4 SET SURG("id")=IEN
SET SURG("name")=$PIECE(NHX,U,2)
SET SURG("dateTime")=$PIECE(NHX,U,3)
+5 SET X=$PIECE(NHX,U,4)
if X
SET SURG("provider")=$TRANSLATE(X,";","^")
+6 SET SURG("status")=$$STATUS(IEN,$PIECE(NHX,U,3))
+7 SET X=$$GET1^DIQ(130,IEN_",",50,"I")
SET SURG("facility")=$$FAC^NHINV(X)
+8 SET SURG("encounter")=$$GET1^DIQ(130,IEN_",",.015,"I")
+9 SET X=$$GET1^DIQ(130,IEN_",",27,"I")
IF X
Begin DoDot:1
+10 SET SURG("type")=$$CPT(X)
+11 ;CPT modifiers
DO GETS^DIQ(130,IEN_",","28*","I","NHMOD")
+12 SET I=""
FOR
SET I=$ORDER(NHMOD(130.028,I))
if I=""
QUIT
Begin DoDot:2
+13 SET X=+$GET(NHMOD(130.028,I,.01,"I"))
SET Y=$$MOD^ICPTMOD(X,"I")
+14 SET SURG("modifier",+I)=$PIECE(Y,U,2,3)
End DoDot:2
End DoDot:1
+15 ;other procedures
DO GETS^DIQ(130,"28,",".42*","I","NHOTH")
+16 SET I=""
FOR
SET I=$ORDER(NHOTH(130.16,I))
if I=""
QUIT
Begin DoDot:1
+17 SET X=+$GET(NHOTH(130.16,I,3,"I"))
if 'X
QUIT
+18 SET SURG("otherProcedure",+I)=$$CPT(X)
End DoDot:1
+19 SET I=0
FOR
SET I=$ORDER(NHY(IEN,I))
if I<1
QUIT
SET X=$GET(NHY(IEN,I))
IF X
Begin DoDot:1
+20 NEW LT,NT
SET LT=$PIECE(X,U,2)
if $PIECE(LT," ")="Addendum"
QUIT
+21 SET NT=$$GET1^DIQ(8925,+X_",",".01:1501")
+22 SET SURG("document",I)=+X_U_LT_U_NT
+23 IF LT["OPERATION REPORT"!(LT["PROCEDURE REPORT")
SET SURG("opReport")=+X_U_LT_U_NT
End DoDot:1
+24 SET SURG("category")="SR"
+25 QUIT
+26 ;
CPT(IEN) ; -- return code^description for CPT code, or "^" if error
+1 NEW X0,NHX,N,I,X,Y
SET IEN=+$GET(IEN)
+2 SET X0=$$CPT^ICPTCOD(IEN)
IF X0<0
QUIT "^"
+3 ;CPT Code^Short Name
SET Y=$PIECE(X0,U,2,3)
+4 ;CPT Description
SET N=$$CPTD^ICPTCOD($PIECE(Y,U),"NHX")
+5 IF N>0
IF $LENGTH($GET(NHX(1)))
Begin DoDot:1
+6 SET X=$GET(NHX(1))
SET I=1
+7 FOR
SET I=$ORDER(NHX(I))
if I<1
QUIT
if NHX(I)=" "
QUIT
SET X=X_" "_NHX(I)
+8 SET $PIECE(Y,U,2)=X
End DoDot:1
+9 QUIT Y
+10 ;
STATUS(GMN,GMDT) ; -- get current STATUS of request
+1 NEW STATUS
SET STATUS="UNKNOWN"
+2 IF $GET(GMN)
IF $GET(GMDT)
DO STATUS^GMTSROB
+3 IF $EXTRACT(STATUS)="("
SET STATUS=$PIECE($PIECE(STATUS,"(",2),")")
+4 QUIT STATUS
+5 ;
+6 ; ------------ Return data to middle tier ------------
+7 ;
XML(SURG) ; -- Return surgery as XML
+1 NEW ATT,X,Y,NAMES
+2 DO ADD("<surgery>")
SET NHINTOTL=$GET(NHINTOTL)+1
+3 SET ATT=""
FOR
SET ATT=$ORDER(SURG(ATT))
if ATT=""
QUIT
Begin DoDot:1
+4 ;multiples
IF $ORDER(SURG(ATT,0))
Begin DoDot:2
+5 DO ADD("<"_ATT_"s>")
+6 SET I=0
FOR
SET I=$ORDER(SURG(ATT,I))
if I<1
QUIT
Begin DoDot:3
+7 SET X=$GET(SURG(ATT,I))
SET NAMES=""
+8 SET NAMES=$SELECT(ATT="document":"id^localTitle^nationalTitle^Z",1:"code^name^Z")
+9 SET Y="<"_ATT_" "_$$LOOP_"/>"
DO ADD(Y)
End DoDot:3
+10 DO ADD("</"_ATT_"s>")
End DoDot:2
SET Y=""
QUIT
+11 SET X=$GET(SURG(ATT))
SET Y=""
if '$LENGTH(X)
QUIT
+12 IF X'["^"
SET Y="<"_ATT_" value='"_$$ESC^NHINV(X)_"' />"
QUIT
+13 SET NAMES=$SELECT(ATT="opReport":"id^localTitle^nationalTitle^Z",1:"code^name^Z")
+14 IF $LENGTH(X)>1
SET Y="<"_ATT_" "_$$LOOP_"/>"
End DoDot:1
if $LENGTH(Y)
DO ADD(Y)
+15 DO ADD("</surgery>")
+16 QUIT
+17 ;
LOOP() ; -- build sub-items string from NAMES and X
+1 NEW STR,P,TAG
SET STR=""
+2 FOR P=1:1
SET TAG=$PIECE(NAMES,U,P)
if TAG="Z"
QUIT
IF $LENGTH($PIECE(X,U,P))
SET STR=STR_TAG_"='"_$$ESC^NHINV($PIECE(X,U,P))_"' "
+3 QUIT STR
+4 ;
ADD(X) ; -- Add a line @NHIN@(n)=X
+1 SET NHINI=$GET(NHINI)+1
+2 SET @NHIN@(NHINI)=X
+3 QUIT
+4 ;
RPT(NHY,ID) ; -- Return report in NHY(n)
+1 SET ID=+$GET(ID)
if ID<1
QUIT
+2 DO TGET^TIUSRVR1(.NHY,ID)
+3 QUIT