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

HLOF777.m

Go to the documentation of this file.
  1. HLOF777 ;ALB/CJM-HL7 - API'S for saving data to file 777 ;02/04/2004
  1. ;;1.6;HEALTH LEVEL SEVEN;**126**;Oct 13, 1995
  1. ;
  1. SAVEMSG(HLMSTATE) ;
  1. ;If a record has not yet been created in file 777, then it will be created. Otherwise, it just stores the segments not yet stored.
  1. ;Input:
  1. ; HLMSTATE (pass by reference) - contains information about the message
  1. ; These subscripts must be defined:
  1. ; ("BATCH")=1 if batch, 0 otherwise
  1. ; ("BODY")=ien file 777
  1. ; ("UNSTORED LINES") - count of lines to be stored. The lines are stored at a lower subscript <message#>,<segment#>,<line#>
  1. ;Output:
  1. ; HLMSTATE("UNSTORED LINES")-set to 0
  1. ;
  1. ;if the record has not been created yet,then create it
  1. I 'HLMSTATE("BODY"),'$$NEW(.HLMSTATE) Q 0
  1. ;
  1. ;any segments to store to disk?
  1. Q:'HLMSTATE("UNSTORED LINES") HLMSTATE("BODY")
  1. ;
  1. I 'HLMSTATE("BATCH") D
  1. .N ARY,SEG,LINE
  1. .S ARY="^HLA("_HLMSTATE("BODY")_",1)"
  1. .S SEG=0
  1. .F S SEG=$O(HLMSTATE("UNSTORED LINES",1,SEG)) Q:'SEG D
  1. ..S LINE=0
  1. ..F S LINE=$O(HLMSTATE("UNSTORED LINES",1,SEG,LINE)) Q:'LINE S @ARY@(LINE,0)=HLMSTATE("UNSTORED LINES",1,SEG,LINE)
  1. .;
  1. I HLMSTATE("BATCH") D
  1. .;NOTE: will not store any segments that come before the first MSH!
  1. .N MSG S MSG=0
  1. .F S MSG=$O(HLMSTATE("UNSTORED LINES",MSG)) Q:'MSG D
  1. ..N ARY,SEG,LINE
  1. ..S ARY="^HLA("_HLMSTATE("BODY")_",2,"_MSG_")"
  1. ..;
  1. ..;if starting a new message, add its 0 node. The message type and event are stored in HLMSTATE("UNSTORED LINES",MSG)
  1. ..I '$D(@ARY@(0)) D
  1. ...S @ARY@(0)=MSG_"^"_$G(HLMSTATE("UNSTORED LINES",MSG))
  1. ...;
  1. ...S ^HLA(HLMSTATE("BODY"),2,"B",MSG,MSG)=""
  1. ..;
  1. ..S SEG=0
  1. ..F S SEG=$O(HLMSTATE("UNSTORED LINES",MSG,SEG)) Q:'SEG D
  1. ...S LINE=0
  1. ...F S LINE=$O(HLMSTATE("UNSTORED LINES",MSG,SEG,LINE)) Q:'LINE S @ARY@(1,LINE,0)=HLMSTATE("UNSTORED LINES",MSG,SEG,LINE)
  1. ;
  1. ;clear the cache
  1. K HLMSTATE("UNSTORED LINES")
  1. S HLMSTATE("UNSTORED LINES")=0
  1. ;S:HLMSTATE("BATCH") HLMSTATE("BATCH","CURRENT MESSAGE")=0
  1. Q HLMSTATE("BODY")
  1. ;
  1. NEW(HLMSTATE) ;
  1. ;This function creates a new entry in file 777.
  1. ;Input:
  1. ; HLMSTATE (required, pass by reference) These subscripts are expected:
  1. ; "DIRECTION"
  1. ; "DT/TM" (optional, $$NOW used as default)
  1. ; "BATCH"
  1. ; "HDR","ENCODING CHARACTERS"
  1. ; "HDR","EVENT"
  1. ; "HDR","FIELD SEPARATOR"
  1. ; "HDR","MESSAGE TYPE"
  1. ; "HDR","VERSION"
  1. ;
  1. ;Output - the function returns the ien of the newly created record
  1. ;
  1. N IEN,TIME,NODE
  1. S IEN=$$NEWIEN(HLMSTATE("DIRECTION"),$$TCP^HLOF778A)
  1. Q:'IEN 0
  1. K ^HLA(IEN)
  1. S HLMSTATE("DT/TM CREATED")=$S($G(HLMSTATE("DT/TM")):HLMSTATE("DT/TM"),1:$$NOW^XLFDT)
  1. ;
  1. S NODE=HLMSTATE("DT/TM CREATED")_"^"_HLMSTATE("BATCH")_"^^^"_$G(HLMSTATE("HDR","VERSION"))
  1. I 'HLMSTATE("BATCH") S $P(NODE,"^",3)=HLMSTATE("HDR","MESSAGE TYPE"),$P(NODE,"^",4)=HLMSTATE("HDR","EVENT")
  1. S $P(NODE,"^",20)=HLMSTATE("HDR","FIELD SEPARATOR")_HLMSTATE("HDR","ENCODING CHARACTERS")
  1. S ^HLA(IEN,0)=NODE
  1. ;
  1. ;for incoming msgs, set the "B" xref later
  1. S:HLMSTATE("DIRECTION")="OUT" ^HLA("B",HLMSTATE("DT/TM CREATED"),IEN)=""
  1. ;
  1. S HLMSTATE("BODY")=IEN
  1. Q IEN
  1. ;
  1. NEWIEN(DIR,TCP) ;
  1. ;This function uses a counter to get the next available ien for file 777. There are 3 different counters, each assigned a specific number range, selected via the input parameters. It does not create a record.
  1. ;Inputs:
  1. ; DIR = "IN" or "OUT" (required)
  1. ; TCP = 1,0 (optional)
  1. ;Output - the function returns the next available ien. Several counters are used:
  1. ; <"OUT">
  1. ; <"IN","TCP">
  1. ; <"IN","NOT TCP">
  1. ;
  1. N IEN,COUNTER
  1. S:DIR="IN" COUNTER=$NA(^HLC("FILE777",DIR,$S(+$G(TCP):"TCP",1:"NOT TCP")))
  1. S:DIR="OUT" COUNTER=$NA(^HLC("FILE777",DIR))
  1. AGAIN ;
  1. S IEN=$$INC^HLOSITE(COUNTER,1)
  1. I IEN>100000000000 D
  1. .L +@COUNTER:200
  1. .I $T,@COUNTER>100000000000 S @COUNTER=1,IEN=1
  1. .L -@COUNTER
  1. I IEN>100000000000 G AGAIN
  1. Q (IEN+$S(DIR="OUT":0,+$G(TCP):100000000000,1:200000000000))