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

KMPDHU02.m

Go to the documentation of this file.
  1. KMPDHU02 ;OAK/RAK - CM Tools Compile & File HL7 Daily Stats ;2/17/04 08:58
  1. ;;3.0;KMPD;;Jan 22, 2009;Build 42
  1. ;
  1. DAILY(KMPDST,KMPDEN) ;-entry point
  1. ;-----------------------------------------------------------------------
  1. ; KMPDST... Start date in internal fileman format.
  1. ; KMPDEN... End date in internal fileman format.
  1. ;
  1. ; This API gathers HL7 data and stores it in file 8973.1 (CM HL7 DATA)
  1. ;
  1. ; Variables used:
  1. ; GBL...... Global where data is stored - for use with indirection
  1. ; GBL1..... globas where compiled data is stored before filing -
  1. ; used with indirection
  1. ;-----------------------------------------------------------------------
  1. ;
  1. Q:'$G(KMPDST)
  1. Q:'$G(KMPDEN)
  1. ; make sure end date has hours
  1. S:'$P(KMPDEN,".",2) $P(KMPDEN,".",2)="99"
  1. S:'$G(DT) DT=$$DT^XLFDT
  1. ;
  1. N ERROR,GBL,GBL1,STR,X
  1. ;
  1. ; get data from hl7 api
  1. W:'$D(ZTQUEUED) !,"Gathering HL7 data..."
  1. ; global with 'raw' hl7 api data
  1. S GBL=$NA(^TMP("KMPDH",$J)) K @GBL
  1. ; set up global to get asynchronous data
  1. K ^TMP($J)
  1. S ^TMP($J,"HLUCM")="DEBUG GLOBAL"
  1. S X=$$CM2^HLUCM(KMPDST,KMPDEN,1,1,"KMPDH","EITHER",.ERROR)
  1. I 'X!($D(ERROR))!('$D(^TMP("KMPDH",$J))) D Q
  1. .W:'$D(ZTQUEUED) " no data to report"
  1. ;
  1. ; global for storing compiled data before filing
  1. S GBL1=$NA(^TMP("KMPDH-1",$J)) K @GBL1
  1. ;
  1. W:'$D(ZTQUEUED) !,"Compiling synchronous HL7 data..."
  1. D SYNC
  1. ;
  1. W:'$D(ZTQUEUED) !,"Compiling asynchronous HL7 data..."
  1. D ASYNC
  1. ;
  1. K @GBL,@GBL1,^TMP($J),^TMP("KMPDHERRTIME",$J)
  1. W:'$D(ZTQUEUED) !,"Finished!"
  1. ;
  1. Q
  1. ;
  1. ;
  1. ASYNC ;- asynchronous data
  1. Q:$G(GBL)=""
  1. Q:$G(GBL1)=""
  1. ;
  1. N COUNT,DATA,DATA1,DATA2,HOUR,I,IEN,IEN1,IEN2,J,LOCAL,MSG,NM,NODE
  1. N OF,PIECE,PR,PTNP,SD,STDT,TIME1,TIME2,UNIT
  1. ;
  1. ; local site name
  1. S LOCAL=$P($$SITE^VASITE,U,2) Q:LOCAL=""
  1. S IEN=0
  1. F S IEN=$O(^TMP($J,"HLUCMSTORE","U",IEN)) Q:'IEN S DATA=^(IEN) D
  1. .; data = Protocol~Ien^Namespace
  1. .; message type
  1. .S MSG=$P(DATA,U,6)
  1. .; quit if not 'complete' message
  1. .Q:'$$ASYNCHK(MSG)
  1. .; protocol - check protocol fist, then inferred protocol
  1. .S PR=$S($P(DATA,U,7)]"":$P(DATA,U,7),$P(DATA,U,8)]"":$P(DATA,U,8),1:"") Q:PR=""
  1. .; namespace - check namespace first, then inferred namespace
  1. .S NM=$S($P(DATA,U,9)]"":$P(DATA,U,9),$P(DATA,U,10)]"":$P(DATA,U,10),1:"") Q:NM=""
  1. .; other facility
  1. .S OF=$P(DATA,U,11) S:OF["~" OF=$P(OF,"~",2) Q:OF=""
  1. .; quit if other facility is LOCAL
  1. .Q:OF[LOCAL
  1. .; start date/time
  1. .S STDT=$P(DATA,U,4) Q:'STDT
  1. .; date without time
  1. .S SD=$P(STDT,".") Q:'SD
  1. .S $P(@GBL1@(SD,PR,NM,OF,99.2),U,11)=$P($P(DATA,U,11),"~")
  1. .S $P(@GBL1@(SD,PR,NM,OF,99.2),U,12)=$P($P(DATA,U,11),"~",2)
  1. .S $P(@GBL1@(SD,PR,NM,OF,99.2),U,13)=$P($P(DATA,U,11),"~",3)
  1. .;
  1. .S (COUNT,HOUR,IEN1)=0 K UNIT
  1. .F S IEN1=$O(^TMP($J,"HLUCMSTORE","U",IEN,IEN1)) Q:'IEN1 D
  1. ..; data1 = piece 1 - Characters
  1. ..; piece 2 - Messages
  1. ..; piece 3 - Seconds
  1. ..; piece 4 - Begining Time
  1. ..; piece 5 - End Time
  1. ..; piece 6 - Type: msg, ca, aa or ca
  1. ..; piece 7 - Protocol~Ien
  1. ..; piece 8 - Namespace
  1. ..S DATA1=$G(^TMP($J,"HLUCMSTORE","U",IEN,IEN1,"CCC")) Q:DATA1=""
  1. ..S COUNT=COUNT+1,UNIT(COUNT)=DATA1
  1. .;
  1. .; back to IEN level
  1. .; quit if unit() array is not complete
  1. .Q:'$$UNITS(MSG)
  1. .; hour of transaction
  1. .S HOUR=+$E($P(STDT,".",2),1,2),HOUR=HOUR+1
  1. .; prime time or non-prime time
  1. .S PTNP=$$PTNP^KMPDHU03(STDT) Q:'PTNP
  1. .; node: 5 - prime time
  1. .; 6 - non-prime time
  1. .S NODE=$S(PTNP=2:6,1:5)
  1. .;
  1. .; update msg unit count - prime time or non-prime time
  1. .S $P(@GBL1@(SD,PR,NM,OF,99.5),U,PTNP)=$P($G(@GBL1@(SD,PR,NM,OF,99.5)),U,PTNP)+1
  1. .;update msg unit count - both prime time & non-prime time
  1. .S $P(@GBL1@(SD,PR,NM,OF,99.5),U,3)=$P($G(@GBL1@(SD,PR,NM,OF,99.5)),U,3)+1
  1. .; totals
  1. .F J=0:0 S J=$O(UNIT(J)) Q:'J F I=1:1:3 D
  1. ..; total
  1. ..S $P(@GBL1@(SD,PR,NM,OF,99.2),U,I)=$P($G(@GBL1@(SD,PR,NM,OF,99.2)),U,I)+$P(UNIT(J),U,I)
  1. ..S $P(@GBL1@(SD,PR,NM,OF,99.3),U,(I+6))=$P($G(@GBL1@(SD,PR,NM,OF,99.3)),U,(I+6))+$P(UNIT(J),U,I)
  1. ..; prime time or non-prime time
  1. ..; ^ piece to set
  1. ..S PIECE=I+$S(PTNP=2:3,1:0)
  1. ..S $P(@GBL1@(SD,PR,NM,OF,99.3),U,PIECE)=$P($G(@GBL1@(SD,PR,NM,OF,99.3)),U,PIECE)+$P(UNIT(J),U,I)
  1. .;
  1. .; msg to ca - originating message to commit ack
  1. .; ^ piece: 1 - characters
  1. .; 2 - count
  1. .; 3 - seconds
  1. .F I=1:1:3 S $P(@GBL1@(SD,PR,NM,OF,NODE+(I*.1)),U,HOUR)=$P($G(@GBL1@(SD,PR,NM,OF,NODE+(I*.1))),U,HOUR)+($P(UNIT(1),U,I)+$P(UNIT(2),U,I))
  1. .;
  1. .; processing time (ca to aa) - commit ack ending time to application
  1. .; ack starting time
  1. .S TIME1=+$P(UNIT(3),U,4),TIME2=+$P(UNIT(2),U,5)
  1. .S $P(@GBL1@(SD,PR,NM,OF,(NODE+(.4))),U,HOUR)=$$TIMEADD^KMPDU($P($G(@GBL1@(SD,PR,NM,OF,(NODE+(.4)))),U,HOUR)+$$FMDIFF^XLFDT(TIME2,(+TIME1),3))
  1. .; processing time (ca to aa) - count
  1. .S $P(@GBL1@(SD,PR,NM,OF,(NODE+(.5))),U,HOUR)=$P($G(@GBL1@(SD,PR,NM,OF,(NODE+(.5)))),U,HOUR)+1
  1. .;
  1. .; aa to ca - application ack to commit ack
  1. .; ^ piece: 1 - characters
  1. .; 2 - count
  1. .; 3 - seconds
  1. .F I=1:1:3 S $P(@GBL1@(SD,PR,NM,OF,NODE+(I+6*.1)),U,HOUR)=$P($G(@GBL1@(SD,PR,NM,OF,NODE+(I+6*.1))),U,HOUR)+($P(UNIT(3),U,I)+$P(UNIT(4),U,I))
  1. ;
  1. D:$D(@GBL1) FILE^KMPDHU03(2)
  1. ;
  1. Q
  1. ;
  1. ASYNCHK(KMPDMSG) ;-- extrinsic function - check for 'complete' message
  1. ;-----------------------------------------------------------------------
  1. ; KMPDMGS... message ack designations
  1. ;
  1. ; Return: 0 - not a complete message
  1. ; 1 - complete message
  1. ;-----------------------------------------------------------------------
  1. Q:$G(KMPDMSG)="" 0
  1. Q:MSG="MSG~CA~AA~CA" 1
  1. Q:MSG="MSG~CA~AR~CA" 1
  1. Q:MSG="MSG~AA" 1
  1. Q 0
  1. ;
  1. UNITS(MSG) ;-- extrinsic function
  1. ;-----------------------------------------------------------------------
  1. ; MSG.... type of message: 'msg~aa', 'msg~ca~aa~ca', etc.
  1. ;
  1. ; Return: 0 - unit() array not complete
  1. ; 1 - unit() array is complete
  1. ;
  1. ; unit() array must be segmented into the following format:
  1. ; unit(1) = msg
  1. ; unit(2) = ca
  1. ; unit(3) = aa
  1. ; unit(4) = ca
  1. ; this data is then used to calculate characters, messages and seconds
  1. ;-----------------------------------------------------------------------
  1. Q:$G(MSG)="" 0
  1. ; all messages must have unit(2)
  1. Q:'$D(UNIT(2)) 0
  1. ; "msg~ca~aa~ca" & "msg~ca~ar~ca" messages must have unit(3) & unit(4)
  1. I MSG="MSG~CA~AA~CA"!(MSG="MSG~CA~AR~CA") Q:'$D(UNIT(3)) 0
  1. I MSG="MSG~CA~AA~CA"!(MSG="MSG~CA~AR~CA") Q:'$D(UNIT(4)) 0
  1. ; 'msg~aaa' messages contain only 2 unit() entries
  1. ; create 4 unit() entries for processing
  1. I MSG="MSG~AA" D
  1. .S (UNIT(3),UNIT(4))=UNIT(2),UNIT(2)=UNIT(1)
  1. .S $P(UNIT(1),U,1,3)="0^0^0"
  1. .S $P(UNIT(4),U,1,3)="0^0^0"
  1. ; calculate seconds
  1. ; msg to ca
  1. S $P(UNIT(2),U,3)=$$FMDIFF^XLFDT($P(UNIT(2),U,5),$P(UNIT(1),U,4),2)
  1. S:$P(UNIT(2),U,3)<0 $P(UNIT(2),U,3)=0
  1. ; ca to aa
  1. S $P(UNIT(3),U,3)=$$FMDIFF^XLFDT($P(UNIT(3),U,5),$P(UNIT(2),U,5),2)
  1. S:$P(UNIT(3),U,3)<0 $P(UNIT(3),U,3)=0
  1. ; aa to ca
  1. S $P(UNIT(4),U,3)=$$FMDIFF^XLFDT($P(UNIT(4),U,5),$P(UNIT(3),U,5),2)
  1. S:$P(UNIT(4),U,3)<0 $P(UNIT(4),U,3)=0
  1. ;
  1. Q 1
  1. ;
  1. SYNC ;- synchronous data
  1. ;-----------------------------------------------------------------------
  1. ; SS1...... subscript 1 - identifies data
  1. ; HR - hourly
  1. ; NMSP - namespace
  1. ; PROT - protocol
  1. ; SS2...... subscript 2 - identifies data sorted within SS1
  1. ; IO - incoming/outgoing messages
  1. ; LR - local/remote messages
  1. ; PR - protocol
  1. ; TM - type of transmission
  1. ;
  1. ; SS3...... subcript 3 - which identifier for SS2 is being sorted
  1. ; IO - I - incoming
  1. ; O - outgoing
  1. ; U - unknown
  1. ; LR - L - local
  1. ; R - remote
  1. ; U - unknown
  1. ; PR - P - placeholder for consistent subscripting
  1. ; TM - M - mailman
  1. ; T - tcp
  1. ; U -unknown
  1. ; SS4...... subscript 4 - according to SS1
  1. ; HR - date.time
  1. ; NMSP - namespace
  1. ; PROT - protocal
  1. ; SS5...... subcript 5 - according to SS1
  1. ; HR - namespace
  1. ; NMSP - date.tim
  1. ; PROT - namespace
  1. ; SS6...... subscript 6 - according to SS1
  1. ; HR - protocol
  1. ; NMSP - protocol
  1. ; PROT - date.time
  1. ;-----------------------------------------------------------------------
  1. Q:$G(GBL)=""
  1. Q:$G(GBL1)=""
  1. N SS1,SS2,SS3,SS4,SS5,SS6
  1. S SS1=""
  1. F S SS1=$O(@GBL@(SS1)) Q:SS1="" I SS1'="RFAC" S SS2="" D
  1. .F S SS2=$O(@GBL@(SS1,SS2)) Q:SS2="" S SS3="" D
  1. ..F S SS3=$O(@GBL@(SS1,SS2,SS3)) Q:SS3="" S SS4="" D
  1. ...F S SS4=$O(@GBL@(SS1,SS2,SS3,SS4)) Q:SS4="" S SS5="" D
  1. ....Q:SS1="PROT"&(SS4="ZZZ")
  1. ....F S SS5=$O(@GBL@(SS1,SS2,SS3,SS4,SS5)) Q:SS5="" S SS6="" D
  1. .....; if SS1="NMSP" or SS1="PROT" quit if SS4 and SS5 (protocol/
  1. .....; namespace pair) = ZZZ
  1. .....I SS1="NMSP"!(SS1="PROT") Q:SS4="ZZZ"&(SS5="ZZZ")
  1. .....F S SS6=$O(@GBL@(SS1,SS2,SS3,SS4,SS5,SS6)) Q:SS6="" D
  1. ......Q:SS1="HR"&(SS6="ZZZ")
  1. ......Q:SS1="NMSP"&(SS6="ZZZ")
  1. ......; compile data into daily stats for file #8973.1 (CM HL7 DATA)
  1. ......D COMPILE^KMPDHU03
  1. ;
  1. D:$D(@GBL1) FILE^KMPDHU03(1)
  1. ;
  1. K @GBL1
  1. ;
  1. Q