Skip to content

Commit 6a683e9

Browse files
authored
Merge pull request #4 from Dokotela/demo/6_sandbox
Can also create new patients on Hapi
2 parents bd792a7 + 0d55623 commit 6a683e9

File tree

6 files changed

+172
-32
lines changed

6 files changed

+172
-32
lines changed

lib/screens/fhir/create.patient.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// class FhirView extends StatelessWidget {
2+
// @override
3+
// Widget build(BuildContext context) {
4+
// return Center(
5+
// child: SharedActionButton(
6+
// title: 'Get FHIR data',
7+
// onPressed: () async {
8+
// List<Quantity> data = await FhirService().getResponse();
9+
// Get.defaultDialog(
10+
// content: Container(
11+
// height: 500,
12+
// width: 300,
13+
// child: ListView(
14+
// shrinkWrap: true,
15+
// children: <Widget>[
16+
// ...data.map((f) {
17+
// return Row(
18+
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
19+
// children: <Widget>[
20+
// Text('${f.value}'),
21+
// Text('${f.unit}'),
22+
// ],
23+
// );
24+
// })
25+
// ],
26+
// ),
27+
// ));
28+
// print(data);
29+
// },
30+
// ),
31+
// );
32+
// }
33+
// }

lib/screens/fhir/fhir.dart

Lines changed: 84 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,94 @@ import 'package:flutter/material.dart';
33
import 'package:get/get.dart';
44
import 'package:symptom_tracker/services/services.dart';
55
import 'package:symptom_tracker/shared/shared.dart';
6+
import 'package:url_launcher/url_launcher.dart';
67

