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

SDESPATSEARCH.m

Go to the documentation of this file.
SDESPATSEARCH  ;ALB/BLB - SDES PATIENT SEARCH; Jun 02, 2023@02:00
 ;;5.3;Scheduling;**833,838,842,843,844,846**;Aug 13, 1993;Build 12
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 ; 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
 ;
 D VALIDATENUMREC(.NUMOFRECORDS,.ERRORS)
 I $D(ERRORS) M RETURN=ERRORS D BUILDJSON(.JSONRETURN,.RETURN) Q
 ;
 S INDEX=$$INDEX(.SEARCHSTRING)
 I SEARCHSTRING'="",SEARCHSTRING'[",",$L(SEARCHSTRING)<3 S PATIENTLIST("Patient",1)="" M RETURN=PATIENTLIST D BUILDJSON(.JSONRETURN,.RETURN) Q
 ;
 D BUILDPATIENTLIST(.PATIENTLIST,$G(SEARCHSTRING),$G(NUMOFRECORDS),$G(INDEX))
 ;
 I '$D(PATIENTLIST) S PATIENTLIST("Patient",1)=""
 M RETURN=PATIENTLIST D BUILDJSON(.JSONRETURN,.RETURN)
 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) ;
 N NUM,PATIENTNAME,DFN,SEARCHCRITERIA
 ;
 I INDEX="B" S SEARCHSTRING=$$TRAILINGSPACES(SEARCHSTRING)
 S SEARCHCRITERIA=$$GETSUB^SDECU(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),NUM)
 Q
 ;
POPULATE(PATIENTLIST,DFN,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)
 ;
 D GETSENSITIVEPAT(.PATIENTLIST,DFN,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,NUM) ;
 N SENSITIVE
 D PTSEC^DGSEC4(.SENSITIVE,DFN)
 S PATIENTLIST("Patient",NUM,"SensitivePatientRestrictedRecord")=$S($G(SENSITIVE(1)):1,1:0)
 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
 ;
VALIDATENUMREC(NUMOFRECORDS,ERRORS) ; number of records to return
 I $G(NUMOFRECORDS)="" S NUMOFRECORDS=10 Q
 I $G(NUMOFRECORDS)>50!($G(NUMOFRECORDS)<1) D ERRLOG^SDESJSON(.ERRORS,382)
 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
 ;