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

SDES2CRTAPREQ.m

Go to the documentation of this file.
SDES2CRTAPREQ ;ALB/BWF,JAS,TJB,JAS - CREATE APPOINTMENT REQUEST; APR 9, 2024
 ;;5.3;Scheduling;**869,871,875,877**;Aug 13, 1993;Build 14
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 ;External References
 ;-------------------
 ; Reference to $$ACTIVPRV^PXAPI is supported by IA #2349
 ; Reference to $$ACTIVE^XUSER is supported by IA #2343
 Q
 ; RPC: SDES2 CREATE APPT REQ
 ;
 ; SDCONTEXT INPUT
 ;
 ;S SDCONTEXT("ACHERON AUDIT ID") = Up to 40 Character unique ID number. Ex: 11d9dcc6-c6a2-4785-8031-8261576fca37
 ;S SDCONTEXT("USER DUZ") = The DUZ of the user taking action in the calling application.
 ;S SDCONTEXT("USER SECID") = The SECID of the user taking action in the calling application.
 ;S SDCONTEXT("PATIENT DFN") = The DFN/IEN of the target patient from the calling application.
 ;S SDCONTEXT("PATIENT ICN") = The ICN of the target patient from the calling application.
 ;
 ; REQUEST INPUT FORMAT
 ;
 ;S REQUEST("DFN")=""                                       REQ (PATIENT IEN)
 ;S REQUEST("APPOINTMENT TYPE")=""                          REQ - APPOINTMENT TYPE - can be the Name or IEN
 ;S REQUEST("PATIENT INDICATED DATE")=""                    REQ (PID DATE IN ISO FORMAT)
 ;S REQUEST("PRIORITY")=""                                  REQ
 ;S REQUEST("REQUEST SUB TYPE")=""                          REQ
 ;S REQUEST("REQUESTED BY")=""                              REQ
 ;S REQUEST("CLINIC IEN")=""                                OPT/REQ  \
 ;S REQUEST("PRIMARY AMIS")=""                              OPT/REQ---> Either CLINIC IEN or PRIMARY AMIS/CREDIT PRIMARY AMIS must be defined
 ;S REQUEST("CREDIT AMIS")=""                               OPT/REQ  /
 ;S REQUEST("STATION NUMBER")=""                            OPT/REQ -- > Either STATION NUMBER or INSTITUTION NAME is REQUIRED
 ;S REQUEST("INSTITUTION NAME")=""                          OPT/REQ --/
 ;S REQUEST("CREATE DATE")=""                               OPT - Defaults to today if not sent
 ;S REQUEST("PROVIDER IEN")=""                              OPT  (Required if 'REQUESTED BY' is 'PROVIDER')
 ;S REQUEST("PRIORITY GROUP")=""                            OPT
 ;S REQUEST("SERVICE CONNECTED")=""                         OPT  (This is for PRIORITY; 1 OR 0, if passed)
 ;S REQUEST("SERVICE CONNECTED PERCENTAGE")=""              OPT
 ;S REQUEST("MODALITY")=""                                  OPT
 ;S REQUEST("PATIENT STATUS")=""                            OPT
 ;S REQUEST("VAOS GUID")=""                                 OPT
 ;S REQUEST("TIME SENSITIVE")=""                            OPT
 ;S REQUEST("REQUEST COMMENT")=""                           OPT
 ;S REQUEST("PATIENT COMMENT")=""                           OPT
 ;S REQUEST("PATIENT PREFERRED START DATE",1)=""            OPT
 ;S REQUEST("PATIENT PREFERRED END DATE",1)=""              OPT
 ;S REQUEST("PATIENT PREFERRED START DATE",2)=""            OPT
 ;S REQUEST("PATIENT PREFERRED END DATE",2)=""              OPT
 ;S REQUEST("PATIENT PREFERRED START DATE",3)=""            OPT
 ;S REQUEST("PATIENT PREFERRED END DATE",3)=""              OPT
 ;S REQUEST("MRTC","NEEDED")=""                             OPT (YES/NO)
 ;S REQUEST("MRTC","PARENT REQUEST")=""                     OPT
 ;S REQUEST("MRTC","DAYS BETWEEN APPTS")=""                 OPT
 ;S REQUEST("MRTC","HOW MANY NEEDED")=""                    OPT
 ;
