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

SDES2PATSEARCH.m

Go to the documentation of this file.
SDES2PATSEARCH  ;ALB/ANU,BLB,BWF - SDES2 PATIENT SEARCH; OCT 13, 2023@02:00
 ;;5.3;Scheduling;**864,866,881**;Aug 13, 1993;Build 10
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 ; clone of SDESPATSEARCH - BLB
 ;
 ; Reference to PATIENT in ICR #7030
 ; Reference to PATIENT in ICR #7029
 ; Reference to PATIENT in ICR #1476
 ; Reference to PATIENT in ICR #10035
 ; Reference to RATED DISABILITIES sub-file in ICR #4807
 ; Reference to DISABILITY CONDITION in #733
 ;
 Q
 ;
 N RETURN,ERRORS,PATIENTLIST,INDEX,VALRET,SDDFN,NUMOFRECORDS,SEARCHSTRING,PARAMETERS,SDDUZ
 ;
 D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
 I $D(ERRORS) S ERRORS("Patient",1)="" D BUILDJSON^SDES2JSON(.JSONRETURN,.ERRORS) Q
 S SDDUZ=$S($G(SDCONTEXT("USER DUZ"))'="":$G(SDCONTEXT("USER DUZ")),1:DUZ)
 ;
 D POPULATEINPUTS(.PARAMS,.SEARCHSTRING,.NUMOFRECORDS,.INDEX)
 D VALIDATE(.ERRORS,.NUMOFRECORDS,SEARCHSTRING)
 I $D(ERRORS) S ERRORS("Patient",1)="" D BUILDJSON^SDES2JSON(.JSONRETURN,.ERRORS) Q
 ;
 D BUILDPATIENTLIST(.PATIENTLIST,$G(SEARCHSTRING),$G(NUMOFRECORDS),$G(INDEX),SDDUZ)
 ;
 I '$D(PATIENTLIST) S PATIENTLIST("Patient",1)=""
 M RETURN=PATIENTLIST D BUILDJSON(.JSONRETURN,.RETURN)
 Q
 ;
POPULATEINPUTS(PARAMS,SEARCHSTRING,NUMOFRECORDS,INDEX) ;
 S NUMOFRECORDS=$G(PARAMS("NUMOFRECORDS"))
 S SEARCHSTRING=$G(PARAMS("SEARCHSTRING"))
 S INDEX=$$INDEX(.SEARCHSTRING)
 Q
 ;
INDEX(SEARCHSTRING) ; returns the index to be searched in ^DPT
 I $G(SEARCHSTRING)?1A4N Q "BS5" ;initial+4SSN
 ;
 I $$ISOTFM^SDAMUTDT($G(SEARCHSTRING))'=-1 D  Q "ADOB" ;DOB
 .S SEARCHSTRING=$$ISOTFM^SDAMUTDT($G(SEARCHSTRING))
 ;
 I $G(SEARCHSTRING)?9N!($G(SEARCHSTRING)?3N1"-"2N1"-"4N)!($G(SEARCHSTRING)?9N.1"P")!($G(SEARCHSTRING)?3N1"-"2N1"-"4N.1"P") D  Q "SSN" ;SSN
 .S SEARCHSTRING=$TR($G(SEARCHSTRING),"-","")
 ;
 Q "B"
 ;
BUILDPATIENTLIST(PATIENTLIST,SEARCHSTRING,NUMOFRECORDS,INDEX,SDDUZ) ;
 N NUM,PATIENTNAME,DFN,SEARCHCRITERIA
 ;
 I INDEX="B" S SEARCHSTRING=$$TRAILINGSPACES(SEARCHSTRING)
 S SEARCHCRITERIA=$$GETSUB^SDES2UTIL(SEARCHSTRING) ;decrements all input types by 1
 I $G(SEARCHSTRING)="" S SEARCHCRITERIA=0
 S NUM=0
 F  S SEARCHCRITERIA=$O(^DPT(INDEX,SEARCHCRITERIA)) Q:SEARCHCRITERIA=""!(NUM=NUMOFRECORDS)!(SEARCHCRITERIA'[SEARCHSTRING)  D
 .S DFN=0
 .F  S DFN=$O(^DPT(INDEX,SEARCHCRITERIA,DFN)) Q:'DFN!(NUM=NUMOFRECORDS)  D
 ..S NUM=NUM+1
 ..D POPULATE(.PATIENTLIST,$G(DFN),SDDUZ,NUM)
 Q
 ;
POPULATE(PATIENTLIST,DFN,SDDUZ,NUM) ;
 N PATIENTDATA
 ;
 D GETS^DIQ(2,DFN,".01;.02;.024;.03;.1;.2405;.301;.302;.351;.361;391;1100.01","IE","PATIENTDATA")
 S PATIENTLIST("Patient",NUM,"DFN")=DFN
 S PATIENTLIST("Patient",NUM,"Name")=$G(PATIENTDATA(2,DFN_",",.01,"E"))
 S PATIENTLIST("Patient",NUM,"DateOfBirth")=$$FMTISO^SDAMUTDT($G(PATIENTDATA(2,DFN_",",.03,"I")))
 S PATIENTLIST("Patient",NUM,"DateOfDeath")=$$FMTISO^SDAMUTDT($G(PATIENTDATA(2,DFN_",",.351,"I")))
 S PATIENTLIST("Patient",NUM,"PreferredName")=$G(PATIENTDATA(2,DFN_",",.2405,"E"))
 S PATIENTLIST("Patient",NUM,"PatientType")=$G(PATIENTDATA(2,DFN_",",391,"E"))
 S PATIENTLIST("Patient",NUM,"Ward")=$G(PATIENTDATA(2,DFN_",",.1,"E")) ;.1
 S PATIENTLIST("Patient",NUM,"FugitiveFelon")=$G(PATIENTDATA(2,DFN_",",1100.01,"E"))
 S PATIENTLIST("Patient",NUM,"Gender")=$G(PATIENTDATA(2,DFN_",",.02,"E")) ;.02
 S PATIENTLIST("Patient",NUM,"GenderIdentity")=$G(PATIENTDATA(2,DFN_",",.024,"E"))
 S PATIENTLIST("Patient",NUM,"MentalHealthProvider")=$P($$START^SCMCMHTC(DFN),U,2)
 S PATIENTLIST("Patient",NUM,"PrimaryCarePractitioner")=$P($$OUTPTPR^SDUTL3(DFN),U,2)
 S PATIENTLIST("Patient",NUM,"ICNNumber")=$$GETICN(DFN)
 S PATIENTLIST("Patient",NUM,"Last4SSN")=$$LAST4SSN^SDESINPUTVALUTL(DFN)
 S PATIENTLIST("Patient",NUM,"NewGAFRequired")=$S($$NEWGAF^SDUTL2(DFN):"New GAF Required",1:"No new GAF required")
 S PATIENTLIST("Patient",NUM,"PriorityGroup")=$$GET1^DIQ(27.11,$$GET1^DIQ(2,DFN,27.01,"I"),.07,"E")
 S PATIENTLIST("Patient",NUM,"EnrollmentSubGroup")=$$GET1^DIQ(27.11,$$GET1^DIQ(2,DFN,27.01,"I"),.12,"E")
 ;
 D GETSENSITIVEPAT(.PATIENTLIST,DFN,SDDUZ,NUM)
 ;
 I $D(^DGPF(26.13,"C",DFN)) D GETFLAGS(.PATIENTLIST,DFN,NUM)
 I '$D(^DGPF(26.13,"C",DFN)) S PATIENTLIST("Patient",NUM,"Flag")=""
 ;
 I $D(^DGS(41.41,"B",DFN)) D GETLASTDEMOUPDAT(.PATIENTLIST,DFN,NUM)
 I '$D(^DGS(41.41,"B",DFN)) S PATIENTLIST("Patient",NUM,"DemographicsUpdated")=""
 ;
 I $D(^DPT(DFN,"E","B")) D GETELIGIBILITY(.PATIENTLIST,DFN,NUM)
 I '$D(^DPT(DFN,"E","B")) S PATIENTLIST("Patient",NUM,"Eligibility")=""
 ;
 I $D(^DPT(DFN,.373)) D GETCONDITIONS(.PATIENTLIST,DFN,NUM)
 I '$D(^DPT(DFN,.373)) S PATIENTLIST("Patient",NUM,"ServiceConnectedCondition")=""
 ;
 I $D(^DPT(DFN,.372)) D GETDISABILITIES(.PATIENTLIST,DFN,NUM)
 I '$D(^DPT(DFN,.372)) S PATIENTLIST("Patient",NUM,"RatedDisabilities")=""
 ;
 I $G(PATIENTDATA(2,DFN_",",.301,"I"))="Y" S PATIENTLIST("Patient",NUM,"ServiceConnected")="YES"_" "_"("_$G(PATIENTDATA(2,DFN_",",.302,"I"))_"%)"
 I $G(PATIENTDATA(2,DFN_",",.301,"I"))="N" S PATIENTLIST("Patient",NUM,"ServiceConnected")="NO"
 Q
 ;
GETSENSITIVEPAT(PATIENTLIST,DFN,SDDUZ,NUM) ;
 N SENSITIVE,MESLOOP,MESCNT
 D SENSITIVE^SDES2UTIL(.SENSITIVE,DFN,SDDUZ)
 S PATIENTLIST("Patient",NUM,"SensitivePatientRestrictedRecord")=$S($G(SENSITIVE(1)):1,1:0)
 S PATIENTLIST("Patient",NUM,"SensitivePatientType")=$G(SENSITIVE(1))
 S MESCNT=0
 S MESLOOP=1 F  S MESLOOP=$O(SENSITIVE(MESLOOP)) Q:'MESLOOP  D
 .S MESCNT=MESCNT+1
 .S PATIENTLIST("Patient",NUM,"SensitiveRecordMessage",MESCNT,"Text")=$G(SENSITIVE(MESLOOP))
 I '$D(PATIENTLIST("Patient",NUM,"SensitiveRecordMessage")) S PATIENTLIST("Patient",NUM,"SensitiveRecordMessage",1)=""
 Q
 ;
GETFLAGS(PATIENTLIST,DFN,NUM) ;
 N NATLOCALFLAGS,FLAGS,FLAGCOUNT,NARRATIVECOUNT
 D GETFLAGS^SDESPATFLAGS(.NATLOCALFLAGS,DFN)
 D DECODE^XLFJSON("NATLOCALFLAGS","FLAGS")
 S FLAGCOUNT=0
 F  S FLAGCOUNT=$O(FLAGS("Flag",FLAGCOUNT)) Q:'FLAGCOUNT  D
 .S PATIENTLIST("Patient",NUM,"Flag",FLAGCOUNT,"ApprovedBy")=$G(FLAGS("Flag",FLAGCOUNT,"ApprovedBy"))
 .S PATIENTLIST("Patient",NUM,"Flag",FLAGCOUNT,"AssignedDate")=$G(FLAGS("Flag",FLAGCOUNT,"AssignedDate"))
 .S PATIENTLIST("Patient",NUM,"Flag",FLAGCOUNT,"Category")=$G(FLAGS("Flag",FLAGCOUNT,"Category"))
 .S PATIENTLIST("Patient",NUM,"Flag",FLAGCOUNT,"FlagName")=$G(FLAGS("Flag",FLAGCOUNT,"Name"))
 .S PATIENTLIST("Patient",NUM,"Flag",FLAGCOUNT,"OriginatingSiteID")=$G(FLAGS("Flag",FLAGCOUNT,"OriginatingSiteID"))
 .S PATIENTLIST("Patient",NUM,"Flag",FLAGCOUNT,"OriginatingSiteName")=$G(FLAGS("Flag",FLAGCOUNT,"OriginatingSiteName"))
 .S PATIENTLIST("Patient",NUM,"Flag",FLAGCOUNT,"OwnerSiteID")=$G(FLAGS("Flag",FLAGCOUNT,"OwnerSiteID"))
 .S PATIENTLIST("Patient",NUM,"Flag",FLAGCOUNT,"OwnerSiteName")=$G(FLAGS("Flag",FLAGCOUNT,"OwnerSiteName"))
 .S PATIENTLIST("Patient",NUM,"Flag",FLAGCOUNT,"ReviewDate")=$G(FLAGS("Flag",FLAGCOUNT,"ReviewDate"))
 .S PATIENTLIST("Patient",NUM,"Flag",FLAGCOUNT,"Type")=$G(FLAGS("Flag",FLAGCOUNT,"Type"))
 .S NARRATIVECOUNT=0
 .F  S NARRATIVECOUNT=$O(FLAGS("Flag",FLAGCOUNT,"Narrative",NARRATIVECOUNT)) Q:'NARRATIVECOUNT  D
 ..S PATIENTLIST("Patient",NUM,"Flag",FLAGCOUNT,"Narrative",NARRATIVECOUNT)=$G(FLAGS("Flag",FLAGCOUNT,"Narrative",NARRATIVECOUNT))
 Q
 ;
GETLASTDEMOUPDAT(PATIENTLIST,DFN,NUM) ; last patient demographic update
 N PREREGIEN,DEMODIFF
 ;
 S PREREGIEN=0,PREREGIEN=$O(^DGS(41.41,"B",DFN,"A"),-1)
 S DEMODIFF=$$FMDIFF^XLFDT(DT,$$GET1^DIQ(41.41,PREREGIEN_",",1,"I"))
 S PATIENTLIST("Patient",NUM,"DemographicsUpdated")=$P($$FMTISO^SDAMUTDT($$GET1^DIQ(41.41,PREREGIEN_",",1,"I")),"T")
 S PATIENTLIST("Patient",NUM,"DemographicsNeedUpdate")=$S(DEMODIFF>179:1,DEMODIFF<180:0)
 Q
 ;
GETELIGIBILITY(PATIENTLIST,DFN,NUM) ; top level primary code + secondary eligibilities
 N ELIGIBILITYIEN,COUNT
 ;
 S COUNT=1
 S PATIENTLIST("Patient",NUM,"Eligibility",COUNT,"PrimaryEligibilityCode")=$$GET1^DIQ(2,DFN_",",.361,"E")
 S PATIENTLIST("Patient",NUM,"Eligibility",COUNT,"PrimaryEligibilityCodeType")=$$GET1^DIQ(8,$$GET1^DIQ(2,DFN_",",.361,"I"),4,"E")
 ;
 S ELIGIBILITYIEN=0
 F  S ELIGIBILITYIEN=$O(^DPT(DFN,"E","B",ELIGIBILITYIEN)) Q:ELIGIBILITYIEN="B"!(ELIGIBILITYIEN="")  D
 .I $$GET1^DIQ(2.0361,ELIGIBILITYIEN_","_DFN_",",.01,"I")=$$GET1^DIQ(2,DFN_",",.361,"I") Q
 .S COUNT=COUNT+1
 .S PATIENTLIST("Patient",NUM,"Eligibility",COUNT,"SecondaryEligibilityCode")=$$GET1^DIQ(2.0361,ELIGIBILITYIEN_","_DFN_",",.01,"E")
 .S PATIENTLIST("Patient",NUM,"Eligibility",COUNT,"SecondaryEligibilityCodeType")=$$GET1^DIQ(8,ELIGIBILITYIEN,4,"E")
 Q
 ;
GETCONDITIONS(PATIENTLIST,DFN,NUM) ; service connected conditions
 N CONDITIONIEN,COUNT
 ;
 S CONDITIONIEN=0,COUNT=0
 F  S CONDITIONIEN=$O(^DPT(DFN,.373,CONDITIONIEN)) Q:'CONDITIONIEN  D
 .S COUNT=COUNT+1
 .S PATIENTLIST("Patient",NUM,"ServiceConnectedCondition",COUNT,"Condition")=$$GET1^DIQ(2.05,CONDITIONIEN_","_DFN_",",.01,"E")
 Q
 ;
GETDISABILITIES(PATIENTLIST,DFN,NUM) ; rated disabilities
 N AECODE,AFFECTED,COUNT,RATEDARRAY
 ;
 D RDIS^DGRPDB(DFN,.RATEDARRAY) ; ICR #4807
 I '$D(RATEDARRAY) D  Q
 . S PATIENTLIST("Patient",NUM,"RatedDisabilities")=""
 ;
 S COUNT=0
 F  S COUNT=$O(RATEDARRAY(COUNT)) Q:'COUNT  D
 . S PATIENTLIST("Patient",NUM,"RatedDisabilities",COUNT,"RatedDisability")=$$GET1^DIQ(31,$P(RATEDARRAY(COUNT),"^")_",",.01,"E") ; ICR #733
 . S PATIENTLIST("Patient",NUM,"RatedDisabilities",COUNT,"DisabilityPercent")=$P(RATEDARRAY(COUNT),"^",2)
 . S PATIENTLIST("Patient",NUM,"RatedDisabilities",COUNT,"ServiceConnected")=$S($P(RATEDARRAY(COUNT),"^",3)=1:"YES",1:"NO")
 . S AECODE=$P(RATEDARRAY(COUNT),"^",4)
 . S AFFECTED=$S(AECODE="BL":"BOTH LOWER",AECODE="BU":"BOTH UPPER",AECODE="RL":"RIGHT LOWER",AECODE="RU":"RIGHT UPPER",AECODE="LL":"LEFT LOWER",AECODE="LU":"LEFT UPPER",1:"")
 . S PATIENTLIST("Patient",NUM,"RatedDisabilities",COUNT,"ExtremityAffected")=AFFECTED
 . S PATIENTLIST("Patient",NUM,"RatedDisabilities",COUNT,"OriginalEffectiveDate")=$$FMTISO^SDAMUTDT($P(RATEDARRAY(COUNT),"^",5))
 . S PATIENTLIST("Patient",NUM,"RatedDisabilities",COUNT,"CurrentEffectiveDate")=$$FMTISO^SDAMUTDT($P(RATEDARRAY(COUNT),"^",6))
 Q
 ;
GETICN(DFN) ; patient ICN
 N ICN
 ;
 S ICN=$$GETICN^MPIF001(DFN)
 I ICN["-1",$$GET1^DIQ(8989.3,1,.01,"E")["TEST" Q $$GET1^DIQ(2,DFN,991.1)
 Q ICN
 ;
VALIDATE(ERRORS,NUMOFRECORDS,SEARCHSTRING) ;
 I $G(NUMOFRECORDS)="" S NUMOFRECORDS=10 Q
 I $G(NUMOFRECORDS)>50!($G(NUMOFRECORDS)<1) D ERRLOG^SDESJSON(.ERRORS,382)
 ;
 I SEARCHSTRING'="",SEARCHSTRING'[",",$L(SEARCHSTRING)<3 S PATIENTLIST("Patient",1)="" D ERRLOG^SDESJSON(.ERRORS,473)
 Q
 ;
TRAILINGSPACES(NAME) ;
 N FIRSTNAME,LASTNAME
 ;
 S FIRSTNAME=$P(NAME,",")
 S LASTNAME=$P(NAME,",",2)
 I $E(LASTNAME)=" " D
 .S LASTNAME=$E(LASTNAME,2,$L(LASTNAME))
 .S NAME=FIRSTNAME_","_LASTNAME
 Q NAME
 ;
BUILDJSON(JSONRETURN,RETURN) ;
 N JSONERROR
 D ENCODE^XLFJSON("RETURN","JSONRETURN","JSONERR")
 Q
 ;