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

SDECAPI4.m

Go to the documentation of this file.
  1. SDECAPI4 ;ALB/SAT - VISTA SCHEDULING RPCS ;JAN 15, 2016
  1. ;;5.3;Scheduling;**627**;Aug 13, 1993;Build 249
  1. ;
  1. Q
  1. ;
  1. GETVISIT(BSDIN,BSDOUT) ;Private Entry Point
  1. ; >> All date/time variables must be in FileMan internal format
  1. ; Special Incoming Variables:
  1. ; BSDIN("FORCE ADD") = 1 ; no matter what, create new visit (Optional)
  1. ; BSDIN ("NEVER ADD") = 1 ; never add visit, just try to find one or more (Optional)
  1. ; BSDIN("ANCILLARY") = 1 ; for ancillary packages to create noon visit if no match found (Optional)
  1. ; BSDIN("SHOW VISITS") = 1 ; this will display visits if more than one match
  1. ; Incoming Variables used in Matching: REQUIRED
  1. ; BSDIN("PAT") = patient IEN (file 2 or 9000001)
  1. ; BSDIN("VISIT DATE") = visit date & time (same as check-in date & time)
  1. ; BSDIN ("SITE") = location of encounter IEN (file 4 or 9999999.06)
  1. ; BSDIN("VISIT TYPE") = internal value for field .03 in Visit file
  1. ; BSDIN("SRV CAT") = internal value for service category
  1. ; BSDIN("TIME RANGE") = # ; range in minutes for matching on visit time; REQUIRED unless FORCE ADD set
  1. ; ; zero=exact matches only; -1=don't match on time
  1. ; These are used to match if sent (Optional)
  1. ; BSDIN("PROVIDER") = IEN for provider to match from file 200
  1. ; BSDIN("CLINIC CODE") = IEN of clinic stop code (file 40.7)
  1. ; BSDIN("HOS LOC") = IEN of hospital location (file 44, field .22 in VISIT file)
  1. ; BSDIN("DEF CC") = IEN of default clinic code for package making call PATCH 1009
  1. ; BSDIN("DEF HL") = IEN of default hospital location for package making call PATCH 1009
  1. ; Incoming Variables used in creating appt and visit
  1. ; BSDIN("APPT DATE") = appt date & time (Required for scheduled appts and walk-ins; check-in will be performed)
  1. ; BSDIN("USR") = user IEN in file 200; REQUIRED
  1. ; BSDIN("OPT") = name for Option Used To Create field, for check-in only (Optional)
  1. ; BSDIN("OI") = reason for appointment; for walk-ins (Optional)
  1. ; Incoming PCC variables for adding additional info to visit (Optional)
  1. ; BSDIN("SDTPB") = Third Party Billed (#.04)
  1. ; BSDIN("SDPVL") = Parent Visit Link (#.12)
  1. ; BSDIN("SDAPPT") = WalkIn/Appt (#.16)
  1. ; BSDIN("SDEVM") = Evaluation and Management Code (#.17)
  1. ; BSDIN("SDCODT") = Check Out Date & Time (#.18)
  1. ; BSDIN("SDLS") = Level of Service -PCC Form (#.19).
  1. ; BSDIN("SDVELG") = Eligibility (#.21)
  1. ; BSDIN("SDPROT") = Protocol (#.25).
  1. ; BSDIN("SDOPT") = Option Used To Create (#.24)
  1. ; BSDIN("SDOLOC") = Outside Location (#2101)
  1. ; Outgoing Array:
  1. ; BSDOUT(0) always set; if = 0 none found and may have error message in 2nd piece
  1. ; if = 1 and BSDOUT(visit ien)="ADD" new visit just created
  1. ; if = 1 and BSDOUT(visit ien)=#; # is time difference in minutes
  1. ; if >1, multiple BSDOUT(visit ien) entries exist
  1. NEW BSDTMP K BSDOUT
  1. M BSDTMP=BSDIN ;don't mess with incoming array
  1. IF '$$HAVEREQ(.BSDTMP,.BSDOUT) Q ;check required fields
  1. ; if FORCE ADD set, bypass check-in & create visit
  1. ; if forced add, skip visit match attempt
  1. ;IF $G(BSDTMP("FORCE ADD")) D APPTDT Q
  1. I '$G(BSDTMP("SDOPT")) D
  1. .I $G(BSDTMP("OPT"))]"",BSDTMP("OPT")?.N,$D(^DIC(19,BSDTMP("OPT"))) S BSDTMP("SDOPT")=BSDTMP("OPT") Q
  1. .I $G(BSDTMP("OPT"))]"",$E(BSDTMP("OPT"),1,1)="`" S BSDTMP("SDOPT")=$TR(BSDTMP("OPT"),"`") Q
  1. .I $G(BSDTMP("OPT"))]"",BSDTMP("OPT")'?.N S BSDTMP("SDOPT")=$O(^DIC(19,"B",BSDTMP("OPT"),0)) Q
  1. .I $G(BSDTMP("SDOPT"))]"",$E(BSDTMP("SDOPT"),1,1)="`" S BSDTMP("SDOPT")=$TR(BSDTMP("SDOPT"),"`") Q
  1. .I $G(BSDTMP("SDOPT"))]"",BSDTMP("SDOPT")'?.N S BSDTMP("SDOPT")=$O(^DIC(19,"B",BSDTMP("SDOPT"),0)) Q
  1. I $G(BSDTMP("FORCE ADD")) D ADDVIST(.BSDTMP,.BSDOUT) Q
  1. ; attempt to find matching visits; return BSDOUT array
  1. I '$G(BSDTMP("FORCE ADD")) D MATCH(.BSDTMP,.BSDOUT)
  1. ;if >1 visits found, return full array and quit, unless they pass it the variable to show visits then we will display
  1. ;(calling app decides next step)
  1. ;IF BSDOUT(0)>1 Q
  1. ;if appt date set, go to check-in
  1. ;IF $G(BSDTMP("APPT DATE")),'$G(BSDTMP("NEVER ADD")) D APPTDT Q
  1. ;if only 1 visit found, return ien and quit
  1. ;IF BSDOUT(0)'=1 Q
  1. ; added 2nd match, move never add checks & not kill variables
  1. ;if called by ancillary package, just create noon visit and quit
  1. ;IF $G(BSDTMP("ANCILLARY")) D Q
  1. ;. K BSDTMP("ANCILLARY"),BSDTMP("PROVIDER") ; set up to find other ancillaries
  1. ;. D MATCH(.BSDTMP,.BSDOUT) I BSDOUT(0)=1 Q ; try to match on hos loc or clinic
  1. ;. I $G(BSDTMP("NEVER ADD"))=1 Q ; if in never add mode, quit after 2nd match
  1. ;. S BSDTMP("VISIT DATE")=BSDTMP("VISIT DATE")\1 ; take off time; PCC will add noon
  1. ;. D ADDVIST(.BSDTMP,.BSDOUT) ; create noon visit
  1. ;if no visits found but in never add mode, just quit
  1. ;IF $G(BSDTMP("NEVER ADD"))=1 Q
  1. ;otherwise, logic falls through to create visit choices
  1. APPTDT ;
  1. I $G(BSDTMP("CALLER"))]"",$G(BSDTMP("CALLER"))="BSD CHECKIN" Q ;interactive visit creation
  1. ;if no appointment date/time sent, just create visit and quit
  1. IF '$G(BSDTMP("APPT DATE")) D ADDVIST(.BSDTMP,.BSDOUT) Q
  1. ; if one matching visit found, check-in but don't create visit
  1. I BSDOUT(0)=1 S BSDTMP("VIEN")=$O(BSDOUT(0))
  1. ;if patient already has appt at this time, call Check-in (which creates visit) then quit
  1. NEW IEN,ERR,V
  1. S IEN=$$SCIEN^SDECU2(BSDTMP("PAT"),BSDTMP("HOS LOC"),BSDTMP("APPT DATE")) ;find appt
  1. I IEN D Q
  1. . ; set variables used by checkin call
  1. . S BSDTMP("CDT")=BSDTMP("VISIT DATE")
  1. . S BSDTMP("CC")=$G(BSDTMP("CLINIC CODE"))
  1. . S BSDTMP("PRV")=$G(BSDTMP("PROVIDER"))
  1. . ; set more variables to use in BSDAPI
  1. . S BSDTMP("CLN")=$G(BSDTMP("HOS LOC"))
  1. . S BSDTMP("ADT")=$G(BSDTMP("APPT DATE"))
  1. . S ERR=$$CHECKIN^SDECAPI(.BSDTMP) ;check in and create visit
  1. . ; reset BSDOUT only if truly added one.
  1. . I 'ERR S V=$$GETVST^SDECU2(BSDTMP("PAT"),BSDTMP("APPT DATE")) I V,'$G(BSDTMP("VIEN")) S:BSDOUT(0)=0 BSDOUT(0)=1 S BSDOUT(V)="ADD" Q
  1. . I ERR S BSDOUT(0)=0_U_$P(ERR,U,2)
  1. ; else call walk-in (which calls make appt, checkin and create visit)
  1. D WALKIN(.BSDTMP,.BSDOUT)
  1. Q
  1. MATCH(IN,OUT) ; find matching visits based on IN array
  1. S OUT(0)=0
  1. NEW END,DATE,VIEN,STOP,DIFF,MATCH
  1. S MATCH=0
  1. D TIME(IN("TIME RANGE"),IN("VISIT DATE"),.DATE,.END)
  1. F S DATE=$O(^AUPNVSIT("AA",IN("PAT"),DATE)) Q:'DATE Q:(DATE>END) D
  1. . S VIEN=0
  1. . F S VIEN=$O(^AUPNVSIT("AA",IN("PAT"),DATE,VIEN)) Q:'VIEN D
  1. . . I $$GET1^DIQ(9000010,VIEN,.11)="DELETED" Q ;check for delete flag just in case xref not killed
  1. . . I IN("SITE")'=$$GET1^DIQ(9000010,VIEN,.06,"I") Q ;no match on loc of enc
  1. . . I IN("VISIT TYPE")'=$$GET1^DIQ(9000010,VIEN,.03,"I") Q ;no match on visit type
  1. . . ; get observation and day surgery visits
  1. . . I IN("SRV CAT")["CENRT" Q ;don't look at HIM excluded visits
  1. . . I $$GET1^DIQ(90000010,VIEN,.07,"I")["CENRT" Q ;don't look at HIM excluded visits
  1. . . I IN("SRV CAT")=$$GET1^DIQ(9000010,VIEN,.07,"I") S MATCH=1 ;no match on service category
  1. . . I IN("SRV CAT")="A",$G(IN("ANCILLARY")),$$GET1^DIQ(9000010,VIEN,.07,"I")="O" S MATCH=1 ;match if observation
  1. . . I IN("SRV CAT")="A",$G(IN("ANCILLARY")),$$GET1^DIQ(9000010,VIEN,.07,"I")="D" S MATCH=1
  1. . . I '$G(MATCH) Q
  1. . . I IN("TIME RANGE")>-1 S STOP=0 D Q:STOP ;check time range
  1. . . . S DIFF=$$TIMEDIF(IN("VISIT DATE"),VIEN) ;find difference in minutes
  1. . . . I $$ABS^XLFMTH(DIFF)>IN("TIME RANGE") S STOP=1
  1. . . I '$$PRVMTCH Q ; if provider sent and didn't match, skip
  1. . . ; if called by ancillary, falls through and sets visit into array
  1. . . ; otherwise, check if app wants to match on clinic code or hosp location
  1. . . I '$G(IN("ANCILLARY")) S STOP=0 D Q:STOP
  1. . . . I $G(IN("HOS LOC")),'$G(IN("CLINIC CODE")) S IN("CLINIC CODE")=$$GET1^DIQ(44,IN("HOS LOC"),8,"I")
  1. . . . I $G(IN("CLINIC CODE")),IN("CLINIC CODE")'=$$GET1^DIQ(9000010,VIEN,.08,"I") S STOP=1 Q ;no match on clinic code
  1. . . . ; if both have appt date and visit was triage clinic, is a match
  1. . . . ; create visit on same day no matter what
  1. . . . I $G(IN("HOS LOC")),(IN("HOS LOC")'=$$GET1^DIQ(9000010,VIEN,.22,"I")) S STOP=1 Q ;no match on hospital location
  1. . . . ; if same clinic & same provider but not triage, make new visit
  1. . . . I $G(IN("APPT DATE")),$$GET1^DIQ(9000010,VIEN,.26,"I"),'$$TRIAGE(VIEN) S STOP=1 Q
  1. . . ; must be good match, increment counter and set array node
  1. . . S OUT(0)=OUT(0)+1
  1. . . S OUT(VIEN)=$$TIMEDIF(IN("VISIT DATE"),VIEN)
  1. Q
  1. ;
  1. PRVMTCH() ; do visits match on provider?
  1. NEW PRVS,IEN
  1. I '$G(IN("PROVIDER")) Q 1 ; if no provider sent, assume okay
  1. ;if visit is triage clinic & new encounter is not ancillary, skip provider match
  1. I $$TRIAGE(VIEN),'$G(IN("ANCILLARY")) Q 1
  1. ; find all v provider entries for visit
  1. S IEN=0 F S IEN=$O(^AUPNVPRV("AD",VIEN,IEN)) Q:'IEN D
  1. . S PRVS(+$G(^AUPNVPRV(IEN,0)))=""
  1. ;if incoming provider in list, this is match
  1. I $D(PRVS(IN("PROVIDER"))) Q 1
  1. ;otherwise, no match
  1. Q 0
  1. ;
  1. TIMEDIF(VDTTM,VIEN) ; return time diff between incoming time and current visit
  1. Q $$FMDIFF^XLFDT(VDTTM,+$G(^AUPNVSIT(VIEN,0)),2)\60
  1. ;
  1. ADDVIST(BSDTMP,BSDOUT) ;
  1. N %DT,SDALVR,SUB,X,Y
  1. N SDDATE,SDHL,SDLOC,SDCODT,SDPAT
  1. S SUB="SD" F S SUB=$O(BSDTMP(SUB)) Q:SUB="" Q:$E(SUB,1,2)'="SD" S SDALVR(SUB)=BSDTMP(SUB)
  1. S SDALVR("AUPNTALK")="",SDALVR("SDANE")="" ;keep it silent
  1. S (SDLOC,SDALVR("SDLOC"))=BSDTMP("SITE") ;facility
  1. S (SDPAT,SDALVR("SDPAT"))=BSDTMP("PAT") ;patient
  1. S SDALVR("SDTYPE")=BSDTMP("VISIT TYPE") ;visit type
  1. S SDALVR("SDCAT")=BSDTMP("SRV CAT") ;srv cat
  1. S (SDDATE,SDALVR("SDDATE"))=BSDTMP("VISIT DATE") ;chkin dt
  1. I $G(BSDTMP("CLINIC CODE")) S SDALVR("SDCLN")="`"_BSDTMP("CLINIC CODE") ;clinic code ien w/`
  1. S (SDHL,SDALVR("SDHL"))=$G(BSDTMP("HOS LOC")) ;clinic name
  1. S SDALVR("SDAPDT")=$G(BSDTMP("APPT DATE")) ;appt date
  1. S SDALVR("SDUSR")=$G(BSDTMP("USR"))
  1. S SDALVR("SDADD")=1 ;force add
  1. S SDCODT=BSDTMP("SDCODT")
  1. ;create visit
  1. ;D EN^SDECALV ;D ^APCDALV
  1. D EN1^SDECALV(.SDALVR)
  1. ;if no visit created,error quit
  1. I '$G(SDALVR("SDVSIT")) D Q
  1. . S BSDOUT(0)="0^Error Creating Visit"
  1. ; set new visit info in out array
  1. S BSDOUT(SDALVR("SDVSIT"))="ADD",BSDOUT(0)=1
  1. Q
  1. ;
  1. WALKIN(BSDATA,OUT) ;EP; create walkin appt which is checked in and visit created
  1. ; also called by BSDAPI3 to create ancillary walkin appt
  1. NEW ERR,V
  1. S OUT(0)=0 ;initialize outgoing count
  1. S BSDATA("CLN")=$G(BSDATA("HOS LOC"))
  1. S BSDATA("TYP")=4 ;4=walkin
  1. S BSDATA("ADT")=$G(BSDATA("APPT DATE"))
  1. I '$D(BSDATA("LEN")) S BSDATA("LEN")=$$GET1^DIQ(44,BSDATA("CLN"),1912)
  1. ; make walkin appt
  1. S ERR=$$MAKE^SDECAPI(.BSDATA) I ERR S $P(OUT(0),U,2)=$P(ERR,U,2) Q
  1. ; set variables used by checkin call
  1. S BSDATA("CDT")=BSDATA("VISIT DATE")
  1. S BSDATA("CC")=$G(BSDATA("CLINIC CODE"))
  1. S BSDATA("PRV")=$G(BSDATA("PROVIDER"))
  1. ; check in appt and create visit
  1. S ERR=$$CHECKIN^SDECAPI(.BSDATA)
  1. ; update out array based on result
  1. ;reset BSDOUT(0) only if added new visit
  1. I 'ERR S V=$$GETVST^SDECU2(BSDATA("PAT"),BSDATA("APPT DATE")) I V,'$G(BSDTMP("VIEN")) S:OUT(0)=0 OUT(0)=1 S OUT(V)="ADD" ;visit added
  1. I ERR S $P(OUT(0),U,2)=$P(ERR,U,2) ;error
  1. Q
  1. ;
  1. HAVEREQ(IN,OUT) ; check required fields
  1. I ('$G(IN("FORCE ADD"))),('$D(IN("TIME RANGE"))) S OUT(0)="0^Missing Time Range" Q 0
  1. I '$D(IN("PAT")) S OUT(0)="0^Missing Patient IEN" Q 0
  1. I '$D(IN("VISIT DATE")) S OUT(0)="0^Missing Visit Date" Q 0
  1. I '$D(IN("SITE")) S OUT(0)="0^Missing Facility/Site" Q 0
  1. I '$D(IN("VISIT TYPE")) S OUT(0)="0^Missing Visit Type" Q 0
  1. I '$D(IN("SRV CAT")) S OUT(0)="0^Missing Service Category" Q 0
  1. I '$D(IN("USR")) S OUT(0)="0^Missing User IEN" Q 0
  1. I $G(IN("HOS LOC")),'$G(IN("CLINIC CODE")) S IN("CLINIC CODE")=$$GET1^DIQ(44,IN("HOS LOC"),8,"I")
  1. ; convert service category
  1. I $G(IN("APPT DATE")),$G(IN("HOS LOC")) S IN("SRV CAT")=$$SERCAT^SDECV(IN("HOS LOC"),IN("PAT"))
  1. Q 1
  1. ;
  1. TIME(RANGE,VISIT,DATE,END) ; set DATE and END based on TIME RANGE setting in minutes
  1. NEW TMDIF,SW
  1. S TMDIF=$S(RANGE<1:0,1:RANGE)
  1. S DATE=$$FMADD^XLFDT(VISIT,,,-TMDIF)
  1. S END=$$FMADD^XLFDT(VISIT,,,TMDIF)
  1. I (DATE\1)<(END\1) S SW=(END\1),END=(DATE\1)_".9999",DATE=SW
  1. S DATE=(9999999-(DATE\1)_"."_$P(DATE,".",2))-.0001
  1. S END=9999999-(END\1)_"."_$P(END,".",2)
  1. I RANGE=-1 S END=(END\1)_".9999",DATE=(DATE\1) ;no time range used; go from begin one day to end
  1. Q
  1. ;
  1. TRIAGE(VST) ; returns 1 if visit's hosp loc is triage type
  1. NEW HL
  1. S HL=$$GET1^DIQ(9000010,VST,.22,"I") I 'HL Q 0
  1. Q +$$GET1^DIQ(9009017.2,HL,.16,"I")
  1. ;