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

SDESUPDRECREQ2.m

Go to the documentation of this file.
SDESUPDRECREQ2 ;ALB/LAB,KML,MGD,RRM,ANU,BWF - VISTA SCHEDULING CREATE EDIT RECALL REQ RPC ;March 06, 2023
 ;;5.3;Scheduling;**823,842,861,864**;Aug 13, 1993;Build 15
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 ; Documented API's and Integration Agreements
 ; --------------------------------------------
 ; Reference to $$LKUP^XPDKEY is supported by IA #1367
 ; Reference to OWNSKEY^XUSRB is supported by IA #3277
 ;
 ;INPUT:
 ;   RECALLIEN - sent for UPDATE of RECALL REQUEST only(Required for Update) IEN pointer to RECALL REMINDERS
 ;   DFN       - (required) DFN Pointer to PATIENT file
 ;   ACCNO     - (optional) Accession # (free-text 1-25 characters)
 ;   SDCMT     - (optional) COMMENT (free-text 1-80 characters)
 ;   FASTING   - (required) FAST/NON-FASTING  valid values:  FASTING,NON-FASTING,NONE
 ;   APPTP     - (required) Test/App pointer or name (.01) to RECALL REMINDERS APPT TYPE file 403.51
 ;   RRPROVIEN - (required) Provider - Pointer to RECALL REMINDERS PROVIDERS file 403.54
 ;   CLINIEN   - (required) Clinic pointer to HOSPITAL LOCATION file
 ;   APPTLEN   - (optional) Length of Appointment  numeric between 10 and 120
 ;   DATE      - (required) Recall Date in ISO8601 format (no time).  e.g., CCYY-MM-DD
 ;   RECPPDT   - (optional) Recall Date (Per patient) in ISO8601 format (no time)  e.g., CCYY-MM-DD
 ;   DAPTDT    - (optional) Date Reminder Sent in ISO8601 format (no time)  e.g., CCYY-MM-DD
 ;   USERIEN   - (optional) User Who Entered Recall pointer to NEW PERSON file; default to current user
 ;   SECPDT    - (optional) Second Print Date in ISO8601 format (no time) e.g., CCYY-MM-DD
 ;   SDENTDT   - (optional) Date recall entered in ISO8601 format  e.g., CCYY-MM-DD)
 ;   EAS       - (optional) EAS Tracking Number
 ;
 ;RETURN:
 ;  Successful Return:
 ;    RETURNJSON = Returns the REQUEST RECALL IEN in JSON formatted string.
 ;    Otherwise, JSON Errors will be returned for any invalid/missing parameters.
 ;
 ; The parameter list for this RPC must be kept in sync.
 ; If you need to add or remove a parameter, ensure that the Remote Procedure File #8994 definition is also updated.
 ;
 ; copy of SDESUPDRECREQ
 Q
 ;
CREATERECREQ(RETN,DFN,ACCNO,SDCMT,FASTING,APPTP,RRPROVIEN,CLINIEN,APPTLEN,DATE,RECPPDT,DAPTDT,USERIEN,SECPDT,SDENTDT,EAS) ;CREATE recall request
 N ERRORS,SDRECREQ,RECALLIEN,SDCREATE,SDFDA,SDMSG,SDIEN
 S RECALLIEN="+1",SDCREATE=1
 D VALIDATE(.ERRORS,SDCREATE)
 I $O(ERRORS("Error",""))'="" D RETURNERROR(.ERRORS,.SDRECREQ,.RETN,SDCREATE) Q
 D BLDREC
 D UPDATE^DIE("","SDFDA","SDIEN","SDMSG")
 I $D(SDMSG) D ERRLOG^SDESJSON(.ERRORS,134),RETURNERROR(.ERRORS,.SDRECREQ,.RETN,SDCREATE) Q
 S SDRECREQ("RecallReqCreate","IEN")=SDIEN(1)
 D BUILDJSON^SDESBUILDJSON(.RETN,.SDRECREQ)
 Q
 ;
