# Implementing arythmia patterns

**URL:** <https://discourse.kitware.com/t/implementing-arythmia-patterns/806>\
**Category:** Pulse Physiology Engine\
**Created:** [February 24, 2022, 2:00pm UTC](https://discourse.kitware.com/t/implementing-arythmia-patterns/806 "2022-02-24T14:00:38Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeanf](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/j/b19c9b/32.png) [@jeanf](https://discourse.kitware.com/u/jeanf)\
**Post date:** [February 24, 2022, 2:00pm UTC](https://discourse.kitware.com/t/implementing-arythmia-patterns/806/1 "2022-02-24T14:00:38Z")

</div>

Hello,

I wish to implement new “states” for the engine as to simulate a variety of arythmic cardiac patterns. I am wondering if you might have advise or guidance on how to go about that? where to look? where to start? Does it already exists and I just missed it?

Here is what I understood so far:

- I think I will have to download the c++ source code, add my stuff and compile it again.
- I will have to add some “cases” into the C# project in unity in order to find them.

I am not sure to understand fully how the changes on the curves are applied and would like to understand the philosophy and architecture of the engine before going into “details”.

ofc I would like to contribute and publish this on your rep if you allow me and would do my best to comply to your “standards”.

Oh, and the project I work on runs in unity.

While looking forward for getting an answer I wish you all the best!

---

<div class="post-metadata">

**Author:** ![jeanf](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/j/b19c9b/32.png) [@jeanf](https://discourse.kitware.com/u/jeanf)\
**Post date:** [February 24, 2022, 3:38pm UTC](https://discourse.kitware.com/t/implementing-arythmia-patterns/806/2 "2022-02-24T15:38:30Z")

</div>

Here are the arythmias we would like to use:

1. Sinus dysrhythmia;
2. Sinus pause;
3. Premature atrial contraction (PAC);
4. Wolf-Parkinson-White
5. Atrial ectopic tachycardia
6. Atrial fibrillation
7. Atrial flutter;
8. Supraventricular tachycardia;
9. Junctional rythme;
10. Junctional tachycardia;
11. AV blocks (1st degree, 2nd degree (type 1 and 2), 3rd degree)
12. Premature ventricular contraction (PVC)
13. Torsade de pointes
14. accelerated idioventricular rythme
15. accelerated jonctionnal rythme

---

<div class="post-metadata">

**Author:** ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)\
**Post date:** [February 24, 2022, 3:41pm UTC](https://discourse.kitware.com/t/implementing-arythmia-patterns/806/3 "2022-02-24T15:41:49Z")

</div>

Our current supported arrhythmia’s are

```auto
enum eHeartRhythm
{
  NormalSinus = 0; /**<< @brief Normal electical signal and mechanical function. */ 
  SinusBradycardia = 1; /**<< @brief Normal electical signal with reduced heart rate. */
  SinusTachycardia = 2; /**<< @brief Normal electical signal and increased heart rate. */
  SinusPulselessElectricalActivity = 3; /**<< @brief Electical signal, but no mechanical function. */
  Asystole = 4; /**<< @brief No electrical signal or mechanical function. */
  CoarseVentricularFibrillation = 5; /**<< @brief No organized electrical signal, no mechanical function. */
  FineVentricularFibrillation = 6; /**<< @brief No organized electrical signal, reduced amplitude compared to coarse VF, no mechanical function. */
  PulselessVentricularTachycardia = 7; /**<< @brief Normal electical signal with reduced amplitude, but no mechanical function. */
  StableVentricularTachycardia = 8; /**<< @brief Ventricular tachycardia electrical signal with increased heart rate. */
  UnstableVentricularTachycardia = 9; /**<< @brief Ventricular tachycardia electrical signal with increased heart rate, reduced heart elastance. */
}

```

Generally,

1. You will need to do a literature search and find citations in papers describing how this new arrhythmia affects the physiology  
(Does it increase\decrease blood pressures\heart rates? and by how much 2x/3x etc.)

2. Implement those changes here  
[https://gitlab.kitware.com/physiology/engine/-/blob/4.x/src/cpp/engine/common/system/physiology/CardiovascularModel.cpp#L1654](https://gitlab.kitware.com/physiology/engine/-/blob/4.x/src/cpp/engine/common/system/physiology/CardiovascularModel.cpp#L1654)  
Depending on what the literature says, we may need to add logic in other places in the code

3. Provide an ECG wavefrom associated with that arrhythmia.  
This would be an array of mV for one cardiac cycle of the arrhythmia.  
So you would need to find and digitize a single cardiac cycle of your new arrhythmia  
You can see that data on the ECG tab of our data.xls  
[https://gitlab.kitware.com/physiology/engine/-/blob/master/data/Data.xlsx](https://gitlab.kitware.com/physiology/engine/-/blob/master/data/Data.xlsx)  
Then associate an ecg waveform with one or more arrhythmias  
[https://gitlab.kitware.com/physiology/engine/-/blob/4.x/src/cpp/engine/common/system/equipment/ElectroCardioGramModel.cpp#L88](https://gitlab.kitware.com/physiology/engine/-/blob/4.x/src/cpp/engine/common/system/equipment/ElectroCardioGramModel.cpp#L88)

From there, there are more things to do, but at a high level, that’s the process

---

<div class="post-metadata">

**Author:** ![rachel.clipp](https://discourse.kitware.com/user_avatar/discourse.kitware.com/rachel.clipp/32/195_2.png) [@rachel.clipp](https://discourse.kitware.com/u/rachel.clipp)\
**Post date:** [February 24, 2022, 3:44pm UTC](https://discourse.kitware.com/t/implementing-arythmia-patterns/806/4 "2022-02-24T15:44:37Z")

</div>

Hello,

Some guidance on code contribution can be found in our wiki [here](https://gitlab.kitware.com/physiology/engine/-/wikis/home).

You would be extending the Arrhythmia action.

If you would like to discuss this, we would be happy to have a quick call to give some guidance. You are welcome to email me at [rachel.clipp@kitware.com](mailto:rachel.clipp@kitware.com) to set up a time to talk.

Thanks,  
Rachel

---

<div class="post-metadata">

**Author:** ![andy](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://discourse.kitware.com/u/andy)\
**Post date:** [March 27, 2024, 8:21am UTC](https://discourse.kitware.com/t/implementing-arythmia-patterns/806/6 "2024-03-27T08:21:16Z")

</div>

hi，I added three patterns and ECG wavefrom. Then, export dll to unity. It runs good with standmale.json. But when I test howtocreatepatient in c++ solution, it crash. HeartBaseline pointer is null. I don’t know why.  
 ![30B25A3B-4F6A-4086-870D-018C102951CB](https://discourse.kitware.com/uploads/default/original/1X/689f75c0a43eb46968a50f53f8045dad7f9207e1.png)

---

<div class="post-metadata">

**Author:** ![andy](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://discourse.kitware.com/u/andy)\
**Post date:** [March 27, 2024, 8:21am UTC](https://discourse.kitware.com/t/implementing-arythmia-patterns/806/7 "2024-03-27T08:21:49Z")

</div>

![B659FB60-CEF7-4c2b-940C-892A15C4171C](https://discourse.kitware.com/uploads/default/original/1X/e5f9cf7e6ca2ea713e132bb4939c9595e3a33e40.png)

---

<div class="post-metadata">

**Author:** ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)\
**Post date:** [March 27, 2024, 11:28am UTC](https://discourse.kitware.com/t/implementing-arythmia-patterns/806/8 "2024-03-27T11:28:20Z")

</div>

There is an if check to test for a null pointer.  
I don’t think your pointer is null…

I’d need to see a call stack to help diagnose any further

---

<div class="post-metadata">

**Author:** ![andy](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://discourse.kitware.com/u/andy)\
**Post date:** [March 28, 2024, 1:20am UTC](https://discourse.kitware.com/t/implementing-arythmia-patterns/806/9 "2024-03-28T01:20:19Z")

</div>

![64A6BB7E-E280-48ff-B9D7-459DD2FF8B58](https://discourse.kitware.com/uploads/default/original/1X/cfb049ad49400e4243f268face33c9a958fd2f3b.png)  
This is call stack. Thanks!

---

<div class="post-metadata">

**Author:** ![andy](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://discourse.kitware.com/u/andy)\
**Post date:** [March 28, 2024, 1:26am UTC](https://discourse.kitware.com/t/implementing-arythmia-patterns/806/10 "2024-03-28T01:26:52Z")

</div>

my pulse engine version is 4.2.0

---

<div class="post-metadata">

**Author:** ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)\
**Post date:** [March 28, 2024, 1:50am UTC](https://discourse.kitware.com/t/implementing-arythmia-patterns/806/11 "2024-03-28T01:50:58Z")

</div>

Try building and running in Debug Mode

Put a break point in `SEScalarFrequency& SEPatient::GetHeartRateBaseline()`  
This method will be hit and the m\_HeartRateBaseline pointer should be null in that function and get allocated there

Then break in the `double SEPatient::GetHeartRateBaseline(const FrequencyUnit& unit) const` and ensure the m\_HeartRateBaseline pointer has the same memory address that it was allocated to

---

<div class="post-metadata">

**Author:** ![andy](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://discourse.kitware.com/u/andy)\
**Post date:** [March 28, 2024, 2:57am UTC](https://discourse.kitware.com/t/implementing-arythmia-patterns/806/12 "2024-03-28T02:57:27Z")

</div>

I fix it. I invoke GetCurrentPatient in SubstanceManager::InitializeLiquidCompartmentNonGases() . Then replace GetInitialPatient. It works.  
Thanks!  
pulse is very good. I like it.

---

<div class="post-metadata">

**Author:** ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)\
**Post date:** [March 28, 2024, 2:14pm UTC](https://discourse.kitware.com/t/implementing-arythmia-patterns/806/13 "2024-03-28T14:14:45Z")

</div>

Ok, I assume you have other code changes as you shouldn’t have to do that with the public code base…

But great!
