Batch Class

Creating a Batch (BHS) which could include hundreds of MSH segments for processing. Normally used in large data processing. However, the server usually breaks down a batch MSH into single "elements" to process them and returns that the batch.

1.0.0

Hierarchy

  • RootBase
    • Batch

Constructors

Properties

_name: string
parent: null | NodeBase
empty: EmptyNode = ...

Accessors

Methods

  • Add a Message to the Batch

    Parameters

    • message: Message

      The Message to add into the batch.

    • Optionalindex: number

      Used Internally mostly to add an MSH segment within a BHS segment at a certain index.

    Returns void

    This adds a Message (MSH) output into the batch. It also increases the count of the BTS segment as the batch final result when in end tells the receiving end how many message (MSH) segments are included.

    1.0.0

  • End Batch

    Returns void

    At the conclusion of building the batch, (Usually add method will be before this) will add the Batch Trailing Segment (BTS) to the end. If a message (MSH) is added after this, that message (MSH) will get added to the first BHS found if there is more than one. This might be typical inside a file output process. FileBatch for more information.

    1.0.0

  • Get BHS Segment at Path

    Parameters

    • path: string | number

      Could be 'BHS.7' or 7, and it shall get the same result.

    Returns HL7Node

    1.0.0

    const date = batch.get('BHS.7')
    

    or

    const date = batch.get(7)
    
  • Get the First Segment

    Parameters

    • name: string

      The name of the segment. At max usually three characters long.

    Returns Segment

    Returns the first segment found in the Batch (BHS). This is only used during the add method in determining if there is more than one Batch of MSH in a File Batch FileBatch which can hold more than one Batch groups.

    1.0.0

  • Get Messages within a submitted Batch

    Returns Message[]

    Returns an array of messages or a HL7ParserError will throw.

    This will parse the passed on "text" in the contractor options and get all the messages (MSH) segments within it and return an array of them.

    1.0.0

    try {
    // parser the batch
    const parser = new Batch({ text: loadedMessage })
    // load the messages
    const allMessage = parser.messages()
    // loop messages
    allMessage.forEach((message: Message) => {
    const messageParsed = new Message({ text: message.toString() })
    })
    } catch (e) {
    // error here
    }
  • Set Batch Segment at Path with a Value

    Parameters

    • path: string | number

      Where you want to set in the segment

    • Optionalvalue: any

      The value. It Can be an Array, String, or Boolean. If the value is not set, you can chain this to expand the paths

    Returns HL7Node

    1.0.0

    const batch = new Batch()
    batch.set('BHS.7', '20231231')

    If the value is not used this can be employed:

    batch.set('BHS.3').set(0).set('BHS.3.1', 'abc');
    
  • Start Batch

    Parameters

    • Optionalstyle: "8" | "12" | "14"

      Your options produce: YYYYMMDDHHMMSS = 14 | YYYYMMDDHHMM = 12 | YYYYMMDD = 8

    Returns void

    This allows you to override the orginial contractor BHS fields that are required. In this case, 'BHS.7' (Date Field) is filled out with a 14-character date field with YYYYMMDDHHMMSS entered in by default.

    1.0.0

    YYYYMMDDHHMMSS (14)
    
  • Create File from a Batch

    Parameters

    • name: string

      File Name

    • OptionalnewLine: boolean

      Provide a New Line

    • Optionallocation: string

      Where to save the exported file

    • extension: string = "hl7"

      Custom extension of the file. Default: hl7

    Returns string

    Will procure a file of the saved MSH in the proper format that includes a FHS and FTS segments with the possibility of more than one BHS segments inside with one or more MSH inside each BHS groups.

    1.0.0

    const batch = new Batch({text: hl7_batch_string})
    batch.toFile('readTestBHS', true, 'temp/')

    You can set an extension parameter on Batch to set a custom extension if you don't want to be HL7.