Learn Python with Talk Python's 270 hours of courses

#241: Opal: Full stack health care apps Transcript

Recorded on Wednesday, Oct 30, 2019.

00:00 Open source has permeated much of the software industry, but what about healthcare?

00:04 This highly regulated and important industry might seem to be the domain of huge specialized

00:09 software companies. On this episode, Fred Kingham is here to introduce us to a project called

00:14 Opal. It was born out of NHS Hack Days in the UK and is a full-stack web framework for building

00:20 healthcare applications. It's based on Django and has a ton of interesting features as a framework

00:25 in general. This is Talk Python to Me, episode 241, recorded November 30th, 2019.

00:31 Welcome to Talk Python to Me, a weekly podcast on Python, the language, the libraries, the ecosystem,

00:49 and the personalities. This is your host, Michael Kennedy. Follow me on Twitter where I'm at

00:54 and Kennedy. Keep up with the show and listen to past episodes at talkpython.fm and follow the show

00:59 on Twitter via at Talk Python. This episode is sponsored by Linode and the University of San

01:04 Francisco. Please check out what they're offering during their segments. It really helps support the

01:09 show. Hi there. Thanks for listening to this episode. Before we get to the interview, I have

01:13 something to share with you. We just launched a new course. It's called Python for Decision Makers and

01:18 Business Leaders. If you're a team lead or deciding whether to use Python for your next project,

01:24 or even the next stage in your career, this course is a great fit for you. It's super unique. Most

01:30 courses teach you how to program with Python. This course is a guided discussion and exploration of

01:36 the Python ecosystem through the lens of your organization and your team. It's full of fact-based

01:41 presentations for the Python ecosystem, covering things like frameworks, types of apps you can build,

01:46 developer jobs, and more. And it explores some of the tools making Python so popular in the data

01:51 science space. It's written both for developers and non-developers alike. So check it out at

01:57 talkpython.fm/decision or just click the link in the show notes. But wait, there's more. I'm working

02:04 on a few interactive events as well. So I'm putting together this live event to help kick off the course.

02:10 It's a free webcast on an interactive platform with lots of QA that's happening in January of 2020.

02:16 Check that out at talkpython.fm/python dash decision dash webcast, or just click it in the show

02:23 notes. Go ahead and register now. Hopefully you can make the live event. But if you can't, you can

02:28 still ask questions, participate in polls and chat. All that stuff will be available on demand afterward

02:34 once the recording is there on that platform. Super fun. So I hope you love both of these things,

02:39 the course and the webcast. Now let's get onto that interview. Fred, welcome to Talk Python to me.

02:45 Hi. Hey, it's great to have you here. We're going to cover some stuff that, you know, I don't think

02:48 we spent any time on the show before. Healthcare and open source. It'll be fun. Sounds great. Yeah.

02:53 Yeah. Now you guys are working on this project called Opal, which has an interesting origin story

02:59 out of the UK healthcare industry and whatnot, which is great. And lots of Python involved. But before we

03:06 get into all that interesting stuff, let's start with your story. How'd you get into programming in Python?

03:10 I started programming on the Atari ST, that venerable computer of the 1980s. I was using something

03:18 called Stoff when I was sort of like seven or eight, you know, when you're creating little

03:22 games, drive the L's through the X's, that kind of thing. Right.

03:26 Full of go-tos, go-tubs and all the joys that come with it. Then I did a philosophy degree and I did a

03:34 conversion course into a master's conversion course into computer science.

03:38 Wow. Philosophy to computer science, huh? That's quite the transition.

03:42 It is. But I don't know. A lot of people, I know a lot of people who've done it.

03:46 Yeah.

03:46 I think there's something about conceptualization, maybe formal logic. There's a whole branch philosophy

03:54 called, what's it called? Logical atomism, I think. Which tries to structure, tries to work

04:00 out Boolean responses to arguments based on conjunctions. Sort of like, if I like trees

04:07 and people who like things are liked, somebody likes me. That kind of weird sort of set logic,

04:14 very Russell-based.

04:16 Right, right. Is it true that I do this or does it follow that I do this? Yeah. Yeah. I think

04:21 actually, now that you say it, there's a lot of thinking. You know, I studied math. I didn't really

04:26 do much programming. I took a couple, like two programming courses in college for little sub

04:31 prerequisites. But I don't feel like I do math at all these days, even though I was in a PhD program

04:36 working on it, right? But I feel like that process that I went through, the type of thinking and the

04:43 way of approaching problems and all that, like, I use that every day. And that seems like it came straight

04:48 out of there, even though I couldn't do math to save my life these days.

04:51 Yeah, exactly.

04:52 All right. Before we move on to philosophy, who's your favorite philosopher?

04:56 David Hume, who is the father of empiricism, who, he writes very interesting books about

05:04 skepticism and causality, the notion of how do you know if something is connected to that,

05:10 to something else? You know, causality does causality equal causation, does correlation equal

05:15 causation. And his books are very readable, and I highly recommend them. He writes them as a

05:20 discourse between, like, two or three people quite often. Discourse is concerning natural religion,

05:25 I think. Dialogue concerning natural religion, exactly.

05:27 Yeah, that's a tough question. There's so many choices throughout the years. All right,

05:31 so you studied philosophy, and then you did this conversion course over to computer science,

05:35 huh?

05:35 I finished my philosophy course, I went traveling for a bit, had a small little accident, ended

05:41 up in a hospital for a bit, came out of that, did a master's conversion course, went into

05:45 banking, because it seemed like a good thing for five odd years. Sort of Wall Street, I guess,

05:52 the investment side, what we would call the city. And then I did some contracting for a few

05:57 years for sort of marketing companies, you know, marketing websites, that kind of thing. And then

06:03 I went to NHS Hack Day, which is a series of hack days that exists in the UK, where clinicians come up

06:11 and they're like, we have this problem. At the moment, there's nothing available at our hospital.

06:16 In a weekend, can you sort of push something out so that I can take it back to my hospital IT

06:22 people who are saying, we can't have this and say, well, these guys have done something similar

06:28 in a weekend, make it happen kind of thing. Yeah, exactly. Like, it's so funny that sometimes

