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

SDES2BLDAPPTOBJ.m

Go to the documentation of this file.
SDES2BLDAPPTOBJ ;ALB/LAB,JAS,BWF,LAB,JAS - VISTA SCHEDULING BUILD APPOINTMENT OBJECT ;OCT 3, 2024
 ;;5.3;Scheduling;**871,877,880,893**;Aug 13, 1993;Build 6
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 Q
 ;
BUILDAPPTOBJ(APPTOBJ,APPTIEN,RECCNT,ERRORS,SDDUZ) ;Called from GET APPT RPCs to build appointment object.
 N SDDFN,CLINIEN,CANCELID,SDIEN
 D GET40984INFO(.APPTOBJ,APPTIEN,.SDDFN,.CLINIEN,.CANCELID,RECCNT)
 D GET2INFO^SDES2BLDAPPT2(.APPTOBJ,APPTIEN,SDDFN,RECCNT,SDDUZ)
 D GET298INFO^SDES2BLDAPPT2(.APPTOBJ,APPTIEN,SDDFN,RECCNT,CLINIEN)
 I CLINIEN="" D ERRLOG^SDESJSON(.ERRORS,555,"Appointment IEN "_APPTIEN_". Unable to retrieve Clinic appointment data") Q
 D GET44INFO^SDES2BLDAPPT44(.APPTOBJ,.CLINIEN,RECCNT)
 S SDIEN=$$GET44RECORDIENS(CLINIEN,APPTOBJ("Appointment",RECCNT,"StartTimeFM"),SDDFN,.APPTOBJ)
 I 'SDIEN D BLANK44003INFO^SDES2BLDAPPT44(.APPTOBJ,RECCNT) Q
 D GET44003INFO^SDES2BLDAPPT44(.APPTOBJ,CLINIEN,SDIEN,RECCNT)
 Q
 ;
