avatarJillian Enright

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

5070

Abstract

do that:</p><div id="2e8b"><pre>eventHandler<span class="hljs-selector-class">.Handle</span>(event1, <span class="hljs-built_in">ExampleMiddlewareFoo</span>(<span class="hljs-built_in">ExampleMiddlewareBar</span>(handle)))</pre></div><h1 id="a8a5">Managing Events with Handlers and Middleware</h1><p id="f869">Most articles I read explain how to use this design pattern; this one deals with implementing the internal logic. So let's start coding.</p><p id="35c4">The full code for this article can be found <a href="https://github.com/xNok/slack-go-demo-socketmode/blob/main/examples/middleware/main.go">here</a> to help you follow along.</p><h2 id="0f88">Designing events</h2><p id="b622">First, we are going to enumerate the list of events that our system can handle. The way we create enumeration in Go is a bit different than in other programming languages. In Go, we are going to use a set of constants sharing the same <code>type</code>. Here I define a type <code>EventType</code>that represents a string with the event's name.</p><div id="b181"><pre>// <span class="hljs-keyword">type</span> <span class="hljs-type">used </span>to enumerate events <span class="hljs-keyword">type</span> <span class="hljs-type">EventType </span>string</pre></div><div id="4817"><pre>const ( event1 EventType <span class="hljs-operator">=</span> <span class="hljs-string">"event1"</span> event2 EventType <span class="hljs-operator">=</span> <span class="hljs-string">"event2"</span> )</pre></div><p id="e041">Next, we define the event itself. In our example, the<code>Event</code> as a type which can be selected among the list of <code>EventType</code> created above.</p><div id="2bc9"><pre><span class="hljs-keyword">type</span> <span class="hljs-type">Event</span> struct { <span class="hljs-type">Type</span> <span class="hljs-type">EventType</span> <span class="hljs-type">Data</span> interface{} }</pre></div><h2 id="df6c">Create an event sender (for test purpose)</h2><p id="60aa">To test our system, we will need to create a small function to send events every 2s. Each<code>Event</code> is transmitted via a <a href="https://tour.golang.org/concurrency/2">channel</a> and, the <code>eventSender</code> below sends a random <code>Event</code> of type <code>event1</code> or <code>event2</code> to a channel.</p><blockquote id="53f3"><p><i>Channels are a type which you can send and receive values, they are great for communication among goroutines. In other words, there are perfect for sending and receive event through your application.</i></p></blockquote><div id="ffd1"><pre><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">eventSender</span><span class="hljs-params">(c <span class="hljs-keyword">chan</span> EventType)</span></span> {</pre></div><div id="7f57"><pre> for { // Send <span class="hljs-selector-tag">a</span> random event <span class="hljs-selector-tag">to</span> the channel rand<span class="hljs-selector-class">.Seed</span>(<span class="hljs-selector-tag">time</span><span class="hljs-selector-class">.Now</span>()<span class="hljs-selector-class">.Unix</span>()) events := []EventType{ event1, event2, } n := rand.<span class="hljs-built_in">Int</span>() % <span class="hljs-built_in">len</span>(events)</pre></div><div id="6101"><pre> c <- events[n] <span class="hljs-comment">// send event to channel</span></pre></div><div id="5285"><pre> // <span class="hljs-keyword">wait</span> a <span class="hljs-built_in">bit</span> <span class="hljs-built_in">time</span>.Sleep(<span class="hljs-number">2</span> * <span class="hljs-built_in">time</span>.Second) } }</pre></div><h2 id="000c">Handler and dispatcher</h2><p id="e562">We first need a struct to hold the list of events we want to listen to and which function to call whenever that event is transmitted. This struct also contains the channel used for communicating events.</p><div id="280d"><pre><span class="hljs-comment">// Create a struct to hold config</span> <span class="hljs-comment">// And simplify dependency injections</span> <span class="hljs-keyword">type</span> EventHandler <span class="hljs-keyword">struct</span> { <span class="hljs-comment">// Event channel</span> Events <span class="hljs-keyword">chan</span> Event <span class="hljs-comment">// hold the registedred event functionss</span> EventMap <span class="hljs-keyword">map</span>[EventType][]<span class="hljs-function"><span class="hljs-keyword">func</span><span class="hljs-params">(Event)</span></span> }</pre></div><p id="aa6c">Next, we need to provide an initializing constructor for our <code>EventHandler</code>.</p><div id="a4ed"><pre><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">NewEventHandler</span><span class="hljs-params">()</span></span> *EventHandler { eventMap := <span class="hljs-built_in">make</span>(<span class="hljs-keyword">map</span>[EventType][]<span class="hljs-function"><span class="hljs-keyword">func</span><span class="hljs-params">(Event)</span></span>) event