06:33 that's the way it is, right? Oh, you can't do that. There's no way. This is impractical. Do you

06:36 know how long this will take? Yeah, it'll take a couple of weeks. Let's just do it. And you know,

06:41 like, sometimes the debate about whether something is possible takes longer than actually doing it.

06:45 But you need this sort of outside perspective, right? So this NHS Hack Days, what is the goal? I mean,

06:50 you said the goal is to like, show what is possible. Is the goal to go there and try to like,

06:55 learn what is needed to maybe I could do a startup? Is it a charitable thing? Like,

07:00 I want to create the software and I want to give it back to the health industry in my country to just

07:04 help everyone what's going on there? It's quite open source. It's not really about the businesses,

07:09 people have tried to launch businesses based on the ideas that have come out of it. People,

07:14 some people go there to learn, some people go there just to learn, you know, experiment in

07:19 technology. It's quite a common reason to go to Hack Day anyway. The idea is definitely to make the NHS

07:24 better in this country or healthcare better. But as I say, people have tried to make companies out of

07:29 their stuff on one side. But on the other side, there's a one in one of the first one, a great

07:35 example is people who essentially have to type in like a series of strings based on whether they see

07:42 certain cells, certain things within a cell. And it was taking people ages. And the solution was

07:49 literally, well, we'll just remap your keyboard, so that you press J and this weird string comes out.

07:55 And suddenly what you've got is people who are taking days at something being able to do it in,

08:01 less than an hour. And it's such a simple solution. And yeah, you could turn that into a business model.

08:08 But realistically, this is just, it's just an easy way of making somebody's life so much easier. And

08:17 it's not hard. Anyone can write that, right? It's not.

08:20 Right. On the other hand, I think I know some people who they did. One of the big problems is

08:26 people who don't take their medications, specifically if they're ill. I know some people who tried to

08:31 create a company. I don't know how I was doing. I've lost track of them. But that was take your meds.

08:37 So essentially people getting a text message when they should take their medication because

08:42 people don't take their medication. It tends to make the whole system right because things, you know,

08:48 suddenly what should be very cheap is super expensive because you then have to go in there

08:53 and make, you know, real.

08:54 Yeah. Do some kind of intervention. Yeah. So like schizophrenic stuff or medication or

09:01 depression medication. I feel like people take that stuff and then they're like, oh, I feel better now.

09:06 I'm better. I don't need my meds. Right. But maybe, you know, maybe it's because you're taking the

09:10 medication. As soon as you stop, you're like, oh, my gosh, it's all back to beginning.

09:14 It's often for like geriatric, well, geriatric, like old people who, you know, they're required

09:20 to take medication once every three hours. And it's so easy to forget. And as soon as you don't,

09:25 well, suddenly you haven't taken, I don't know, that medication and you're at risk of a heart attack.

09:31 Yeah, of course. Yeah. I guess if the frequency is a couple of hours, it's tricky. Yeah.

09:35 Yeah. Cool. So we've, you've got these NHS hack days, which sounds like a really good idea. I don't

09:41 know if we have that in the US. Maybe we do, but I've never heard of it. You know, I probably one of

09:47 these cool benefits of government healthcare. Interesting. So, so, you know, it's not all just

09:53 for profit. Like who wants to go help? I don't know, like your local HMO make more money or that

09:59 local health insurance company. Right. I'm not going to go do a hack day for any insurance company

10:04 whatsoever. Right. Unless it's just weird. Anyway, this is cool. So you guys have these

10:09 and you went there and, Opal was born out of it, huh? So yeah, Opal was born out of,

10:15 out of that by, by my, my wife, a colleague, like a couple of years before,

10:20 before I joined open healthcare. And then I was contracting. I was, I went to a couple of these

10:27 hack days and been to a couple of years in a row. And then I went to work for, went to an interview at

10:33 quite a sort of prestigious startup. it was quite as intense a process. Like, I don't know,

10:37 six hours of continuous interviews. And then in the last one, the founder of the company said,

10:42 where do you see yourself in 10 years? And I said, writing software for open source software for the

10:48 NHS. So then I turned down their offer and went to work for open healthcare. Cause I realized by going

10:55 through that process, that was actually what I wanted to do. So why not do it now?

10:59 It's pretty grand.

11:00 That's grand. So I think this is a good test. People should give themselves periodically,

11:06 right? The five year, the 10 year test, you know, in this case, it was where do you see yourself? Like

11:11 in the broad sense, but it could also be, you know, look at the people that are five or 10 years more

11:16 senior than you and your company. What do they do? Do you, do you want to do that? If you don't want to

11:21 be doing that, the time to like start finding a different path is now, right? Because that's,

11:26 that could be right where you're headed. I think that's a great motivation.

11:29 When you go into an interview and you see the people who are interviewing you,

11:33 the first thing you should think is, do I want to be these people? Do these people

11:37 seem happy with their lives and their life choices?

11:39 Yeah, that's really great. I totally agree with that. All right. So that's a pretty big goal. And

11:46 I think it's a very cool thing, but I also see it as challenging just as a career, right?

11:53 I want to go write open source software for NHS. How did you tie that back to the career in your

11:59 mind? Like, how are you going to pay the bills while doing that?

12:01 The business model is essentially quite clearly there. Like if you can create a good service,

12:07 medical software is big business. I don't see the open source as in any way a blocker to this.

12:14 I want to, like the NHS are paying us money. We're not doing this out of the goodness of our hearts.

12:20 the open source means that the quality of the software can be more rigorously tested,

12:26 that there's not so much of a contractual lock-in because one of the problems that you get, I was

12:34 talking to a hospital that will remain nameless and a lot of the medical data is with one system and

12:41 they want to shift to another system. And they said, how much to move it across? And they were told 10

12:46 million quid, 10 million pounds. Yeah. The hospital was like, we can't afford that.

12:51 So we just dumped the data and the sort of computer proprietor said, well, it'll be 10 million pounds to

12:58 delete the data. That's rough.

13:00 Yeah. Right. There's a bad system of contractual lock-ins. So by being open source,

13:06 we can provide great quality software, we can charge for great quality software, but if they

13:11 don't like us, they're not locked into us because anyone can look at the source code that we've

