SDES2GETEXPENTRY ;ALB/BLB - SDES2 GET EXPANDED ENTRY ;Sep 25, 2023
;;5.3;Scheduling;**861**;Aug 13, 1993;Build 17
;;Per VHA Directive 6402, this routine should not be modified
Q
;
GETEXPANDEDENTRY(JSON,SDCONTEXT,PATIENTDATA) ;
N RETURN,ERRORS,EXPANDEDENTRY,DFN,APPTIEN,CLINICIEN,VISITFILEIEN
;
D VALIDATE(.ERRORS,PATIENTDATA("APPOINTMENT IEN"),.SDCONTEXT)
I $D(ERRORS) M RETURN=ERRORS S EXPANDEDENTRY("ExpandedEntry",1)="" D BUILDJSON^SDES2JSON(.JSON,.RETURN) Q
;
D POPULATE(.PATIENTDATA,.DFN,.APPTIEN,.CLINICIEN,.VISITFILEIEN)
;
D GETDIAGNOSIS(.EXPANDEDENTRY,VISITFILEIEN)
D GETSTOPCODES(.EXPANDEDENTRY,CLINICIEN)
D GETPROVIDERS(.EXPANDEDENTRY,VISITFILEIEN)
D GETPROCEDURES(.EXPANDEDENTRY,VISITFILEIEN)
D GETPATIENTCLASS(.EXPANDEDENTRY,APPTIEN)
;
I '$D(EXPANDEDENTRY) S EXPANDEDENTRY("Expandedentry",1)=""
M RETURN=EXPANDEDENTRY D BUILDJSON^SDES2JSON(.JSON,.RETURN)
Q
;
POPULATE(PATIENTDATA,DFN,APPTIEN,CLINICIEN,VISITFILEIEN) ;
N ENCOUNTERIEN
S APPTIEN=PATIENTDATA("APPOINTMENT IEN")
S DFN=$$GET1^DIQ(409.84,APPTIEN,.05,"I")
S CLINICIEN=$$GET1^DIQ(409.831,$$GET1^DIQ(409.84,APPTIEN,.07,"I"),.04,"I")
S ENCOUNTERIEN=$$GETAPT^SDVSIT2(DFN,$$GET1^DIQ(409.84,APPTIEN,.01,"I"),CLINICIEN)
S VISITFILEIEN=$$GET1^DIQ(409.68,ENCOUNTERIEN,.05,"I")
Q
;
GETDIAGNOSIS(EXPANDEDENTRY,VISITFILEIEN) ;
N PURPOSOFVISITIEN,COUNT
;
S PURPOSOFVISITIEN=0,COUNT=0
F S PURPOSOFVISITIEN=$O(^AUPNVPOV("AD",VISITFILEIEN,PURPOSOFVISITIEN)) Q:'PURPOSOFVISITIEN D
.S COUNT=COUNT+1
.S EXPANDEDENTRY("ExpandedEntry","ICDDiagnosisCode",COUNT)=$$GET1^DIQ(9000010.07,PURPOSOFVISITIEN,.01,"E")
.S EXPANDEDENTRY("ExpandedEntry","Diagnosis",COUNT)=$$GET1^DIQ(9000010.07,PURPOSOFVISITIEN,.04,"E")
I '$D(EXPANDEDENTRY("ExpandedEntry","ICDDiagnosisCode")) S EXPANDEDENTRY("ExpandedEntry","ICDDiagnosisCode")=""
I '$D(EXPANDEDENTRY("ExpandedEntry","Diagnosis")) S EXPANDEDENTRY("ExpandedEntry","Diagnosis",1)=""
Q
;
GETSTOPCODES(EXPANDEDENTRY,CLINICIEN) ;
S EXPANDEDENTRY("ExpandedEntry","StopCode","AmisStopCodeNumber")=$$GET1^DIQ(40.7,$$GET1^DIQ(44,CLINICIEN,8,"I"),1)
S EXPANDEDENTRY("ExpandedEntry","StopCode","AmisStopCodeName")=$$GET1^DIQ(44,CLINICIEN,8,"E")
S EXPANDEDENTRY("ExpandedEntry","StopCode","CreditStopCodeName")=$$GET1^DIQ(44,CLINICIEN,2503,"E")
S EXPANDEDENTRY("ExpandedEntry","StopCode","CreditStopCodeNumber")=$$GET1^DIQ(40.7,$$GET1^DIQ(44,CLINICIEN,2503,"I"),1,"I")
I '$D(EXPANDEDENTRY("ExpandedEntry","StopCode")) S EXPANDEDENTRY("ExpandedEntry","StopCode")=""
Q
;
GETPROVIDERS(EXPANDEDENTRY,VISITFILEIEN) ;
N VISITPROVIDERIEN,COUNT
;
S VISITPROVIDERIEN=0,COUNT=0
F S VISITPROVIDERIEN=$O(^AUPNVPRV("AD",VISITFILEIEN,VISITPROVIDERIEN)) Q:'VISITPROVIDERIEN D
.S COUNT=COUNT+1
.S EXPANDEDENTRY("ExpandedEntry","Provider",COUNT)=$$GET1^DIQ(9000010.06,VISITPROVIDERIEN,.01,"E")
I '$D(EXPANDEDENTRY("ExpandedEntry","Provider")) S EXPANDEDENTRY("ExpandedEntry","Provider",1)=""
Q
;
GETPROCEDURES(EXPANDEDENTRY,VISITFILEIEN) ;
N PROCEDUREIEN,MODIFIERIEN,COUNT,COUNT2
;
S PROCEDUREIEN=0,COUNT=0
F S PROCEDUREIEN=$O(^AUPNVCPT("AD",VISITFILEIEN,PROCEDUREIEN)) Q:'PROCEDUREIEN D
.S COUNT=COUNT+1
.S EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",COUNT,"ClinicalProcedureCode")=$$GET1^DIQ(9000010.18,PROCEDUREIEN,.01,"I")
.S EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",COUNT,"NumberOfTimesProcedurePerformed")=$$GET1^DIQ(9000010.18,PROCEDUREIEN,.16,"I")
.S EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",COUNT,"ProviderNarrative")=$$GET1^DIQ(9000010.18,PROCEDUREIEN,.04,"E")
.;
.S MODIFIERIEN=0,COUNT2=0
.F S MODIFIERIEN=$O(^AUPNVCPT(PROCEDUREIEN,1,MODIFIERIEN)) Q:'MODIFIERIEN D
..S COUNT2=COUNT2+1
..S EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",COUNT,"ClinicalProcedureModifierCode",COUNT2)=$$GET1^DIQ(81.3,$$GET1^DIQ(9000010.181,MODIFIERIEN_","_PROCEDUREIEN_",",.01,"I"),.01,"I")
..S EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",COUNT,"ClinicalProcedureModifier",COUNT2)=$$GET1^DIQ(81.3,$$GET1^DIQ(9000010.181,MODIFIERIEN_","_PROCEDUREIEN_",",.01,"I"),.02,"I")
I '$D(EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure")) S EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",1)=""
Q
;
GETPATIENTCLASS(EXPANDEDENTRY,APPTIEN) ;
N CLASSNAME,CLASSTYPEIEN,CLASSIEN,OUTPENCOUNTERIEN
;
S OUTPENCOUNTERIEN=$$GET1^DIQ(2.98,$$GET1^DIQ(409.84,APPTIEN,.01,"I")_","_$$GET1^DIQ(409.84,APPTIEN,.05,"I")_",",21,"I")
S CLASSNAME=""
F S CLASSNAME=$O(^SD(409.41,"B",CLASSNAME)) Q:CLASSNAME="" D
.S CLASSTYPEIEN=0
.F S CLASSTYPEIEN=$O(^SD(409.41,"B",CLASSNAME,CLASSTYPEIEN)) Q:'CLASSTYPEIEN D
..S EXPANDEDENTRY("ExpandedEntry","PatientClassification",CLASSTYPEIEN,"ClassificationName")=CLASSNAME
..;
..I $D(^SDD(409.42,"AO",OUTPENCOUNTERIEN,CLASSTYPEIEN)) D Q
...S CLASSIEN=0,CLASSIEN=$O(^SDD(409.42,"AO",OUTPENCOUNTERIEN,CLASSTYPEIEN,CLASSIEN))
...S EXPANDEDENTRY("ExpandedEntry","PatientClassification",CLASSTYPEIEN,"IsClassificationActive")=$$GET1^DIQ(409.42,CLASSIEN,.03,"E")
..;
..S EXPANDEDENTRY("ExpandedEntry","PatientClassification",CLASSTYPEIEN,"IsClassificationActive")="NO"
Q
;
VALIDATE(ERRORS,APPTIEN,SDCONTEXT) ;
N VALRETURN
D VALFILEIEN^SDES2VALUTIL(.VALRETURN,.ERRORS,409.84,APPTIEN,1,,14,15) ;
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDES2GETEXPENTRY 5346 printed Dec 13, 2024@02:54:01 Page 2
SDES2GETEXPENTRY ;ALB/BLB - SDES2 GET EXPANDED ENTRY ;Sep 25, 2023
+1 ;;5.3;Scheduling;**861**;Aug 13, 1993;Build 17
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 QUIT
+4 ;
GETEXPANDEDENTRY(JSON,SDCONTEXT,PATIENTDATA) ;
+1 NEW RETURN,ERRORS,EXPANDEDENTRY,DFN,APPTIEN,CLINICIEN,VISITFILEIEN
+2 ;
+3 DO VALIDATE(.ERRORS,PATIENTDATA("APPOINTMENT IEN"),.SDCONTEXT)
+4 IF $DATA(ERRORS)
MERGE RETURN=ERRORS
SET EXPANDEDENTRY("ExpandedEntry",1)=""
DO BUILDJSON^SDES2JSON(.JSON,.RETURN)
QUIT
+5 ;
+6 DO POPULATE(.PATIENTDATA,.DFN,.APPTIEN,.CLINICIEN,.VISITFILEIEN)
+7 ;
+8 DO GETDIAGNOSIS(.EXPANDEDENTRY,VISITFILEIEN)
+9 DO GETSTOPCODES(.EXPANDEDENTRY,CLINICIEN)
+10 DO GETPROVIDERS(.EXPANDEDENTRY,VISITFILEIEN)
+11 DO GETPROCEDURES(.EXPANDEDENTRY,VISITFILEIEN)
+12 DO GETPATIENTCLASS(.EXPANDEDENTRY,APPTIEN)
+13 ;
+14 IF '$DATA(EXPANDEDENTRY)
SET EXPANDEDENTRY("Expandedentry",1)=""
+15 MERGE RETURN=EXPANDEDENTRY
DO BUILDJSON^SDES2JSON(.JSON,.RETURN)
+16 QUIT
+17 ;
POPULATE(PATIENTDATA,DFN,APPTIEN,CLINICIEN,VISITFILEIEN) ;
+1 NEW ENCOUNTERIEN
+2 SET APPTIEN=PATIENTDATA("APPOINTMENT IEN")
+3 SET DFN=$$GET1^DIQ(409.84,APPTIEN,.05,"I")
+4 SET CLINICIEN=$$GET1^DIQ(409.831,$$GET1^DIQ(409.84,APPTIEN,.07,"I"),.04,"I")
+5 SET ENCOUNTERIEN=$$GETAPT^SDVSIT2(DFN,$$GET1^DIQ(409.84,APPTIEN,.01,"I"),CLINICIEN)
+6 SET VISITFILEIEN=$$GET1^DIQ(409.68,ENCOUNTERIEN,.05,"I")
+7 QUIT
+8 ;
GETDIAGNOSIS(EXPANDEDENTRY,VISITFILEIEN) ;
+1 NEW PURPOSOFVISITIEN,COUNT
+2 ;
+3 SET PURPOSOFVISITIEN=0
SET COUNT=0
+4 FOR
SET PURPOSOFVISITIEN=$ORDER(^AUPNVPOV("AD",VISITFILEIEN,PURPOSOFVISITIEN))
if 'PURPOSOFVISITIEN
QUIT
Begin DoDot:1
+5 SET COUNT=COUNT+1
+6 SET EXPANDEDENTRY("ExpandedEntry","ICDDiagnosisCode",COUNT)=$$GET1^DIQ(9000010.07,PURPOSOFVISITIEN,.01,"E")
+7 SET EXPANDEDENTRY("ExpandedEntry","Diagnosis",COUNT)=$$GET1^DIQ(9000010.07,PURPOSOFVISITIEN,.04,"E")
End DoDot:1
+8 IF '$DATA(EXPANDEDENTRY("ExpandedEntry","ICDDiagnosisCode"))
SET EXPANDEDENTRY("ExpandedEntry","ICDDiagnosisCode")=""
+9 IF '$DATA(EXPANDEDENTRY("ExpandedEntry","Diagnosis"))
SET EXPANDEDENTRY("ExpandedEntry","Diagnosis",1)=""
+10 QUIT
+11 ;
GETSTOPCODES(EXPANDEDENTRY,CLINICIEN) ;
+1 SET EXPANDEDENTRY("ExpandedEntry","StopCode","AmisStopCodeNumber")=$$GET1^DIQ(40.7,$$GET1^DIQ(44,CLINICIEN,8,"I"),1)
+2 SET EXPANDEDENTRY("ExpandedEntry","StopCode","AmisStopCodeName")=$$GET1^DIQ(44,CLINICIEN,8,"E")
+3 SET EXPANDEDENTRY("ExpandedEntry","StopCode","CreditStopCodeName")=$$GET1^DIQ(44,CLINICIEN,2503,"E")
+4 SET EXPANDEDENTRY("ExpandedEntry","StopCode","CreditStopCodeNumber")=$$GET1^DIQ(40.7,$$GET1^DIQ(44,CLINICIEN,2503,"I"),1,"I")
+5 IF '$DATA(EXPANDEDENTRY("ExpandedEntry","StopCode"))
SET EXPANDEDENTRY("ExpandedEntry","StopCode")=""
+6 QUIT
+7 ;
GETPROVIDERS(EXPANDEDENTRY,VISITFILEIEN) ;
+1 NEW VISITPROVIDERIEN,COUNT
+2 ;
+3 SET VISITPROVIDERIEN=0
SET COUNT=0
+4 FOR
SET VISITPROVIDERIEN=$ORDER(^AUPNVPRV("AD",VISITFILEIEN,VISITPROVIDERIEN))
if 'VISITPROVIDERIEN
QUIT
Begin DoDot:1
+5 SET COUNT=COUNT+1
+6 SET EXPANDEDENTRY("ExpandedEntry","Provider",COUNT)=$$GET1^DIQ(9000010.06,VISITPROVIDERIEN,.01,"E")
End DoDot:1
+7 IF '$DATA(EXPANDEDENTRY("ExpandedEntry","Provider"))
SET EXPANDEDENTRY("ExpandedEntry","Provider",1)=""
+8 QUIT
+9 ;
GETPROCEDURES(EXPANDEDENTRY,VISITFILEIEN) ;
+1 NEW PROCEDUREIEN,MODIFIERIEN,COUNT,COUNT2
+2 ;
+3 SET PROCEDUREIEN=0
SET COUNT=0
+4 FOR
SET PROCEDUREIEN=$ORDER(^AUPNVCPT("AD",VISITFILEIEN,PROCEDUREIEN))
if 'PROCEDUREIEN
QUIT
Begin DoDot:1
+5 SET COUNT=COUNT+1
+6 SET EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",COUNT,"ClinicalProcedureCode")=$$GET1^DIQ(9000010.18,PROCEDUREIEN,.01,"I")
+7 SET EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",COUNT,"NumberOfTimesProcedurePerformed")=$$GET1^DIQ(9000010.18,PROCEDUREIEN,.16,"I")
+8 SET EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",COUNT,"ProviderNarrative")=$$GET1^DIQ(9000010.18,PROCEDUREIEN,.04,"E")
+9 ;
+10 SET MODIFIERIEN=0
SET COUNT2=0
+11 FOR
SET MODIFIERIEN=$ORDER(^AUPNVCPT(PROCEDUREIEN,1,MODIFIERIEN))
if 'MODIFIERIEN
QUIT
Begin DoDot:2
+12 SET COUNT2=COUNT2+1
+13 SET EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",COUNT,"ClinicalProcedureModifierCode",COUNT2)=$$GET1^DIQ(81.3,$$GET1^DIQ(9000010.181,MODIFIERIEN_","_PROCEDUREIEN_",",.01,"I"),.01,"I")
+14 SET EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",COUNT,"ClinicalProcedureModifier",COUNT2)=$$GET1^DIQ(81.3,$$GET1^DIQ(9000010.181,MODIFIERIEN_","_PROCEDUREIEN_",",.01,"I"),.02,"I")
End DoDot:2
End DoDot:1
+15 IF '$DATA(EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure"))
SET EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",1)=""
+16 QUIT
+17 ;
GETPATIENTCLASS(EXPANDEDENTRY,APPTIEN) ;
+1 NEW CLASSNAME,CLASSTYPEIEN,CLASSIEN,OUTPENCOUNTERIEN
+2 ;
+3 SET OUTPENCOUNTERIEN=$$GET1^DIQ(2.98,$$GET1^DIQ(409.84,APPTIEN,.01,"I")_","_$$GET1^DIQ(409.84,APPTIEN,.05,"I")_",",21,"I")
+4 SET CLASSNAME=""
+5 FOR
SET CLASSNAME=$ORDER(^SD(409.41,"B",CLASSNAME))
if CLASSNAME=""
QUIT
Begin DoDot:1
+6 SET CLASSTYPEIEN=0
+7 FOR
SET CLASSTYPEIEN=$ORDER(^SD(409.41,"B",CLASSNAME,CLASSTYPEIEN))
if 'CLASSTYPEIEN
QUIT
Begin DoDot:2
+8 SET EXPANDEDENTRY("ExpandedEntry","PatientClassification",CLASSTYPEIEN,"ClassificationName")=CLASSNAME
+9 ;
+10 IF $DATA(^SDD(409.42,"AO",OUTPENCOUNTERIEN,CLASSTYPEIEN))
Begin DoDot:3
+11 SET CLASSIEN=0
SET CLASSIEN=$ORDER(^SDD(409.42,"AO",OUTPENCOUNTERIEN,CLASSTYPEIEN,CLASSIEN))
+12 SET EXPANDEDENTRY("ExpandedEntry","PatientClassification",CLASSTYPEIEN,"IsClassificationActive")=$$GET1^DIQ(409.42,CLASSIEN,.03,"E")
End DoDot:3
QUIT
+13 ;
+14 SET EXPANDEDENTRY("ExpandedEntry","PatientClassification",CLASSTYPEIEN,"IsClassificationActive")="NO"
End DoDot:2
End DoDot:1
+15 QUIT
+16 ;
VALIDATE(ERRORS,APPTIEN,SDCONTEXT) ;
+1 NEW VALRETURN
+2 ;
DO VALFILEIEN^SDES2VALUTIL(.VALRETURN,.ERRORS,409.84,APPTIEN,1,,14,15)
+3 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+4 QUIT
+5 ;