GET40984INFO(APPTOBJ,APPTIEN,SDDFN,CLINIEN,CANCELID,RECCNT) ;
 N IENS,RESOURCEIEN,APPTDATA,APPTSTATDT,APPREQIEN,APPREQPTR,ORIGAPPTREQTYP,ARRAY40984,SDMSG
 S IENS=APPTIEN_","
 D GETS^DIQ(409.84,IENS,".01;.02;.03;.04;.05;.06;.07;.08;.09;.12;.13;.121;.122;.14;.16;.17;.18;.2;.22;1;2;3;4;100","IE","ARRAY40984","SDMSG")
 S RESOURCEIEN=$G(ARRAY40984(409.84,IENS,.07,"I"))
 S CLINIEN=$$GET1^DIQ(409.831,RESOURCEIEN,.04,"I")
 S SDDFN=$G(ARRAY40984(409.84,IENS,.05,"I"))
 S APPTOBJ("Appointment",RECCNT,"AppointmentDateTime")=$$FMTISO^SDAMUTDT($G(ARRAY40984(409.84,IENS,.01,"I")),CLINIEN)
 S APPTOBJ("Appointment",RECCNT,"AppointmentIEN")=APPTIEN
 S APPTOBJ("Appointment",RECCNT,"AppointmentTypeIEN")=$G(ARRAY40984(409.84,IENS,.06,"I"))
 S APPTOBJ("Appointment",RECCNT,"AppointmentType")=$G(ARRAY40984(409.84,IENS,.06,"E"))
 S APPTOBJ("Appointment",RECCNT,"CancelDateTime")=$$FMTISO^SDAMUTDT($G(ARRAY40984(409.84,IENS,.12,"I")),CLINIEN)
 S APPTOBJ("Appointment",RECCNT,"DateAppointmentMade")=$$FMTISO^SDAMUTDT($G(ARRAY40984(409.84,IENS,.09,"I")))
 S APPTOBJ("Appointment",RECCNT,"CancellationReason")=$G(ARRAY40984(409.84,IENS,.122,"E"))
 S CANCELID=$G(ARRAY40984(409.84,IENS,.121,"I"))
 S:'CANCELID APPTOBJ("Appointment",RECCNT,"CancelledByUser",1)=""
 I CANCELID D
 . S APPTOBJ("Appointment",RECCNT,"CancelledByUser","ID")=$G(ARRAY40984(409.84,IENS,.121,"I"))
 . S APPTOBJ("Appointment",RECCNT,"CancelledByUser","Name")=$G(ARRAY40984(409.84,IENS,.121,"E"))
 . S APPTOBJ("Appointment",RECCNT,"CancelledByUser","SecId")=$$GET1^DIQ(200,CANCELID,205.1,"I")
 S APPTOBJ("Appointment",RECCNT,"CheckIn")=$$FMTISO^SDAMUTDT($G(ARRAY40984(409.84,IENS,.03,"I")),CLINIEN)
 S APPTOBJ("Appointment",RECCNT,"CheckInEntered")=$$FMTISO^SDAMUTDT($G(ARRAY40984(409.84,IENS,.04,"I")))
 S APPTOBJ("Appointment",RECCNT,"CheckOut")=$$FMTISO^SDAMUTDT($G(ARRAY40984(409.84,IENS,.14,"I")),CLINIEN)
 S APPTOBJ("Appointment",RECCNT,"Clinic","ClinicIEN")=CLINIEN
 S APPTSTATDT=$$APPTSTATUS^SDES2GETSTATUS(APPTIEN,CLINIEN)
 S APPTOBJ("Appointment",RECCNT,"CurrentStatus")=$P(APPTSTATDT,U)
 S APPTOBJ("Appointment",RECCNT,"Status")=$P(APPTSTATDT,U)
 S APPTOBJ("Appointment",RECCNT,"DesiredDateOfAppointment")=$$FMTISO^SDAMUTDT($G(ARRAY40984(409.84,IENS,.2,"I")))
 S APPTOBJ("Appointment",RECCNT,"StatusCancelDateTime")=$$FMTISO^SDAMUTDT($P(APPTSTATDT,U,2),CLINIEN)
 S APPTOBJ("Appointment",RECCNT,"EASTrackingNumber")=$G(ARRAY40984(409.84,IENS,100,"I"))
 S APPTOBJ("Appointment",RECCNT,"EndTime")=$$FMTISO^SDAMUTDT($G(ARRAY40984(409.84,IENS,.02,"I")),CLINIEN)
 S APPTOBJ("Appointment",RECCNT,"LengthOfAppt")=$G(ARRAY40984(409.84,IENS,.18,"E"))
 K ARRAY40984(409.84,IENS,1,"I"),ARRAY40984(409.84,IENS,1,"E")
 I $D(ARRAY40984(409.84,IENS,1)) M APPTOBJ("Appointment",RECCNT,"Note")=ARRAY40984(409.84,IENS,1)
 I '$D(APPTOBJ("Appointment",RECCNT,"Note")) S APPTOBJ("Appointment",RECCNT,"Note")=""
 S APPREQIEN=$P($G(ARRAY40984(409.84,IENS,.22,"I")),";")
 S APPREQPTR=$P($G(ARRAY40984(409.84,IENS,.22,"I")),";",2)
 I APPREQPTR[403.5 S ORIGAPPTREQTYP="R"
 I APPREQPTR[123 S ORIGAPPTREQTYP=$$GET1^DIQ(123,APPREQIEN,13,"I")
 I APPREQPTR[409.85 S ORIGAPPTREQTYP=$$GET1^DIQ(409.85,APPREQIEN,4,"I")
 S APPTOBJ("Appointment",RECCNT,"OriginatingRequestType")=$G(ORIGAPPTREQTYP)
 I $G(ARRAY40984(409.84,IENS,.16,"I"))'="" D
 . S APPTOBJ("Appointment",RECCNT,"Provider","ID")=$G(ARRAY40984(409.84,IENS,.16,"I"))
 . S APPTOBJ("Appointment",RECCNT,"Provider","Name")=$G(ARRAY40984(409.84,IENS,.16,"E"))
 . S APPTOBJ("Appointment",RECCNT,"Provider","SecId")=$$GET1^DIQ(200,$G(ARRAY40984(409.84,IENS,.16,"I")),205.1,"I")
 S:($G(ARRAY40984(409.84,IENS,.16,"I"))="") APPTOBJ("Appointment",RECCNT,"Provider",1)=""
 S APPTOBJ("Appointment",RECCNT,"RequestIEN")=APPREQIEN
 S APPTOBJ("Appointment",RECCNT,"RequestType")=$G(ARRAY40984(409.84,IENS,.22,"E"))
 S APPTOBJ("Appointment",RECCNT,"Resource","Name")=$G(ARRAY40984(409.84,IENS,.07,"E"))
 S APPTOBJ("Appointment",RECCNT,"Resource","ClinicIEN")=CLINIEN
 S APPTOBJ("Appointment",RECCNT,"ResourceIEN")=RESOURCEIEN
 S APPTOBJ("Appointment",RECCNT,"StartTimeFM")=$G(ARRAY40984(409.84,IENS,.01,"I"))
 S APPTOBJ("Appointment",RECCNT,"VVSApptID")=$G(ARRAY40984(409.84,IENS,2,"I"))
 S APPTOBJ("Appointment",RECCNT,"Walkin")=$G(ARRAY40984(409.84,IENS,.13,"E"))
 S APPTOBJ("Appointment",RECCNT,"MRTCFlag")=0
 S:((APPREQPTR[409.85)&($$GET1^DIQ(409.85,APPREQIEN,43.8)'="")) APPTOBJ("Appointment",RECCNT,"MRTCFlag")=1
 S APPTOBJ("Appointment",RECCNT,"DataEntryClerk")=$G(ARRAY40984(409.84,IENS,.08,"E"))
 D GETPATCOMMENTS(.APPTOBJ,APPTIEN,RECCNT)
 D CHECKINSTEPS(.APPTOBJ,APPTIEN,RECCNT)
 D GETNOTEAUDIT(.APPTOBJ,APPTIEN,RECCNT)
 Q
 ;
GETPATCOMMENTS(APPTOBJ,APPTIEN,RECCNT) ;
 N SUBIEN,COUNT
 S SUBIEN=0,COUNT=0
 F  S SUBIEN=$O(^SDEC(409.84,APPTIEN,6,SUBIEN)) Q:'SUBIEN  D
 .S COUNT=COUNT+1
 .S APPTOBJ("Appointment",RECCNT,"PatientComments",COUNT)=$$GET1^DIQ(409.846,SUBIEN_","_APPTIEN_",",.01,"E")
 I '$D(APPTOBJ("Appointment",RECCNT,"PatientComments")) S APPTOBJ("Appointment",RECCNT,"PatientComments",1)=""
 Q
 ;
CHECKINSTEPS(APPTOBJ,APPTIEN,RECCNT) ;
 N SDIEN,NUM,DATETIME
 S (SDIEN,NUM)=0
 F  S SDIEN=$O(^SDEC(409.84,APPTIEN,3,SDIEN)) Q:'SDIEN  D
 .S NUM=NUM+1
 .S DATETIME=$$GET1^DIQ(409.843,SDIEN_","_APPTIEN_",",1,"I")
 .S APPTOBJ("Appointment",RECCNT,"CheckInSteps",NUM,"IEN")=SDIEN
 .S APPTOBJ("Appointment",RECCNT,"CheckInSteps",NUM,"Status")=$$GET1^DIQ(409.843,SDIEN_","_APPTIEN_",",.01,"E")
 .S APPTOBJ("Appointment",RECCNT,"CheckInSteps",NUM,"DateTime")=$$FMTISO^SDAMUTDT(DATETIME)
 I '$D(APPTOBJ("Appointment",RECCNT,"CheckInSteps")) S APPTOBJ("Appointment",RECCNT,"CheckInSteps",1)=""
 Q
 ;
GETNOTEAUDIT(APPTOBJ,APPTIEN,RECCNT) ;
 N SUBIEN,COUNT
 S SUBIEN=0,COUNT=0
 F  S SUBIEN=$O(^SDEC(409.84,APPTIEN,"NOTEAUD",SUBIEN)) Q:'SUBIEN  D
 .S COUNT=COUNT+1
 .S APPTOBJ("Appointment",RECCNT,"NoteAuditing",COUNT,"DateNoteAdded")=$$FMTISO^SDAMUTDT($$GET1^DIQ(409.847,SUBIEN_","_APPTIEN_",",.01,"I"))
 .S APPTOBJ("Appointment",RECCNT,"NoteAuditing",COUNT,"NoteAddedByDUZ")=$$GET1^DIQ(409.847,SUBIEN_","_APPTIEN_",",1,"I")
 .S APPTOBJ("Appointment",RECCNT,"NoteAuditing",COUNT,"NoteAddedByName")=$$GET1^DIQ(409.847,SUBIEN_","_APPTIEN_",",1,"E")
 .S APPTOBJ("Appointment",RECCNT,"NoteAuditing",COUNT,"Note")=$$GET1^DIQ(409.847,SUBIEN_","_APPTIEN_",",2,"I")
 I '$D(APPTOBJ("Appointment",RECCNT,"NoteAuditing")) S APPTOBJ("Appointment",RECCNT,"NoteAuditing",1)=""
 Q
 ; 
GET44RECORDIENS(CLINICIEN,APPTSTARTTIME,SDDFN,APPTOBJ) ;
 ;want to process through until we get to the correct appointment for time and clinic
 N FOUND,IENS44003,SUBIEN,APPTCNT,MATCH,CHECKIEN
 S FOUND=0,APPTCNT=0
 S SUBIEN=0 F  S SUBIEN=$O(^SC(CLINICIEN,"S",APPTSTARTTIME,1,SUBIEN)) Q:'SUBIEN!($G(FOUND)=1)  D
 .I $$GET1^DIQ(44.003,SUBIEN_","_APPTSTARTTIME_","_CLINICIEN_",",.01,"I")=SDDFN D
 .. S CHECKIEN=SUBIEN_","_APPTSTARTTIME_","_CLINICIEN_","
 .. S MATCH=$$MATCHAPPOINTMENT(.APPTOBJ,CHECKIEN)
 .. Q:'MATCH
 ..S APPTCNT=APPTCNT+1
 ..S IENS44003=SUBIEN_","_APPTSTARTTIME_","_CLINICIEN_",",FOUND=1 Q
 Q $G(IENS44003)
 ;
MATCHAPPOINTMENT(APPTOBJ,CHECKIEN) ;
 Q:(APPTOBJ("Appointment",RECCNT,"CancelDateTime")="")&($$GET1^DIQ(44.003,CHECKIEN,310,"I")="C") 0
 Q 1
 ;