« Return to show page
Transcript for Episode #241:
Opal: Full stack health care apps
00:00 Michael Kennedy: Open source has permeated much of the software industry, but what about healthcare? This highly regulated and important industry might seem to the the domain of huge, specialized software companies. On this episode, Fred Kingham is here to introduce us to a project called Opal. It was born out of NHS hack days in the UK, and is a full stack, web framework for building healthcare applications. It's based on Django, and has a ton of interesting features as a framework in general. This is Talk Python to Me, Episode 241, recorded November 30th, 2019. Welcome to Talk Python to Me, a weekly podcast on Python! The language, the libraries, the ecosystem, and the personalities. This is your host Michael Kennedy. Follow me on twitter where I'm @mkennedy. Keep up with the show and listen to past episodes at talkpython.fm. And follow the show on twitter via @talkpython. This episode is sponsored by Linode and the University of San Francisco. Please check out what they're offering during their segments, it really helps support the show. Hi there, thanks for listening to this episode. Before we get to the interview, I have something to share with you. We just launched a new course, it's called Python for Decision Makers and Business Leaders. If you're a team lead, or deciding whether to use Python for your next project, or even the next stage in your career, this course is a great fit for you. It's super unique, most courses teach you how to program with Python, this course is a guided discussion and exploration of the Python ecosystem, through the lens of your organization and your team. It's full of fact-based presentations for the Python ecosystem, covering things like frameworks, types of apps you can build, developer jobs, and more. And it explores some of the tools making Python so popular in the data science space. It's written both for developers, and non-developers alike. So check it out, at talkpython.fm/decision, or just click the link in the show notes. But wait, there's more! I'm working on a few interactive events as well, so I'm putting together this live event to help kick off the course. It's a free webcast, on an interactive platform with lots of QA, that's happening in January of 2020. Check that out at talkpython.fm/python-decision-webcast, or just click it in the show notes. Go ahead and register now, hopefully you can make the live event, but if you can't, you can still ask questions, participate in polls and chat, all that stuff will be available on-demand afterward, once the recording is there on that platform. Super fun! So I hope you love both of these things, the course and the webcast. Now, let's get on to that interview. Fred, welcome to Talk Python to Me.
02:45 Fred Kingham: Hi!
02:46 Michael Kennedy: Hey it's great to have you here. We're going to cover some stuff that, you know, I don't think we've spent any time on on the show before, healthcare and open source, it'll be fun!
02:52 Fred Kingham: Sounds great, yep.
02:53 Michael Kennedy: Now, you guys are working on this project called Opal, which has an interesting origin story out of the UK healthcare industry and whatnot, which is great, and lots of Python involved, but before we get into all that interesting stuff, let's start with your story, how did you get to programming and Python?
03:11 Fred Kingham: I started programming on the Atari ST, that venerable computer of the 1980s. I was using something called STOS when I was sort of like seven or eight, you know when you're creating little games, drive the Ls through through your Xs, that kind of thing.
03:26 Michael Kennedy: Right.
03:27 Fred Kingham: Full of gotos, go sub and all the joys that come with it. Then I did a philosophy degree, and I did a conversion course into, a Master's conversion course in computer science.
03:38 Michael Kennedy: Wow philosophy to computer science huh? That's quite the transition.
03:42 Fred Kingham: It is, but I did it, and I know a lot of people who've done it.
03:46 Michael Kennedy: Yeah?
03:47 Fred Kingham: I think there's something about conceptualization, maybe formal logic. There's a whole branch of philosophy called, what's it called, logical atomism I think? Which tries to structure, tries to work out Boolean responses to arguments based on conjunctions, sort of like, if I like trees, and people who like things are liked, somebody likes me, that kind of weird, sort of stack logic, very Russell based.
04:16 Michael Kennedy: Right right, is it true that I do this, or does it follow that I do this? Yeah, I think actually, now that you say it, there's a lot of thinking, I studied math. I didn't really do much programming, I took a couple, like two programming courses in college for little sub-prerequisites, but I don't feel like I do math at all these days, even though I was in a PhD program working on it right? But I feel like that process that I went through, the type of thinking, and the way of approaching problems, and all that like, I use that every day, and that seems like it came straight out of there, even though, I couldn't do math to save my life these days.
04:51 Fred Kingham: Yeah, exactly!
04:53 Michael Kennedy: Alright, before we move off philosophy, who's your favorite philosopher?
04:56 Fred Kingham: David Hume, who is the father of empiricism. Who, he writes very interesting books about skepticism and causality. The notion of, how do you know something is connected to that, or something else, causality does force out people's positions, like does some correlation equal causation? And his books are very readable, and I highly recommend them, he writes about the discourse between like two or three people quite often. Discourse is only natural to religion I think. Dialogs concerning naturalism and religion.
05:28 Michael Kennedy: Yeah that's a tough question, there's too many choices throughout the years. Alright, so you studied philosophy and then you did this conversion course over to computer science huh?
05:35 Fred Kingham: I finished my philosophy course, I went traveling for a bit. I had a small little accident, ended up in the hospital for a bit, came out of that saw the Master's conversion course, went into banking because it seemed like a good thing for five odd years? Sort of Wall Street I guess, the investment side. What we always called The City, and I did some contracting for a few years, for sort of marketing companies, you know marketing websites, that kind of thing. And then I went to NHS Hack Day, which is a series of Hack Days that exist in the UK where clinicians come up and are like, we have this problem, at the moment there's nothing available at our hospital, in a weekend can you sort of push something out so that I can take it back to my hospital IT people who would say, we can't hack this. And say, well these guys have done something similar in a weekend, make it happen kind of thing.
06:31 Michael Kennedy: Yeah exactly like, it's so funny that sometimes that's the way it is right? Oh you can't do that, there's no way this is impractical, do you know how long this will take? Yeah it'll take a couple of weeks, let's just do it and you know, sometimes the debate about whether something is possible takes longer than actually doing it. But you need that sort of outside perspective right? So this NHS Hack days, what is the goal? I mean, you said the goal is to show what is possible, is the goal to go there and try to like learn what is needed so maybe I can do a start-up? Is it a charitable thing? Like I want to create the software and I want to give it back to the health industry in my country to just help everyone? What's goin' on there?
07:06 Fred Kingham: It's quite open source-y, it's not really about the businesses, people have tried to launch businesses based on the ideas that have come out of it. Some people go there just to learn, some people go there just to learn, experiment in technologies, it's quite a common reason to go to a hack day anyway. The other is actually to make the NHS better in this country, or healthcare better. But, as I said people have tried to make companies out of this stuff, on one side, but on the other side those are, in one of the first ones, a great example is, people who essentially have to type in like, a series of strings based on whether they see certain cells, certain things within a cell, and it was taking people ages, and the solution was literally, well we'll just remap your keyboard so that you press J and this weird string comes out. And suddenly what you've got is, people who were taking days at something, being able to do it in less than an hour. And it's such a simple solution, and yeah you could turn that into a business model, but realistically, this is just, it's just an easy way of making somebody's life so much easier, and it's not hard, anyone can write that right? It's not...
08:19 Michael Kennedy: Right.
08:20 Fred Kingham: On the other hand, I think I know some people who've tried, they did, one of the big problems is people who don't take their medications, specifically if they're ill, and there's some people who tried to create a company, I don't know how well it's going, I've lost track of them, but that was, take your meds, so essentially people getting a text message when they should take their medication because, people don't take their medication, it tends to make the whole system break, because things suddenly, what should be very cheap is super expensive, cause you then have to go in there and make real...
08:55 Michael Kennedy: Do some kind of intervention yeah. So like schizophrenic stuff, medication, or depression medication, I feel like people take that stuff, and then they're like, oh I feel better now, I'm better, I don't need my meds right? But maybe, you know, maybe it's because you're taking the medication right? And as soon as you stop you're like, oh my gosh, it's all back to the beginning!
09:15 Fred Kingham: It's also for like geriatric, well geriatric, like old people who, you know, required to take medications, these medications once every three hours. And it's so easy to forget, and as soon as you don't, well suddenly you haven't taken, I don't know, heart medication, and you're at risk for a heart attack.
09:31 Michael Kennedy: Yeah of course. Yeah I guess if the frequency is a couple of hours, it's tricky. Yeah cool, so you've got these NHS hack days, which sounds like a really good idea, I don't know if we have that in the US, maybe we do but, I've never heard of it. Probably one of these cool benefits of government healthcare, interesting. So, you know it's not all just for profit, like who wants to go help, I don't know like, your local HMO make more money, or the local health insurance company, right? I'm not going to go do a hack day for any insurance company whatsoever right, unless... It's just weird, anyway. So you guys have these, and you went there and Opal was born out of it huh?
10:12 Fred Kingham: So yeah, Opal was born out of that, by my work colleague, so like a couple of years before, before I joined Open Healthcare. And then I was contracting, I went to couple of these Hack Days, I'd been to a couple in a row. And then I went to work for, I went to an interview at quite a prestigious start-up, and it was quite an intensive process, like I don't know six hours of continuous interviews. And then in the last one, the founder of the company says, where do you see yourself in 10 years? And I said, writing software for open source software for the NHS. So then I turned down their offer, and went to Open Healthcare cause I realized, why go through that process, that was actually what I wanted to do so, why not do it now?
11:00 Michael Kennedy: I love it, that's great. So I think this is a good test people should give themselves periodically, the five year or the 10 year test, you know? In this case it was, where do you see yourself, like in the broad sense, but it could also be, look at the people that are five or 10 years more senior than you in your company, what do they do, do you want to do that? If you don't want to be doing that, the time to like, start finding a different path is now. Because that could be right where you're headed! I think that's a great motivation.
11:29 Fred Kingham: When you go into an interview, and you see the people who are interviewing you, the first thing you should think is, do I want to be these people? Do these people seem happy with their lives and their life choices because.
11:40 Michael Kennedy: Yeah that's really great, I totally agree with that. Alright, so that's a pretty big goal and I think it's a very cool thing, but I also see it as challenging, just as a career right? Like I want to go write open source software for NHS, how did you tie that back to the career in your mind? Like how are you going to pay the bills while doing that?
12:02 Fred Kingham: The business model is, essentially quite clearly that. If you can create a good service, medical software is big business, I don't see the open source as in any way a blocker to this. I want to like, the NHS are paying us money, we're not doing this out of the goodness of our hearts. The open source means that, the quality of the software can be more rigorously tested, that there's not so much of a contractual lock-in, because one of the problems that you get, I was talking to hospitals that were on my mailing list, and a lot of their medical data was this one system, and they wanted to switch to another system. And they said how much to move that across? They were told 10 million quid, 10 million pounds. So the hospitals likely can't afford that. So they just dump the data, and sort of computer provider said, well that'll be 10 million pounds to delete the data.
12:59 Michael Kennedy: Oh that's rough!
13:01 Fred Kingham: Yeah right? It's a file system of contractual lock-in. So by being open source, we can provide great quality, better software. We can charge for great quality software, but if they don't like us, they're not locked into us because anyone can look at the source code that we've written, and sort of take over if necessary. Hopefully, that's never happened so far. And we'd like to think it won't.
13:23 Michael Kennedy: I think so, and it's based on super popular stuff. Things that most people who know Python could walk in and get up to speed on in a week or so, at least. And Python being the most popular language, or at least contending for that, that's a pretty solid statement that people can just pick this up. So tell us what Opal is.
13:46 Fred Kingham: Opal is a web framework for building healthcare applications that store medical data about people.
13:52 Michael Kennedy: Cool, so we had Django, we have Flask, we have Pyramid, we have Starlette, we have these other frameworks, why do we need Opal? What does it do in addition to just, Django create an app, or cookiecutter Pyramid or Flask?
14:08 Fred Kingham: Yeah, so that's a super interesting question, because in the levels, Opal is kind of, it's a domain specific framework. So you have Django, Django is do anything on the web. So Django arrives on the scene, I'm too young to remember this! So Django arrives on the scene, and suddenly you were able to say, well I want to create a poll task, and you're always able to do it on a lunch break, and I was able to do a week's work in a lunch break and that's amazing, and it revolutionized things right? And then, from there you don't have too many sort of domain specific, I guess blogging software is the most domain specific, where you have software which is, frameworks which are, I'm just going to build a blog, I'm going to do one thing.
14:57 Michael Kennedy: Right.
14:58 Fred Kingham: Something like Django, and then you've super specialized on top of that.
15:01 Michael Kennedy: Like where WordPress or Ghost or something, I hadn't even really considered blogging, blog frameworks platforms as, you know, domain specific, but yeah you're right, they definitely are. And it makes a ton of sense right? I'm just, you know. Thinking about what you get, so this is built on Django, Opal is, so it's not like another framework in the sense of that it's trying to compete with those, but it's, let's take Django, and let's take all the boilerplate junk that you have to write to build something in the the clinical domain, make that happen, and now get started right?
15:37 Fred Kingham: What we can do is we can say, we know you're going to have patients, we know you're going to have episodes of care, we know you're probably going to have these bunch of clinical models. And we can therefore make loads of assumptions, which means that we can scaffold things out quite quickly, so we know that you're going to have a patient list page, patient detail pages, and different types of episodes of care. We know that you're going to want forms that, forms for example conditions, for diagnoses that are going to hang off an episode of care, so we can say, we can scaffold you up forms for the conditions, we can scaffold you display templates, we can give you a REST endpint for an episode which will give you all of the things which are hanging off that, so you've got that for your diagnosis, maybe your treatments, maybe your blood cultures, maybe your lab tests. We can just do that super quickly, because we know that's what the modeling structure that you're going to want.
16:41 Michael Kennedy: That's great, so you don't have to think about all those things, you just start using them, and these are all classes, these are Django entities right? In the Django ORM. But you could create ones that are more specialized, you could create other ones that go in there, so it sounds like a lot of the core data model's already put together, and things like that right?
17:01 Fred Kingham: We have sort of a specialized model called a sub-record, that we know, that you can use, which we know will have a relationship to a patient, or relationship to an episode. And because we know that model structure, we can automatically wire that into forms and stuff as I said, but also into search, into data extracts, we don't, Opal doesn't enforce, like the model structure, it offers this, and this, a lot of what these kind of frameworks do, is they, and what Opal tries to do, is get you 80% of the way there. Once you're there, once you've done, once you've started prototyping, you might be like, oh I want to just use more sort of Django stuff. Opal doesn't stop any of that, it just gives you a helping hand in what we think the right direction is.
17:51 Michael Kennedy: Yeah just that quick boost. And even though this came out of this NHS Hack Weeks, I suspect somebody could take this as the starting point for another one of those, and really bust out something pretty amazing, pretty quickly it sounds like. Cause it just puts all this stuff together for you. So one of the things that these episode sub-records, which are the Django models do that, I don't know, is kind of interesting to me is, it creates a relationship between the entities already, which is pretty cool. But it also creates a JSON API for creating and updating, and searching them. It creates, makes sure that the Angular layer, we'll talk about Angular in a little bit, the Angular, front-end layer knows about it. Bunch of stuff like that, right? That's pretty cool.
18:39 Fred Kingham: Any modern work developer knows that you're probably going to want a Django REST framework, endpoint for a Django app. So exactly, right up front it gives you that. It does some schema description, so that, if you're looking for other developers to use to like, programmatically read your endpoints, you can give them that description, and they'll have an understanding of what data can be available. So yeah, I think it's alright.
19:04 Michael Kennedy: That's pretty sweet. So it comes with batteries included, but these batteries are more like stethoscopes, and tongue depressors, and.
19:12 Fred Kingham: That's excellent, I'm stealing that.
19:14 Michael Kennedy: Feel free to steal it, it's all good. I'm sure there's better analogies in the health space, but that's a good start. This portion of Talk Python to Me, is brought to you by Linode. Are you looking for hosting that's fast, simple, and incredibly affordable? Well look past that bookstore, and check out Linode at talkpython.fm/linode, that's L-I-N-O-D-E. Plans start at just five dollars a month for a dedicated server, with a gig of RAM. They have 10 data centers across the globe, so no matter where you are, or where your users are, there's a data center for you. Whether you want to run a Python web app, host a private Git server, or just a file server, you'll get native SSDs on all the machines, a newly upgraded 200 gigabit network, 24/7 friendly support, even on holidays, and a seven day money back guarantee. Need a little help with your infrastructure? They even offer professional services to help you with architecture, migrations, and more. Do you want a dedicated server for free for the next four months? Just visit talkpython.fm/linode. When I think of this project, it sounds cool like if I as a primarily web developer, when I'm writing code, when I'm thinking of like how would I use this, obviously I would go out and I would build some cool healthcare app if that was the domain I wanted to spend some time on. But when you think about this project, who do you have in mind? Like have you made this for people like me? Have you made this for the IT folks inside the company? Have you made it for doctors? Like who do you have in mind using, or who's ended up using Opal?
20:48 Fred Kingham: That's an excellent question, so in reality we use this ourselves obviously, we use this in a number of major hospitals for sort of a whole bunch of teams. And, actually when building a framework, you need to sort of eat your dog food?
21:05 Michael Kennedy: Yep.
21:05 Fred Kingham: We are the dog. And this is designed for other dogs like us, so other developers, being brought into hospitals, or who already work in hospitals, to develop healthcare applications. That being said, doctors as it turns out, incredibly smart, technically minded individuals. And a number of them have picked up and experimented with Opal, for their own sort of side projects, and for projects for the hospitals. I'm not sure a doctor has ever released an Opal application into hospitals, maybe you'd want to give it a code review first.
21:44 Michael Kennedy: It's going to need some refactoring, I'm not so sure about this. But you know, I think that's really cool, and I do think that's one of the things that Python makes more possible for folks, who are really smart and technically minded like doctors, to just say, you know I have this problem, and it's got to be frustrating to go to work, at least in the US, you never log into your computer, you log in to like some Citrix remote desktop thing, there's probably all these frustrating like layers, and they're just like, you know what? If I could just have this thing, it seems so easy! And they probably just, start busting something out right? And then they can bring that, and be that proof that you talked about from the NHS Hack Days for example.
22:24 Fred Kingham: Exactly, they can just go, look it's not that hard.
22:27 Michael Kennedy: I have a funny story I'll tell you real quick about a doctor and programming. I was at the doctor, I don't remember why, it was nothing major just some random thing with the doctor. Maybe 2010? Something like that? Quite a while ago. And the doctor said what do you do? Said I'm a programmer, and he said what language do you program? At the time I'm like, well program this language called C#, which I was at the time, and he says, pauses for a sec and he looks at me, and I thought he was just trying to make small talk, so he could like, before he stabs me with a needle or something. Looks over goes, you excited about the new release of Visual Studio? I'm like, what? Excuse me? He's like, yeah this new stuff they're doing is so great, I'm really, I'm like, are you a real doctor, like who are you? Like who gave you that robe?
23:11 Fred Kingham: Yeah, did this make you trust him more or less?
23:15 Michael Kennedy: Both, both. But it's so interesting, because at the time I'm like, oh surely they don't care there. But the more I interact with doctors, the more I realize, yeah for sure, they have these challenges, and you can bring in programming languages to solve those. At some point the pressure gets too high, you're just like, I'm going to write this website that's going to solve this problem. I do see it as an extra challenge in the healthcare space, over some other, let's say accounting or something right? Maybe account's not even the best counter-example, but in healthcare you have to be a little more careful with your data and stuff, so you can't just like, oh I threw it on like a random server on the internet, and it's easy now. Like well, maybe that's not going to fly.
23:53 Fred Kingham: To me one of the interesting things about the medical space in relation to other spaces, as I said, I used to do some sort of banking stuff, but you had, and what you have in a lot of places, you have something like stocks, stocks are essentially manmade inventions right? And therefore, they've already, a man's mind can comprehend what they were, or a person's mind can comprehend what were, and draw the limitations around that, and they're a legal entity that's described. Whereas when you look at modeling in a medical sense, it's such a broad, you're just describing concepts to real-world conditions, that means that modeling becomes far far fuzzier. Sort of, when you're saying sort of like, obesity can lead to dying of like drowning, well nobody dies of drowning, they die of, like an oxygen deficit kind of thing.
23:53 Michael Kennedy: Right right.
23:53 Fred Kingham: So when you're filling in your medical notes, what do you do? Well you know like, which I think makes, and different doctors will put in different things, because if you're a blood cancer specialist, then your concept of dying of this, I don't know, okay, maybe I don't know blood cancer for certain, but definitely when prescribing a blood panel, prescribing a blood test. If you work in microbiology, your description is going to be different from a doctor who's another specialty. Which I think is super interesting.
23:53 Michael Kennedy: It is. And I think it really makes the modeling challenging right? We already talked, there's some of the sub-model, sub-episode classes, like the Django model classes, that model these things, but they're coming from a certain perspective, right? Like one of the things that you talked about on the, maybe on the tutorial, I can't remember where I saw this, but a cough, it could be symptom of a condition, or the cough itself could be a condition. So if they kind of say, hey I need you to treat me because I have a cough, then that's probably the condition. But if they have a cold, then it's just a symptom right? So how do you record that in your database? Which is it a symptom or a condition right? These are challenging.
23:53 Fred Kingham: I sat in a room with doctors having full blown arguments at each other, about exactly this. And it's kind of like, well if you don't know, how do you expect us to know that?
23:53 Michael Kennedy: Yeah well that's the problem, or the challenge of building something for a domain, especially if you are not yourself a doctor, or you are a specialist in that domain, it makes it harder to model stuff in that domain, as a programmer. But it's also the value right?
23:53 Fred Kingham: That is one of the things that Opal tries to do, the programmer, well I've been a programmer for about 12 years now, I've been around the block, a doctor has had at least five years at a university, probably two years after that still sort of learning the ropes, you know, they're going to be eight, nine years down the line. And so, what Opal tries to do is kind of create, through essentially in some levels, the Django sort of modeling, Django models is to kind of create a bridge where two very complicated domains can kind of meet and discuss in a way that they can understand each other.
23:53 Michael Kennedy: I guess it's that shared experience right? So maybe, an interesting way to talk about, like give people a sense of what this is, and how it works, maybe we could talk through a getting started story. So you have a tutorial on the website, and it says, as a doctor you want to know what's going on with your patients under your care so you can treat them effectively and whatnot, so you need some kind of app or something to manage that, let's build that in Opal. Which is pretty interesting. So you do want to maybe just talk us through this whole getting started story here?
23:53 Fred Kingham: Opal does a similar thing to, I guess Django apps in start of projects, but again, more specific for medical applications. So, out of the box, we essentially give you some core clinical models that we think are pretty good, and you might like. And we give you some reference data that you might want to change, but is the kind of thing that you laid in and stable, so we give you a list of conditions that doctors have given us in the past, and said these are the kind of conditions we want to record, we give you sort of basic, sort of demographic lookup at lists. But again, you know like, gender, ethnicity, you might want to change them, but out of the box, give me something sensibile. When you run the create project, you get sensible defaults, and it gives you an episode details page, and a way of adding patients. Because, we know from the domain, that these are things you're going to want.
23:53 Michael Kennedy: Yeah. And it feels very much like getting started with Django itself. So the way you get Opal is you just pip install it. That's cool right? You just pip install this, or put it as a requirement. And then you says opal start-project, and you give it a name, very Django-esque. Go in there, go in that folder, and you say Python, manage that .py, run server, right? Like you could just replace Opal with Django, and so far you're on the same path right?
23:53 Fred Kingham: Minus step four, for good reason, exactly we've take what Django, what we think Django did well, and hopefully extended that. So yeah exactly, so it gives third Django settings, which are probably going to be the ones you want. It gives you, gives you empty like, sets you up wherever you like.
23:53 Michael Kennedy: Right, so basically if I'm a Django developer, it's super easy for me to drop in, and get started with Opal, I just have to learn the new batteries that you've added right? And the conventions that you follow.
23:53 Fred Kingham: And we've given you can do that. But if you're that Django developer, it really shouldn't take you, it really shouldn't be too difficult to figure out what we're doing. And as I say, once, if you're a Django developer and you're like, I like what you've done with this, but I'd like to do this in regular Django, we don't stop you from defining your own views in any way you like.
23:53 Michael Kennedy: How much of what Opal gives you in terms of the scaffolding business here, how much of it is a, at the beginning of my project, one time only? Or is there a way to periodically add new entities and new views? So maybe I have like, I have demographics and treatments and diagnoses, and all that stuff comes out of the box, but then say like, oh I need a surgery, and I'm going to add that, is there a way to run like a command line option to do all that magic to add it in? Or do I, am I kind of on my own once I start it?
23:53 Fred Kingham: Can you add in a carer model for example, for a patient, for an episode? You add in your Django model, and then you run manage apply scaffold, what we'll do is we will create you a form template, and a display template, and then you have to go into your patient detail, and, which will already have a list of similar sort of record panels as we call them, and you can just add in that, but with carer instead of...
23:53 Michael Kennedy: Right.
23:53 Fred Kingham: So what that gives you is a display template, and a way of adding, automatically wires you in like a modal form, so you click add one, and it would bring you up a modal form. And then what we do, is we look at a method called _is_singleton where you can add property provided by a _is_singleton on model, and that tells the system that, one to one model, or one to many model. So if you have like demographics, you're only ever going to have one, you're only going to have one name right? Well, that can be tricky. You're only going to have one demographics model related to a person. Now you may have multiple treatments, and so that tells the record panel whether to allow, let me add many treatments, or just let me edit the single demographics model.
23:53 Michael Kennedy: That is awesome, because then you can just keep adding these Django models, and then just rerun scaffold and it does all the stuff for you right? All the magic?
23:53 Fred Kingham: Exactly, so just look for your model, and then create you form, a whole bunch of forms come off the back of that. We are different from vanilla Django, we use template tags for our form fills, cause under the covers, this is all, there's a whole bunch of Angular that's happening so we're not refreshing the page, we're bringing up modal, we're editing, we're changing it, we're saving it, everything's just working. Visit doctor the other day, and what was really evident is, they changed one of the models, and then they looked at the form, and personally I really like API design, and when somebody like doesn't even need to look at the docs, and they're like, oh I just need to change this to this, and you're like that's grand, my work here is done.
23:53 Michael Kennedy: Yeah you know you built a good API when their first guess, their first intuition is exactly what you'd hope they would do. Super cool, so one of the things that I saw in the tutorial that was pretty interesting, is you have these relationships, like what problem or symptom did this person have, and there's probably a big prefilled list like a drop down select, you can pull down and choose you know, they've got a fever, their foot is broken, their bone is broken. But it also allows you to type in free text, so you have this column type, field type, foreign key or free text, that was really interesting to me. You guys came up with that right, it's not part of Django?
23:53 Fred Kingham: Yeah that's all our pattern, I've seen like, different people in different places, all of them having to roll their own sort of customized implementation of exactly the same thing, it's such a common thing that, I want to put in a sort of a foreign key relationship, or free text. And what this does is it does exactly that, it's a free text box, you can type in whatever you like, but there'll be an autocomplete bunch of options, and you can select one of those and it'll save it as a relation, or as a foreign key. And one of the things that's nice, is that it also supports synonyms, so say you can have a cough or a sore throat, or a pained throat? You kind of get the idea, quite often there's two terms for the same thing, in terms of symptoms. And what the doctor can do, or what they can tell us to do, is say, wheezing and breathlessness are the same thing, and it will reconcile as those are, you have a consistent view of what the patient might have.
23:53 Michael Kennedy: Okay that's a really cool feature, I love it, I think that's great. And it seems like it shows up really nicely in the UI. So let's talk about, you mentioned Angular and whatnot, you've obviously been talking about Django, but let's dig into some of the tech. You want to tell us what's involved, how you built it?
23:53 Fred Kingham: We've got Django on the back end, and then, at the moment we've got Angular JS on the front-end, and Bootstrap. A lot of these, as we say, it's framework that, people who come to Opal, aren't necessarily going to have a background with Opal, and the technologies are very much, Stack Overflow will answer my question. So we've got Angular JS, and then there's a bunch of magic that why things scale up for you. So as we say, there's a schema that you can get out for each of your models, which describes the model, and Angular JS consumes that, and it uses that when constructing forms.
23:53 Michael Kennedy: Does it talk back over Django REST framework?
23:53 Fred Kingham: Yeah. And then Angular, because we have the concept of form template, and display templates, and they're all scaffolded out for you, we can make reasonable assumptions and Angular can, ideally you don't even have to touch Angular that much, but you can. So we use a model for the front end, which I haven't really used that much before, it's one that my colleague sort of did which is, actually what I want is, I want all of a patient, so whereas in previous projects that I've worked on, I'd be like, well they want treatments, they want diagnoses, through separate API endpoints, pull that. When you go for a patient, or an episode, it's like using DRF, I think they we don't use. So essentially you get an episode, you then it serializes everything under it. So when you doing front end code, you know what is available without having to worry about, will this load if this didn't load? Which is really nice.
23:53 Michael Kennedy: I see, so it like traverses the form queue relationships, and it creates a hierarchical JSON response type of thing?
23:53 Fred Kingham: Exactly exactly. So we serialize everything for that episode in one go because experience has shown that's what doctors want, and that makes it a lot easier in the front end to know that the model is going to be similar to that.
23:53 Michael Kennedy: It's worth it once you're saying, you know what, we'll pay the extra price, and we'll ship the episode along with the patient, and it's going to be fine because, you don't want to have two ways to do it.
23:53 Fred Kingham: You can pre-fetch related all of the things, and the number of data inquiries you're doing is pretty efficient.
23:53 Michael Kennedy: This portion of Talk Python to Me, is brought to you by the University of San Francisco. Learn how to use Python to analyze the digital economy, in the new Masters in Applied Economics, at the University of San Francisco. Located at the epicenter of digital disruption, USF is the ideal launching pad for the next phase of your career. Their new STEM designated economics program, doesn't just provide technical training in high demand skills like machine learning, causal inference, experimental design, and econometrics, it takes the next step, teaching you how to apply these techniques to understand the economics of platforms, auctions, pricing, and competitive business strategy, in the world of big data. The program is open to beginner, and to advanced coders, looking to apply their skills in a new area. Applications are now open for the Fall 2020 classes. To learn more and to get an application fee waver, go to talkpython.fm/usf, that's talkpython.fm/usf. Speaking of databases, it sounds like you're using Postgres?
23:53 Fred Kingham: Yes we use Postgres. When you do the sort of tutorial app, vanilla gives you SQLite, because you don't necessarily want to teach people how to install Postgres onto their computer.
23:53 Michael Kennedy: Yeah SQLLite's beautiful like that right? You can just say, you have basically a full database, but you don't have to do anything. Can you make a file? Alright let's go with that, you know what I mean?
23:53 Fred Kingham: I love it.
23:53 Michael Kennedy: Yeah I do too.
23:53 Fred Kingham: I think it should be used more, a lot of the times when people are exchanging like, CSVs and like big institutions are kind of like, oh why don't you just stick it in an SQLite and ship it.
23:53 Michael Kennedy: Yeah yeah for sure. So it sounds like it's a pretty good project in terms of how it's all put together, some of the technologies. What's the deployment story look like, is this you got to make sure you set up Postgres, you set up Celery, you set up uWSGI, or Gunicorn, or whatever it is you're going to set up, and then is it a bunch of steps, or is there some pre-canned way that people can run a magic script and have the infrastructure?
23:53 Fred Kingham: At the moment we don't have that pre-canned script. I mean we do for out own deployments in-house.
23:53 Michael Kennedy: Sure.
23:53 Fred Kingham: Obviously all scripted out, but the reason why we haven't is because, hospitals vary quite a lot in their sort of VPN technologies. So what we tend to do is, have boxes on the hospital sites that are running the software, that sort of gets us around any sort of security issues. And depending on the VPN, sometimes you can only log in on the VPN via a windows machine doing this and the other. Whereas others, you can wire together with Ansible and do your deploy scripts through Ansible, so sometimes you've got sometimes you've got Ansible scripts, so we don't have that vanilla out of the box deployment script which would be quite nice, but yeah.
23:53 Michael Kennedy: What I've been hearing a lot lately for setups like this is, what we're going to do is use Docker. I'm a fan of Docker, but I feel like that adds another layer of like, okay you did have to know Python web frameworks, and you have to know Postgres, well now you kind of sort of have to know this, but you also have to know Docker, you know what I mean? It's like, on one hand it gets simpler, on the other it like expands out the things you have to maintain and manage, so I don't know, it's tricky.
23:53 Fred Kingham: No I think that's great, I think we have been looking at that, I think I looked at it a while back, and maybe I'm wrong, I could be wrong with my memory, but I think that the version of Ubuntu that they were running it on, was not going to casually allow us to run Docker.
23:53 Michael Kennedy: Right it was too old or something.
23:53 Fred Kingham: Maybe that's, exactly.
23:53 Michael Kennedy: Yeah speaking more broadly, because this is healthcare it has special constraints on where it can live right? But if you're building this kind of thing for something that wasn't so regulated, it might be cool to build some sort of Kubernetes thing, and then you could just plug it into one of these managed Kubernete clusters.
23:53 Fred Kingham: Yeah that would be cool.
23:53 Michael Kennedy: That would be cool, that seems like a pretty easy way to say, look you don't have to actually worry about running it, you just get this service, and you just jam it in there, and you can scale it with these knobs, you're good. But when it's down to you running the clusters.
23:53 Fred Kingham: We talk to clinicians a lot, because we deal with a lot of sort of like niche services, and so we're not the greatest of when we don't have a clinician's experience, so we do a lot of like, just roll up a Heroku box with this branch roll up to this branch, send them both out to the doctors and say, how are these playing well with these, but we haven't branched out to Kubernetes
23:53 Fred Kingham: Well I mean, we are actually sort of, we are now running it where, we're now working on Opal 1, so previously we've been on 0.* releases. And as such, we are aiming to move off the Angular there, because it's end-of-life. And we're currently doing, we're essentially experimenting with Vue and React, just progressively building up sort of, in the former system, we can actually show you it.
23:53 Michael Kennedy: That's cool.
23:53 Fred Kingham: It's the whole experimenting with both. I've heard you like Vue, I'm a big fan of Vue. So I have a version of Opal that just runs Vue. But, it's making sure that what we've got is easy in terms of the developer, and I can't make, just because I like Vue, have I experimented enough with React? And I think more of the problem is shipping it? So now what we've got at the moment, and what's quite nice is, you declare your the file names into either plugins, or into an application. And Django compressor just does it all for you, whereas now, if you're looking at something like Vue, or React commonly, you need to, you don't need to, but webpack is kind of the assumed approach, and then you've got the Django webpack loader, but the Django webpack loader, they've done, what I've currently seen, I don't pretend to be an expert at this. It doesn't necessarily load from packages, so for example you pip installed Opal, or you don't, if you want the static of files which are coming through with that, the Django webpack loader won't actually pick those up. So then you have to say well, do we then store the static files on NPM, and so we then, you pip install opal and through some magic we'll bring in the static files from NPM, but then obviously you have to pull from two different packages, and you have to contemplate that. It's a super interesting problem, and I'm quite enjoying playing with it.
23:53 Michael Kennedy: It sounds challenging. It sounds a little bit, I don't know in the UK if you know the game Whack-a-Mole, it's like this arcade game. You know, it reminds me of that right? Like I'm going to, bam I solved this problem, oh it pops up over there, whack I solved that problem, now it's back here like. You squeeze on one side, and it pops out the other, and you know, it's challenging right?
23:53 Fred Kingham: It's super challenging, but to be honest, I don't know, different programmers find different problems interesting. I do find this interesting, I do sometimes think it could all be simpler. But that is probably my own ignorance.
23:53 Fred Kingham: Yeah it was like, oh I've just done NPM install, suddenly your computer gets hot.
23:53 Michael Kennedy: Yeah exactly. Yeah yeah interesting. Okay well I'm a big fan of you, I definitely think it's special. I like that it's as well. Now let's see, let me ask you a couple other questions, getting a little towards the end of the show here. One thing I guess is interesting to talk about, just real briefly is, Opal is open source, go to GitHub, I can get it, do whatever I want right? I can pip install it?
23:53 Fred Kingham: Yeah!
23:53 Michael Kennedy: But you work at Open Healthcare UK, which is that like, a boutique app shop, for the healthcare industry, or how would you describe it?
23:53 Fred Kingham: The way the healthcare in hospitals commonly works, is that, what you have is, the product prization, if that's a word, is massive lifestyle APR, and then an NCA data repository for all pins and hospitals doing all things.
23:53 Michael Kennedy: It's like the SAP of hospitals, it's going to do everything, just install this and it'll be fine right?
23:53 Fred Kingham: Exactly. And what you find is that, it does a pretty good job. But for, it does 80%, but for the extra 20%, what you've got is Word Docs flying around, Excel spreadsheets, the occasional Access Database, or good old fashioned pen and paper. And sometimes this makes sense is pretty useful. So we have, what we do is we fix up that 20%. So you're a, we do microbiology for example, we do some of that stuff, which is sort of, people who specialize in blood cultures, we go and we're like, we talk to the doctors, and we get their requirements, and we, sort of, more specific to them. And yeah, we cover that 20%.
23:53 Michael Kennedy: That's cool, so basically the role of Opal is, this thing that you guys have built, it'll let you quickly, it'll supercharge your creation of these apps, to cover the 20% that you talk about, but it's also awesome that it's open source and other people can take it and run with it, is that right?
23:53 Fred Kingham: That's right, that's exactly right. This is not that much of the specific problem, this is a general problem I think world-wide, I don't think in the states, they've kind of got a magical APR that fixes your problems either right?
23:53 Michael Kennedy: No no no no, of course not. Cool so it seems like a solid blend of, here's this open source thing that people can work on and they can use, but is also there to support your business. And one of the things I feel like, just doesn't seem to work really well, is the PayPal donate button on open source projects. Right, it's just my experience of hearing folks who seem like they have pretty popular projects, is like, it's definitely not a career at that point. There's got to be something else, and this seems like a really nice synergy around that, so that's cool.
23:53 Fred Kingham: Our main reason for open source isn't, it's open source because healthcare applications deserve the rigors that being open source allows you to have, and inspection. Open source is kind of like a function for, you should buy our software because it's open source, and therefore, hopefully you can trust it more, and yeah, that's the sales pitch I guess.
23:53 Michael Kennedy: It's the antidote to that 10 million quid problem. 10 million to convert and 10 million to delete. Which one to you prefer? Alright well, I guess on that, are you looking for contributors to this project? Are there restrictions if people want to take it and run with it and do something else?
23:53 Fred Kingham: Our sort of, what we would like is, I said we're moving front end framework, I don't think, I think every developer right now probably has experience between different front end frameworks, we'd love some opinions on that. We'd love anyone to come and have a look, come and have a look at the GitHub repo, offer suggestions, any breaks in docs, any breaks in anything really, that would be super interesting. Also we come at this from having years of experience, we've built healthcare applications in the UK, well does that necessarily grow at an international, something that's internationally applicable. We, at the moment, we have NHS on a model. That will not be happening soon, we are going to move up to that kind of thing, this would be a global solution to a global problem, not a UK solution.
23:53 Michael Kennedy: Congratulations on this project Fred, this looks really useful for folks out there.
23:53 Fred Kingham: Thank you very much, it's been great talking with you.
23:53 Michael Kennedy: Yeah. Now before you get out of here though, I got the two final questions I got to ask you, is if you're going to work on Opal and write some code over there, what editor do you use?
23:53 Fred Kingham: I use Vimplugin on VS Code. Which is interesting, I occasionally go back into pure Vim, before VS Code I used Sublime, I used IntelliJ when I was a Java programmer, all using the Vim plugin. And so I feel like I've spent my life doing this sort of weird hybrid of Vim versus a more integrated, open environment.
23:53 Michael Kennedy: A constant pull, yeah. But VS Code sounds like a good one these days, it's got a lot of momentum for sure. And then, notable PyPI package?
23:53 Fred Kingham: I really like cached properties in Django, which are, if you've never used them, essentially it's an annotation that there's, here's a method, store the results of this method on the object, and then, whenever I call this method, first time I call it, calculate it, and return the answer, subsequently store the results of the method. I just think it's as useful a pattern as being discussed as part of core Python for some time, Danny Greenfield I think? Hi Danny, he has a package on PyPI that does this, because it's such a common function. And then, in Python 3.8, just a few weeks ago, we now have functools cached_property. So it's been so I was hoping to have functools.cached_property as my notable package, which is potentially cheating because it's part of the core library. But it's super useful.
23:53 Michael Kennedy: It's new enough right, it just got shipped. I think that's cool, I think that's one of the really easy ways to speed up things. The only challenge with that is, you have to be careful on what cache invalidation means, right that can be challenging to deal, whenever you're dealing with caching.
23:53 Fred Kingham: And if you look at the patch, there's a long discussion about it.
23:53 Michael Kennedy: Yeah I can imagine. But it, you know, it can just completely change the way the performance looks. So it's, and it's so easy to do those types of things. Pretty cool, good one. Alright, final call to action, people want to get started with Opal, what do they do?
23:53 Fred Kingham: Pip install it, take a look at the docs, we kind of covered them a little bit today, I think they're pretty good, so pip install it. Go through the tutorial, and let us know what you think!
23:53 Michael Kennedy: Super.
23:53 Fred Kingham: The code is all at openhealthcare/opal on GitHub. Github/openhealthcare/opal. So yeah, you can go and just browse the code as well.
23:53 Michael Kennedy: Sounds good, thanks for being on the show, it was great to talk with ya.
23:53 Fred Kingham: Great Michael, thanks very much!
23:53 Michael Kennedy: Yeah, bye. This has been another episode of Talk Python to Me. Our guest on this episode was Fred Kingham. And it's been brought to you by Linode, and the University of San Francisco. Linode is your go-to hosting for whatever you're building with Python. Get four months free at talkpython.fm/linode, that's L-I-N-O-D-E. Learn how to use Python to analyze the digital economy, in the Masters of Applied Economics at the University of San Francisco. Just go to talkpython.fm/usf to find out more. Want to level up your Python? If you're just getting started, try my Python Jumpstart By Building 10 Apps course, or if you're looking for something more advanced, check out our new Async course that digs into all the different types of Async programming you can do in Python. And of course, if you're interested in more than one of these, be sure to check out our Everything Bundle. It's like a subscription that never expires. Be sure to subscribe to the show, open your favorite podcatcher, and search for Python, we should be right at the top. You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct RSS feed at /rss on talkpython.fm. This is your host Michael Kennedy, thanks so much for listening, I really appreciate it. Now get out there and write some Python code!