# IoT-Based Medical Image Monitoring System Using HL7 in a Hospital Database
## 2 Materials and Methods
### Ultrasound Machine to Raspberry Pi HL7 Messaging Process
#### 2.1.1 HL7 Block Formation and Messages  
The HL7 block format is as follows:  
```
<SB>Message<EB><CR>
```  
Here: <SB>-SB stands for Start Block Character, which is a 1-byte ASCII character, such as <VT> or <0x0B>. Message--This denotes a message with a certain number of bytes of data. It is a block of HL7 data content. <EB>-End Block, or EB, is a 1-byte ASCII character such as <FS> or <0x1C>. <CR>-CB denotes a carriage return containing one byte of data. For instance, 0x0D. There are two types of connection from the ULSM to the RSPI3 and vice versa: (a) Active connection and (b) Passive connection. Here, the proposed model used an active connection - (a)Active Connection: Connection established on both sides (i) Persistent (ii) Transient (i) Persistent  
1. On startup, try to connect to the listening or passive system's set IP address and port. 2. If the connection fails, wait a brief time before retrying the connection. Once all possible retries have been used up, the connection will either be deactivated at the operator's request, or the instrument will be switched off. 3. Maintain the connection at all times, even if there are no further messages to send. 4. Retry the connection if a disconnection is detected outside of a data exchange. 5. A message transmission fault is displayed if a disconnection is detected during a data exchange (for example, while waiting for a response), and the ULSM stops the HL7 connection. The above steps are described in Algorithms 1-3 accordingly. Algorithm 1 shows how the ULSM communicates with the RSPI3, Algorithm 2 shows how the RSPI3 communicates with the ULSM using socket programming, and Algorithm 3 describes how the listener receives HL7 messages. ```
1 Start
2 whileUltrasoundMachineWantsToSendMessagedo ifisConnectionIsActivethen Send HL7 Message to RSPI3 [SB EB CR] else while!isConnectionIsActivedo isConnectionIsActive = Established A Socket or TCP/ IP [IP + PORT] Connection With RSPI3 SLEEP(Few Seconds) End
```  
**Algorithm 1**Ultrasound Machine to RSPI3 Message Transfer  
```
1. Try to connect only when a message is ready to be sent. 2. When a message is ready to be sent, connect to the listening or passive system's preset IP address and port. 3. If the connection fails, it needs to wait a few moments before attempting it again, as in the Persistent method. 4. Only keep the connection open if there are further messages to send. Close the connection if this is not the case. A message transmission fault is displayed if a disconnection is detected during a data exchange (for example, while waiting for a response), and the ULSM stops the HL7 connection. ```
1 Start
2 whileUltrasoundMachineWantsToSendMessagedo
3 ifisConnectionIsActivethen
4 Send HL7 Message to Ultrasound Machine [SB EB CR]
5 else
6 whileisConnectionIsActivedo
7 isConnectionIsActive = Established A Socket or
7 TCP / IP [IP + PORT] Connection With
8 Ultrasound Machine
8 SLEEP(Few Seconds)
9 End
```
**Algorithm 2**RSPI3 to Ultrasound Machine Message Transfer

In HL7 communication, different kinds of messages are used, such as the Connection Messages (see Table A1), Order Messages (Table A2), Result Messages (Table A3), and Acknowledgement Messages (Table A4). ### Result Data Extraction

The ultrasound machine sends a result message based on HL7 via a socket-based connection. The HL7 result message contains a few segments which are MSH (Message Header), PID (Patient information with ID), SID (Sample ID), OBR (Observation Result), and OBX (Observation Result Data). From those segments, the proposed model extracts that information via a segment-based data extraction model, which is a string-based concatenation model. After that, the extracted result data are used for further processes such as (i) storing in the database, or (ii) data processing for FTP and IoT. Result Data Stored in the LIS (Lab Information System)

1. Raw data of the results are stored in the LIS (Laboratory Information System) via API (Application Programming Interface). 2. Extracted data are: 1. Patient's info 2. Sample ID 3.