SDES2GETXPENTRY2 ;ALB/BLB,ANU - SDES2 GET EXPANDED ENTRY 2 ;APR 25, 2024
;;5.3;Scheduling;**867,878**;Aug 13, 1993;Build 11
;;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,$G(PATIENTDATA("APPOINTMENT IEN")),.SDCONTEXT)
I $D(ERRORS) S ERRORS("ExpandedEntry",1)="" D BUILDJSON^SDES2JSON(.JSON,.ERRORS) 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)=""
D BUILDJSON^SDES2JSON(.JSON,.EXPANDEDENTRY)
Q
;
POPULATE(PATIENTDATA,DFN,APPTIEN,CLINICIEN,VISITFILEIEN) ;
N ENCOUNTERIEN
S APPTIEN=$G(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
;
I '$G(VISITFILEIEN) S EXPANDEDENTRY("ExpandedEntry","Diagnosis",1)="" Q
S PURPOSOFVISITIEN=0,COUNT=0
F S PURPOSOFVISITIEN=$O(^AUPNVPOV("AD",VISITFILEIEN,PURPOSOFVISITIEN)) Q:'PURPOSOFVISITIEN D
.S COUNT=COUNT+1
.S EXPANDEDENTRY("ExpandedEntry","Diagnosis",COUNT,"ICDDiagnosisCode")=$$GET1^DIQ(9000010.07,PURPOSOFVISITIEN,.01,"E")
.S EXPANDEDENTRY("ExpandedEntry","Diagnosis",COUNT,"ProviderNarrative")=$$GET1^DIQ(9000010.07,PURPOSOFVISITIEN,.04,"E")
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
;
I '$G(VISITFILEIEN) S EXPANDEDENTRY("ExpandedEntry","Provider",1)="" Q
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
;
I '$G(VISITFILEIEN) S EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",1)="" Q
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,SDISCLACTIVE
;
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
..;
..S SDISCLACTIVE="Not Applicable"
..I $D(^SDD(409.42,"AO",OUTPENCOUNTERIEN,CLASSTYPEIEN)) D
...S CLASSIEN=0,CLASSIEN=+$O(^SDD(409.42,"AO",OUTPENCOUNTERIEN,CLASSTYPEIEN,CLASSIEN))
...S SDISCLACTIVE=$S($$GET1^DIQ(409.42,CLASSIEN,.03,"I")=1:"Yes",$$GET1^DIQ(409.42,CLASSIEN,.03,"I")=0:"No",1:"Not Applicable")
..S EXPANDEDENTRY("ExpandedEntry","PatientClassification",CLASSTYPEIEN,"IsClassificationActive")=SDISCLACTIVE
..;
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[HSDES2GETXPENTRY2 5521 printed Dec 13, 2024@02:54:20 Page 2
SDES2GETXPENTRY2 ;ALB/BLB,ANU - SDES2 GET EXPANDED ENTRY 2 ;APR 25, 2024
+1 ;;5.3;Scheduling;**867,878**;Aug 13, 1993;Build 11
+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,$GET(PATIENTDATA("APPOINTMENT IEN")),.SDCONTEXT)
+4 IF $DATA(ERRORS)
SET ERRORS("ExpandedEntry",1)=""
DO BUILDJSON^SDES2JSON(.JSON,.ERRORS)
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 DO BUILDJSON^SDES2JSON(.JSON,.EXPANDEDENTRY)
+16 QUIT
+17 ;
POPULATE(PATIENTDATA,DFN,APPTIEN,CLINICIEN,VISITFILEIEN) ;
+1 NEW ENCOUNTERIEN
+2 SET APPTIEN=$GET(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 IF '$GET(VISITFILEIEN)
SET EXPANDEDENTRY("ExpandedEntry","Diagnosis",1)=""
QUIT
+4 SET PURPOSOFVISITIEN=0
SET COUNT=0
+5 FOR
SET PURPOSOFVISITIEN=$ORDER(^AUPNVPOV("AD",VISITFILEIEN,PURPOSOFVISITIEN))
if 'PURPOSOFVISITIEN
QUIT
Begin DoDot:1
+6 SET COUNT=COUNT+1
+7 SET EXPANDEDENTRY("ExpandedEntry","Diagnosis",COUNT,"ICDDiagnosisCode")=$$GET1^DIQ(9000010.07,PURPOSOFVISITIEN,.01,"E")
+8 SET EXPANDEDENTRY("ExpandedEntry","Diagnosis",COUNT,"ProviderNarrative")=$$GET1^DIQ(9000010.07,PURPOSOFVISITIEN,.04,"E")
End DoDot:1
+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 IF '$GET(VISITFILEIEN)
SET EXPANDEDENTRY("ExpandedEntry","Provider",1)=""
QUIT
+4 SET VISITPROVIDERIEN=0
SET COUNT=0
+5 FOR
SET VISITPROVIDERIEN=$ORDER(^AUPNVPRV("AD",VISITFILEIEN,VISITPROVIDERIEN))
if 'VISITPROVIDERIEN
QUIT
Begin DoDot:1
+6 SET COUNT=COUNT+1
+7 SET EXPANDEDENTRY("ExpandedEntry","Provider",COUNT)=$$GET1^DIQ(9000010.06,VISITPROVIDERIEN,.01,"E")
End DoDot:1
+8 IF '$DATA(EXPANDEDENTRY("ExpandedEntry","Provider"))
SET EXPANDEDENTRY("ExpandedEntry","Provider",1)=""
+9 QUIT
+10 ;
GETPROCEDURES(EXPANDEDENTRY,VISITFILEIEN) ;
+1 NEW PROCEDUREIEN,MODIFIERIEN,COUNT,COUNT2
+2 ;
+3 IF '$GET(VISITFILEIEN)
SET EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",1)=""
QUIT
+4 SET PROCEDUREIEN=0
SET COUNT=0
+5 FOR
SET PROCEDUREIEN=$ORDER(^AUPNVCPT("AD",VISITFILEIEN,PROCEDUREIEN))
if 'PROCEDUREIEN
QUIT
Begin DoDot:1
+6 SET COUNT=COUNT+1
+7 SET EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",COUNT,"ClinicalProcedureCode")=$$GET1^DIQ(9000010.18,PROCEDUREIEN,.01,"I")
+8 SET EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",COUNT,"NumberOfTimesProcedurePerformed")=$$GET1^DIQ(9000010.18,PROCEDUREIEN,.16,"I")
+9 SET EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",COUNT,"ProviderNarrative")=$$GET1^DIQ(9000010.18,PROCEDUREIEN,.04,"E")
+10 ;
+11 SET MODIFIERIEN=0
SET COUNT2=0
+12 FOR
SET MODIFIERIEN=$ORDER(^AUPNVCPT(PROCEDUREIEN,1,MODIFIERIEN))
if 'MODIFIERIEN
QUIT
Begin DoDot:2
+13 SET COUNT2=COUNT2+1
+14 SET EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",COUNT,"ClinicalProcedureModifierCode",COUNT2)=$$GET1^DIQ(81.3,$$GET1^DIQ(9000010.181,MODIFIERIEN_","_PROCEDUREIEN_",",.01,"I"),.01,"I")
+15 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
+16 IF '$DATA(EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure"))
SET EXPANDEDENTRY("ExpandedEntry","ClinicalProcedure",1)=""
+17 QUIT
+18 ;
GETPATIENTCLASS(EXPANDEDENTRY,APPTIEN) ;
+1 NEW CLASSNAME,CLASSTYPEIEN,CLASSIEN,OUTPENCOUNTERIEN,SDISCLACTIVE
+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 SET SDISCLACTIVE="Not Applicable"
+11 IF $DATA(^SDD(409.42,"AO",OUTPENCOUNTERIEN,CLASSTYPEIEN))
Begin DoDot:3
+12 SET CLASSIEN=0
SET CLASSIEN=+$ORDER(^SDD(409.42,"AO",OUTPENCOUNTERIEN,CLASSTYPEIEN,CLASSIEN))
+13 SET SDISCLACTIVE=$SELECT($$GET1^DIQ(409.42,CLASSIEN,.03,"I")=1:"Yes",$$GET1^DIQ(409.42,CLASSIEN,.03,"I")=0:"No",1:"Not Applicable")
End DoDot:3
+14 SET EXPANDEDENTRY("ExpandedEntry","PatientClassification",CLASSTYPEIEN,"IsClassificationActive")=SDISCLACTIVE
+15 ;
End DoDot:2
End DoDot:1
+16 QUIT
+17 ;
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 ;