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

SDES2CRTVISIT.m

Go to the documentation of this file.
SDES2CRTVISIT ;ALB/JAS - SDES2 VISTA SCHEDULING API for creating Visits when necessary ;APR 25, 2024
 ;;5.3;Scheduling;**878**;Aug 13, 1993;Build 11
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 ; Based off of SDECALV & SDECALV1 with a portion of code pulled from SDECEKL
 ;
EN1(SDVISITOUT,SDVISITIN)  ;VISIT CREATION
 ;INPUT:
 ; SDVISITIN("SDDATE")  .01  VISIT/ADMIT DATE&TIME in fm format
 ; $$NOW^XLFDT          .02  DATE VISIT CREATED
 ; SDVISITIN("SDTYPE")  .03  TYPE  valid values:
 ;   I:IHS,C:CONTRACT,T:TRIBAL,O:OTHER,6:638 PROGRAM,V:VA
 ; SDVISITIN("SDPAT")   .05  Patient pointer to PATIENT file 2
 ; SDVISITIN("SDLOC")   .06  LOC. OF ENCOUNTER pointer to LOCATION file
 ; SDVISITIN("SDCAT")   .07  Service Category
 ; SDVISITIN("SDCLN")   .08  DSS ID (Clinic Stop)
 ; SDVISITIN("SDPVL")   .12  Parent Visit Link
 ; DT                   .13  Date Last Modified in fm format
 ; SDVISITIN("SDCODT")  .18  Check out Date&Time
 ; SDVISITIN("SDVELG")  .21  Eligibility pointer to ELIGIBILITY CODE file 8
 ; SDVISITIN("SDHL")    .22  Hospital Location pointer to file 44
 ; SDVISITIN("SDUSR")   .23  Created by user pointer to NEW PERSON
 ; SDVISITIN("SDOPT")   .24  Option used to Create pointer to OPTION file
 ; SDVISITIN("SDPROT")  .25  Protocol pointer to PROTOCOL file
 ; SDVISITIN("SDOLOC")  2101 outside location
 ;
 D VALVISIT(.SDVSTARRAY,.SDVISITIN)
 ;
 I $G(SDVSTARRAY("SDADD")) D GENVISIT(.SDVISITCRT,.SDVSTARRAY)   ; forced add
 I $G(SDVISITCRT("SDVSIT")),$G(SDVISITCRT("SDCLN")),$$GET1^DIQ(9000010,SDVISITCRT("SDVSIT")_",",.08,"I")="" D
 . N SDFDA
 . S SDFDA(9000010,SDVISITCRT("SDVSIT")_",",.08)=SDVISITCRT("SDCLN")
 . D FILE^DIE("","SDFDA","SDERR")
 ;
 I $D(SDVISITCRT) D
 . S SDVISITOUT("SDPAT")=$G(SDVISITCRT("SDPAT"))
 . S SDVISITOUT("SDVSIT")=$G(SDVISITCRT("SDVSIT"))
 . S:$G(SDVISITCRT("NEW")) SDVISITOUT("NEW")=SDVISITCRT("NEW")
 . S:$G(SDVISITCRT("SDAFLG")) SDVISITOUT("SDAFLG")=SDVISITCRT("SDAFLG")
 D CLNUP
 Q
 ;
GENVISIT(SDVISITCRT,SDVISITIN) ; GENERATE NEW VISIT
 ;
 N D0,DA,DIC,DIE,DR,X,Y,%DT
 N AUPNDOB,AUPNDOD,AUPNSEX
 N SDDOB,SDDOD,SDFDA,SDIEN,SDMSG,SDSEX,VID
 S Y=SDVISITIN("SDPAT") D ^AUPNPAT K Y
 S SDSEX=AUPNSEX,SDDOB=AUPNDOB,SDDOD=AUPNDOD
 S X=$G(SDVISITIN("SDDATE")),%DT="TRXN" D ^%DT S X=Y I X=-1 D  Q
 . S SDVISITCRT("SDAFLG")=1,SDVISITCRT("SDERR")=".01^"_SDVISITIN("SDDATE")_"^DATE INVALID FOR PATIENT,CANNOT CREATE VISIT .01 VALUE"
 D VSIT01^AUPNVSIT
 I '$D(X) S SDVISITCRT("SDAFLG")=1,SDVISITCRT("SDERR")=".01^"_SDVISITIN("SDDATE")_"^DATE INVALID FOR PATIENT,CANNOT CREATE VISIT .01 VALUE" Q
 S SDFDA="SDFDA(9000010,""+1,"")"
 S @SDFDA@(.01)=$G(SDVISITIN("SDDATE"))
 S @SDFDA@(.02)=$$NOW^XLFDT
 S @SDFDA@(.03)=$G(SDVISITIN("SDTYPE"))
 S @SDFDA@(.05)=$G(SDVISITIN("SDPAT"))
 S @SDFDA@(.06)=$G(SDVISITIN("SDLOC"))
 S @SDFDA@(.07)=$G(SDVISITIN("SDCAT"))
 S @SDFDA@(.08)=$G(SDVISITIN("SDCLN"))
 S @SDFDA@(.12)=$G(SDVISITIN("SDPVL"))
 S @SDFDA@(.13)=DT
 S @SDFDA@(.18)=$G(SDVISITIN("SDCODT"))
 S @SDFDA@(.21)=$G(SDVISITIN("SDVELG"))
 S @SDFDA@(.22)=$G(SDVISITIN("SDHL"))
 S @SDFDA@(.23)=$G(SDVISITIN("SDUSR"))
 S @SDFDA@(.24)=$G(SDVISITIN("SDOPT"))
 S @SDFDA@(.25)=$G(SDVISITIN("SDPROT"))
 S @SDFDA@(2101)=$S($G(SDVISITIN("SDOLOC"))]"":SDVISITIN("SDOLOC"),1:"")
 S VID=$$GETVID^VSITVID S @SDFDA@(15001)=VID
 D UPDATE^DIE("","SDFDA","SDIEN","SDMSG")
 ;
 I $D(SDMSG) S SDVISITCRT("SDAFLG")=1,SDVISITCRT("SDERR")=".01^"_SDVISITIN("CDT")_"^VISIT CREATION FAILED" Q
 S SDVISITCRT("SDVSIT")=+SDIEN(1)
 I $T(GETVID^VSITVID)]"",$$GET1^DIQ(150.9,"1,",402,"I")]"" D
 . S VID=$$GETVID^VSITVID
 . S DIE=9000010,DA=SDVISITCRT("SDVSIT"),DR="15001///"_VID
 . D ^DIE K VID,DIE,DR,DA
 S SDVISITCRT("NEW")=1
 Q
 ;