13:16 written and sort of take it over if necessary. Hopefully that's never happened so far and we'd

13:22 like to think it won't.

13:23 I think so. And you know, it's based on super popular stuff, right? Things that most people

13:28 who know Python could walk in and get up to speed on in a week or so, at least. And you know, Python

13:36 being the most popular language or at least contending not for that, that's a pretty solid

13:42 statement that people can just pick this up. So tell us what Opal is.

13:45 Opal is a web framework for building healthcare applications that store medical data about people.

13:51 Cool. So we have Django, we have Flask, we have Pyramid, we have Starlet, we have these other

13:57 frameworks. Why do we need Opal? What does it do in addition to just, you know, Django, you know,

14:05 create app or cookie cutter, Pyramid or Flask?

14:08 Yeah. So that's a super interesting question because in the levels, Opal is kind of, it's a domain

14:14 specific framework. So you have Django, Django is do anything on the web. So Django,

14:21 Django arrives on the scene. And I don't know if you're too young to remember this. But Django

14:26 arrives on the scene and suddenly you were able to say, well, I want to create a polls app. And

14:30 you know, I was able to do it in a lunch break. And I was able to do a week's work in a, in a

14:36 lunch break. And that's, that's amazing. And it revolutionized things, right? And then from

14:43 there, you don't have that too many sort of domain specific, I guess, blogging software is the,

14:48 is the most domain specific where you have software, which is a framework, which are,

14:54 I'm just going to build a blog. I'm going to do one thing. So you've taken, right?

14:57 Got something like Django and then you're super specialized on top of that.

15:01 Right. Like WordPress or ghost or something. I hadn't even really considered blogging,

15:05 blog frameworks, platforms as, you know, domain specific. But yeah, you're right. They,

15:11 they definitely are. And it makes a ton of sense, right? I'm just, you know,

15:14 thinking about what you get. So this is built on Django, Opal is. So it's not like

15:20 another framework in the sense of that it's trying to compete with those, but it's,

15:24 let's take Django and let's, let's take all the boilerplate junk that you have to write

15:30 to build something in the clinical domain, make that happen. And now get started, right?

15:37 What we can do is we can say, we know you're going to have patients. We know you're going to have

15:42 episodes of care. We know, yeah, we know you're probably going to have these bunch of clinical models.

15:50 And we can therefore make loads of assumptions, which means that we can scaffold things out quite

15:57 quickly. So we know that you're going to have a patient list page, patient detail pages of different

16:03 types of episodes of care. We know that you're going to want forms for, forms for, for example,

16:09 conditions for diagnoses that are going to hang off an episode of care. So we can say,

16:15 we can scaffold you up forms for the condition. We can scaffold you display templates. We can give

16:22 you a rest endpoint for an episode, which will give you all of the things which are hanging off that.

16:27 So you've got that for your treatment, your diagnosis, maybe your treatments, maybe your blood cultures,

16:33 maybe your lab tests. We can just do that super quickly because we know that's what the modeling

16:39 structure that you're going to want.

16:41 That's great. So you don't have to think about all those things. You just start using them. And these

16:46 are all classes. These are Django entities, right? In the Django ORM. But you could create ones that are

16:53 more specialized. You could create other ones that go in there, right? So it's, it sounds like a lot of

16:58 the core data models already put together and, and things like that, right?

17:01 We have sort of a specialized model called a sub record that we know that you, you can use, which we

17:10 know will have a relationship to a patient or relationship to an episode. And because we know

17:15 that model structure, we can automatically wire that into forms and stuff, as I said, but also into

17:22 search, into data extract. We don't, Opal doesn't enforce like a model structure. It offers this. And this,

17:30 a lot of what these kinds of frameworks do is they, and what Opal tries to do is get you 80% of

17:37 the way there. You know, once you're there, once you've done, once you've started prototyping, you

17:41 might be like, Oh, I want to just use more sort of vanilla Django stuff. Opal doesn't stop any of that.

17:46 It just gives you a helping hand in what we think the right direction.

17:51 Yeah. I just that quick, quick boost. And even though this came out of those NHS hack

17:58 weeks, I suspect somebody could take this as the starting point for another one of those and really

18:03 bust out something pretty amazing, pretty quickly. It sounds like, cause it just puts all this stuff

18:07 together for you. So one of the things that these episodes, sub records, which are the Django models

18:14 do that. I don't know. It's kind of interesting to me is it creates a relationship between the

18:20 entities already, right? Which is pretty cool. But it also creates a JSON API for creating and updating and

18:26 searching them. It creates, make sure that the angular layer, we'll talk about angular in a little

18:32 bit, the angular front end layer knows about it. bunch of stuff like that, right? That's pretty cool.

18:39 Any modern develop web developer knows that you're probably going to want to have Django rest framework

18:43 endpoints for a Django app. So exactly right at Spox, it gives you those. It does some schema

18:49 description so that if you're looking for other developers to use to like programmatically read

18:56 your endpoints, you can give them that description and they'll have an understanding of

19:00 what data is going to be available. so yeah, I think, I think it's all right.

19:04 That's pretty sweet. So it comes with batteries included, but these batteries are more like

19:08 stethoscopes and tongue depressors. That's excellent. I'm stealing that. That's fine.

19:13 Feel free to steal it. It's all good. I'm sure there's better, better, analogies in the health space, but that's a good start.

19:19 This portion of Talk Python to me is brought to you by Linode. Are you looking for hosting that's fast,

19:27 simple, and incredibly affordable? Well, look past that bookstore and check out Linode at

19:31 talkpython.fm/linode. That's L I N O D E plans start at just $5 a month for a dedicated server with a gig

19:39 of RAM. They have 10 data centers across the globe. So no matter where you are or where your users are,

19:44 there's a data center for you. Whether you want to run a Python web app, host a private

19:48 Git server, or just a file server, you'll get native SSDs on all the machines, a newly upgraded 200 gigabit

19:55 network, 24 seven friendly support, even on holidays and a seven day money back guarantee.

20:00 Need a little help with your infrastructure. They even offer professional services to help you with

20:05 architecture, migrations, and more. Do you want a dedicated server for free for the next four months?

20:10 Just visit talkpython.fm/linode. When I think of this project, it sounds cool. Like if I, as a primarily