Options

s := <span class="hljs-built_in">make</span>(<span class="hljs-keyword">chan</span> Event)</pre></div><div id="78bb"><pre> return <span class="hljs-variable">&</span>EventHandler<span class="hljs-punctuation">{</span> <span class="hljs-symbol"> Events:</span> events, <span class="hljs-symbol"> EventMap:</span> eventMap, <span class="hljs-punctuation">}</span> <span class="hljs-punctuation">}</span></pre></div><p id="98fe">Then, we can create our <code>Handle</code> function that associates the event with a callback function.</p><div id="308c"><pre><span class="hljs-comment">// register the handler function to handle an event type</span> func (h *EventHandler) <span class="hljs-built_in">Handle</span>(e EventType, f <span class="hljs-built_in">func</span>(Event)) { h<span class="hljs-selector-class">.EventMap</span><span class="hljs-selector-attr">[e]</span> = <span class="hljs-built_in">append</span>(h<span class="hljs-selector-class">.EventMap</span><span class="hljs-selector-attr">[e]</span>, f) }</pre></div><p id="e42a">Finally, we create the <code>EventDispatcher</code> function, the core of this mechanism. The <code>EventDispatcher</code>process any event sent to a channel, check its type, and if any function has been registering for that type, we call all registered functions.</p><div id="6597"><pre><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(h *EventHandler)</span></span> EventDispatcher() { <span class="hljs-keyword">for</span> evt := <span class="hljs-keyword">range</span> h.Events { log.Printf(<span class="hljs-string">"event recieved: %v"</span>, evt) <span class="hljs-keyword">if</span> handlers, ok := h.EventMap[evt.Type]; ok { <span class="hljs-comment">// If we registered an event</span> <span class="hljs-keyword">for</span> _, f := <span class="hljs-keyword">range</span> handlers { <span class="hljs-comment">// exacute function as goroutine</span> <span class="hljs-keyword">go</span> f(evt) } } } }</pre></div><h1 id="13e4">Using our system</h1><p id="4d4e">Everything is ready; we can start using our event handling system.</p><ol><li>Instantiate our event Handler</li><li>Register which event to listen to and what function to callback</li><li>Start the event sender</li><li>Start the event dispatcher</li></ol><div id="62ab"><pre><span class="hljs-keyword">func</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span> {</pre></div><div id="5b09"><pre> <span class="hljs-variable">eventHandler</span> := <span class="hljs-function"><span class="hljs-title">NewEventHandler</span>()</span></pre></div><div id="d244"><pre> eventHandler.Handle(event1, <span class="hljs-keyword">func</span><span class="hljs-params">()</span> { <span class="hljs-built_in">log</span>.Printf(<span class="hljs-string">"event Handled: %v"</span>, event1) })</pre></div><div id="5c56"><pre> <span class="hljs-variable">go</span> <span class="hljs-function"><span class="hljs-title">eventSender</span>(<span class="hljs-variable">eventHandler.Events</span>)</span></pre></div><div id="30f2"><pre> eventHandler<span class="hljs-selector-class">.EventDispatcher</span>()</pre></div><div id="9bf2"><pre>}</pre></div><p id="e590">The result should be along those lines:</p><figure id="5ee7"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*_D-GCRSu3K8CgTBXewJjJQ.gif"><figcaption></figcaption></figure><p id="19d6">Since we only handle an event of type <code>event1</code>, only <code>event1</code> shows as <code>Hansled</code>. All is good!</p><p id="d48a">The full code for this article can be found <a href="https://github.com/xNok/slack-go-demo-socketmode/blob/main/examples/middleware/main.go">here</a>.</p><h1 id="6f5e">Interesting Articles tackling the same topic</h1><ul><li><a href="https://drstearns.github.io/tutorials/gomiddleware/">Middleware Patterns in Go</a></li><li><a href="https://sathishvj.medium.com/web-handlers-and-middleware-in-golang-2706c2ecfb75">Web Handlers and Middleware in GoLang</a></li><li><a href="https://readmedium.com/lightweight-event-management-implemented-by-go-a654d59ac65">Lightweight event management implemented by Go</a></li><li><a href="https://readmedium.com/the-7-most-important-software-design-patterns-d60e546afb0e">The 7 Most Important Software Design Patterns</a></li></ul><p id="13e7"><i>Do you want <b>unlimited access</b> to all my content and many other writers’ content on Medium? Consider using my affiliate link to <a href="https://couedeloalexandre.medium.com/membership">become a Medium member today</a></i></p><h2 id="853a">Further reads</h2> <figure id="81d2"> <div> <div> <img class="ratio" src="http://placehold.it/16x9"> <iframe class="" src="https://couedeloalexandre.medium.com/embed/list/3f9d03f2cb8f" allowfullscreen="" frameborder="0" height="184" width="undefined"> </div> </div> </figure></iframe></div></div></figure></article></body>

