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

INHUSEQ2.m

Go to the documentation of this file.
  1. INHUSEQ2 ;DGH; 13 Jan 95 09:22;More SEQuence number protocol functions
  1. ;;3.01;BHL IHS Interfaces with GIS;;JUL 01, 2001
  1. ;COPYRIGHT 1991-2000 SAIC
  1. ;
  1. ;Following functions are used when CHCS is originiating system for
  1. ;sequence number protocol. Originiating system need only send
  1. ;a message containing an MSH segment to initiate or to resynch
  1. ;the link.
  1. INIT ;This entry point initializes seq. no. protocol. It creates
  1. ;a MSH with MSH-9 =0. It is called from a menu option.
  1. N INSEQ,SRC
  1. S INSEQ=0,SRC="Initialization message"
  1. D DEST Q
  1. ;
  1. SYNCH ;This entry point resynches the link. It creates a MSH with
  1. ;MSH-9 = -1. It is called from a menu option.
  1. N INSEQ,SRC
  1. S INSEQ=-1,SRC="Re-synchronization message"
  1. D DEST Q
  1. ;
  1. DEST ;Prompt for background process. The process must be inactive and
  1. ;must have a destination. Seq. No. Protocol is by destination.
  1. N DIC,X,Y,DEST,TT,DXS,ING,INUIF,MSH,INDELIM,INSUBDEL,INSUBCOM,BP,INREP,MSG,DST
  1. S DIC=4004,DIC(0)="AEZ",DIC("S")="I $P(^(0),U,7)" D ^DIC Q:Y<1
  1. S BP=+Y I $D(^INRHB("RUN","SRVR",BP)) S MSG="This process is active. You must shut this job down before proceeding." D DISP Q
  1. S DST=$P(Y(0),U,7) I '$D(^INRHD(DST)) S MSG="Destination does not exist" D DISP Q
  1. S DEST=$P(^INRHD(DST,0),U)
  1. ;Create MSH segment !!NOTE that MESSAGE TYPE field is null.
  1. S MESSID=$$MESSID^INHD
  1. S INDELIM=$$FIELD^INHUT(),INSUBDEL=$$COMP^INHUT(),INSUBCOM=$$SUBCOMP^INHUT(),INREP=$$REP^INHUT()
  1. S ING="INDATA"
  1. S MSH="MSH"_INDELIM_INSUBDEL_INREP_"~"_INSUBCOM
  1. S DXS="N X1 S %=$P($H,"","",2) S:%<60 %=60 S:$G(X)'=""S"" %=%\60*60 S:$G(X)=""H"" %=%\3600*3600 S X=DT_(%\60#60/100+(%\3600)+(%#60/10000)/100) S X=X,Y(1)=$G(X) S X=""TS"""
  1. N Y,X1 X DXS S X1=Y(1) S X=$$TRX^INHSG(X1,X,"O") S L1=X
  1. S $P(MSH,U,7)=L1,$P(MSH,U,10)=MESSID,$P(MSH,U,13)=INSEQ,$P(MSH,U,15)="AL"
  1. S @ING@(1)=MSH
  1. ;create entry in UIF, but don't set in output queue
  1. S INUIF=$$NEW^INHD(MESSID,DEST,SRC,ING,0,"O",1)
  1. I INUIF<0 N INSTERR S INSTERR="",MSG="Error creating entry in UIF" D ERROR^INHS("UIF creation failed in routine ^INHUSEQ2",2),DISP Q
  1. ;set into destination queue (required for sequence # protocol)
  1. S X=$$DSTQUE^INHUSEN3(INUIF,.INERR)
  1. I X S MSG="Error creating entry in queue" D ENT^INHE(INUIF,DEST,.INERR),DISP Q
  1. ;Now that entry is in "BP" queue, start background process
  1. S X=$$A^INHB(BP)
  1. I 'X S MSG="Background process failed to start" D DISP Q
  1. Q
  1. ;
  1. DISP ;Display message to user
  1. W !?5,MSG S X=$$CR^INHU1 Q
  1. ;
  1. ;following functions are called from other routines
  1. SEQ(GBL,SEQ,INERR) ;Return Sequence number from MSH
  1. ;;;;THIS FUNCTION MAY NOT BE NEEDED
  1. ;INPUT
  1. ;--GBL = global being checked, can be ^INTHU
  1. ;--------If numeric, assumed to be IEN for ^INTHU
  1. ;--------If non-numeric, assumed to be global reference
  1. ;RETURN
  1. ;0=success 1=failure
  1. N LCT,X,SEQ
  1. S X=$$VERIF^INHUSEN(GBL,.INMSH)
  1. I X S ERR(1)="Message does not have the MSH segment in the correct location" Q 1
  1. S INDELIM=$E(INMSH,4)
  1. S SEQ=+$P(INMSH,INDELIM,13)
  1. Q 0
  1. ;
  1. ;
  1. EXPECT(GBL,EXPCT,STAT,ERR) ;Returns expected seq # and status from MSA
  1. ;INPUT
  1. ;--GBL = global being checked, can be ^INTHU
  1. ;--------If numeric, assumed to be IEN for ^INTHU
  1. ;--------If non-numeric, assumed to be global reference
  1. ;--EXPCT = Expected sequence #, MSA-5
  1. ;--STAT = Status, MSA-2
  1. ;--ERR = error message array
  1. ;RETURN
  1. ;0=success 1=error
  1. N MSA,MSH,LCT
  1. I GBL S LCT=0 D GETLINE^INHOU(GBL,.LCT,.MSH)
  1. I 'GBL S MSH=$G(@GBL@(1))
  1. I MSH'["MSH" S ERR(1)="Message does not have the MSH segment in the correct location" Q 1
  1. S INDELIM=$E(MSH,4)
  1. ;Check for MSA segment in line count subsequent to MSH
  1. I GBL D GETLINE^INHOU(GBL,.LCT,.MSA)
  1. I 'GBL S MSA=$G(@GBL@(2))
  1. I '$D(MSA) S ERR="Message does not have a MSA segment in the correct location" Q 1
  1. I MSA'["MSA" S ERR="Message does not have a MSA segment in the correct location" Q 1
  1. S STAT=$P(MSA,INDELIM,2),EXPCT=$P(MSA,INDELIM,5)
  1. Q 0
  1. ;
  1. REQUE(INDSTR,INSEND,INERR) ;Requeue previously sent messages
  1. ;INPUT:
  1. ;INDSTR = (REQ) Destination of backgroundprocess
  1. ;INSEND = (REQ) Array of messages in format INSEND(SEQ)=UIF
  1. ;INERR = (OPT) Variable for error messages (PBR)
  1. ;OUTPUT:
  1. ;0=success 1=error
  1. N SEQ,P,H,UIF
  1. ;For sequenced message, priority and time to process don't matter
  1. S (P,H)=0
  1. F I=1:1:5 L +^INLHDEST(INDSTR):5 Q:$T
  1. E S INERR="Unable to lock message queue ^INLHDEST("_$P(^INRHD(INDSTR,0),U)_") " Q 1
  1. S SEQ="" F S SEQ=$O(INSEND(SEQ)) Q:'SEQ D
  1. .S UIF=INSEND(SEQ)
  1. .S ^INLHDEST(INDSTR,P,H,UIF)=""
  1. L -^INLHDEST(INDSTR)
  1. Q 0