CREATEREQUEST(JSONRETURN,SDCONTEXT,REQUEST) ;
 N REQUESTIEN,ERRORS,RETURN,INSTITUTIONIEN,FILEDATA,ORIGUSER
 ;
 D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
 I $D(ERRORS) S ERRORS("Request",1)="" D BUILDJSON^SDES2JSON(.JSONRETURN,.ERRORS) Q
 S ORIGUSER=$S($G(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
 ;
 M FILEDATA=REQUEST
 D VALIDATE(.REQUEST,.FILEDATA,.INSTITUTIONIEN,.ERRORS)
 ;
 I $D(ERRORS) S ERRORS("Request",1)="" D BUILDJSON^SDES2JSON(.JSONRETURN,.ERRORS) Q
 ;
 S REQUESTIEN=$$BUILDER(.FILEDATA,INSTITUTIONIEN,ORIGUSER,$G(SDCONTEXT("ACHERON AUDIT ID")))
 ;
 S RETURN("Request","IEN")=$G(REQUESTIEN)
 ;
 D BUILDJSON^SDES2JSON(.JSONRETURN,.RETURN)
 Q
 ;
VALIDATE(REQUEST,FILEDATA,INSTITUTIONIEN,ERRORS) ;
 N VALRETURN
 ; Validate required fields first, quit if any errors related to required variables
 D VALFILEIEN^SDES2VALUTIL(.VALRETURN,.ERRORS,2,$G(REQUEST("DFN")),1,,1,2)
 ;
 D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,8.7,$G(REQUEST("APPOINTMENT TYPE")),0,,,180)
 S FILEDATA("APPOINTMENT TYPE")=$G(VALRETURN(409.85,8.7,"I"))
 ;
 ; CLINIC VALIDATION - Quit here if validation fails. Clinic is needed for subsequent checks
 ;
 I $G(REQUEST("CLINIC IEN"))'="" D VALFILEIEN^SDES2VALUTIL(.VALRETURN,.ERRORS,44,$G(REQUEST("CLINIC IEN")),1,,,19)
 ;
 I $G(REQUEST("CLINIC IEN"))="",$G(REQUEST("PRIMARY AMIS"))="" D ERRLOG^SDES2JSON(.ERRORS,530)
 ; CLINIC IEN or PRIMARY AMIS is allowed, NOT both
 ;
 I $G(REQUEST("CLINIC IEN"))'="",($G(REQUEST("PRIMARY AMIS"))'=""!($G(REQUEST("CREDIT AMIS"))'="")) D ERRLOG^SDES2JSON(.ERRORS,202)
 ;
 ; cannot have credit amis with no primary amis
 I $G(REQUEST("CREDIT AMIS"))'="",$G(REQUEST("PRIMARY AMIS"))="" D ERRLOG^SDES2JSON(.ERRORS,234)
 I $G(REQUEST("PRIMARY AMIS"))'="" D VALPRIMAMIS(.ERRORS,.REQUEST,.FILEDATA)
 ;
 I $G(REQUEST("CREDIT AMIS"))'="" D VALCREDITAMIS(.ERRORS,.REQUEST,.FILEDATA)
 ;
 I $G(REQUEST("PRIMARY AMIS"))'="",$G(REQUEST("CREDIT AMIS"))'="" D CONDAMISCHECK^SDES2VAL44(.ERRORS,$G(REQUEST("PRIMARY AMIS")),$G(REQUEST("CREDIT AMIS")))
 ;
 S FILEDATA("PATIENT INDICATED DATE")=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(REQUEST("PATIENT INDICATED DATE")),$G(REQUEST("CLINIC IEN")),1,159,160)
 ;
 D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,10,$G(REQUEST("PRIORITY")),1,,457,211)
 I VALRETURN S FILEDATA("PRIORITY")=$G(VALRETURN(409.85,10,"I"))
 ;
 D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,11,$G(REQUEST("REQUESTED BY")),1,,62,198)
 I VALRETURN D
 .S FILEDATA("REQUESTED BY")=$G(VALRETURN(409.85,11,"I"))
 .I $G(FILEDATA("REQUESTED BY"))=1 D  Q
 ..D VALFILEIEN^SDES2VALUTIL(.VALRETURN,.ERRORS,200,$G(REQUEST("PROVIDER IEN")),1,,53,54)
 ..I VALRETURN,('$$ACTIVE^XUSER($G(REQUEST("PROVIDER IEN")))!('$$ACTIVPRV^PXAPI($G(REQUEST("PROVIDER IEN"))))) D ERRLOG^SDES2JSON(.ERRORS,560)
 ;
 D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,4,$G(REQUEST("REQUEST SUB TYPE")),1,,60,61)
 ;
 I $G(REQUEST("CREATE DATE"))="" S FILEDATA("CREATE DATE")=$$FMTISO^SDAMUTDT(DT,$G(REQUEST("CLINIC IEN")))
 S FILEDATA("CREATE DATE")=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(FILEDATA("CREATE DATE")),$G(REQUEST("CLINIC IEN")),,,49)
 ;
 S INSTITUTIONIEN=$$STATIONTOINST(.ERRORS,$G(REQUEST("STATION NUMBER")),$G(REQUEST("INSTITUTION NAME")))
 ;
 ; Validate Optional fields
 I $L($G(REQUEST("MODALITY"))) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,6,$G(REQUEST("MODALITY")),,,,224) Q:'VALRETURN
 .S FILEDATA("MODALITY")=$G(VALRETURN(409.85,6,"I"))
 ;
 I $L($G(REQUEST("PRIORITY GROUP"))) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,10.5,$G(REQUEST("PRIORITY GROUP")),,,,199) Q:'VALRETURN
 .S FILEDATA("PRIORITY GROUP")=$G(VALRETURN(409.85,10.5,"I"))
 ;
 I $L($G(REQUEST("SERVICE CONNECTED"))) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,15,$G(REQUEST("SERVICE CONNECTED")),,,,200)
 .S FILEDATA("SERVICE CONNECTED")=$G(VALRETURN(409.85,15,"I"))
 ;
 I $L($G(REQUEST("SERVICE CONNECTED PERCENTAGE"))) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,14,$G(REQUEST("SERVICE CONNECTED PERCENTAGE")),,,,201) Q:'VALRETURN
 .;I $G(FILEDATA("SERVICE CONNECTED"))=0,+$G(REQUEST("SERVICE CONNECTED PERCENTAGE")) D ERRLOG^SDES2JSON(.ERRORS,232)
 ;
 I $L($G(REQUEST("PATIENT STATUS"))) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,.02,$G(REQUEST("PATIENT STATUS")),,,,203) Q:'VALRETURN
 .S FILEDATA("PATIENT STATUS")=$G(VALRETURN(409.85,.02,"I"))
 ;
 I $L($G(REQUEST("REQUEST COMMENT"))) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,25,$G(REQUEST("REQUEST COMMENT")),,,,443)
 ;
 I $L($G(REQUEST("TIME SENSITIVE"))) D
 .D VALFIELD^SDES2VALUTIL(.VALRETURN,.ERRORS,409.85,47,$G(REQUEST("TIME SENSITIVE")))
 .I VALRETURN S FILEDATA("TIME SENSITIVE")=$G(VALRETURN(409.85,47,"I"))
 ;
 I $D(REQUEST("PATIENT PREFERRED START DATE")),$D(REQUEST("PATIENT PREFERRED END DATE")) D VALIDATEDATEPREF(.ERRORS,.REQUEST)
 I $D(REQUEST("MRTC")) D VALIDATEMRTCDATA(.ERRORS,.REQUEST,.FILEDATA)
 I $G(REQUEST("MRTC","PARENT REQUEST")),$G(REQUEST("DFN")) S FILEDATA("MRTC","CHILD SEQUENCE NUMBER")=$$MRTCHILDSEQUENCE($G(REQUEST("MRTC","PARENT REQUEST")),$G(REQUEST("DFN")))
 I $G(REQUEST("MRTC","PARENT REQUEST")) D
 . I $G(FILEDATA("MRTC","CHILD SEQUENCE NUMBER")),$G(FILEDATA("MRTC","CHILD SEQUENCE NUMBER"))>$$GET1^DIQ(409.85,$G(REQUEST("MRTC","PARENT REQUEST")),43,"I") D ERRLOG^SDES2JSON(.ERRORS,544)
 . S FILEDATA("MRTC","ORDER ID")=$$GET1^DIQ(409.85,$G(REQUEST("MRTC","PARENT REQUEST")),46,"I")
 Q
 ;
