Connecting Patients to Doctors in Real-Time Using Django

Video in TIB AV-Portal: Connecting Patients to Doctors in Real-Time Using Django

Formal Metadata

Connecting Patients to Doctors in Real-Time Using Django
Title of Series
Part Number
Number of Parts
CC Attribution - ShareAlike 4.0 International:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
Release Date

Content Metadata

Subject Area
Your challenge, should you choose to accept it, is to create a system that allows patients to connect to doctors licensed in their state efficiently. How I used Django, Celery, Redis and Websockets to create a real-time matching system for Doctor On Demand.
Computer animation
Point (geometry) Hecke operator Bit Student's t-test Freeware Disk read-and-write head Metropolitan area network Element (mathematics) Product (business)
Shared memory
Process (computing) Meeting/Interview Smartphone Insertion loss Neuroinformatik
Axiom of choice Graph (mathematics) Sampling (statistics) Video game System call Physical system
Point (geometry) Trail Game controller Standard deviation Regulator gene Information State of matter Gender Multiplication sign Source code System call Rule of inference Fluid statics Web application Process (computing) Computer animation Personal digital assistant Website Video game Software framework Office suite Physical system
Android (robot) Scheduling (computing) State of matter Internettelefonie Online help Web browser Mass Cartesian coordinate system System call Flow separation Number Personal digital assistant Different (Kate Ryan album) Term (mathematics) Videoconferencing Telemedizin Pole (complex analysis) Physical system
Web page Trail Process (computing) Computer configuration State of matter Software developer Website System call Front and back ends
Web page Ocean current Server (computing) Multiplication sign Real-time operating system Client (computing) Number Front and back ends Web 2.0 Goodness of fit Computer configuration Term (mathematics) Queue (abstract data type) Cuboid Endliche Modelltheorie Task (computing) Scaling (geometry) Matching (graph theory) Arm Demo (music) Database Proof theory Process (computing) Personal digital assistant Octave Configuration space Object (grammar)
Point (geometry) Filter <Stochastik> Service (economics) Perfect group Information Variety (linguistics) State of matter Weight Multiplication sign Real-time operating system Database Client (computing) Mereology System call Different (Kate Ryan album) Query language Computer configuration Internet service provider Endliche Modelltheorie Mathematical optimization
Point (geometry) Priority queue Matching (graph theory) Link (knot theory) State of matter Multiplication sign 1 (number) Database Client (computing) System call Subset Process (computing) Personal digital assistant Queue (abstract data type) Videoconferencing Data structure Freeware Computer architecture
Web page Point (geometry) Trail Server (computing) Uniqueness quantification Multiplication sign Real number Data storage device Gene cluster Database Mereology System call Number Process (computing) Computer configuration Task (computing) Physical system
Computer animation Multiplication sign Mereology
and and and this and this is the kind of like this
earlier work that out elements of so what is the doctrine in the rest of the talk will not make a heck of a lot of sense if you don't know what the product actually does and I could explain it to you myself spike shortly after we once we got a bit of free publicity that we could never have hoped to ask for in a million years we get picked up by the cold air shows so for a there I will let him explain exactly what we do with that of free advertisement so what so what works and you can tell when it was released because of the reference to the the 1 of the students get
on with man that he is thing on of the whole point this is the same as the 1 that I think he is the head
have of the friend medical called expertise in the use of a more formal likely duties then we should do not to hold you use share for you and I will thank you from the east side of the
from your computer smartphone on heavily would you find all of the following the
voice quality of the work for us the
job all use the er I don't
think you can do grow pollution uses the loss of their health
systems by the people of this stuff is just prevocational about his life yes
was a you with the choice of the calls what I want you to use and I I was you know you will be at the heart of the matter that you whole whose for them to lose then is that we can use a small sample of graphs aloof from health and the so on and so this so long as we can and
will just cut that offer American automatically goes the point of all and our
website that would actually look like you
in but in symptoms an FIL out a few basic pieces of information like you're at a doctor's office and system connect you with the doctor in minutes if everything is working correctly which it normally does so if so that clip was actually a little bit scary because we're on the West Coast and all a sudden we had friends on the east coast calling is suddenly I came to see your article bearish on what and what happened there but it turned out to be a really good thing and it's a lot easier than me trying to explain it he doesn't much better than I ever had doctors get paid per call and so stuff with the website is the same as you might expect we have all the same issues that any web app has you have data that people need to access lots of it is static custom people after they have visits they have charts associated with those visits we have access controls we have all of the standard stuff flights from when I was looking at gender O'Connor that 0 hey they're still accepting proposals 1 of my coworkers like all you know that thing that you build that as the matching use talk about that knows like of what source they could do just not accept me know the worse that they could do is accepting of so there's there's lots of cool stuff there are lots of other talks about how to make that stuff work well and frameworks and API is that is not what I'm talking about today not everything is the same the biggest thing that is different is the fact that we have to keep track of where people are in the call process that people want to initiate this matching process you don't know exactly how long it's going to take because you don't know exactly which doctor is going to pick up and you don't know on if 1 of the doctors is asleep at the wheel you have to call other doctors found to make sure that it connects appropriately so mean also the you have to deal with the fact that regulations say that I can't just write you to any licensed physician in the US 0 no not my life would be much simpler if we had 1 indivisible country that did not involve states instead what I have to deal with is the fact that Dr. A. has licenses in these 5 states Dr. B has licenses in the 7 states that I can only connect you with a document is licensed in the state that you were currently located and assume you have never seen a doctor before there are other rules if you have seen a doctor before but if this is your 1st time I have to connected to doctors licensing your state there are 50 to cues in that case because there's all of the US states there's EC there's international calls it can actually go to any doctor and so there are also some other territories so they're over 50 to different to z have to deal with
on so 1 question might ask is this sounds like it's been solved before right like this this matching people who need help to people who can help them sound at all like in application anyone else has ever dealt with in the past ready customer support so why not just use an existing customer support system and do the running out by I there there are a number of reasons and partly why I'm here is if anyone knows something that would mean that I built the system in Maine and I don't have to maintain it or make it work better please tell me of the awesome of an by assuming that that is not the case I we looked at several different systems and none of them could meet the requirement that we had where when patients are calling it actually has to be a video call for most purposes to satisfy state requirements for on a legitimate telemedicine visit were doctor can prescribe medication if appropriate actually want to bless before a pharmacy pole chapter were not and there are a significant percentage of our calls that don't involve prescriptions of but the question it so I liked In this case it has to be a video call so we would need something that can support the VBE from support OS Android and web clients in terms of connecting their customer support routing system with ah video the video technology that we use and there was nothing that was flexible enough to drop in in that manner that I found there there seem to be mostly monolithic solutions for call-routing where if you have a customer support system and you have a voice over IP or traditional PBX that they support then they will do everything for you they will handle the scheduling their massive amounts of ways that you can configure it but if you just need something simple and you just wanna plug it in not so easy and so I got the opportunity to look at a bunch of different things and again I may not come
to be the unique snowflake that I think of and I would love for someone to tell me that I can just for all this comes out and never have to worry about again so that something off the shelf what
did I get to the next I got the chance to use a lot of technologies that I might be common in more pipeline backends development but that you often see is kind of site it's In up so the 1st option that we needed to solve look at was well before I get into the 1st option of what I considered and the data that you need to keep track of true this is pretty straightforward you have all your patience they're calling and and what state they're located and and then you have all of your doctors that are currently online and available and what their current status it's so but to simplify things about the current status is there more than these in reality but processes can be considered available for a call currently being page 4 call and or actively in a all and and what states a and so that's all the data that you need to keep track of ends 1st option
is to just use long
running HTTP requests no this has a number of issues and so 1 thing that it does work for is a very quick proof of concept if you just need to get something running and show people how this is supposed to work so this is actually the 1st thing that I did and you set the time out to be really really long on your web server you allow the requests to go on forever minutes at a time and assuming that you know that your doctors are generally behaving correctly which they are in a proof of concept setting because it's all staged on men everything is fine and dandy it's simple to implement it's good for prototyping and you just kind of user database and check what's going on and the in terms of the other but visit object and that has a status of whether or not connected yet you can use models for everything and it's all fine and dandy when you have a few demo patience and a demo doctor but it does not scale and worse than that even if it did it's flaky and unreliable because of client was a connection on they don't necessarily have a way to get that that's back on the if they did how would they find out the result on so you end up Starting with something more like option to where if
the clients flaky anyway on you do need a way for them to recover from that and see where they are in the current match process and get reconnected to a doctor so you might as well start I was having ability for the patients clients to ask what its current status is and whether you found doctor yet so Ajax polling on and then on the back end because you don't have this long-running request for the match of what I did is used celery which is an asynchronous task queue are written in Python it integrates really well with Django on another talk would be on like all of the configuration options for and will not go into that there there are many but it works well out of the box but there's lots of stuff you can do to turn it on and that kind of fellow naturally into this use case because I could have celery lots of workers running in the background on it scales really well as we have more patients coming in there just able to I check the status of the doctors and page a doctor 1 at a time we have like a built-in business requirement that if the 1st octave it's called doesn't answer within a minute then you stop eating another 1 another 1 and another 1 ends these can just go on for as long as they need to with some arbitrary time out of and so that's all great so the prose that is increased task you don't for about request timeouts and cons for polling it's no longer real time in the way that your long-running your question so with the long-running request you just respond as soon as you have a match in your great with pulling arm to simulate real time you have to keep making this request to the server over and over and over again and discovered the a better way the and there is so you can save pulling is back
up but the optimization that I went to was using WebSockets which is an HTML 5 technology that allows the clients to receive pushes from service the channel it's light weight it's perfect for this and then on our mobile devices you also add in all of push notifications so if the user has enabled suppression of cations are you can use that to as soon as a doctor accepts the call and immediately push that information to the clients and then even if you have point as a background back up it doesn't have to be as frequent for it to appear real time to the majority of the patients calling it the cons on it is if you estimated moving parts I you have to worry about setting up the sector service if you don't want to set up your own there are now sass providers to do website for you like in the biggest 1 pusher no hope that so stage 2
i in making this thing work well tracking doctors status of we have a lot of doctors that can be online at any time and they all have licenses in a variety of different states like if the 4 the 1st option would just be too you have all this BN models and then every time someone makes a call and make the appropriate queries to figure out who's online who's not that slope the update on the prose of this approach by just using a database all are that there are no external dependencies and I think that is really the only pro because it's slow the data can get still really fast you have to make all of these extra reads and writes for database it's an efficient it's not good and thinning on how your models the set up and the way that a set up involves quite a few filters and joins to do this just using database so I've found
that red it's worked as a really good solution to this problem on because I needed the data to be persistent and right you know I will fix that later I these I and on video for an hour on the half a we alright so red is is really good for persistent data structures and the data structures that I used are the obvious ones in this case we have a data structure that has the doctors ID and their current status and that's what we update so it's used as a cache on for this ephemeral data of what status the doctor currently has because we only care about it while they're on-chip that's not something we you store long term of and the other thing it is useful inredis that I found is i choose so the 1st link there is just the official Raynos clients well official but the biggest REST client available in Python the 2nd 1 is on a few package they use so I what you can do in this case is instead of storing everything in the database on have cues and readers of the doctors their license in each state so when they become available push them into these cues and then as patients want to see doctors in the States pop off the next doctor check the status and then if they're available match them on if they're still just discard them at that point and you can keep using cues this way I 1 disadvantage of this so if you start with just a FIFO queuing at that a separate queue for every state and you can end up with duplicates depending on how you do it on where the doctors that have licenses in more states will get richer and Dick see more patients of because they'll end up in more cues more frequently eyes so 1 of the opposition's you can do instead is to I used a priority queue which will have deep pockets and the way that a FIFO queue would if you just have ideas and it's kind of tending to the end of and then it has a score so whoever's seeing patients the least recently can get the next patient available in that state but the last thing that I came across that
I thought was interesting in this and the process of developing this architecture was atomic all acceptance in February are the last half of February we decided to do this wonderful thing where we may all calls for free for 2 weeks around that was painful for me everything worked so it was actually really great but i'll one-quarter case I discovered at that time was that it was possible to have multiple doctors accepts a call simultaneously I thought I had protected against it using pipelines but I hadn't done it correctly so actually switched on to something that was a lot easier to read
I and that was just to use a simple I'll walk and this is just kind of a way that you can do distributed locks interests in their official documentation what you do is you set a unique ID and that 2nd part that's the value is it doesn't matter what that is if you just using it all as a lock and if you did something else with it but this is the standard nice store the 2 options are that it expires after a certain amount of time and then you only set this if it's not already set so what this does is on the say I said Dr. to on and or actually say that call attempt to so this page is calling in their call is number 2 in both doctors try and except at the same time I mark call to I a set the value as some random value and only 1 of them the only only 1 that gets the lock gets to accept the cost you can end up with the doctors accepting all at same time as just a neat trick if you're using red it's already and you come across something that would users so in the
end we have improved system where the database does what it's good at we have celery on taking care of asynchronous processes that can and whenever they need to a specialization improve their efficiency and we can at some point in the future offload all the silly tasks to other servers at clusters well it's very skilled what's nice I'm and rightist keeps track of our from real data and light with persistent cues and that is the end of my talk so there's no some
time for questions Thank you for listening use was was the 1st part of managing general kind and I'm really glad to be here at the end of this