UPDRECALLREQ(RETN,RECALLIEN,DFN,ACCNO,SDCMT,FASTING,APPTP,RRPROVIEN,CLINIEN,APPTLEN,DATE,RECPPDT,DAPTDT,USERIEN,SECPDT,EAS) ;update recall request
 N ERRORS,SDRECREQ,SDFDA,SDMSG,SDIEN
 S SDCREATE=0
 D VALIDATE(.ERRORS,SDCREATE)
 I $O(ERRORS("Error",""))'="" D RETURNERROR(.ERRORS,.SDRECREQ,.RETN,SDCREATE) Q
 D BLDREC
 D FILE^DIE(,"SDFDA","SDMSG")
 I $D(SDMSG) D ERRLOG^SDESJSON(.ERRORS,134),RETURNERROR(.ERRORS,.SDRECREQ,.RETN,SDCREATE) Q
 S SDRECREQ("RecallReqEdit","IEN")=RECALLIEN
 D BUILDJSON^SDESBUILDJSON(.RETN,.SDRECREQ)
 Q
 ;
BLDREC ;build and file record
 S SDFDA=$NA(SDFDA(403.5,RECALLIEN_",")) ;recall
 S SDFDA(403.5,RECALLIEN_",",.01)=DFN
 S:$G(ACCNO)'="" SDFDA(403.5,RECALLIEN_",",2)=$E(ACCNO,1,25)
 S:SDCMT'="" SDFDA(403.5,RECALLIEN_",",2.5)=$E(SDCMT,1,80)
 S SDFDA(403.5,RECALLIEN_",",2.6)=FASTING
 S SDFDA(403.5,RECALLIEN_",",3)=APPTP
 S SDFDA(403.5,RECALLIEN_",",4)=RRPROVIEN
 S SDFDA(403.5,RECALLIEN_",",4.5)=CLINIEN
 S:APPTLEN'="" SDFDA(403.5,RECALLIEN_",",4.7)=APPTLEN
 S SDFDA(403.5,RECALLIEN_",",5)=DATE
 S:RECPPDT'="" SDFDA(403.5,RECALLIEN_",",5.5)=RECPPDT
 S:DAPTDT'="" SDFDA(403.5,RECALLIEN_",",6)=DAPTDT
 S SDFDA(403.5,RECALLIEN_",",7)=USERIEN
 S:SDCREATE SDFDA(403.5,RECALLIEN_",",7.5)=SDENTDT ;only add if creating new record, cannot edit
 S:SECPDT'="" SDFDA(403.5,RECALLIEN_",",8)=SECPDT
 S:EAS'="" SDFDA(403.5,RECALLIEN_",",100)=EAS
 Q
 ;
VALIDATE(ERRORS,SDCREATE) ;
 D INITINPUTPAR(SDCREATE) ;initialize input parameter
 S RECALLIEN=$$VALIDATERECALIEN(.ERRORS,RECALLIEN)
 S DFN=$$VALIDATEDFN(.ERRORS,DFN)
 S FASTING=$$VALIDATEFASTING(.ERRORS,FASTING)
 S APPTP=$$VALIDATEAPPTP(.ERRORS,APPTP)
 S RRPROVIEN=$$VALIDATERRPRVIEN(.ERRORS,RRPROVIEN)
 S CLINIEN=$$VALIDATECLINIEN(.ERRORS,CLINIEN)
 S DATE=$$VALIDATERECALLDT(.ERRORS,DATE)
 I $G(SDCREATE) S SDENTDT=$$VALIDATERCDTNTRD(.ERRORS,SDCREATE,SDENTDT)
 S APPTLEN=$$VALIDATEAPPTLEN(.ERRORS,APPTLEN)
 S RECPPDT=$$VALIDATERECPPDT(.ERRORS,RECPPDT)
 S DAPTDT=$$VALIDATEDAPTDT(.ERRORS,DAPTDT)
 S USERIEN=$$VALIDATEUSERIEN(.ERRORS,USERIEN)
 S SECPDT=$$VALIDATESECPDT(.ERRORS,SECPDT)
 S SDCMT=$$VALIDATESDCMT(.ERRORS,SDCMT)
 S EAS=$$VALIDATEEAS(.ERRORS,EAS)
 Q
 ;