Healthcare and Executive Functions

Why accessing healthcare is neither inclusive nor equitable

Created by author

Healthcare and executive functions

Something healthcare professionals and policy-makers often seem to overlook is this: It takes a lot of executive functioning and mental energy to regularly access healthcare (or to access it at all).

First, we have to figure out when we want to schedule the appointment and what dates and times will work best for us.

Then we have to contact the doctor’s office.

Many clinics still don’t have online booking, so we have to contact them by phone. This is not accessible for non-speakers, Deaf and Hard of Hearing patients, as well as people who have severe anxiety around phone calls.

Getting through to the office can pose a challenge. Sometimes we repeatedly get a busy signal and have to remember to call back later.

Medical administrators are not secretaries, they often have specialized training for doing admin work in the medical field. This means they have duties which take them away from their desk, including assisting the doctor with patients.

At my GP, if the admin person is away from their desk, the call goes to voicemail. The problem is, the outgoing message instructions patients not to leave a voicemail message unless they need to cancel their appointment. It specifically states that messages will not be returned, and they must call back at a later time to schedule an appointment.

I always leave a message anyway because I am 99% certain I will not remember to call back later, or I won’t have time to continue calling until I happen to get lucky and get through to a human being. I hate the phone to begin with, so I am not interested in having to call multiple times throughout the day.

Inaccessibility

Eventually we get through to our doctor’s office and connect with a real, live person. While navigating a phone call, we then have to compare the doctor’s (usually limited) availability with our own, finally agreeing on a date and time.

We must remember to write down the appointment, or put it into our electronic calendars, and set reminders (*don’t forget to set extra reminders!).

Created by author

Then actually getting to the appointment is a lot of work for many of us. Many neurodivergent (ND) folks don’t like driving and find using public transit extremely stressful.

Lots of us also find it very anxiety-provoking to sit in a clinic waiting room, especially if they’re not sensory-friendly. Many clinics are loud, busy, have bright overhead lighting, and strong scents from cleaning products.

After all that, we get into the appointment and hope our doctor will take us seriously when we express a concern. Sometimes we encounter medical professionals who get it, unfortunately it’s much. more likely we don’t.

