File Batch Class

Create a File Batch (FHS) which will could include many BHS/BTS segments, which could include many Message (MSH) segments to output the contents into a file on the OS. These files could then be used to send manually or read by another system to interpret the contents. This class helps in generating the particulars for that file generation to make sure that it follows the correct format.

1.0.0

Hierarchy

  • RootBase
    • FileBatch

Constructors

Properties

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

Accessors

Methods

  • AAdd a Message or a Batch to the File

    Parameters

    Returns void

    This adds a Message (MSH) output into the file batch. If there is a Batch ("BHS") already part of this file, any new Message type will be added to the first found BHS regardless if the second Batch is added last.

    1.0.0

  • Create a file to be stored.

    Parameters

    • name: string

      Name of the file.

    Returns void

    1.0.0

  • End Batch

    Returns void

    At the conclusion of building the file batch, (Usually add method will be before this) will add the File Batch Trailing Segment (FTS) 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 one, otherwise it will just be added. This might be typical inside a file output process.

    1.0.0

  • Get FHS Segment at Path

    Parameters

    • path: string | number

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

    Returns HL7Node

    1.0.0

    const fileBatch = file.get('FHS.7')
    

    or

    const fileBatch = file.get(7)
    
  • Get Messages within a submitted File 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. This will happen regardless of the depth of the segments.

    1.0.0

    try {
    // parser the batch
    const parser = new FileBatch({ 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');
    
  • Parameters

    • _name: string
    • Optional_newLine: boolean
    • Optional_location: string

    Returns void