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

RGADTUT.m

Go to the documentation of this file.
  1. RGADTUT ;HIRMFO/GJC-utility; determine pat. subscriptions (A01/A03) ;09/21/99
  1. ;;1.0;CLINICAL INFO RESOURCE NETWORK;**17**;30 Apr 99
  1. ;
  1. ; Integration Agreements (IAs) utilized in this application:
  1. ; #2270-call to HLSUB (ACT, GET & UPDATE)
  1. ; #2271-call to LINK^HLUTIL3
  1. ; #2541-call to $$KSP^XUPARAM
  1. ; #2706-call to $$UPDATE^MPIFAPI
  1. ; #2796-call to RGHLLOG (EXC, START & STOP)
  1. ; #2988-call to FILE^VAFCTFU
  1. ;
  1. ; Note: SHARE function is called from RGADT1 to determine if VistA HL7
  1. ; messages are to be built (is GENERATE^HLMA to be called?)
  1. ;
  1. SHARE(RGZSTR) ; determine if the patient is shared:
  1. ; a) If shared, return one to RGADT1 and call GENERATE^HLMA
  1. ; b) If not shared and the host facility is the CMOR, update
  1. ; host TFL record, do not call GENERATE^HLMA
  1. ; c) If not shared and the host facility is not the CMOR, add
  1. ; the CMOR to the subscription list, return one to RGADT1
  1. ; and call GENERATE^HLMA
  1. ;
  1. ; input=> RGZSTR-patient_dfn^date_last_treated^event_type
  1. ; yield=> 0 to prevent calling GENERATE^HLMA, else make the call
  1. ;
  1. ; note: 1) Event Type will equal A01 or A03. This needs to be
  1. ; converted a valid ADT/HL7 EVENT REASON (#391.72) entry.
  1. ; 2) RGSD101 & RGDG101 are assumed to have a global scope
  1. ;
  1. N HLDT,HLINKP,HLINKX,RGZCMOR,RGZDFN,RGZDT,RGZEVT,RGZFLG,RGZHLL,RGZMPI
  1. N RGZSF,RGZSUB
  1. S RGZDFN=$P(RGZSTR,"^"),RGZDT=$P(RGZSTR,"^",2),RGZEVT=$P(RGZSTR,"^",3)
  1. S RGZMPI=$$MPINODE^MPIFAPI(RGZDFN),RGZSF=$$KSP^XUPARAM("INST")
  1. ; note to myself: missing MPI node, update TFL & return 0
  1. ;I +RGZMPI=-1 D TFL Q 0 <= should never occur, RGADT1 checks for ICN
  1. S RGZCMOR=$P($G(RGZMPI),"^",3),RGZSUB=$P($G(RGZMPI),"^",5)
  1. D:RGZSUB GET^HLSUB(RGZSUB,0,,.RGZHLL) ; find shared sites
  1. S RGZFLG=+$O(RGZHLL("LINKS",$C(32)),-1)
  1. ; at this point if RGZFLG>0 yield RGZFLG, else evaluate the conditions
  1. ; listed above (b & c)
  1. I 'RGZFLG D ; no shared sites, take action (RGZFLG may be reset)
  1. .I 'RGZCMOR D TFL Q ;CMOR not found, subsequent conditions not met
  1. .;
  1. .;b) the host site is the CMOR, update local TFL record, quit
  1. .I RGZSF,(RGZSF=RGZCMOR) D TFL Q
  1. .;
  1. .;c) if we're not the CMOR, we'll add the CMOR to the subscription list
  1. .I RGZSF,(RGZSF'=RGZCMOR) D
  1. ..N RGZ774,RGZERR,RGZLL
  1. ..D LINK^HLUTIL3(RGZCMOR,.RGZLL)
  1. ..;log. link for CMOR missing, log exception, file data in TFL & quit
  1. ..I '$O(RGZLL(0)) D Q
  1. ...D EXC("Cannot add CMOR (#4): "_RGZCMOR_", as a subscriber to: "_RGZSF_" (#4)")
  1. ...D TFL
  1. ...Q
  1. ..;found the CMOR's logical link, add the subscription
  1. ..S RGZLL=RGZLL($O(RGZLL(0))),RGZ774=$$ACT^HLSUB
  1. ..D UPD^HLSUB(RGZ774,RGZLL,1,"","","",.RGZERR)
  1. ..; if update errored: log exception, file data into TFL & quit
  1. ..I $O(RGZERR(0)) D Q
  1. ...D EXC("Subscription add (#774) failed for DFN: "_RGZDFN_", subscriber: "_RGZLL)
  1. ...D TFL
  1. ...Q
  1. ..;subscription added, set flag (HL7 message can be generated)
  1. ..E S RGZFLG=1
  1. ..;update the SUBSCRIPTION CONTROL NUMBER (#991.05) field, file #2
  1. ..K RGZERR N RGZARR
  1. ..S RGZARR(991.05)=RGZ774,RGZERR=$$UPDATE^MPIFAPI(RGZDFN,"RGZARR")
  1. ..;if error updating field, file an exception
  1. ..I +RGZERR=-1 D EXC("Subscription add (fld: 991.05, file: #2) failed for DFN: "_RGZDFN_", subscriber: "_RGZLL)
  1. ..Q
  1. .Q
  1. Q RGZFLG ;shared site(s) found/added? 0=no, else yes...
  1. ;
  1. EXC(RGX) ; log an exception because:
  1. ;a) logical link not found for CMOR
  1. ;b) new subscription not added to Subscription Control (#774) file
  1. ;c) subscription control pointer not added to "MPI" node (fld: 991.05)
  1. ; input: RGX-exception text
  1. D START^RGHLLOG(),EXC^RGHLLOG(224,RGX,RGZDFN),STOP^RGHLLOG(0)
  1. Q
  1. TFL ; update the Treating Facility List file on:
  1. ; an exception -or- no subscribers CMOR data missing -or-
  1. ; "MPI" node missing -or- no subscribers & host is the CMOR
  1. ; Note: RGZSF is global in scope
  1. N RGZEVR I RGZEVT="A01" S RGZEVR="A1"
  1. E S RGZEVR=$S(($D(RGSD101))#2:"A3",1:"A2")
  1. D:RGZSF FILE^VAFCTFU(RGZDFN,RGZSF_"^"_RGZDT_"^"_RGZEVR,1)
  1. ;3rd param=1, do not involve the ADT/HL7 PIVOT (#391.71) file
  1. Q