BUILDER(REQUEST,INSTITUTIONIEN,ORIGUSER,EAS) ;
 N FDA,RETURNIEN
 S FDA(409.85,"+1,",.01)=$G(REQUEST("DFN"))
 S FDA(409.85,"+1,",.02)=$G(REQUEST("PATIENT STATUS"))
 S FDA(409.85,"+1,",1)=$G(REQUEST("CREATE DATE"))
 S FDA(409.85,"+1,",2)=$G(INSTITUTIONIEN)
 S FDA(409.85,"+1,",4)=$G(REQUEST("REQUEST SUB TYPE"))
 S FDA(409.85,"+1,",5)=$G(REQUEST("VAOS GUID"))
 S FDA(409.85,"+1,",6)=$G(REQUEST("MODALITY"))
 S FDA(409.85,"+1,",8)=$G(REQUEST("CLINIC IEN"))
 S FDA(409.85,"+1,",8.5)=$G(REQUEST("PRIMARY AMIS"))
 S FDA(409.85,"+1,",8.6)=$G(REQUEST("CREDIT AMIS"))
 S FDA(409.85,"+1,",8.7)=$G(REQUEST("APPOINTMENT TYPE"))
 S FDA(409.85,"+1,",9)=$G(ORIGUSER)
 S FDA(409.85,"+1,",9.5)=$$NOW^XLFDT
 S FDA(409.85,"+1,",10)=$G(REQUEST("PRIORITY"))
 S FDA(409.85,"+1,",10.5)=$G(REQUEST("PRIORITY GROUP"))
 S FDA(409.85,"+1,",11)=$G(REQUEST("REQUESTED BY"))
 S FDA(409.85,"+1,",12)=$G(REQUEST("PROVIDER IEN"))
 S FDA(409.85,"+1,",14)=$G(REQUEST("SERVICE CONNECTED PERCENTAGE"))
 S FDA(409.85,"+1,",15)=$G(REQUEST("SERVICE CONNECTED"))
 S FDA(409.85,"+1,",22)=$G(REQUEST("PATIENT INDICATED DATE"))
 S FDA(409.85,"+1,",23)="O"
 S FDA(409.85,"+1,",25)=$G(REQUEST("REQUEST COMMENT"))
 S FDA(409.85,"+1,",41)=$G(REQUEST("MRTC","NEEDED"))
 S FDA(409.85,"+1,",42)=$G(REQUEST("MRTC","DAYS BETWEEN APPTS"))
 S FDA(409.85,"+1,",43)=$G(REQUEST("MRTC","HOW MANY NEEDED"))
 S FDA(409.85,"+1,",43.1)=$G(REQUEST("MRTC","CHILD SEQUENCE NUMBER"))
 S FDA(409.85,"+1,",43.8)=$G(REQUEST("MRTC","PARENT REQUEST"))
 S FDA(409.85,"+1,",46)=$G(REQUEST("MRTC","ORDER ID"))
 S FDA(409.85,"+1,",47)=$S($G(REQUEST("TIME SENSITIVE"))'="":$G(REQUEST("TIME SENSITIVE")),1:0)
 S FDA(409.85,"+1,",49)=$G(REQUEST("PID CHANGE ALLOWED"))
 S FDA(409.85,"+1,",100)=$G(EAS)
 ;
 D UPDATE^DIE("","FDA","RETURNIEN") K FDA
 S REQUESTIEN=$G(RETURNIEN(1))
 ;
 D ADDPIDHISTORY(REQUESTIEN,$G(REQUEST("PATIENT INDICATED DATE")),ORIGUSER)
 ;
 I $G(REQUEST("MRTC","PARENT REQUEST"))'=""&($G(REQUESTIEN)'="") D ADDMRTCMULT(REQUESTIEN,REQUEST("MRTC","PARENT REQUEST"),REQUEST("PATIENT INDICATED DATE"))
 ;
 I ($D(REQUEST("PATIENT COMMENT")))!($D(REQUEST("PATIENT PREFERRED START DATE"))) D BUILDCOMMENTS(.REQUEST,REQUESTIEN)
 ;
 D AUDIT(REQUESTIEN,$G(REQUEST("CLINIC IEN")),$G(REQUEST("PRIMARY AMIS")),ORIGUSER)
 ;
 Q REQUESTIEN
 ;