INITINPUTPAR(SDCREATE) ;Initialized Input Paramaters
 S:SDCREATE<1 RECALLIEN=$G(RECALLIEN)
 S DFN=$G(DFN)
 S ACCNO=$G(ACCNO)
 S SDCMT=$G(SDCMT)
 S FASTING=$G(FASTING)
 S APPTP=$G(APPTP)
 S RRPROVIEN=$G(RRPROVIEN)
 S CLINIEN=$G(CLINIEN)
 S APPTLEN=$G(APPTLEN)
 S DATE=$G(DATE)
 S RECPPDT=$G(RECPPDT)
 S DAPTDT=$G(DAPTDT)
 S USERIEN=$G(USERIEN)
 S SECPDT=$G(SECPDT)
 S SDENTDT=$G(SDENTDT)
 S EAS=$G(EAS)
 Q
 ;
VALIDATERECALIEN(ERRORS,RECALLIEN) ;Validate Recall IEN
 I $G(RECALLIEN)="" D ERRLOG^SDESJSON(.ERRORS,16) Q RECALLIEN
 I (RECALLIEN'="+1")&('$D(^SD(403.5,$G(RECALLIEN)))) D ERRLOG^SDESJSON(.ERRORS,17) Q RECALLIEN
 ;check that user has the correct security key
 I $$KEY(RECALLIEN)>0 D ERRLOG^SDESJSON(.ERRORS,135)
 Q RECALLIEN
 ;
VALIDATEDFN(ERRORS,DFN) ;Validate Patient DFN
 I DFN="" D ERRLOG^SDESJSON(.ERRORS,1)
 I DFN'="",'$D(^DPT(DFN,0)) D ERRLOG^SDESJSON(.ERRORS,2)
 Q DFN
 ;
VALIDATEFASTING(ERRORS,FASTING) ;Validate Fasting
 I FASTING="" D ERRLOG^SDESJSON(.ERRORS,141) Q FASTING
 S FASTING=$S($$UP^XLFSTR(FASTING)="FASTING":"f",$$UP^XLFSTR(FASTING)="NON-FASTING":"n",$$UP^XLFSTR(FASTING)="F":"f",$$UP^XLFSTR(FASTING)="N":"n",FASTING="@":"@",1:138)
 I FASTING=138 D ERRLOG^SDESJSON(.ERRORS,138)
 Q FASTING
 ;
VALIDATEAPPTP(ERRORS,APPTP) ;Validate Appointment Type
 I APPTP="" D ERRLOG^SDESJSON(.ERRORS,139) Q APPTP
 I +APPTP,$D(^SD(403.51,APPTP,0)) Q APPTP
 I +APPTP,'$D(^SD(403.51,APPTP,0)) D ERRLOG^SDESJSON(.ERRORS,132) Q APPTP
 S APPTP=$O(^SD(403.51,"B",APPTP,""))
 I APPTP="" D ERRLOG^SDESJSON(.ERRORS,132) Q APPTP
 Q APPTP
 ;
VALIDATERRPRVIEN(ERRORS,RRPROVIEN) ;Validate Recall Provider IEN
 I RRPROVIEN="" D ERRLOG^SDESJSON(.ERRORS,137) Q RRPROVIEN
 I $G(RRPROVIEN)'="",'$D(^SD(403.54,RRPROVIEN)) D ERRLOG^SDESJSON(.ERRORS,131)
 Q RRPROVIEN
 ;
VALIDATECLINIEN(ERRORS,CLINIEN) ;Validate Clinic IEN
 I CLINIEN="" D ERRLOG^SDESJSON(.ERRORS,18) Q CLINIEN
 I CLINIEN'="",'$D(^SC(CLINIEN)) D ERRLOG^SDESJSON(.ERRORS,19)
 Q CLINIEN
 ;
VALIDATERECALLDT(ERRORS,RECALLDATE) ;Validate Recall Date
 I RECALLDATE="" D ERRLOG^SDESJSON(.ERRORS,140) Q RECALLDATE
 I RECALLDATE'="" S RECALLDATE=$$ISOTFM^SDAMUTDT(RECALLDATE)
 I RECALLDATE=-1 D ERRLOG^SDESJSON(.ERRORS,133)
 Q RECALLDATE
 ;