Many doctors don’t understand that neurodivergent folks — especially Autistics — struggle with alexithymia (difficulty describing our internal experiences and feelings), and we also perceive, process, and express discomfort differently.

Doctors may assume we are exaggerating if we are in extreme pain due to something that a neurotypical (NT) person may experience as mild discomfort. Conversely, we may not be believed when we are in intense pain because we are not adequately performing Patient In Pain for them.

Some Autistic people don’t connect with their bodies well and struggle with interoception. Some have an incredibly high pain tolerance.

An Autistic patient could have a very serious injury or condition, but not appear to be in much pain, thus leading medical professionals to believe they are “fine” when they are most certainly not.

Tips for appointments

For those who, like me, struggle with making and attending appointments.

  • Bring a support person. It may help to have a trusted person go with you for emotional support, but be sure to make it clear to your doctor that they are speaking with you, and not the person accompanying you.
  • Strategic scheduling. It can also help to schedule appointments as strategically as possible.
  • Some people find it works best to schedule them early in the day so they don’t get stuck in waiting mode.
  • Others find it’s best to schedule appointments in the afternoon, so they don’t feel rushed to get out of the house in the morning.
  • Recovery time. For me, I also have to keep in mind the amount of emotional energy this is going to withdraw.
  • I need to be careful not to schedule a lot of demanding tasks or activities on the same day, so I can give myself time to recover.

Dear medical system,

When people are overwhelmed, burnt out, or depressed, we do not have the capacity to jump through hoops in order to access care.

The easier it is, the more likely patients will follow through with booking and attending a much-needed appointment.

The more barriers there are to overcome, the more likely we are to give up and stop seeking help.

We understand the medical system is a mess for everyone, not just for us, we do.

We aren’t asking for it to be easy, or even easier than it is for others. We’re simply asking for equitable access. You would think the medical system, of all institutions, would understand providing accessible services.

You’d think.

The essentials

For medical professionals who do strive to make their services more accessible to all patients:

  • Ensure your office is fully accessible for anyone using mobility aids (yes, there are doctor’s offices who have poor design and don’t properly maintain their ramps, for example).
  • Offer online booking. Please. It’s nearly 2024, we’ve had widespread access to the Internet for over thirty years. We’ve had (mostly) secure web banking for over 25 years. I think we can handle booking appointments.
  • Ensure your staff are trained to understand at least the basics of various neurodevelopmental differences (such as ADHD, Autism, dyspraxia, apraxia, etc.) and their commonly co-occurring conditions (such as hypermobility).
  • Believe your patients. Take your patients seriously. Don’t gate-keep access to assessments, referrals, or specialized services, especially with regards to conditions about which you are not well informed.
  • Medical trauma is real. You are not the only medical professional your patient has encountered in their lifetime. They may have a history of medical mistreatment and trauma of which you are unaware. If a patient is hesitant to trust you, please try not to take it personally.
  • Presume competence. If your patient has done a bunch of their own research and you roll your eyes as Dr. Google invades your appointment once again, stop and think about why people often turn to the Internet for help. It’s often because our medical system is inadequate and patients frequently need to self-advocate just to get proper care.

Go back to the basics of your training and remember you were taught that the patient is the expert in their own experience. Don’t forget this.

While you have many years of medical training, and your expertise and knowledge are highly valuable, please don’t dismiss your patients based on assumptions you are making.

Please check your biases and be willing to learn from your patients, just as we wish to learn from you.

Thank you.

© Jillian Enright, Neurodiversity MB

Author’s note: Finishing this article actually reminded me that I’m overdue for my bi-annual eye exam. You see? BRB!

Related articles

Ways to support my work

You can leave a “tip” on Ko-Fi at https://Ko-Fi.com/NeurodiversityMB

Become a paid subscriber to my Substack publication

Check out my online store at https://NeurodiversityMB.ca/shop

Read and share my articles from twoemb.medium.com

Learn more

Healthcare
Health
Autism
Accessibility
Adhd
Recommended from ReadMedium