78
class FhirView extends StatelessWidget {
9+
final lastName = TextEditingController(text: '');
10+
final firstName = TextEditingController(text: '');
11+
12+
@override
13+
void dispose() {
14+
lastName.dispose();
15+
firstName.dispose();
16+
}
17+
818
@override
919
Widget build(BuildContext context) {
10-
return Center(
11-
child: SharedActionButton(
12-
title: 'Get FHIR data',
13-
onPressed: () async {
14-
List<Quantity> data = await FhirService().getResponse();
15-
Get.defaultDialog(
16-
content: Container(
17-
height: 500,
18-
width: 300,
19-
child: ListView(
20-
shrinkWrap: true,
21-
children: <Widget>[
22-
...data.map((f) {
23-
return Row(
24-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
25-
children: <Widget>[
26-
Text('${f.value}'),
27-
Text('${f.unit}'),
28-
],
29-
);
30-
})
31-
],
32-
),
33-
));
34-
print(data);
35-
},
36-
),
20+
return Column(
21+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
22+
children: [
23+
Row(
24+
children: <Widget>[
25+
_nameContainer(lastName, 'Last name'),
26+
_nameContainer(firstName, 'First name'),
27+
],
28+
),
29+
_linkContainer(firstName, lastName),
30+
_patient(firstName, lastName),
31+
_fhir,
32+
],
3733
);
3834
}
3935
}
36+
37+
Container _linkContainer(
38+
TextEditingController first, TextEditingController last) =>
39+
Container(
40+
child: InkWell(
41+
child: Text(
42+
'Click to see new patient',
43+
style: TextStyle(
44+
color: Colors.purple,
45+
fontSize: 18,
46+
decoration: TextDecoration.underline,
47+
),
48+
),
49+
onTap: () async => await launch('http://hapi.fhir.org/baseR4/'
50+
'Patient?given=${first.text}&family=${last.text}&_pretty=true'),
51+
),
52+
);
53+
54+
Container _nameContainer(TextEditingController name, String text) => Container(
55+
width: 200,
56+
child: TextField(
57+
controller: name,
58+
decoration: InputDecoration(hintText: text),
59+
),
60+
);
61+
62+
SharedActionButton _patient(
63+
TextEditingController first, TextEditingController last) =>
64+
SharedActionButton(
65+
title: 'Create Patient',
66+
onPressed: () async {
67+
await FhirService().createPatient(first.text, last.text);
68+
},
69+
);
70+
71+
SharedActionButton _fhir = SharedActionButton(
72+
title: 'Get FHIR data',
73+
onPressed: () async {
74+
List<Quantity> data = await FhirService().getResponse();
75+
Get.defaultDialog(
76+
content: Container(
77+
height: 500,
78+
width: 300,
79+
child: ListView(
80+
shrinkWrap: true,
81+
children: <Widget>[
82+
...data.map((f) {
83+
return Row(
84+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
85+
children: <Widget>[
86+
Text('${f.value}'),
87+
Text('${f.unit}'),
88+
],
89+
);
90+
})
91+
],
92+
),
93+
));
94+
print(data);
95+
},
96+
);

lib/screens/fhir/fhir.screen.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ class FhirScreen extends StatelessWidget {
1818
appBar: SharedAppBar(
1919
title: 'FHIR',
2020
actions: [
21-
IconButton(icon: Icon(Icons.close), onPressed: () => Get.offAll(HomeScreen())),
21+
IconButton(
22+
icon: Icon(Icons.close),
23+
onPressed: () => Get.offAll(HomeScreen())),
2224
],
2325
),
2426
body: _buildBody(),

lib/services/fhir.service.dart

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ class FhirService {
1010
final String identifier = 'test-client';
1111
final String secret = 'verysecret';
1212
final String grantType = 'client_credentials';
13-
var response1 = await http
14-
.post('$server/auth/token?client_id=$identifier&grant_type=$grantType&client_secret=$secret', headers: headers);
13+
var response1 = await http.post(
14+
'$server/auth/token?client_id=$identifier&grant_type=$grantType&client_secret=$secret',
15+
headers: headers);
1516
if (response1.statusCode == 200) {
1617
var parsedbody = json.decode(response1.body);
1718

1819
print('parsedbody: $parsedbody');
1920
var token = parsedbody['token_type'] + ' ' + parsedbody['access_token'];
2021
headers.putIfAbsent('Authorization', () => token);
2122
}
22-
var response2 = await http.get('$server/fhir/Observation?patient=test123&category=vital-signs', headers: headers);
23+
var response2 = await http.get(
24+
'$server/fhir/Observation?patient=test123&category=vital-signs',
25+
headers: headers);
2326
Bundle vitalsBundle = Bundle.fromJson(json.decode(response2.body));
2427
print('vitalsBundle: $vitalsBundle');
2528

@@ -66,4 +69,20 @@ class FhirService {
6669
}
6770
return data;
6871
}
72+
73+
Future<void> createPatient(String first, String last) async {
74+
var newPatient = Patient(
75+
name: [
76+
HumanName(
77+
given: [first],
78+
family: last,
79+
),
80+
],
81+
);
82+
83+
final String server = 'http://hapi.fhir.org/baseR4/';
84+
final Map<String, String> headers = {'Content-type': 'application/json'};
85+
await http.post('$server/Patient?_format=json&_pretty=true',
86+
headers: headers, body: jsonEncode(newPatient.toJson()));
87+
}
6988
}

pubspec.lock

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,34 @@ packages:
562562
url: "https://pub.dartlang.org"
563563
source: hosted
564564
version: "1.1.6"
565+
url_launcher:
566+
dependency: "direct main"
567+
description:
568+
name: url_launcher
569+
url: "https://pub.dartlang.org"
570+
source: hosted
571+
version: "5.4.7"
572+
url_launcher_macos:
573+
dependency: transitive
574+
description:
575+
name: url_launcher_macos
576+
url: "https://pub.dartlang.org"
577+
source: hosted
578+
version: "0.0.1+5"
579+
url_launcher_platform_interface:
580+
dependency: transitive
581+
description:
582+
name: url_launcher_platform_interface
583+
url: "https://pub.dartlang.org"
584+
source: hosted
585+
version: "1.0.7"
586+
url_launcher_web:
587+
dependency: transitive
588+
description:
589+
name: url_launcher_web
590+
url: "https://pub.dartlang.org"
591+
source: hosted
592+
version: "0.1.1+5"
565593
vector_math:
566594
dependency: transitive
567595
description:
@@ -599,4 +627,4 @@ packages:
599627
version: "2.2.1"
600628
sdks:
601629
dart: ">=2.7.0 <3.0.0"
602-
flutter: ">=1.12.13+hotfix.4 <2.0.0"
630+
flutter: ">=1.12.13+hotfix.5 <2.0.0"

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies:
3939
fhir_r4:
4040
git:
4141
url: git://github.com/Dokotela/fhir_r4.git
42+
url_launcher: ^5.4.7
4243

4344
# The following adds the Cupertino Icons font to your application.
4445
# Use with the CupertinoIcons class for iOS style icons.

0 commit comments

Comments
 (0)