VALIDATERCDTNTRD(ERRORS,SDRCREATE,RECDTENTRD) ;Validate Recall Date Entered
 I (SDRCREATE)&($G(RECDTENTRD)'="") S RECDTENTRD=$$ISOTFM^SDAMUTDT(RECDTENTRD)
 I (RECDTENTRD=-1)!(RECDTENTRD="") S RECDTENTRD=DT ;
 Q RECDTENTRD
 ;
VALIDATEAPPTLEN(ERRORS,LENGTHOFAPPT) ;Validate Length of Appointment
 S LENGTHOFAPPT=$G(LENGTHOFAPPT,"") I LENGTHOFAPPT="" Q LENGTHOFAPPT
 I '+LENGTHOFAPPT D ERRLOG^SDESJSON(.ERRORS,116) Q LENGTHOFAPPT
 I LENGTHOFAPPT'="" S:((+LENGTHOFAPPT<10)!(+LENGTHOFAPPT>120)) LENGTHOFAPPT=""
 Q LENGTHOFAPPT
 ;
VALIDATERECPPDT(ERRORS,RECPPTDT) ;Validate Recall Date Per Patient
 S RECPPTDT=$G(RECPPTDT,"") S RECPPTDT=$$ISOTFM^SDAMUTDT(RECPPTDT)
 I RECPPTDT=-1 S RECPPTDT=""  ;VSE-2396
 Q RECPPTDT
 ;
VALIDATEDAPTDT(ERRORS,DTRMSENT) ;Validate Date Reminder Sent
 S DTRMSENT=$G(DTRMSENT,"")
 S DTRMSENT=$$ISOTFM^SDAMUTDT(DTRMSENT)
 I DTRMSENT=-1 S DTRMSENT=""  ;VSE-2396
 Q DTRMSENT
 ;
VALIDATEUSERIEN(ERRORS,USERIEN) ;Validate User IEN
 S USERIEN=$G(USERIEN,"")
 I USERIEN'?.N S USERIEN=DUZ Q USERIEN
 I (USERIEN="")!('$D(^VA(200,+USERIEN))) S USERIEN=DUZ
 Q USERIEN
 ;
VALIDATESECPDT(ERRORS,SECPRNTDT) ;Validate Second Print Date
 S SECPRNTDT=$G(SECPRNTDT,"")
 I SECPRNTDT'="" S SECPRNTDT=$$ISOTFM^SDAMUTDT(SECPDT)
 I SECPRNTDT=-1 S SECPRNTDT=""  ;VSE-2396
 Q SECPRNTDT
 ;
VALIDATESDCMT(ERRORS,SDCMT) ;Validate Length of Appointment
 S SDCMT=$G(SDCMT,"")
 S SDCMT=$TR($G(SDCMT),"^"," ")
 Q SDCMT
 ;
VALIDATEEAS(ERRORS,SDEAS) ;Validate SDEAS
 S SDEAS=$G(SDEAS,"")
 I $L(SDEAS) S SDEAS=$$EASVALIDATE^SDESUTIL(SDEAS)
 I SDEAS=-1 D ERRLOG^SDESJSON(.ERRORS,142)
 Q SDEAS
 ;
RETURNERROR(ERRORS,SDRECREQ,RETN,SDCREATE) ;
 M SDRECREQ=ERRORS
 D SETEMPTYOBJ(.SDRECREQ,SDCREATE)
 D BUILDJSON^SDESBUILDJSON(.RETN,.SDRECREQ)
 Q
 ;
SETEMPTYOBJ(SDRECREQ,SDCREATE) ;Set the object to NULL
 I SDCREATE S SDRECREQ("RecallReqCreate","IEN")="" Q
 S SDRECREQ("RecallReqEdit","IEN")=""
 Q
 ;
KEY(RECALLIEN) ;check that user has the correct SECURITY KEY
 ;INPUT:
 ; RECALLIEN - Pointer to RECALL REMINDERS file 403.5
 ;RETURN
 ;  0=User has the correct SECURITY KEY
 ;  135=error number - user does not have correct security keys
 N KEY,KY,RET,SDPRV,SDFLAG
 S RET=135
 S (SDPRV,KEY,SDFLAG)="" S SDPRV=$P($G(^SD(403.5,+RECALLIEN,0)),U,5) D
 .I SDPRV="" S RET=0
 .I SDPRV'="" S KEY=$P($G(^SD(403.54,SDPRV,0)),U,7) D
 ..I KEY="" S RET=0 Q
 ..N VALUE
 ..S VALUE=$$LKUP^XPDKEY(KEY) K KY D OWNSKEY^XUSRB(.KY,VALUE,DUZ)
 ..I $G(KY(0))'=0 S RET=0
 Q RET
 ;