VALVISIT(SDVSTARRAY,SDVISITIN) ;Validation for SDVISITIN variables
 ;
 S SDVSTARRAY("SDAPDT")=$G(SDVISITIN("APPT DATE"))
 S SDVSTARRAY("SDCAT")=$G(SDVISITIN("SDCAT"))
 S SDVSTARRAY("SDEVM")=$G(SDVISITIN("SDEVM"))
 S SDVSTARRAY("SDDATE")=$G(SDVISITIN("SDDATE"))
 S SDVSTARRAY("SDHL")=$G(SDVISITIN("SDHL"))
 S SDVSTARRAY("SDLOC")=$G(SDVISITIN("SDLOC"))
 S SDVSTARRAY("SDCODT")=$G(SDVISITIN("SDCODT"))
 S SDVSTARRAY("SDOLOC")=$G(SDVISITIN("SDOLOC"))
 S SDVSTARRAY("SDOPT")=$G(SDVISITIN("SDOPT"))
 S SDVSTARRAY("SDPAT")=$G(SDVISITIN("SDPAT"))
 S SDVSTARRAY("SDPROT")=$G(SDVISITIN("SDPROT"))
 S SDVSTARRAY("SDPVL")=$G(SDVISITIN("SDPVL"))
 S SDVSTARRAY("SDTPB")=$G(SDVISITIN("SDTPB"))
 S SDVSTARRAY("SDTYPE")=$G(SDVISITIN("SDTYPE"))
 S SDVSTARRAY("SDUSR")=$G(SDVISITIN("SDUSR"))
 S SDVSTARRAY("SDVELG")=$G(SDVISITIN("SDVELG"))
 S SDVSTARRAY("SDVSIT")=$G(SDVISITIN("SDVSIT"))
 S SDVSTARRAY("SDADD")=$G(SDVISITIN("SDADD"))
 ; EDIT PASSED-IN VARIABLES
 N DIC,X,Y
 S:$P(SDVSTARRAY("SDDATE"),".",2)="" SDVSTARRAY("SDDATE")=+SDVSTARRAY("SDDATE")_".12"
 S SDVSTARRAY("SDDATE")=$E(SDVSTARRAY("SDDATE"),1,12)
 S:'$D(SDVSTARRAY("SDTYPE")) SDVSTARRAY("SDTYPE")="I"
 I SDVSTARRAY("SDTYPE")="" S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")=".03^"_SDVSTARRAY("SDTYPE")_"^TYPE OF VISIT MISSING" Q
 S:$G(SDVSTARRAY("SDCAT"))="" SDVSTARRAY("SDCAT")="A"
 S:$E(SDVSTARRAY("SDPAT"))="`" SDVSTARRAY("SDPAT")=$E(SDVSTARRAY("SDPAT"),2,99)
 I '$D(^AUPNPAT(SDVSTARRAY("SDPAT"),0)) D  Q
 . S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")=".05^"_SDVSTARRAY("SDPAT")_"^PATIENT NOT IN AUPNPAT GLOBAL" Q
 S:$E(SDVSTARRAY("SDLOC"))="`" SDVSTARRAY("SDLOC")=$E(SDVSTARRAY("SDLOC"),2,99)
 I '$D(^AUTTLOC(SDVSTARRAY("SDLOC"),0)) S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")=".06^"_SDVSTARRAY("SDLOC")_"^LOCATION PTR NOT IN AUTTLOC" Q
 I $D(SDVSTARRAY("SDOLOC")),SDVSTARRAY("SDOLOC")?.E1C.E D  Q
 . S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")="2101^"_SDVSTARRAY("SDOLOC")_"^OUTSIDE LOCATION FAILED INPUT TX" Q
 I $G(SDVSTARRAY("SDOLOC"))]"",$L(SDVSTARRAY("SDOLOC"))<2!($L(SDVSTARRAY("SDOLOC"))>50) D  Q
 . S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")="2101^"_SDVSTARRAY("SDOLOC")_"^OUTSIDE LOCATION FAILED INPUT TX" Q
 I $D(SDVSTARRAY("SDCLN")),SDVSTARRAY("SDCLN")="" K SDVSTARRAY("SDCLN") Q
 Q:'$D(SDVSTARRAY("SDCLN"))
 S:$E(SDVSTARRAY("SDCLN"))="`" SDVSTARRAY("SDCLN")=$E(SDVSTARRAY("SDCLN"),2,99)
 I SDVSTARRAY("SDCLN")?1N.N,'$D(^DIC(40.7,SDVSTARRAY("SDCLN"),0)) D  Q
 . S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")=".08^"_SDVSTARRAY("SDCLN")_"^CLINIC NOT VALID" Q
 I SDVSTARRAY("SDCLN")'?1N.N S X=SDVSTARRAY("SDCLN"),DIC="^DIC(40.7,",DIC(0)="M" D ^DIC S:+Y>0 SDVSTARRAY("SDCLN")=+Y
 I SDVSTARRAY("SDCLN")'?1N.N S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")=".08^"_SDVSTARRAY("SDCLN")_"^CLINIC NOT VALID" Q
 I $D(SDVSTARRAY("SDTPB")) S X="`"_SDVSTARRAY("SDTPB") I '$D(X) D  Q
 . S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")=".04^"_SDVSTARRAY("SDTPB")_"^.04 VALUE MUST BE IN INTERNAL FORMAT AND PASS INPUT TX"
 ;
 I $D(SDVSTARRAY("SDPVL")),'$D(^AUPNVSIT(SDVSTARRAY("SDPVL")))!($P($G(^AUPNVSIT(SDVSTARRAY("SDPVL"),0)),U,11)) D  Q
 . S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")=".12^"_SDVSTARRAY("SDPVL")_"^MUST BE INTERNAL VALUE AND VALID VISIT PTR"
 ;
 I $G(SDVSTARRAY("SDEVM"))]"",'SDVSTARRAY("SDEVM") D  Q
 . S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")=".17^"_SDVSTARRAY("SDEVM")_"^EVAL&MAN NOT VALID INTERNAL FORMAT"
 ;
 I $G(SDVSTARRAY("SDCODT"))]"" S X=$$FMTE^XLFDT(SDVSTARRAY("SDCODT")) X $P(^DD(9000010,.18,0),U,5,99) I '$D(X) D  Q
 . S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")=".18^"_SDVSTARRAY("SDCODT")_"^CHECK OUT DATE/TIME FAILED INPUT TX"
 ;
 I $G(SDVSTARRAY("SDVELG"))]"",'SDVSTARRAY("SDVELG") D  Q
 . S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")=".21^"_SDVSTARRAY("SDVELG")_"^VA ELIG NOT VALID INTERNAL FORMAT"
 ;
 I $G(SDVSTARRAY("SDHL"))]"",'SDVSTARRAY("SDHL") D  Q
 . S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")=".22^"_SDVSTARRAY("SDHL")_"^HOSPITAL LOCATION NOT VALID INTERNAL FORMAT"
 ;
 I $G(SDVSTARRAY("SDOPT"))]"",'SDVSTARRAY("SDOPT") D  Q
 . S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")=".24^"_SDVSTARRAY("SDOPT")_"^OPTION USED TO CREATE NOT VALID INTERNAL FORMAT"
 Q
 ;
 I $G(SDVSTARRAY("SDPROT"))]"",'SDVSTARRAY("SDPROT") D  Q
 . S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")=".25^"_SDVSTARRAY("SDPROT")_"^PROTOCOL USED TO CREATE NOT VALID INTERNAL FORMAT"
 ;
 I SDVSTARRAY("SDAPDT")]"" S X=$$FMTE^XLFDT(SDVSTARRAY("SDAPDT")) X $P(^DD(9000010,.26,0),U,5,99) I '$D(X) D  Q
 . S SDVSTARRAY("SDAFLG")=1,SDVSTARRAY("SDERR")=".26^"_SDVSTARRAY("SDAPDT")_"^APPT DATE/TIME FAILED INPUT TX - MUST BE IN INTERNAL FM FORMAT"
 Q
 ;
CLNUP ;
 K AUPNPAT,AUPNDAYS,SDVISITIN,SDVISITCRT,SDVSTARRAY
 Q