20:20 web developer, when I'm writing code, when I'm thinking of like, how would I use this? Obviously,

20:25 I would go out and I would build some cool healthcare app if that was the domain I wanted to spend some

20:31 time on. But when you think about this project, who do you have in mind? Like, have you made this for

20:37 people like me? Have you made this for the IT folks inside the company? Have you made it for doctors?

20:43 Like, who do you have in mind using or who's ended up using Opal?

20:47 That's a nice question. So in reality, we use this ourselves. Obviously, we exist in a number of

20:55 major hospitals for sort of a whole bunch of teams. And I think that when building a framework, you know,

21:03 you need to, what is it? Eat your dog food? Yeah, we are the dog. And this is designed for other

21:08 dogs like us. So other developers being brought into hospitals or who already work in hospitals

21:15 to develop healthcare applications. That being said, doctors, as it turns out, incredibly smart,

21:23 technically minded individuals. And a number of them have picked up an experiment with Opal for their own

21:30 sort of side project and for projects for their hospitals. I'm not sure a doctor has ever released an

21:37 local application into a hospital. And maybe you'd want to give it a code review first.

21:41 It's going to need some refactoring. I'm not so sure about this. But you know, I think that's really

21:47 cool. And I do think that's one of the things that Python makes more possible for folks who are really

21:53 smart and technically minded like doctors to just say, you know, I have this problem. And it's got to be

21:57 frustrating to go to work, at least in the US, it's you never log into your computer, you log into like some

22:03 Citrix, remote desktop thing. And you know, it just there's probably all these frustrating like layers.

22:09 And they're just like, you know what, if I could just have this thing, it seems so easy.

22:14 And you know, they probably just, you know, start busting something out, right. And then they can bring

22:19 that in and be that proof that you talked about, like from the NHS hack days sort of example.

22:24 Exactly. They can just say, look, it's not that hard.

22:26 I have a funny story. I'll tell you real quick about a doctor and programming. I was at the doctor.

22:32 I don't remember why it was nothing major, just some random thing with the doctor.

22:36 Maybe 2010, something like that, quite a while ago. And the doctor said, what do you do?

22:44 So I'm a programmer. And I said, what language do you program at the time? I'm like, well,

22:47 programming this language called C#, which I was at the time.

22:50 And he says, pauses for a second. He looks at me. And I thought he was just trying to make small

22:54 talk. Right. So he could like, before he stabbed me with a needle or something, looks over, goes,

22:57 you excited about the new release of Visual Studio? I'm like, excuse me? He's like, yeah,

23:03 this new stuff they're doing is so great. I'm really, I'm like, are you a real doctor? Who are you?

23:07 Like, who gave you that robe? I'm not sure I want that.

23:10 Yeah. Did this make you trust him more or less? What's the, both, both, but it's so interesting because you like at the time, I'm like, oh, sure.

23:20 They're surely they don't care. But the more I interact with doctors, the more I realize,

23:23 you know, yeah, for sure. They, they have these challenges and you can bring in programming

23:27 languages to solve those at some point, like the pressure gets too high. You're just like,

23:31 I'm going to write this website. That's going to solve this problem. I do see it as an extra

23:34 challenge in the healthcare space over, you know, some other, I said, say accounting or something,

23:39 right? And then maybe it kind of is not even the best counter example, but in healthcare,

23:43 you have to be a little more careful with your data and stuff. So you can't just like,

23:47 I just threw it on like a random server on the internet and it's easy now. Like,

23:51 well, maybe that's not going to fly.

23:53 To me, one of the interesting things about the medical space in relation to other space. So

23:58 as I say, I used to just sort of do some investment banking stuff.

24:01 what you have there and what you have in a lot of places, you have things like stocks,

24:04 stocks are essentially manmade inventions, right? And therefore they've already like a man's mind can

24:12 comprehend what they were and, or a person's mind can comprehend what they were and draw the

24:17 limitations around that. And there's, there are legal entity in that to describe. Whereas when you look

24:21 at modeling in a medical sense, it's such a, a broad, we're just ascribing concepts to real world

24:30 conditions. That means that modeling comes far, far fuzzier. Sort of when you're saying sort of like

24:37 obesity, somebody's dying of like drowning, well, nobody dies of drowning. They die of like an oxygen

24:43 deficit kind of thing. Right, right.

24:45 So when you're filling in your medical notes, what do you do? Well, you know, like, which I think

24:50 means and different doctors will put in different things because if you're a blood cancer specialist,

24:57 then your concepts of dying of this, I don't, okay, maybe I don't know that. Maybe I don't know blood

25:03 cancer for certain, but definitely when describing a blood cancer, describing a blood test, if you work

25:09 in microbiology, your description is going to be different from a doctor who was another specialist,

25:14 which I think is super interesting.

25:15 It is. And, you know, I think it really makes the modeling challenging, right? And we already talked

25:21 that there are some of the, the sub model, some episode, sub episode classes, like the Django model

25:26 classes that model these things, but they're coming from a certain perspective, right? Like one of the

25:32 things that you talked about on the, maybe on the tutorial, I can't remember where I saw this, but

25:37 to, you know, a cough, it could be a symptom of a condition or the cough itself could be a

25:43 condition. So if they come and say, Hey, I need you to treat me because I have a cough,

25:47 then that's probably the condition. But if they have a cold, then it's just a symptom, right?

25:54 So how do you record that in your database?

25:56 Which is it a symptom or a condition, right? These are, these are challenging.

26:01 I sat in a room with doctors having full blown arguments at each other about exactly this. And

26:07 it's kind of like, well, if you don't know, how do you expect us to know that?

26:10 Yeah. Well, that's the problem or the challenge of building something for a domain, especially if you're

26:17 not yourself a doctor or you're a specialist in that domain, it makes it harder to model stuff in that

26:23 domain as a programmer. But it's also the value, right?

26:27 That is one of the things that I will try to say, you know, the programmers, I, well, I've been a

26:34 programmer for 12 years now. I've been around the block. A doctor has had, what, at least five years

26:41 a university, probably two years after that, still sort of learning the ropes, you know,

26:46 they're going to be eight, nine years down the line. And so the, what Opal tries to do is trying to

