# ECG
## ECG 概述
-- [12 lead ECG](https://docs.google.com/presentation/d/11_8-fpVnIrqGM9UpKYh4e1yU_3c3cbCg/edit?usp=share_link&ouid=107126242390772765102&rtpof=true&sd=true)、[Long term ECG](https://d3i71xaburhd42.cloudfront.net/9251bde5bf8c651798c8c75c7e508b7a2ad9d0e3/2-Figure2-1.png)
## 各式心電圖資料規格概述
- [EBM data](https://hackmd.io/26qcRbfLRbSXu01XVkETXw?view#EBM-data)
- DICOM ECG
-- DICOM 有規範 ECG 格式,但現行許多心電圖產生的資料規格不一,如下範例:
### [MIT 212 format ECG PPT](https://docs.google.com/presentation/d/1cVWlN6MBVLGLkUJh8brUC3pSmWBH8gQS/edit?usp=share_link&ouid=107126242390772765102&rtpof=true&sd=true)
- [參考說明 1](https://mos2718.github.io/MICexp/MITecg/Index.html)、[參考說明 2](https://blog.csdn.net/qq_26938759/article/details/79695215)
- ECG 檔案及程式範例: [PY 程式解讀](https://drive.google.com/file/d/11U0ZQ9oxJfdF8wYWlBUCk5bWcnTi-PQj/view?usp=share_link)、[C 程式](https://drive.google.com/file/d/1XMIFUlfDiLLzDfbQwL4AJrtPH9i9K-vM/view?usp=sharing)
-- 希望基於 FHIR 將心電圖轉成標準規格
## [參考資料解析步驟](https://hackmd.io/ksxMra5MT4m6IUoSQ3-vcw?view#Parsing-clinical-data)
- 此簡單的程式可用以分析各式資料,如 [MIT ECG](https://www.physionet.org/content/mitdb/1.0.0/),假設我們清楚資料規格(最難)
```=c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE * pFile;
pFile = fopen ( "d:\\100.dat" , "rb" );
if (pFile==NULL) {printf("file open error");}
unsigned char buffer[24000];
int readBytes;
readBytes = 360*3*5; //sample rate 360, 1.5 * 2 leads, 5 seconds
size_t result;
result = fread (buffer,1, readBytes,pFile);
int i;
for(i=0;i< readBytes;i++)
{printf("%d \n",buffer[i]); }
fclose (pFile);
}
```
```cpp
buffer[readBytes]=0;
int i;
unsigned char b1,b2,b3;
int v;
fprintf (pFileOut, "var ECGdat =[ \n");
for(i=0;i< readBytes;i= i+3)
{b1= buffer[i];
b2= buffer[i+1];
b3 =buffer[i+2];
v = (b2 /16) *256 +b1;
printf("%u, ",v );
v = (b2 % 16) *256 +b3;
printf("%u \n ", v );
}
```

## FHIR ECG and connectathon
- 未來希望轉換成標準規格,如下 FHIR ECG,如下:
- [video 1 Jack Hsiao](http://203.64.84.150:51888/user5/MITW/2022-09-27WG2ECG.mp4)、[video 2 苑容](http://203.64.84.150:51888/user5/23/2023-09-14FHIRwaveform.mp4)、 [PPT](https://docs.google.com/presentation/d/1-bRGRzBdBb5--so-5CG_xy146rgjdlRa/edit?usp=sharing&ouid=107126242390772765102&rtpof=true&sd=true)、[FHIR ECG example](https://hl7.org/fhir//observation-example-sample-data.json.html)