Cómo escribir un archivo DICOM a partir de una señal digital de ECG en c#

Comenzaremos a trabajar a partir de estas muestras de voltaje ecg sin procesar en formato csv (Comma Separated Values) , por ejemplo:

time    voltage (mV)
0.000   9.169110459
0.001   9.144672532
0.002   9.144672532
0.003   9.169110459
0.004   9.169110459
0.005   9.169110459
0.006   9.169110459
0.007   9.144672532
0.008   9.217986315
0.009   9.169110459
0.01    9.169110459
0.011   9.169110459
0.012   9.169110459
0.013   9.144672532
0.014   9.144672532
0.015   9.169110459
0.016   9.169110459
0.017   9.169110459
0.018   9.169110459
0.019   9.169110459
0.02    9.169110459
0.021   9.169110459
0.022   9.144672532
0.023   9.169110459
Lo que vamos a hacer es convertirlo en un archivo DICOM, para poder verlo en un visor de ecg como el kit de herramientas de ECG para c #: https://sourceforge.net/projects/ecgtoolkit-cs/

¿Cómo haría para esta conversión? He hecho algunas búsquedas en Google, pero no he encontrado una herramienta que sea capaz de escribir archivos DICOM a partir de datos en bruto.

EDITAR:

Terminé yendo por un archivo SCP ya que esto era más fácil. Terminé usando la biblioteca de arriba para crear un archivo scp. Código siguiente:


using System;
using System.Linq;
using ECGConversion;
using ECGConversion.ECGDemographics;
using ECGConversion.ECGSignals;

namespace SCPWriter
{
    public static class CreateScpEcg
    {
        public static void CreateScpEcgFile(double[] voltages, int sampleRate, string directory, string patientId)
        {
            var rhythm = voltages;

            var filePath = directory + patientId;

            // get an empty ECG format file
            IECGFormat format = ECGConverter.Instance.getFormat("SCP-ECG");
            if (format != null)
            {
                // five required actions for the demographic info.
                format.Demographics.Init();
                format.Demographics.PatientID = patientId;
                format.Demographics.LastName = "";
                format.Demographics.TimeAcquisition = DateTime.Now;
                // make an AcquiringDeviceID object
                AcquiringDeviceID acqID = new AcquiringDeviceID(true);

                // can also specify your own acquiring device info
                Communication.IO.Tools.BytesTool.writeString("MYDEVI", acqID.ModelDescription, 0, acqID.ModelDescription.Length);
                // set the Acquiring Device ID (required)
                format.Demographics.AcqMachineID = acqID;
                // declare the signal part.
                var leadType = new LeadType[] { LeadType.I };
                var rhythmAVM = 1;
                var rhythmSPS = sampleRate;
                Signals sigs = new Signals((byte)leadType.Length);
                sigs.RhythmAVM = rhythmAVM;
                sigs.RhythmSamplesPerSecond = rhythmSPS;

                for (int i = 0; i < sigs.NrLeads; i++)
                {
                    // very important to assign signal.

                    sigs[i] = new Signal();
                    sigs[i].Type = leadType[i];
                    sigs[i].Rhythm = rhythm.Select(Convert.ToInt16).ToArray();
                    sigs[i].RhythmStart = 0;
                    sigs[i].RhythmEnd = rhythm.Length - 1;
                }
                // store signal to the format.
                if (format.Signals.setSignals(sigs) != 0)
                {
                    Console.Error.WriteLine("setSignals failed!");
                    return;
                }
                // write the file
                var outputFile = filePath + ".scp";


                ECGWriter.Write(format, outputFile, true);
                if (ECGWriter.getLastError() != 0)
                {
                    Console.Error.WriteLine("Writing failed: {0}!", ECGWriter.getLastErrorMessage());
                    return;
                }
            }
        }


    }
}

Estos datos corresponden a la derivación D1, pero obviamente se pueden agregar las 12 derivaciones  en esta línea: var leadType = new LeadType [] {LeadType.I}

Referencias:
https://github.com/marcodebe/dicomecg_convert
https://stackoverflow.com/questions/40121146/how-to-write-a-dicom-file-from-raw-ecg-data
https://sourceforge.net/projects/ecgtoolkit-cs/

Comentarios

Entradas más populares de este blog

ESCANEO DEL CODIGO PDF417 DEL DNI (Documento Nacional de Identidad digital)

¿Que tipos de Mensajes de HL7 hay?

¿Que es Razor?