26:52 create through, essentially the, in some levels, the Django sort of modeling, Django models is to kind of

26:59 create a bridge where two very, very complicated domains can kind of meet and discuss in a way that

27:05 they can understand each other. I guess it's that shared experience, right?

27:08 So maybe an interesting way to talk about, to give people a sense of what this is and how it works.

27:15 Maybe we could talk through a getting started story. So you have a tutorial on the website and it says,

27:23 as a doctor, you want to know what's going on with your patients under your care so you can treat them

27:27 effectively and whatnot. So you need some kind of app or something to manage that. Let's build that in,

27:33 in Opal, which is pretty interesting. So do you want to maybe just talk us through,

27:38 like this whole getting started story here? Opal does similar thing to, I guess, Django app and start

27:45 projects, but again, more specific for, for medical applications. So out of the box, we essentially

27:52 give you some core clinical models that we think are pretty good and you might like, and we give you some

27:58 reference data that you might want to change, but it's the kind of thing that you want loaded in this

28:04 table. So we give you a list of conditions that doctors have given us in the past and said,

28:11 these are the kind of conditions we want to record. We give you sort of basic sort of demographic lookup

28:17 lists. So again, you know, like gender, ethnicity, you might want to change them, but out of the box,

28:23 give me something sensible. When you run the create project, you get sensible defaults and it gives you a

28:31 patient list and episode detail page and a way of adding patients because we know from the domain

28:38 that these things that you're going to want. Yeah. And it feels very much like getting started with

28:42 Django itself. So the way you get Opal is you just pip install it. That's cool. All right. You just pip

28:48 install this or put it as a requirement. And then you say, Opal start project, and you give it a name,

28:53 very Django-esque. Go in there and go in that folder and you say, Python manage that py run server,

29:00 right? Like you could just replace Opal with Django. And so far you're on the same path, right?

29:05 I mean, that might just be for a good reason. Exactly. We've taken what Django, we think Django did

29:10 well and hopefully extended that. So yeah, exactly. So it gives you the Django settings, which are probably

29:18 going to be the ones you want. It gives you an S you like, you know, it sets you up with a S you like.

29:22 Right. So basically, if I'm a Django developer, it's super easy for me to drop in and get started with

29:28 Opal. I just have to learn the new batteries that you've added, right? And the conventions that you

29:33 follow. We've given you some sugar. But if you're a Django developer, it really shouldn't take you,

29:38 it shouldn't be too difficult to figure out what we're doing. And I will say, once, you know,

29:43 if you want, if you're a Django developer, you're like, I like what you've done with this,

29:48 but I'd like to do this in vanilla Django. We don't stop you from defining your own views and

29:53 doing what you like. How much of what Opal gives you in terms of this scaffolding business here,

29:59 how much of it is a, at the beginning of my project, one time only, or is there a way to

30:06 periodically add new entities and new views? Right. So maybe I have like, like I have demographics

30:13 and treatments and diagnosis and all that stuff comes out of the box, but then say like, oh,

30:17 I need a surgery and I'm going to add that. Is there a way to run like a command line option to,

30:22 to do all that magic to add it in? Or do I, am I kind of on my own once I started?

30:27 So you add in a carer model, for example, for a patient, for an episode, you add in your Django

30:34 model and then you run managed applied scaffold. What we'll do is we will create you a form template

30:41 and a display template. And then you have to go into your patient detail and which will already have

30:48 a list of similar sort of record panels as we call them. And you can just add in that,

30:54 but with care instead of what that gives you is a display template and a way of adding automatically

31:03 wires you in like a modal form. So you click add one and it would bring you up a modal form.

31:08 And then what we do is we look at a method called underscore is Singleton. We look at a property

31:13 called underscore is Singleton on model. And that tells us if it's a one to one model or a one to many

31:18 models. So obviously like demographics, you're only going to have one, but you're only going to have one

31:23 name, right? Well, it's not be true. You're only going to have one demographics model related to

31:28 a person, whereas you may have multiple treatments. And so that tells the record panel whether to allow,

31:33 let me add many treatments or just let me edit the single demographics model.

31:38 That is awesome because then you could just keep adding these Django models and then just rerun

31:44 scaffold and it does all the stuff for you, right? All the magic.

31:47 Exactly. So it just ellips your model and then creates your form, a whole bunch of point fields

31:52 off the back of that. We are different from vanilla Django. We use a template tag for our form fields

31:59 because under the covers, this is all, there's, there's a whole bunch of angular that's happening.

32:04 So we're not refreshing the page. We're bringing up a model. We're editing it. We're changing it.

32:09 We're saving it. Everything just working with the doctor the other day. And what was really lovely is

32:13 they changed one of the models and then they looked at form. And personally, I really like API design.

32:23 And when somebody like doesn't even need to look at the dots and they're like, oh, I just need to change

32:28 this to this. And you're like, that's grand. Yeah. My work here is done. Yeah. You know,

32:33 you build a good API when they're their first guess, their first intuition is exactly what you'd hope

32:38 they would do. Exactly. Super cool. So one of the things I saw in the tutorial that was pretty

32:42 interesting is you have these relationships like, you know, what problem or symptom did this person

32:48 have, and there's probably a big pre-filled list, like a dropdown select. You can pull down and choose,

32:54 you know, they've got a fever, their foot is broken, whatever their bone is broken.

32:59 But it's, it also allows you to type in free text. So you have this column type field type,

33:05 foreign key or free text. That was really interesting to me is that you guys came up with that,

33:09 right? That's not part of Django. Yeah, that's all our pattern. I've seen like different people in

33:15 different places, all of them having to roll their own sort of customized implementation of

33:20 exactly the same thing. It's such a common thing that I want to put in a sort of a foreign key

33:25 relationship or free text. And what this does is it does exactly that. It's a free text box,

33:32 you can type in whatever you like, but there'll be an auto complete bunch of options. And you can

33:36 select one of those and it'll save it as a relational, as a foreign key method. And one of the things

33:41 that's nice is that they, it also supports symptoms. So say you can have a cough or a sore throat or,

33:50 I don't know, a pain, pain throat. I don't know. Yeah. You kind of get the idea that quite often

