# Energy-Efficient De-Duplication Mechanism for Healthcare Data Aggregation in IoT
## 4 Proposed Solution
In step 6, the case of emergency conditions is checked, and the system may adopt the lossless behavior without skipping the readings and concatenate in an original string as given in steps 17-19. The same steps are executed when the threshold is approached to share the full readings. The threshold can be set as 10 or above as per the criteria approved for the scenario. It is applied when sensors take readings frequently and transmit them at regular intervals having to detect even minor changes in readings for the patient. In case of exceeding the threshold, the count is reinitialized to zero and the control will be moved to steps 17-19 in the next execution to concatenate the full readings in original format. In steps 24-30, the function AggregateMessage (IN_ARGS) is described which is used for processing a single sensor reading. If the sensor reading lies in the normal range then only a Boolean digit \"0\" is transmitted and concatenated to the data string. In steps 31-46, both flags are initialized as True, and the function AggregateMessage (IN_ARGS1, IN_ARGS2) is presented that takes two parameters. This function checks every reading against separate thresholds THL1, THU1, THL2, and THU2. If (IN_ARGS1 and IN_ARGS2) reading lies outside the threshold, then original values are concatenated to the dataString and set flag1 and flag2 as False. Then, flag1 and flag2 are checked, if it is true then it indicates normal data, and Boolean digit 0 is transmitted. After processing all sensor nodes, the algorithm sends the de-duplicated data to Fog Servers. ```
1. Input: Set of healthcare Sensor nodes [n\({}_{1}\), n\({}_{2}\),..., n\({}_{k}\)]
2. Output: De-duplicated Data list
3. Set dataString as List
4. N[j]:Reading[] = sensors generated readings saved after timer t
5. If emergency_flag is OFF OR count equals 0 then //Flag status is set in received message
6. For I = 1 to k do // for all k sensors
7. If (N[j].Reading[].count equals 1) then
8. AggregateMessage (N[j].Readings[])
9. Else If (N[j].Reading[].count equals 2)
10. AggregateMessage (N[j].Readings[0], N[j].Readings[1])
11. End If
12. End For
13. If count > threshold then //Threshold set to a number, e.g., 10 or above to add full readings
14. Set count to 0
15. End If
16. Else If
17. For i = 1 to k do // for all k sensors add full readings
18. Concatenate N[j].Readings[] in dataString in originalform
19. End For
20. End If
21. Increment count by 1
22. Calculate Hash\({}_{\text{org}}\) of data before transmission
23. Send dataString from CHs to Fog Servers
24. Function AggregateMessage (IN_ARGS) // List of input arguments
25. If IN_ARGS.value < TH\({}_{L}\) OR IN_ARGS.value > TH\({}_{U}\) then
26. Concatenate IN_ARGS.value in dataString //for upper or lower values
27. Else
28. Concatenate Boolean digit 0 in dataString //for normal data
29. End if
30. End Function AggregateMessage (IN_ARGS1, IN_ARGS2) // List of input arguments
31. Initialize flag1 = flag2 = True
33. If IN_ARGS1.value < TH\({}_{L1}\) OR IN_ARGS1.value > TH\({}_{U1}\) then
34. Concatenate IN_ARGS1.value in dataString //for upper or lower values
35. Set flag1 as False
36. End If
37. If IN_ARGS2.value < TH\({}_{L2}\) OR IN_ARGS2.value > TH\({}_{U2}\) then
38. Concatenate IN_ARGS2.value in dataString //for upper or lower values
39. Set flag2 as False
40. End If
41. If flag1 equals True then
42. Concatenate IN_ARGS1 as Boolean digit 0 in dataString //for normal data
43. Else If flag2 equals True
44. Concatenate IN_ARGS2 as Boolean digit 0 in dataString //for normal data
45. End if
46. End Function
```  
**Algorithm 1**Transmission of Non-duplicated data to CH  
The CH receives aggregated data from sensor nodes which is described by using Algorithm 2. The CH, after receiving concatenated data strings, processes it. When data are received at CH, the status of emergency flag is also checked, and if it is true, it indicates that the patient has a critical condition.