Please enable JavaScript to view this site.

HL7 C# Script Reference

 

The CHS_Message class is the object representation of a HL7 message.

 

This class implements the COREException class for your convenience.     

 

See Also: CHS_Segment, CHS_Field

 

               

 

Public MSH Shortcut Properties (Read / Write):

 

These properties can be addressed or set directly from code as they represent shortcuts into fields in the MSH segment.

 

Example:

CHS_Message msg = globals.CreateNewMessage();

msg.MessageType = "ADT";

msg.MessageEvent = "A08";

 

Property Name

Data Type

AcceptAckType

string - Get or Set the Accept Acknowledgment Type from MSH 15.1

HL7Version

string - Get or Set the HL7 Version from MSH 12.1

MessageControlID

string - Get or Set the Message Control ID from MSH 10.1

MessageDate

HL7DateConverter - Get or Set the Message Date from MSH 7.1

MessageEvent

string - Get or Set the Message Event from MSH 9.2

MessageType

string - Get or Set the Message Type from MSH 9.1

ReceivingApplication

string - Get or Set the Receiving Application from MSH 5.1

ReceivingFacility

string - Get or Set the Receiving Facility from MSH 6.1

SendingApplication

string - Get or Set the Sending Application from MSH 3.1

SendingFacility

string - Get or Set the Sending Facility from MSH 4.1

 

 

Public Properties:

 

Property Name

Data Type

SegmentCount

int (read-only) - Will be the number of CHS_Segment objects the HL7 message contains.

 

Public Methods:

 

Method

Return Value

AddFullSegment(string value)

CHS_Segment - If you pass a fully formed HL7 segment string in value it will add the segment to the end of the message and return the CHS_Segment object. Will return null if value is not a valid HL7 segment string. NOTE: Adding MSH segments are ignored if one exists.

 

AddNewSegment(CHS_Segment segment)

CHS_Segment - Adds a disconnected CHS_Segment created with CreateNewSegment() OR CHS_Segment.Clone() into the message object at the end.  NOTE: Adding MSH segments are ignored if one exists.

AddSegment(string segmentName)

CHS_Segment - Adds a new CHS_Segment named segmentName to the end of the message, segmentName must be a valid 3 character name for a HL7 segment. NOTE: Adding MSH segments are ignored if one exists.

ContainsSegment(string segmentName)

bool - Returns true if the message contains a CHS_Segment object named segmentName.

CreateNewSegment(string value)

CHS_Segment - Creates a new CHS_Segment object which is NOT part of the HL7 message (a disconnected CHS_Segment). You can then call AddNewSegment() to add a copy of the segment to the message. The benefit here is that you can call AddNewSegment() multiple times so that if you have many repeating segments to add to your message which are largely the same (Example: OBX segments or NTE segments) you can reuse the same CHS_Segment object.

ExportToFile(string fileName, bool overwrite = false)

bool - Saves the MessageValue() into a file on the file system fileName and returns true if successful or false on error. If overwrite is false and fileName exists the MessageValue() is appended to the end of fileName.

ExportToFolder(string path)

bool - Saves the MessageValue() into a file on the file system in folder path returns true if successful or false on error. This uses the globals.SuggestedFileTitle() method to create the file name.

GetAllSegments()

List<CHS_Segment> - Returns a List<> object containing all CHS_Segment objects in the message.

GetFirstSegmentNamed(string name)

CHS_Segment - Returns the first CHS_Segment in the message with the SegmentName name or null if one does not exist.

GetSegmentsNamed(string name)

List<CHS_Segment> - Returns a List<> object containing all CHS_Segment objects in the message with the SegmentName name or an empty List<> if none exist.

GetSegmentsNamed(string[] names)

List<CHS_Segment> - Returns a List<> object containing all CHS_Segment objects in the message with the SegmentName contained in the string array names or an empty List<> if none exist.

InsertSegmentAt(int index, CHS_Segment segment)

CHS_Segment - Inserts a disconnected CHS_Segment segment into the message at position index. Note that index is 1 based with index 1 belonging the MSH segment.

MessageValue()

string- Returns the current string value of the HL7 message.

Publish()

bool - Writes the MessageValue() into a file on the file system in globals.OutputFolder. You could also call ExportToFolder(globals.OutputFolder) for the same result.

RemoveAllSegmentsNamed(string[] names)

RemoveAllSegmentsNamed(List<string> names)

bool - Removes all segments from the message where segment name is in the string array names (or List<string> names). NOTE: If MSH is included it is ignored.

RemoveAllSegmentsNotNamed(string[] names)

RemoveAllSegmentsNotNamed(List<string> names)

bool - Removes all segments from the message where segment name is NOT in the string array names (or List<string> names). NOTE: MSH segment is never removed.

RemoveSegment(CHS_Segment segment)

bool - Removes CHS_Segment segment from the message. NOTE: MSH segment is never removed.

RemoveSegmentsNamed(string name)

bool - Removes all segments from the message where segment name is equal to name. NOTE: Will NOT remove the MSH segment.

ToString()

string- Returns the current string value of the HL7 message. Functionally equivalent to MessageValue().

 

 

  

Keyboard Navigation

F7 for caret browsing
Hold ALT and press letter

This Info: ALT+q
Nav Header: ALT+n
Page Header: ALT+h
Topic Header: ALT+t
Topic Body: ALT+b
Exit Menu/Up: ESC