source: WorldVistAEHR/trunk/r/VISTA_OFFICE_EHR-VEPE/VEPERI3.m@ 1000

Last change on this file since 1000 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 3.9 KB
Line 
1VEPERI3 ;DAOU/WCJ - Incoming HL7 messages ;10/10/06 15:11
2 ;;1.0;VOEB;;Jun 12, 2005
3 ;;;VISTA OFFICE/EHR;
4 ;;Per VHA Directive 10-93-142, this routine should not be modified.
5 ;
6 ;**Program Description**
7 ; Find patient
8 ; Add if not found and addflag set
9 Q
10 ;
11 ; Find the patient's DFN
12 ; If patient can not be found, add it or save it off depending on the flag being
13 ; passed in
14 ;
15FINDPAT(HLP,FE,DFN,NPADDFLG,HLMTIEN) ;
16 N NAME,DOB,HRN,ID,SEX,MSHDTTM,%DT,X,RESULT,MBI,SSN
17 ;
18 S FE=0
19 ;
20 ; There are some required fields to lookup a patient
21 S MSHDTTM=$$GETDATA("MSH",1000,6)
22 I MSHDTTM="" D Q
23 . S FE=$$FATALERR^VEPERI6(1,"DATA","REQUIRED PATIENT IDENTIFIER - MSH DATE/TIME MISSING",HLMTIEN,.HLP) Q
24 ;
25 S NAME=$$GETDATA("PID",1000,5)
26 I NAME="" D Q
27 . S FE=$$FATALERR^VEPERI6(1,"DATA","REQUIRED PATIENT IDENTIFIER - NAME MISSING",HLMTIEN,.HLP) Q
28 ;
29 S DOB=$$GETDATA("PID",1000,7)
30 I DOB="" D Q
31 . S FE=$$FATALERR^VEPERI6(1,"DATA","REQUIRED PATIENT IDENTIFIER - DOB MISSING",HLMTIEN,.HLP) Q
32 I DOB["/" D Q:FE
33 . S %DT="",X=DOB D ^%DT
34 . I Y>0 S DOB=Y Q
35 . S FE=$$FATALERR^VEPERI6(1,"DATA","REQUIRED PATIENT IDENTIFIER - DOB INVALID",HLMTIEN,.HLP) Q
36 ;
37 ; This won't be there since we are no longer doing a 2 way interface
38 ; S HRN=$$GETDATA("PID",1000,2) ;not required
39 S HRN=""
40 ;
41 S ID=$$GETDATA("PID",1000,3)
42 I ID="" D Q
43 . S FE=$$FATALERR^VEPERI6(1,"DATA","REQUIRED PATIENT IDENTIFIER - ID MISSING",HLMTIEN,.HLP) Q
44 ;
45 S SEX=$$GETDATA("PID",1000,8)
46 I SEX="" D Q
47 . S FE=$$FATALERR^VEPERI6(1,"DATA","REQUIRED PATIENT IDENTIFIER - SEX MISSING",HLMTIEN,.HLP) Q
48 ;
49 S RESULT=$$LKUP^VEPERIC(HLMTIEN,MSHDTTM,"",DOB,ID,HRN,NAME,SEX)
50 ;
51 ; -1 is BAD. Error is logged in VEPERIC
52 I RESULT=-1 S FE=1 Q
53 ;
54 ; We have a match
55 I +RESULT S DFN=RESULT Q
56 ;
57 ; Me thinks we have a new patient
58 S MBI=$$GETDATA("PID",1000,24) ; multiple birth indicator
59 S SSN=$$GETDATA("PID",1000,19) ; social security number
60 I RESULT=0 D Q:FE
61 .I NPADDFLG D ADDPAT(NAME,DOB,SEX,.DFN,FE,HLMTIEN,.HLP) Q
62 .I 'NPADDFLG D SAVEPAT(NAME,DOB,SEX,ID,HLMTIEN,MSHDTTM,.DUZ,FE,.HLP)
63 Q
64 ;
65 ; The data will be in one of two places.
66 ; On if it was mapped or manipulated after coming in or another if it was not.
67 ; SETID is always 1000 on non repeating segments such as PID
68GETDATA(SEG,SETID,SEQ) ;
69 N DATA
70 S DATA=$G(HLP(SEG,SETID,SEQ,0)) I DATA]"" Q DATA
71 Q $G(HLP(SEG,SETID,SEQ))
72 ;
73 ; Save the information on this record for another day
74 ; Dates need be in MMDDYYYY@HHMMSS or MM/DD/YYYY@HHMMSS
75 ;
76SAVEPAT(NAME,DOB,SEX,ID,HLMTIEN,MSGDTTM,DUZ,FE,HLP) ;
77 N DIE,DIC,X,DR
78 S X="`"_HLMTIEN
79 S DIC=19904.21,DIC(0)="L"
80 S DIC("DR")=".02///^S X=NAME;.03///^S X=DOB;.04///^S X=SEX;.06///^S X=ID;.07///NOW;.08///^S X=DUZ;.09///^S X=MSGDTTM"
81 D ^DIC
82 ;
83 I '+Y D Q
84 . S FE=$$FATALERR^VEPERI6(1,"SYSTEM","CAN'T ADD TO NEW PATIENT HOLD FILE 19904.21",HLMTIEN,.HLP) Q
85 ;
86 Q
87 ;
88 ; Add a patient to file 2 & 9000001
89 ; This just adds a stub to get the patient started.
90ADDPAT(NAME,DOB,SEX,DFN,FE,HLMTIEN,HLP) ;
91 N DIC,HRN,IENS,DATA,DLAYGO,RET,X,FDA
92 ;
93 ; These variables are most likely set by DIC,DIE and IHS lookup routines.
94 N Y,VAERR,FDAIEN,DIW,DGUSER,DFN,DDER,DA,C,DICR,SSN
95 N AUPNSEX,AUPNPAT,AUPNLK,AUPNDOD,AUPNDOB,AUPNDAYS,AGE,%I,%1,%L
96 ;
97 S FE=0
98 I $G(NAME)=""!($G(DOB)="")!($G(SEX)="") D Q
99 . S FE=$$FATALERR^VEPERI6(1,"DATA","NAME, DOB OR SEX MISSING FROM PATIENT ADD",HLMTIEN,.HLP) Q
100 ;
101 ; Add stub patient
102 ; Force the entry because we already determined it was a new patient
103 S X=""""_NAME_""""
104 S DIC=2,DIC(0)="L",DLAYGO=2
105 S DIC("DR")=".301///N;391///VISTA OFFICE EHR;1901///N;.03///"_DOB_";.02///"_SEX
106 D ^DIC
107 I Y<0 D Q
108 . S FE=$$FATALERR^VEPERI6(1,"PATADD","PROBLEM ADDING PATIENT",HLMTIEN,.HLP) Q
109 ;
110 S DFN=+Y
111 ;
112 ; Create patient in IHS global
113 S HRN=$$GENHRN^MPIFAG1()
114 S IENS="?+1,"_+Y_","
115 S DATA="FDA"
116 S FDA(9000001.41,IENS,.01)=DUZ(2)
117 S FDA(9000001.41,IENS,.02)=HRN
118 D UPDATE^DIE("",DATA,"FDAIEN","RET")
119 I $D(RET) D Q
120 . S FE=$$FATALERR^VEPERI6(1,"PATADD","PROBLEM ADDING PATIENT HRN",HLMTIEN,.HLP) Q
121 Q
Note: See TracBrowser for help on using the repository browser.