ADDPIDHISTORY(REQUESTIEN,PID,USER) ;
 N PIDFDA,FDA,OLDPID,PARENTIEN
 ;
 I PID=$$GET1^DIQ(409.854,$O(^SDEC(409.85,REQUESTIEN,10,"A"),-1)_","_REQUESTIEN_",",1,"I") Q
 ;
 S PIDFDA(409.854,"+1,"_REQUESTIEN_",",.01)=$$NOW^XLFDT
 S PIDFDA(409.854,"+1,"_REQUESTIEN_",",1)=PID
 S PIDFDA(409.854,"+1,"_REQUESTIEN_",",2)=$$GET1^DIQ(200,$G(USER),.01,"E")
 D UPDATE^DIE(,"PIDFDA") K PIDFDA
 ;
 S OLDPID=$$GET1^DIQ(409.85,REQUESTIEN_",",22,"I")
 S PARENTIEN=$$GET1^DIQ(409.85,REQUESTIEN_",",43.8,"I")
 ;
 S FDA(409.85,REQUESTIEN_",",22)=PID
 D FILE^DIE(,"FDA") K FDA
 ;
 I PARENTIEN,$D(^SDEC(409.85,PARENTIEN)) D
 . N PREFIEN S PREFIEN=$O(^SDEC(409.85,PARENTIEN,5,"B",OLDPID,0))
 . S FDA(409.851,PREFIEN_","_PARENTIEN_",",.01)=PID
 . D FILE^DIE(,"FDA") K FDA
 Q
 ;
