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

SDES2CRTVETAPPT.m

Go to the documentation of this file.
SDES2CRTVETAPPT ;ALB/BLB,MGD,TJB - SDES2 CREATE VET REQ AND APPT ;Jun 17, 2024
 ;;5.3;Scheduling;**867,869,877,881**;Aug 13, 1993;Build 10
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 ;  REQUEST("APPOINTMENT END TIME")          = (Required) APPT END TIME - ISO FORMAT
 ;  REQUEST("APPOINTMENT LENGTH")            = (Required) APPT LENGTH IN MINUTES (5-240)
 ;  REQUEST("APPOINTMENT START TIME")        = (Required) APPT START TIME - ISO FORMAT
 ;  REQUEST("CLINIC IEN")                    = (Required) CLINIC IEN
 ;  REQUEST("CREATE DATE")                   = (Required) DATE/TIME ENTERED (#409.85,9.5) in ISO8601 date/time format to include offset (e.g. CCYY-MM-DDTHH:MM-NNNN)
 ;  REQUEST("PATIENT INDICATED DATE")        = (Required) CID/PID DATE - ISO FORMAT
 ;  REQUEST("DFN")                           = (Required) PATIENT IEN
 ;  REQUEST("APPOINTMENT REASON")            = (Optional) FREE TEXT (1-150)
 ;  REQUEST("COLLATERAL VISIT")              = (Optional) COLLATERAL - 1 FOR YES
 ;  REQUEST("APPOINTMENT TYPE IEN")          = (Optional) POINTER TO APPOINTMENT TYPE FILE (#409.1)
 ;                 Either APPOINTMENT TYPE IEN or APPOINTMENT TYPE NAME is Required
 ;  REQUEST("APPOINTMENT TYPE NAME")         = (Optional) NAME from APPOINTMENT TYPE FILE (#409.1)
 ;  REQUEST("EAS")                           = (Optional) Enterprise APPT Scheduling Tracking Number associated to an appt.
 ;  REQUEST("FOLLOWUP")                      = (Optional) FOLLOWUP VISIT - 1 FOR YES 0 FOR NO
 ;  REQUEST("INSTITUTION NAME")              = (Optional) Institution name from the INSTITUTION file
 ;  REQUEST("MODALITY")                      = (Optional) Valid Values: FACE2FACE, TELEPHONE, VIDEO
 ;  REQUEST("NOTE")                          = (Optional) NOTE - FREE TEXT 1-150
 ;  REQUEST("OVERBOOK")                      = (Optional) OVERBOOK (0 for no, 1 for yes)
 ;  REQUEST("PATIENT COMMENT")               = (Optional) Patient-entered comments when using VAOS or other web-service (stored at 409.85,60 a word processing field)
 ;  REQUEST("PATIENT ELIGIBILITY IEN")       = (Optional) ELIGIBILITY IEN
 ;  REQUEST("PATIENT PREFERRED END DATE",1)  = (Optional) PATIENT PREFERRED END DATE 1 - ISO FORMAT
 ;  REQUEST("PATIENT PREFERRED END DATE",2)  = (Optional) PATIENT PREFERRED END DATE 2 - ISO FORMAT
 ;  REQUEST("PATIENT PREFERRED END DATE",3)  = (Optional) PATIENT PREFERRED END DATE 3 - ISO FORMAT
 ;  REQUEST("PATIENT PREFERRED START DATE",1)= (Optional) PATIENT PREFERRED START DATE 1 - ISO FORMAT
 ;  REQUEST("PATIENT PREFERRED START DATE",2)= (Optional) PATIENT PREFERRED START DATE 2 - ISO FORMAT
 ;  REQUEST("PATIENT PREFERRED START DATE",3)= (Optional) PATIENT PREFERRED START DATE 3 - ISO FORMAT
 ;  REQUEST("PATIENT STATUS")                = (Optional) PATIENT STATUS - "NEW" OR "ESTABLISHED
 ;  REQUEST("PRIORITY")                      = (Optional) PRIORITY - "ASAP" or FUTURE
 ;  REQUEST("PRIORITY GROUP")                = (Optional) ENROLLMENT PRIORITY - GROUP 1 - GROUP 7
 ;  REQUEST("REQUEST COMMENT")               = (Optional) REQUEST COMMENT
 ;  REQUEST("SECONDARY STOP CODE")           = (Optional) Secondary Stop Code Number pointer to CLINIC STOP file #40.7 used to populate the REQ SECONDARY STOP CODE field in 409.85
 ;  REQUEST("SERVICE CONNECTED")             = (Optional) Valid Values: YES, NO
 ;  REQUEST("SERVICE CONNECTED PERCENTAGE")  = (Optional) SC % = 0-100
 ;  REQUEST("STATION NUMBER")                = (Optional) STATION NUMBER (#99),INSTITUTION (#4)
 ;  REQUEST("STOP CODE")                     = (Optional) CLINIC STOP pointer to CLINIC STOP file 40.7 used to populate the REQ SERVICE/SPECIALTY field in 409.85
 ;  REQUEST("VAOS GUID")                     = (Optional) VAOS GUID
 ;
 Q
 ;
CREATEREQANDAPPT(JSON,SDCONTEXT,REQUEST) ;
 N ERRORS,RETURN,REQUESTIEN,JSONREQUEST,REQUESTRETURN,JSONAPPT,APPTRETURN,APPOINTMENT,JSONDISP,DISPOSITION,VALRETURN
 ;
 ; validate
 D VALIDATE(.ERRORS,.VALRETURN,.SDCONTEXT,$G(REQUEST("DFN")),$G(REQUEST("APPOINTMENT START TIME")),$G(REQUEST("APPOINTMENT END TIME")),$G(REQUEST("CLINIC IEN")))
 I $D(ERRORS) S ERRORS("Appointment","IEN")="",ERRORS("Request","IEN")="" D BUILDJSON^SDES2JSON(.JSON,.ERRORS) Q
 ;
 ; create request
 D CREATEREQUEST(.JSONREQUEST,.REQUESTRETURN,.REQUEST,.REQUESTIEN,.ERRORS)
 I $D(ERRORS) S ERRORS("Appointment","IEN")="",ERRORS("Request","IEN")="" D BUILDJSON^SDES2JSON(.JSON,.ERRORS) Q
 S RETURN("Request","IEN")=REQUESTIEN
 ;
 ; create appointment
 D CREATEAPPT(.JSONAPPT,.APPTRETURN,.APPTIEN,REQUESTIEN,.SDCONTEXT,.ERRORS)
 I $D(ERRORS) S ERRORS("Appointment","IEN")="",ERRORS("Request","IEN")="" D DELETEREQUEST(REQUESTIEN),BUILDJSON^SDES2JSON(.JSON,.ERRORS) Q
 S RETURN("Appointment","IEN")=APPTIEN
 ;
 ; disposition request
 D DISPOSITIONREQ(.DISPOSITION,.JSONDISP,.SDCONTEXT,REQUESTIEN,$G(REQUEST("PATIENT COMMENT")))
 ;
 ; json
 D BUILDJSON^SDES2JSON(.JSON,.RETURN)
 Q
 ;
CREATEREQUEST(JSONREQUEST,REQUESTRETURN,REQUEST,REQUESTIEN,ERRORS) ;
 N INSTITUTIONIEN,VALIDATEREQUEST
 S REQUEST("REQUESTED BY")="PATIENT"
 S REQUEST("REQUEST SUB TYPE")="APPT"
 M VALIDATEREQUEST=REQUEST
 D VALIDATE^SDESCREATEAPPREQ(.VALIDATEREQUEST,.INSTITUTIONIEN,.ERRORS)
 I $D(ERRORS) Q
 ;
 D CREATEREQUEST^SDESCREATEAPPREQ(.JSONREQUEST,.REQUEST)
 D DECODE^XLFJSON("JSONREQUEST","REQUESTRETURN")
 S REQUESTIEN=$G(REQUESTRETURN("Request","IEN"))
 Q
 ;
CREATEAPPT(JSONAPPT,APPTRETURN,APPTIEN,REQUESTIEN,SDCONTEXT,ERRORS) ;
 N VAL,VALIDATEAPPT
 D BUILDAPPTARRAY(.REQUEST,.APPOINTMENT,REQUESTIEN)
 ;
 M VALIDATEAPPT=APPOINTMENT
 D VALIDATE^SDES2CREATEAPPT(.ERRORS,.SDCONTEXT,.VALIDATEAPPT,.VAL)
 I $D(ERRORS) Q
 ;
 D CREATE^SDES2CREATEAPPT(.JSONAPPT,.SDCONTEXT,.APPOINTMENT)
 D DECODE^XLFJSON("JSONAPPT","APPTRETURN")
 S APPTIEN=$G(APPTRETURN("Appointment","IEN"))
 Q
 ;
DISPOSITIONREQ(DISPOSITION,JSONDISP,SDCONTEXT,REQUESTIEN,COMMENTS) ;
 S DISPOSITION("DISP")="REMOVED/SCHEDULED-ASSIGNED"
 S DISPOSITION("REQUEST ID")=REQUESTIEN
 S DISPOSITION("DISPDT")=$TR($$FMTE^XLFDT($$NOW^XLFDT,"7DZ"),"/","-")
 S DISPOSITION("PATCMMTS")=COMMENTS
 D DISPOSITION^SDES2ARCLOSE(.JSONDISP,.SDCONTEXT,.DISPOSITION)
 Q
 ;
DELETEREQUEST(REQUESTIEN) ;
 N FDA
 S FDA(409.85,REQUESTIEN_",",.01)="@"
 D FILE^DIE(,"FDA") K FDA
 Q
 ;
VALIDATE(ERRORS,VALRETURN,SDCONTEXT,DFN,START,END,CLINICIEN) ;
 D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
 D VALFILEIEN^SDES2VALUTIL(.VALRETURN,.ERRORS,2,DFN,1,,1,2)
 D VALFILEIEN^SDES2VALUTIL(.VALRETURN,.ERRORS,44,CLINICIEN,1,,18,19)
 D CHECKAPPTOVERLAP(.ERRORS,DFN,START,END)
 ;
 S START=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,START,CLINICIEN,1,165,166)
 S END=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,END,CLINICIEN,1,167,168)
 Q
 ;
CHECKAPPTOVERLAP(ERRORS,DFN,START,END) ; checking for overlaps with existing appointments
 N APPTIEN,APPTSTART,APPTEND,OVERLAP
 ;
 S APPTIEN=0,OVERLAP=0
 F  S APPTIEN=$O(^SDEC(409.84,"CPAT",DFN,APPTIEN)) Q:'APPTIEN!(OVERLAP)  D
 .S APPTSTART=$$GET1^DIQ(409.84,APPTIEN,.01,"I")
 .S APPTEND=$$GET1^DIQ(409.84,APPTIEN,.02,"I")
 .I START>=APPTSTART,START<APPTEND S OVERLAP=1 Q
 .I END>APPTSTART,END<=APPTEND S OVERLAP=1
 I $G(OVERLAP) D ERRLOG^SDESJSON(.ERRORS,540)
 Q
 ;
BUILDAPPTARRAY(REQUEST,APPOINTMENT,REQUESTIEN) ;
 S APPOINTMENT("START DATE TIME")=$G(REQUEST("APPOINTMENT START TIME"))
 S APPOINTMENT("END DATE TIME")=REQUEST("APPOINTMENT END TIME")
 S APPOINTMENT("DFN")=$G(REQUEST("DFN"))
 S APPOINTMENT("RESOURCE IEN")=$S($G(REQUEST("CLINIC IEN"))="":"",1:$$GETRES^SDESINPUTVALUTL($G(REQUEST("CLINIC IEN")),1))
 S APPOINTMENT("WALKIN")=""
 S APPOINTMENT("PATIENT INDICATED DATE")=$$FMTISO^SDAMUTDT($G(REQUEST("PATIENT INDICATED DATE")))
 S APPOINTMENT("EXTERNAL ID")=""
 S APPOINTMENT("REQUEST TYPE")="A|"_REQUESTIEN
 S APPOINTMENT("PROVIDER IEN")=""
 S APPOINTMENT("CLINIC IEN")=$G(REQUEST("CLINIC IEN"))
 S APPOINTMENT("NOTE")=$G(REQUEST("NOTE"))
 S APPOINTMENT("APPOINTMENT TYPE")=$G(REQUEST("APPOINTMENT TYPE IEN"))
 S APPOINTMENT("APPOINTMENT TYPE NAME")=$G(REQUEST("APPOINTMENT TYPE NAME"))
 S APPOINTMENT("PATIENT STATUS")=$G(REQUEST("PATIENT STATUS"))
 S APPOINTMENT("APPOINTMENT LENGTH")=$G(REQUEST("APPOINTMENT LENGTH"))
 S APPOINTMENT("SERVICE CONNECTED")=$G(REQUEST("SERVICE CONNECTED"))
 S APPOINTMENT("SERVICE CONNECTED PERCENTAGE")=$G(REQUEST("SERVICE CONNECTED PERCENTAGE"))
 S APPOINTMENT("MRTC")=0
 S APPOINTMENT("MRTC PARENT")=""
 S APPOINTMENT("APPOINTMENT REASON")=$G(REQUEST("APPOINTMENT REASON"))
 S APPOINTMENT("PATIENT ELIGIBILITY")=$G(REQUEST("PATIENT ELIGIBILITY IEN"))
 S APPOINTMENT("OVERBOOK")=$G(REQUEST("OVERBOOK"))
 S APPOINTMENT("LAB DATE TIME")=""
 S APPOINTMENT("XRAY DATE TIME")=""
 S APPOINTMENT("EKG DATE TIME")=""
 S APPOINTMENT("PURPOSE")=3    ;Always set to '3' - per Judy Mercado
 S APPOINTMENT("COLLATERAL")=$G(REQUEST("COLLATERAL VISIT"))
 S APPOINTMENT("SCHEDULE REQUEST TYPE")="P"  ;Always set to 'P' - per Judy Mercado
 S APPOINTMENT("NEXT AVAILABLE APPOINTMENT")=0    ;Always set to '0' - per Judy Mercado
 S APPOINTMENT("FOLLOWUP")=$G(REQUEST("FOLLOWUP"))
 Q
 ;