33:57 there's two terms for the same thing, symptoms and what the doctors can do or what they can tell us to do

34:04 is say, wheezyness and breathlessness are the same thing. And it will reconcile those so that you have

34:10 a consistent view of what the patient might have if they both fit in.

34:13 Okay. That's a really cool feature. I love it. That's that's, I think that's great. And it seems

34:17 like it shows up really nicely in the UI. So let's talk about, you know, you mentioned Angular and whatnot,

34:23 we've obviously been talking about Django, but let's dig into some of the tech.

34:26 Want to tell us what's involved? What, how you built it?

34:30 We've got Django on the back end. And then at the moment, we've got AngularJS on the front end

34:34 and Bootstrap. A lot of these, as I say, it's, it's framework for people who come to Opal aren't

34:41 necessarily going to have a background with Opal and the technologies are very much well,

34:44 just stack overflow will answer my question. That's super easy for that. So yes, we've got

34:49 AngularJS and then there's a bunch of magic that wires things together for you. So as I say, there's

34:56 a schema that you can get out for particular for each of your models, which describes the model and

35:03 AngularJS consumes that and it uses that when constructing forms.

35:07 Does it talk back over Django rest framework?

35:09 Yeah. And then Angular, because we have the concept of form templates and display templates,

35:15 and they're all scaffolded out for you. We can make reasonable assumptions and Angular can,

35:20 ideally, you don't even have to like touch Angular that much, but you can. So we use a model for the

35:28 front end, which I haven't really used that much before. It's one that my colleague sort of did,

35:35 which is actually what I want is I want all of a patient. So whereas in previous projects I've worked

35:41 on, I'd be like, well, the patient, they want treatments, they want diagnoses, do separate

35:48 API endpoints for that. When you go for a patient or an episode, it's like using a DRF. I think they

35:54 like using a nested serializer. We don't use a nested serializer. So essentially, you get an episode,

36:00 then it serializes everything under it. So when you're doing front end code, you know what is

36:06 available without having to worry about, well, this loaded, this didn't load, which is really nice.

36:11 It's a lovely fact.

36:12 I see. So it like traverses the foreign key relationships and it creates a hierarchical

36:16 JSON response type of thing.

36:18 Exactly. Exactly.

36:18 Okay. And so we serialize everything for that episode in one go because experience is showing

36:24 that's what doctors want. And that makes it a lot easier in the front end to know that the model is

36:29 going to be similar to the back end.

36:30 It's worth just saying, you know what, we'll pay the extra price and we'll ship the episode

36:34 along with the patient and it's going to be fine because you don't have two ways to do it.

36:39 You can pre-fetch related all of the things and the number of database queries you're doing is

36:44 pretty efficient.

36:45 This portion of Talk Python to me is brought to you by the University of San Francisco.

36:51 Learn how to use Python to analyze the digital economy in the new master's in applied economics

36:57 at the University of San Francisco. Located at the epicenter of digital disruption,

37:01 USF is the ideal launching pad for the next phase of your career.

37:05 Their new STEM designated economics program doesn't just provide technical training in high demand

37:10 skills like machine learning, causal inference, experimental design, and econometrics.

37:15 It takes the next step, teaching you how to apply these techniques to understand the economics of

37:20 platforms, auctions, pricing, and competitive business strategy in the world of big data.

37:25 The program is open to beginner and to advanced coders looking to apply their skills in a new area.

37:31 Applications are now open for the fall 2020 classes.

37:35 To learn more and get an application fee waiver, go to talkpython.fm/usf.

37:41 That's talkpython.fm/usf.

37:44 Speaking of databases, it sounds like you're using Postgres.

37:48 Yeah, we use Postgres.

37:49 When you do the sort of tutorial app, vanilla, it gives you FDLite because if you're a hack day,

37:55 you don't necessarily want to teach people how to install Postgres onto their computer.

38:00 Yeah, SQLite's beautiful like that, right? You can just say you have basically a full database.

38:05 But you don't have to do anything. Can you make a file? All right, let's go with that. You know what I mean?

38:09 I love it.

38:09 Yeah, I do too.

38:11 I think it should be used more. A lot of the times when people are exchanging like CSBs in like big

38:16 app institutions, I'm kind of like, oh, why don't you just stick it in an FDLite database and ship an FDLite database?

38:21 Yeah, it's super great.

38:23 For sure.

38:24 So it sounds like it's a pretty good project in terms of how it's all put together, some of the technologies.

38:28 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, I don't know, Microwiskey or G-Unicorn or whatever it is you're going to set up.

38:38 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?

38:45 So at the moment, we don't have that pre-canned script. I mean, we do for our own deployments in-house.

38:50 Sure.

38:51 Obviously all scripted up. But the reason why we haven't is because hospitals vary quite a lot in the sort of VPN technologies.

39:01 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.

39:11 And depending on the VPN, sometimes you can only log in on the VPN via a Windows machine doing this, the other, whereas others you can wire together with Ansible and do your deploy scripts with Ansible.

39:23 So sometimes you've got the fabric scripts, sometimes Ansible scripts. So we don't have that vanilla out of the box deployment scripts, which would be quite nice.

39:31 What I've been hearing a lot lately for setups like this is what we're going to do is use Docker.

39:38 I mean, 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.

39:46 Well, now you kind of sort of have to know this, but you also have to know Docker.

39:50 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.

39:57 So I don't know. It's tricky.

39:59 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.

40:06 But I think that the version of Ubuntu that they were running it on was not going to casually allow us to run Docker on it.

40:14 Right.

40:14 But maybe, maybe that's exactly.

40:16 Yeah. Speaking more broadly, I mean, because this is healthcare, it has special constraints on where it can live.

40:21 Right. But if you were building this kind of thing for something that wasn't so regulated, it might be cool to build some sort of Kubernetes thing and you could just plug it into one of these managed Kubernetes clusters.

40:32 Yeah, that would be cool.

40:33 Right. Like that, that would be cool. That seems like a pretty easy way to say, look, you don't have to actually worry about running it.

40:39 You just get this service and you just jam it in there and you can scale it with these knobs. You're good.

40:44 Right. But when it's down to you running the clusters, we talk to clinicians a lot because we deal with a lot of sort of like new services.