ADDMRTCMULT(CHILD,PARENT,PATIENTINDDATE) ;Update the MRTC subfiles
 D ADDMRTCLINKS(CHILD,PARENT)
 D ADDMRTCPIDLINKS(PARENT,PATIENTINDDATE)
 Q
 ;
 N FDA
 Q:$O(^SDEC(409.85,PARENT,2,"B",CHILD))
 S FDA(409.852,"+1,"_PARENT_",",.01)=CHILD
 D UPDATE^DIE(,"FDA") K FDA
 Q
 ;
 N SDFDA
 Q:$O(^SDEC(409.85,PARENT,5,"B",PATIENTINDDATE,0))
 S SDFDA(409.851,"+1,"_PARENT_",",.01)=PATIENTINDDATE
 D UPDATE^DIE("","SDFDA") K SDFDA
 Q
 ;
MRTCHILDSEQUENCE(PARENTREQUESTIEN,DFN) ; return next sequence # for child mrtc
 N COUNT,REQUESTIEN,IENS,NEXTSEQUENCENUM,CHILD,LASTCHILD
 S REQUESTIEN=0,COUNT=0,LASTCHILD=""
 F  S REQUESTIEN=$O(^SDEC(409.85,"B",DFN,REQUESTIEN)) Q:'REQUESTIEN  D
 .I $$GET1^DIQ(409.85,REQUESTIEN,43.8,"I")=PARENTREQUESTIEN D
 ..S COUNT=COUNT+1
 ..S CHILD(REQUESTIEN)=COUNT
 I $D(CHILD) D
 .S LASTCHILD=$O(CHILD(LASTCHILD),-1)
 .S NEXTSEQUENCENUM=$G(CHILD($G(LASTCHILD)))+1
 I '$D(CHILD) S NEXTSEQUENCENUM=1
 Q NEXTSEQUENCENUM
 ;
AUDIT(REQUESTIEN,CLINICIEN,STOPCODE,ORIGUSER) ;
 N FDA
 S FDA(409.8545,"+1,"_REQUESTIEN_",",.01)=$$NOW^XLFDT
 S FDA(409.8545,"+1,"_REQUESTIEN_",",1)=$G(ORIGUSER)
 S FDA(409.8545,"+1,"_REQUESTIEN_",",2)=$G(CLINICIEN)
 S FDA(409.8545,"+1,"_REQUESTIEN_",",3)=$G(STOPCODE)
 D UPDATE^DIE("","FDA") K FDA
 Q
