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

TIUPXAP3.m

Go to the documentation of this file.
  1. TIUPXAP3 ;SLC/RMO - Link Document to Visit API ;Apr 11, 2018@12:07
  1. ;;1.0;TEXT INTEGRATION UTILITIES;**179,290**;Jun 20, 1997;Build 548
  1. ;
  1. LNKVST(TIUDA,TIUVSIT) ;Entry point to link a document to an existing visit
  1. ; Input -- TIUDA TIU Document file (#8925) IEN
  1. ; Output -- 1=Successful and 0=Failure
  1. ; TIUVSIT Visit file (#9000010) IEN
  1. N OKF,TIUMVSTF
  1. ;
  1. ;Check if document needs to be linked to a visit
  1. I $D(^TIU(8925,TIUDA,0)),$P(^(0),U,3)'>0 D
  1. . ;Get existing visit to associate with document
  1. . D GETVST(TIUDA,.TIUVSIT,.TIUMVSTF)
  1. . ;If only one visit update the document with the visit
  1. . I $G(TIUVSIT)>0,'$G(TIUMVSTF) D
  1. . . I $$UPDVST^TIUPXAP2(TIUDA,TIUVSIT) S OKF=1
  1. Q +$G(OKF)
  1. ;
  1. GETVST(TIUDA,TIUVSIT,TIUMVSTF) ;Get visit to associate with document
  1. ; Input -- TIUDA TIU Document file (#8925) IEN
  1. ; Output -- TIUVSIT Visit file (#9000010) IEN
  1. ; TIUMVSTF Multiple Visit Flag
  1. ; 1=Multiple Visits
  1. ;
  1. N TIUD0,TIUDFN,TIUEDT,TIUHL,TIUVSITS,TIUVSTR
  1. ;
  1. ;Set variables
  1. S TIUD0=$G(^TIU(8925,TIUDA,0))
  1. S TIUDFN=$P(TIUD0,U,2),TIUEDT=$P(TIUD0,U,7)
  1. S TIUHL=$P($G(^TIU(8925,TIUDA,12)),U,11)
  1. S TIUVSTR=TIUHL_";"_TIUEDT_";"_$P(TIUD0,U,13)
  1. ;
  1. ;Check if document is an addendum, if it is use visit of parent
  1. I +$$ISADDNDM^TIULC1(TIUDA) D G GETVSTQ
  1. . I $D(^TIU(8925,+$P(TIUD0,U,6),0)),$P(^(0),U,3)>0 S TIUVSIT=$P(^(0),U,3)
  1. ;
  1. ;Check if a document has already been entered for the Vstring,
  1. ;if it has use the visit in the AVSTRV cross-reference
  1. I +$G(TIUVSTR),+$O(^TIU(8925,"AVSTRV",+TIUDFN,TIUVSTR,0))>0 D G GETVSTQ:$G(TIUVSIT)>0
  1. . S TIUVSIT=+$O(^TIU(8925,"AVSTRV",+TIUDFN,TIUVSTR,0))
  1. . I $P($G(^AUPNVSIT(+TIUVSIT,0)),U,5)'=TIUDFN S TIUVSIT=""
  1. ;
  1. ;Check PCE for a visit
  1. S TIUVSITS=$$GETENC^PXAPI(TIUDFN,TIUEDT,TIUHL)
  1. I TIUVSITS>0 S TIUVSIT=+TIUVSITS
  1. ;
  1. ;Set a flag if multiple visits
  1. I $P(TIUVSITS,U,2)'="" S TIUMVSTF=1
  1. GETVSTQ K ^TMP("PXKENC",$J)
  1. Q
  1. LNKSVST(TIUY,TIUDFN,TIUDA,TIUVSTR) ;Entry point to link a document via its
  1. ; SECONDARY VISIT field to a daily
  1. ; hospitalization visit
  1. ; Input -- TIUDFN Patient file (#2) IEN
  1. ; TIUDA TIU Document file (#8925) IEN
  1. ; TIUVSTR IEN of visit or visit string
  1. ; Output -- TIUY=1 for Successful or
  1. ; 0^Message for Failure
  1. K TIUY
  1. S TIUY=0
  1. S TIUDFN=+$G(TIUDFN) I ('TIUDFN)!('$D(^DPT(TIUDFN))) D Q
  1. .S $P(TIUY,U,2)="Invalid patient specified."
  1. S TIUDA=+$G(TIUDA) I ('TIUDA)!('$D(^TIU(8925,TIUDA))) D Q
  1. .S $P(TIUY,U,2)="Invalid document number specified."
  1. N TIUVSIT,TIUVDT
  1. S TIUVSTR=$G(TIUVSTR),TIUVSIT=0
  1. I TIUVSTR?1.N D Q:$P(TIUY,U,2)'=""
  1. .S TIUVSIT=TIUVSTR,TIUVSTR=""
  1. .I ('TIUVSIT)!('$D(^AUPNVSIT(TIUVSIT))) S $P(TIUY,U,2)="Invalid visit specified." Q
  1. .I $P($G(^AUPNVSIT(TIUVSIT,0)),U,7)'="D" D
  1. ..S $P(TIUY,U,2)="The specified visit does not have a service category of daily hospitalization."
  1. I TIUVSTR'="" D Q:$P(TIUY,U,2)'=""
  1. .I TIUVSTR'?1.N1";"7N.1".".N1";"1U D Q
  1. ..S $P(TIUY,U,2)="Invalid visit string format."
  1. .I $P(TIUVSTR,";",3)'="D" D Q
  1. ..S $P(TIUY,U,2)="The specified visit does not have a service category of daily hospitalization." Q
  1. .;Check PCE for a visit
  1. .N TIUVSITS,TIUPXAPI,SUCCESS,PIECE,EXIT
  1. .S TIUVDT=$P(TIUVSTR,";",2)
  1. .S TIUVSITS=$$GETENC^PXAPI(TIUDFN,TIUVDT,+TIUVSTR)
  1. .F PIECE=1:1:$L(TIUVSITS,U) D Q:TIUVSIT>0
  1. ..S TIUVSIT=$P(TIUVSITS,U,PIECE)
  1. ..I $P($G(^TMP("PXKENC",$J,TIUVSIT,0)),U,7)'="D" S TIUVSIT=0
  1. .K ^TMP("PXKENC",$J)
  1. I TIUVSTR="",'TIUVSIT S $P(TIUY,U,2)="No visit specified." Q
  1. ;No visit found, create one
  1. I 'TIUVSIT D
  1. .K ^TMP("TIUPXAPI",$J),TIUVSIT S TIUPXAPI=$NA(^TMP("TIUPXAPI",$J))
  1. .S @TIUPXAPI@("ENCOUNTER",1,"ENC D/T")=TIUVDT
  1. .S @TIUPXAPI@("ENCOUNTER",1,"PATIENT")=TIUDFN
  1. .S @TIUPXAPI@("ENCOUNTER",1,"HOS LOC")=+TIUVSTR
  1. .S @TIUPXAPI@("ENCOUNTER",1,"SERVICE CATEGORY")=$P(TIUVSTR,";",3)
  1. .S @TIUPXAPI@("ENCOUNTER",1,"ENCOUNTER TYPE")="P"
  1. .I $$PROVIDER^TIUPXAP1(DUZ,TIUVDT) S @TIUPXAPI@("PROVIDER",1,"NAME")=DUZ
  1. .S SUCCESS=$$DATA2PCE^PXAPI(TIUPXAPI,"TIU","TEXT INTEGRATION UTILITIES",.TIUVSIT,DUZ,0)
  1. .K @TIUPXAPI
  1. I '+$G(TIUVSIT) D Q
  1. .S $P(TIUY,U,2)="Couldn't find nor create a visit for the given visit string."
  1. ;Set the document's SECONDARY VISIT field
  1. N TIUDATA
  1. K SUCCESS
  1. S TIUDATA(1207)=TIUVSIT
  1. D FILE^TIUSRVP(.SUCCESS,TIUDA,.TIUDATA,1)
  1. I '+SUCCESS S $P(TIUY,U,2)=$P(SUCCESS,U,2) Q
  1. ;Set the parent document's SECONDARY VISIT field
  1. N TIUDAD
  1. S TIUDAD=+$P($G(^TIU(8925,TIUDA,0)),U,6)
  1. I TIUDAD>0 D Q:$P(TIUY,U,2)'=""
  1. .I '$D(^TIU(8925,TIUDAD)) S $P(TIUY,U,2)="Parent document not found." Q
  1. .K SUCCESS,TIUDATA
  1. .S TIUDATA(1207)=TIUVSIT
  1. .D FILE^TIUSRVP(.SUCCESS,TIUDAD,.TIUDATA,1)
  1. .I '+SUCCESS S $P(TIUY,U,2)=$P(SUCCESS,U,2) Q
  1. S TIUY=1
  1. Q