40:51 And as I say, we're not the greatest judges of when we don't have a clinician's experience.

40:55 So we do a lot of like just roll up a hierarchy box with this branch, roll up a hierarchy as well through this branch, send them both over to the doctors and say, try these, play both of these.

41:05 But we haven't, we haven't branched out to Kubernetes, which is what the cool kids are using.

41:09 For now, anyway, you never know. You chose a JavaScript front end framework. And, you know, what is the lifetime half-life maybe of one of those things?

41:19 I mean, Angular has been going for a while, but we had Angular 1 and Angular 2. I feel like those are almost different things with different programming languages.

41:26 And that's a big decision, but you got to pick one, right? Like that's how it goes.

41:31 Well, I mean, we are, we are, we're now rolling, we're, we're now working on Opal 1. So previously been on zero point star releases.

41:40 And as such, we are aiming to move off the, the AngularJS because it's end of life.

41:47 And we are currently doing, we're essentially practicing experimenting with Vue, React, just, you know, to, it's just progressively building off sort of,

41:56 the Angular forms with some, with some extra sugar.

41:58 That's cool.

41:59 It's the whole experimenting with those. I've heard you like Vue. I'm a big fan of Vue.

42:04 Yeah.

42:05 So I have a version of Opal that just runs Vue, but it's making sure that what we've got is easy and simple for the developer.

42:13 And, you know, I can't make it, I, just because I like Vue, do well, have I experimented enough with React? It's tricky.

42:19 And I mean, I think more of the problem is shipping it.

42:23 So, you know, now what we've got at the moment and what's quite nice is static assets.

42:29 You declare your static assets, the file names into, into either plugins or into an application and Django compressor just does it all for you.

42:39 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, the assumed approach.

42:50 And then you've got the Django webpack loader, but the Django webpack loader, based on what I've currently seen, I don't tend to be an expert at this, is doesn't necessarily load from packages.

43:03 So, for example, you pit installed Opal, or you don't, if you want the static files, which are coming through with that, the Django webpack loader won't actually pick those up.

43:15 So then you have to say, well, so do we then store the static files on NPM?

43:20 And so we then put, you pip install Opal and through some magic, we'll bring in the static files from NPM.

43:32 But then obviously then you're supporting two different packages and you need to concentrate that.

43:36 It's a super interesting problem.

43:39 And I'm quite enjoying playing with it.

43:41 It sounds challenging.

43:42 It sounds a little bit, I don't know, in the UK, if you know the game Whack-A-Mole.

43:45 It's like this arcade game where you be, you know, it reminds me of that, right?

43:49 Like, I'm going to, bam, I solved this problem.

43:52 Oh, it pops up over there.

43:53 Whack, I solved that problem.

43:54 Now it's back here.

43:55 Like, you know, you squeeze on one side and it pops out the other.

43:58 And, you know, it's challenging, right?

44:00 It seems challenging.

44:01 But yeah, to be honest, I don't know.

44:04 Different programmers find different problems interesting.

44:07 I do find this interesting.

44:08 I do sometimes think it could all be simpler.

44:11 But that is probably my own ignorance.

44:14 Yeah, I feel like JavaScript went from being like, oh, it's the most easy, simple little thing to, oh, this is, there's a lot of stuff going on here.

44:23 I'm not really sure why, how this is happening here.

44:26 Yeah, well, it's like, oh, I'll just run NPM install.

44:29 Suddenly my computer gets hot.

44:31 Yeah.

44:31 Exactly.

44:32 Yeah, interesting.

44:33 Okay, well, I'm a big fan of you.

44:35 I definitely think it's special.

44:37 I like that as well.

44:39 Now, let's see.

44:40 Let me ask you a couple other questions.

44:42 We're getting a little towards the end of the show here.

44:45 One thing I guess it's interesting to talk about, just real briefly, is Opal is open source.

44:52 Go to GitHub.

44:53 I can get it, do whatever I want, right?

44:55 I can pip install it.

44:56 Yeah.

44:56 But you work at Open Healthcare UK, which is that like a boutique app shop for the healthcare industry?

45:04 Or how would you describe it?

45:06 The way the healthcare in hospitals commonly works is that what you have is the productization,

45:15 if that's a word, is massive, large-scale EPI are pumped in and it aims to be a data repository

45:22 for all teams in the hospital doing all things.

45:26 It's like the SAP of hospitals.

45:28 It's going to do everything.

45:30 Just install this and it'll be fine, right?

45:32 Exactly.

45:32 Okay.

45:33 And what you find is that it does a pretty good job, but for, it does 80%, but for the

45:42 extra 20%, what you've got is Word docs flying around, Excel spreadsheet, the occasional access

45:49 database, or good old-fashioned pen and paper.

45:52 Yeah.

45:52 And sometimes this 20% is pretty darn useful.

45:55 So we have, what we do is we fix up that 20%.

46:00 So you're a, we do microbiology, for example, we do some of that sort of stuff, which is

46:06 sort of teams which specialize in blood cultures.

46:10 We go in there and we're like, and we talk to the doctors and we get their requirements and

46:17 we tailor stuff as sort of kind of specific to them.

46:21 And yeah, we cover that 20%.

46:23 That's cool.

46:23 So basically the role of Opal is this thing that you guys have built, it'll let you quickly,

46:29 it'll, you know, supercharge your creation of these apps to cover that 20% that you talk

46:35 about, but it's also awesome that it's open source and other people can take it and run

46:39 with it.

46:39 Is that right?

46:39 That's right.

46:40 That's exactly right.

46:41 This is not that much of a specific problem.

46:44 This is a general problem.

46:45 I think worldwide, I don't think, I don't think in the States they've kind of got a magical

46:49 EPR that fixes all problems either, right?

46:51 No, no, no, no, of course not.

46:53 Yeah.

46:53 Cool.

46:53 So it seems like a solid blend of here's this open source thing that people can work on and

46:59 they can use, but is also there to support your business.

47:02 And, you know, one of the things I feel like just doesn't seem to work really well is the

47:08 PayPal donate button on open source projects, right?

47:12 It's just my experience of hearing folks who seem like they have pretty popular projects