BUILDCOMMENTS(REQUEST,REQUESTIEN) ;
 N REQCOMMS,NUM,NUM2,DONE,PREFDATES,PATCOMMS,RANGE,COUNT
 S NUM=0
 ;
 I $D(REQUEST("PATIENT COMMENT")) D
 .D WP^SDECUTL(.PATCOMMS,$G(REQUEST("PATIENT COMMENT")))
 .D WP^DIE(409.85,REQUESTIEN_",",60,"","PATCOMMS")
 ;
 I '$G(REQUEST("PATIENT PREFERRED START DATE",1)) Q
 ;
 S NUM=0,COUNT="",COUNT=$O(REQUEST("PATIENT PREFERRED START DATE",COUNT),-1)
 F NUM=1:1:COUNT D
 .S STARTDATE=$G(REQUEST("PATIENT PREFERRED START DATE",NUM))
 .S ENDDATE=$G(REQUEST("PATIENT PREFERRED END DATE",NUM))
 .S STARTDATE=$$ISOTFM^SDAMUTDT(STARTDATE),STARTDATE=$$FMTE^XLFDT(STARTDATE)
 .S ENDDATE=$$ISOTFM^SDAMUTDT(ENDDATE),ENDDATE=$$FMTE^XLFDT(ENDDATE)
 .S RANGE(NUM)="Patient preferred date range #"_NUM_": "_STARTDATE_" to "_ENDDATE
 D WP^DIE(409.85,REQUESTIEN_",",60,"A","RANGE")
 Q
 ;
STATIONTOINST(ERRORS,STATIONNUM,INSTNAME) ;
 N INSTITUTIONIEN
 I STATIONNUM="",INSTNAME="" D ERRLOG^SDES2JSON(.ERRORS,204) Q 0
 I STATIONNUM="",INSTNAME'="" S INSTITUTIONIEN=$$FIND1^DIC(4,"","X",INSTNAME,"B") I 'INSTITUTIONIEN D ERRLOG^SDES2JSON(.ERRORS,205) Q 0
 I STATIONNUM'="" S INSTITUTIONIEN=$$FIND1^DIC(4,"","X",STATIONNUM,"D") I 'INSTITUTIONIEN D ERRLOG^SDES2JSON(.ERRORS,197) Q 0
 Q INSTITUTIONIEN
 ;
VALPRIMAMIS(ERRORS,REQUEST,FDATA) ; PRIMARY AMIS STOP CODE
 N SDPRIMAMIS,SDAMISERROR
 S SDPRIMAMIS=$G(REQUEST("PRIMARY AMIS"))
 S SDAMISERROR=$$VALIDATEAMIS^SDES2UTIL(.SDPRIMAMIS,"P")
 I SDAMISERROR D ERRLOG^SDES2JSON(.ERRORS,SDAMISERROR) Q
 S FDATA("PRIMARY AMIS")=SDPRIMAMIS
 Q
 ;
VALCREDITAMIS(ERRORS,REQUEST,FDATA) ; CREDIT AMIS STOP CODE
 N SDCREDITAMIS,SDAMISERROR
 S SDCREDITAMIS=$G(REQUEST("CREDIT AMIS"))
 S SDAMISERROR=$$VALIDATEAMIS^SDES2UTIL(.SDCREDITAMIS,"C")
 I SDAMISERROR D ERRLOG^SDES2JSON(.ERRORS,SDAMISERROR) Q
 S FDATA("CREDIT AMIS")=SDCREDITAMIS
 Q
 ;
