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

INTSTR.m

Go to the documentation of this file.
  1. INTSTR ;DGH; 29 Apr 97 16:39;Required field/segment validation
  1. ;;3.01;BHL IHS Interfaces with GIS;;JUL 01, 2001
  1. ;COPYRIGHT 1991-2000 SAIC
  1. ;
  1. Q ;no top entry
  1. ;
  1. EN(INEXPND,INREQLST) ;Entry point with user interaction to select a message
  1. ;INPUT:
  1. ; INEXPND = 1 for expanded display, 0 for not
  1. ; INREQLST = (OPT) array of UIF entries
  1. ;If array of messages to validate is not supplied, prompt.
  1. ;;Enhancement needed for this tag
  1. ;;1) %ZIS call
  1. N DIC,INLST,INUIF,SELCT,INMSG
  1. I '$D(INREQLST) D
  1. .W "Select uif entry"
  1. .S DIC="^INTHU(",DIC(0)="AEQM" D ^DIC W !
  1. .Q:Y<1
  1. .S SELCT=1,INREQLST(1)=+Y
  1. ;If there is still nothing in array, quit
  1. I '$D(INREQLST) S INMSG="Nothing selected" D IO(INMSG) Q
  1. ;Otherwise, loop through array
  1. S INLST="" F S INLST=$O(INREQLST(INLST)) Q:'INLST D
  1. .S INUIF=INREQLST(INLST)
  1. .;kill activity log multiple
  1. .K ^INTHU(INUIF,1)
  1. .S INMSG="UIF Transaction "_$P(^INTHU(INUIF,0),U,5) D IO(INMSG)
  1. .D MAIN(INUIF,INEXPND)
  1. ;If selections were made inside this routine, kill them
  1. I $G(SELCT) K INREQLST
  1. Q
  1. ;
  1. MAIN(INUIF,INEXPND) ;Main program loop
  1. ;INPUT
  1. ; INUIF = Entry in UIF to validate
  1. ; INEXPND = 1 for expanded and for not (reverse of INEXPAND
  1. ; used in calling routine)
  1. ;KEY VARIABLES
  1. ; UIFMES(UCNT) = message array from the UIF file (may be sparse array)
  1. ; DEFMES = message array as the message is defined
  1. ; USID = segment id for UIF segment
  1. ; MSID = segment id for defined message segment
  1. N LVL,UIFMES,INOUT,OTT,TT1,DMESS,INMSG,DEFMES,INCDEC,INTT,LINE,MSH,MATCH,ORD,OUT,SEGID,VALSTR,VAR,INERR,DEST,TYPE,LVL,UCNT,INDELIM,LCT,EXPAND,IEN,I,J,X,Y,DEBUG,INSUBDEL
  1. ;If needed, DEBUG will have to be set using a break point
  1. I $G(DEBUG) D
  1. .S INMSG="" F I=1:1:79 S INMSG=INMSG_"+"
  1. .D IO(INMSG)
  1. S INERR=0 K LVL,UIFMES,DEFMES,LCT
  1. S INERR=$$UIF^INTSTR1(INUIF,.UIFMES,.INDELIM,.INSUBDEL)
  1. I INERR S INMSG="Unable to validate required fields" D IO(INMSG) Q
  1. I '$D(^INTHU(INUIF,3)) S INMSG="Message contains no segments",INERR=1 D IO(INMSG) Q
  1. I $G(DEBUG) S INMSG="Validating message "_$P(^INTHU(INUIF,0),U,5) D IO(INMSG)
  1. I $G(DEBUG)>1 D
  1. .D IO("UIFMES array:")
  1. .S QX=$Q(UIFMES) Q:'$L(QX) S INMSG=QX_"="_$G(@(QX)) D IO(INMSG)
  1. .F S QX=$Q(@(QX)) Q:'$L(QX) S INMSG=QX_"="_$G(@(QX)) D IO(INMSG)
  1. ;Find the message type for this message
  1. S INOUT=$P(^INTHU(INUIF,0),U,10)
  1. I INOUT="I" D Q:INERR
  1. .;If incoming, get Transaction Type from Destination data
  1. .S TYPE=$$TYPE^INHOTM(INUIF)
  1. .I 'DEST S INMSG="Can not validate. Transaction has no destination",INERR=1 D IO(INMSG) Q
  1. .I 'TYPE S INMSG="Can not validate. Destination has no method of processing",INERR=1 D IO(INMSG) Q
  1. .I TYPE'=1 S INMSG="Can not validate. This destination is not currently supported",INERR=1 D IO(INMSG) Q
  1. .S OTT=+$P(^INRHD(DEST,0),U,2) I 'OTT S INMSG="Can not validate. Missing transaction type or entry for destination "_$P(^INRHD(DEST,0),U),INERR=1 D IO(INMSG) Q
  1. ;If outbound, get originating TT from 11th piece
  1. I INOUT="O" D Q:INERR
  1. .S OTT=$P(^INTHU(INUIF,0),U,11)
  1. .Q:OTT
  1. .S INMSG="Can not validate. Originating Transaction Type not found",INERR=1 D IO(INMSG)
  1. I '$D(^INRHT(OTT)) S INMSG="Can not validate. No entry in Transaction Type File for this transaction type",INERR=1 D IO(INMSG) Q
  1. S INMSG="Validating Transaction Type: "_$P(^INRHT(OTT,0),U) D IO(INMSG)
  1. ;Determine if a message uses this originating transaction type.
  1. D FNDMSG(OTT,.DMESS)
  1. ;If DMESS is found, compare actual message with this. If it is not
  1. ;found, it may be a replicated transacton--so check replication file.
  1. ;If found there, re-define OTT to be the "base" transaction type.
  1. I 'DMESS,$D(^INRHR("B",OTT)) D
  1. .S IEN=$O(^INRHR("B",OTT,"")),OTT=$P(^INRHR(IEN,0),U,2)
  1. .S INMSG="Validating Base Transaction Type: "_$P(^INRHT(OTT,0),U) D IO(INMSG)
  1. .;Now determine if a message uses the "base" transaction type.
  1. .D FNDMSG(OTT,.DMESS)
  1. I 'DMESS S INMSG="Can not validate. No message defined for transaction type" D IO(INMSG) Q
  1. ;Run the verification
  1. S INMSG="Validating message: "_$P(^INTHL7M(DMESS,0),U) D IO(INMSG)
  1. ;;Enhancement: Allow user to select message type instead of doing lookup
  1. ;W "Select message type"
  1. ;S DIC="^INTHL7M(",DIC(0)="AEQ" D ^DIC Q:Y<1
  1. ;also set DIC to default to the type found above.
  1. D MSG^INTSTR1(DMESS,.DEFMES)
  1. I '$D(DEFMES) S INMSG="Can not validate. No structure is defined for this message" D IO(INMSG) Q
  1. I $G(DEBUG)>1 D
  1. .D IO("DEFMES array:")
  1. .S QX="DEFMES"
  1. .F S QX=$Q(@(QX)) Q:'$L(QX) S INMSG=QX_"="_$G(@(QX)) D IO(INMSG)
  1. S LVL(1)=$O(DEFMES("")),UCNT=$O(UIFMES("")),INERR=0
  1. ;S INCDEC=1 D LOOP^INTSTR2(INUIF,.LVL,.UCNT,.INCDEC,.INERR)
  1. S INCDEC=1 D LOOP^INTSTR2(INUIF,.LVL,.UIFMES,.UCNT,.INCDEC,.DEFMES,.INERR)
  1. ;
  1. ;As final check, loop through UIFMES array to see if all
  1. ;segments have been validated.
  1. I INEXPND D IO("---- Required Field summary -------------------------")
  1. S UCNT="" F S UCNT=$O(UIFMES(UCNT)) Q:'UCNT D
  1. .S STATUS=$P(UIFMES(UCNT),U,2)
  1. .;In expanded mode, display validation status of all segments.
  1. .I INEXPND,STATUS D
  1. ..S INMSG="Segment "_$P(UIFMES(UCNT),U)_": Required fields "_$S(STATUS=1:"present",1:"missing")
  1. ..D IO(INMSG)
  1. .Q:$P(UIFMES(UCNT),U,2)
  1. .;Whether expanded or not, display status of segments not validated.
  1. .S INERR=2,INMSG="Warning. Segment "_$P(UIFMES(UCNT),U)_" could not be validated" D IO(INMSG)
  1. ;Display final message
  1. S INMSG=$S('INERR:"All required fields are present",INERR=2:"Message structure is incorrect",1:"Message contains errors") D IO(INMSG)
  1. Q
  1. ;
  1. FNDMSG(OTT,DMESS) ;find message that contains the ttype
  1. ;INPUT:
  1. ; OTT = Originating Transaction Type
  1. ;OUTPUT:
  1. ; DMESS = (PBR) the ien of the message (Script Generator
  1. ; Message File entry) containing OTT.
  1. ; DMESS=0 if no message contains OTT.
  1. N IEN,TT1,INTT
  1. S (IEN,DMESS)=0 F S IEN=$O(^INTHL7M(IEN)) Q:'IEN!DMESS D
  1. .Q:'$D(^INTHL7M(IEN,2))
  1. .S TT1=0 F S TT1=$O(^INTHL7M(IEN,2,TT1)) Q:'TT1!DMESS D
  1. ..S INTT=$G(^INTHL7M(IEN,2,TT1,0))
  1. ..I INTT=OTT S DMESS=IEN Q
  1. Q
  1. ;
  1. IO(INMSG,INDRCT) ;print messages
  1. ;If called as part of Unit Test Utility, DISPLAY^INTSUT1 is used.
  1. ;;Future development: i
  1. ;INPUT:
  1. ; INMSG=message to print
  1. ; INDRCT (OPT) = 1 if called as a stand alone function
  1. I '$G(INDRCT) D DISPLAY^INTSUT1(INMSG,0) Q
  1. ;;Future development: Build in writes to IO. A call to %ZIS needed
  1. ;;at top.
  1. I $G(INDRCT) W INMSG,! Q
  1. Q
  1. ;
  1. TEST(INEXPND,INSTEP) ;Run a test of nn messages in INTHU
  1. ;INPUT:
  1. ; INEXPND=1 for expanded mode, 0 for not
  1. ; INSTEP = 1 to pause (step) between messages
  1. N N,INREQLST,UIF
  1. W !,"Enter number of messages from INTHU to validate " R N:3600
  1. Q:'+N
  1. W !,"This runs a test validation on the last "_N_" messages in INTHU",!
  1. W "Press any key to start",! R *x:3600
  1. S U="^"
  1. K INREQLST
  1. S UIF="A" F I=1:1:N S UIF=$O(^INTHU(UIF),-1) Q:'UIF D
  1. .;S INREQLST(I)=UIF
  1. .S INMSG="UIF Transaction "_$P(^INTHU(UIF,0),U,5) D IO(INMSG)
  1. .D MAIN(UIF,INEXPND)
  1. .I $G(INSTEP) D IO("Press any key to continue") R *X:3600
  1. Q
  1. ;