47:16 is like, you know, it's definitely not a career at that point.

47:20 There's got to be something else.

47:21 And this seems like a really nice synergy around that.

47:24 So that's cool.

47:24 Our motivation for open source isn't.

47:27 It's open source because healthcare applications deserve the rigor that being open source allows

47:35 you to have and the inspection.

47:37 Open source is kind of like a function for you should buy our software because it's open source

47:44 and therefore hopefully you can trust it more.

47:47 And yeah, that's the sales feel, I guess.

47:50 It's the antidote to that 10 million quid problem.

47:54 10 million to convert and 10 million to delete.

47:58 Which one do you prefer?

47:59 Exactly.

48:01 Well, I guess on that, are you looking for contributors to this project?

48:05 You know, are there restrictions that people want to take it and run with it and do something else?

48:08 I'll sort of, what we would like is, as I say, we're moving front-end framework.

48:14 I don't think, I think everyone has, I think every developer right now probably has experience

48:19 between moving between different jobs for front-end framework.

48:21 We'd love some opinions on that.

48:23 We'd love anyone to come and have a look.

48:26 Come and have a look at the GitHub repo, offer suggestions, any breaks in docs, any breaks in

48:31 anything really.

48:32 That would be super interesting.

48:33 Also, you know, we've come at this from having years of experience with building healthcare

48:38 applications in the UK.

48:40 Well, does that necessarily create an international, something that's internationally applicable?

48:45 Sure.

48:46 At the moment, we have NHS number as a field on a model.

48:50 That will not be happening soon.

48:52 We are going to move off that.

48:54 But that kind of thing, you know, this should be a global solution to a global problem, not

49:01 a UK solution.

49:02 Congratulations on this project, Fred.

49:04 It looks really useful for folks out there.

49:07 Thank you very much.

49:08 It's been quite short to you.

49:09 It's quite a little grand.

49:10 Yeah.

49:10 Now, before you get out of here, though, I've got the two final questions I've got to ask

49:15 you.

49:15 So if you're going to work on Opal and write some code over there, what editor do you use?

49:20 I use the Vim plugin on VS Code, which is interesting.

49:26 I occasionally go back into pure Vim.

49:29 Before VS Code, I used Sublime.

49:33 I used IntelliJ when I was a Java programmer or using the Vim plugin.

49:38 Vim plugin.

49:38 And so I think I feel like I've spent my life doing this sort of weird hybrid of helpful

49:45 Vim versus a more integrated environment.

49:48 A constant pool.

49:49 Yeah.

49:50 But VS Code sounds like a good one these days.

49:52 It's got a lot of momentum for sure.

49:54 And then notable PyPI baggage?

49:56 I really like cache properties in Django, which are, if you've never used them, essentially

50:01 it's an annotation that says, here's a method.

50:05 Store the results of this method on the object.

50:09 And then whenever I call this method, first time I call it, calculate it and return the

50:15 answer.

50:15 Subsequently, store the results of the method.

50:17 I just think it's a beautiful pattern.

50:20 It's been something that's been discussed as part of core Python for some time.

50:26 Danny Greenfield, I think.

50:28 Hi, Danny.

50:29 He has a package on PyPy that does this because it's such a common function.

50:34 And then in Python 3.8, just a few weeks ago, we now have functools cache property.

50:42 So it's been moved into core.

50:44 So I was hoping to have functools.cache property as my notable package, which is potentially

50:49 cheating because part of the core library.

50:51 But it's super useful.

50:52 It's new enough, right?

50:53 It just got shipped.

50:54 I think that's cool.

50:55 I think that's one of the really easy ways to speed up things.

50:58 The only challenge with that is you have to be careful on what cache invalidation means,

51:03 right?

51:04 That can be challenging to deal whenever you're doing caching.

51:06 And if you look at the pet, there's a long discussion about it.

51:09 I can imagine.

51:10 But, you know, it can just dramatically, it can just completely change the way the performance

51:15 looks, right?

51:15 So it's so easy to do those types of things.

51:18 Pretty cool.

51:19 Good one.

51:19 All right.

51:20 Final call to action.

51:21 People want to get started with Opal.

51:22 What do they do?

51:23 Pick and install it.

51:24 Take a look at the docs.

51:25 We've kind of covered them a little bit today.

51:27 I think they're pretty good.

51:29 So pick and install it.

51:30 Go through the tutorial and let us know what you think.

51:33 The code is all at openhealthcare.com on GitHub.

51:37 GitHub.com.

51:40 So, yeah, you can go and just browse the code as well.

51:43 Sounds good.

51:43 Thanks for being on the show.

51:44 It was great to talk with you.

51:45 Great, Michael.

51:45 Thanks very much.

51:46 Yeah, bye.

51:47 This has been another episode of Talk Python to Me.

51:50 Our guest on this episode was Fred Kingham, and it's been brought to you by Linode and the

51:54 University of San Francisco.

51:56 Linode is your go-to hosting for whatever you're building with Python.

52:00 Get four months free at talkpython.fm/linode.

52:04 That's L-I-N-O-D-E.

52:06 Learn how to use Python to analyze the digital economy in the Masters of Applied Economics at

52:12 the University of San Francisco.

52:13 Just go to talkpython.fm/USF to find out more.

52:18 Want to level up your Python?

52:20 If you're just getting started, try my Python Jumpstart by Building 10 Apps course.

52:25 Or if you're looking for something more advanced, check out our new async course that digs into

52:30 all the different types of async programming you can do in Python.

52:33 And of course, if you're interested in more than one of these, be sure to check out our

52:37 Everything Bundle.

52:38 It's like a subscription that never expires.

52:40 Be sure to subscribe to the show.

52:42 Open your favorite podcatcher and search for Python.

52:44 We should be right at the top.

52:45 You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the

52:51 direct RSS feed at /rss on talkpython.fm.

52:54 This is your host, Michael Kennedy.

52:56 Thanks so much for listening.

52:58 I really appreciate it.

52:59 Now get out there and write some Python code.

53:01 Bye.

53:02 Bye.

53:03 Bye.

53:03 Bye.

53:03 Bye.

53:04 Thank you.

Back to show page
Talk Python's Mastodon Michael Kennedy's Mastodon