VALIDATEDATEPREF(ERRORS,REQUEST) ;
 N ARYIEN,ARYIEN2,DATE,ERR,STARTDATE,ENDDATE
 S ARYIEN=0,ERR=0
 F  S ARYIEN=$O(REQUEST("PATIENT PREFERRED START DATE",ARYIEN)) Q:'ARYIEN!($G(ERR))  D
 .S STARTDATE=$G(REQUEST("PATIENT PREFERRED START DATE",ARYIEN))
 .S STARTDATE=$$ISOTFM^SDAMUTDT(STARTDATE)
 .I STARTDATE=-1!($L(STARTDATE,".")=1) S ERR=1 D ERRLOG^SDES2JSON(.ERRORS,206) Q
 .S ENDDATE=$G(REQUEST("PATIENT PREFERRED END DATE",ARYIEN))
 .S ENDDATE=$$ISOTFM^SDAMUTDT(ENDDATE)
 .I ENDDATE=-1!($L(ENDDATE,".")=1) S ERR=1 D ERRLOG^SDES2JSON(.ERRORS,206) Q
 .I ENDDATE<STARTDATE D ERRLOG^SDES2JSON(.ERRORS,29,"Start Date:"_STARTDATE_" - End Date: "_ENDDATE)
 I $G(REQUEST("PATIENT PREFERRED START DATE",1)),'$G(REQUEST("PATIENT PREFERRED END DATE",1)) D ERRLOG^SDES2JSON(.ERRORS,195) Q
 I $G(REQUEST("PATIENT PREFERRED START DATE",2)),'$G(REQUEST("PATIENT PREFERRED END DATE",2)) D ERRLOG^SDES2JSON(.ERRORS,195) Q
 I $G(REQUEST("PATIENT PREFERRED START DATE",3)),'$G(REQUEST("PATIENT PREFERRED END DATE",3)) D ERRLOG^SDES2JSON(.ERRORS,195) Q
 I '$G(REQUEST("PATIENT PREFERRED START DATE",1)),$G(REQUEST("PATIENT PREFERRED END DATE",1)) D ERRLOG^SDES2JSON(.ERRORS,195) Q
 I '$G(REQUEST("PATIENT PREFERRED START DATE",2)),$G(REQUEST("PATIENT PREFERRED END DATE",2)) D ERRLOG^SDES2JSON(.ERRORS,195) Q
 I '$G(REQUEST("PATIENT PREFERRED START DATE",3)),$G(REQUEST("PATIENT PREFERRED END DATE",3)) D ERRLOG^SDES2JSON(.ERRORS,195) Q
 Q
 ;
VALIDATEMRTCDATA(ERRORS,REQUEST,FILEDATA) ;
 N VRET
 D VALFIELD^SDES2VALUTIL(.VRET,.ERRORS,409.85,41,$G(REQUEST("MRTC","NEEDED")),1,,539,208)
 S FILEDATA("MRTC","NEEDED")=$G(VRET(409.85,41,"I"))
 ; if this is not an mrtc, check for other mrtc fields and quit
 I $G(FILEDATA("MRTC","NEEDED"))=0 D  Q
 .I $D(REQUEST("MRTC","PARENT REQUEST"))!($D(REQUEST("MRTC","DAYS BETWEEN APPTS")))!(($D(REQUEST("MRTC","HOW MANY NEEDED")))) D ERRLOG^SDES2JSON(.ERRORS,233)
 ; if this is an MRTC, validate fields as required
 I $G(REQUEST("MRTC","PARENT REQUEST"))'="" D
 .D VALFILEIEN^SDES2VALUTIL(.VRET,.ERRORS,409.85,$G(REQUEST("MRTC","PARENT REQUEST")),1,,536,207)
 .I VRET D
 ..I $$GET1^DIQ(409.85,$G(REQUEST("MRTC","PARENT REQUEST")),.01,"I")'=$G(REQUEST("DFN")) D ERRLOG^SDES2JSON(.ERRORS,533)
 ..I $$GET1^DIQ(409.85,$G(REQUEST("MRTC","PARENT REQUEST")),42,"I")'=$G(REQUEST("MRTC","DAYS BETWEEN APPTS")) D ERRLOG^SDES2JSON(.ERRORS,52,"DAYS BETWEEN does not match parent.")
 ..I $$GET1^DIQ(409.85,$G(REQUEST("MRTC","PARENT REQUEST")),43,"I")'=$G(REQUEST("MRTC","HOW MANY NEEDED")) D ERRLOG^SDES2JSON(.ERRORS,52,"HOW MANY NEEDED does not match parent.")
 D VALFIELD^SDES2VALUTIL(.VRET,.ERRORS,409.85,42,$G(REQUEST("MRTC","DAYS BETWEEN APPTS")),1,,537,209)
 D VALFIELD^SDES2VALUTIL(.VRET,.ERRORS,409.85,43,$G(REQUEST("MRTC","HOW MANY NEEDED")),1,,538,210)
 Q