Skip to content

Commit ff50acc

Browse files
authored
Merge pull request FireJuun#5 from FireJuun/demo/6_sandbox
Demo/6 sandbox
2 parents 4ad71d8 + 6843fd2 commit ff50acc

File tree

11 files changed

+210
-32
lines changed

11 files changed

+210
-32
lines changed

ios/Podfile.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ PODS:
282282
- nanopb/decode (0.3.9011)
283283
- nanopb/encode (0.3.9011)
284284
- PromisesObjC (1.2.8)
285+
- url_launcher (0.0.1):
286+
- Flutter
287+
- url_launcher_macos (0.0.1):
288+
- Flutter
289+
- url_launcher_web (0.0.1):
290+
- Flutter
285291

286292
DEPENDENCIES:
287293
- cloud_firestore (from `.symlinks/plugins/cloud_firestore/ios`)
@@ -290,6 +296,9 @@ DEPENDENCIES:
290296
- firebase_core (from `.symlinks/plugins/firebase_core/ios`)
291297
- firebase_core_web (from `.symlinks/plugins/firebase_core_web/ios`)
292298
- Flutter (from `Flutter`)
299+
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)
300+
- url_launcher_macos (from `.symlinks/plugins/url_launcher_macos/ios`)
301+
- url_launcher_web (from `.symlinks/plugins/url_launcher_web/ios`)
293302

294303
SPEC REPOS:
295304
trunk:
@@ -326,6 +335,12 @@ EXTERNAL SOURCES:
326335
:path: ".symlinks/plugins/firebase_core_web/ios"
327336
Flutter:
328337
:path: Flutter
338+
url_launcher:
339+
:path: ".symlinks/plugins/url_launcher/ios"
340+
url_launcher_macos:
341+
:path: ".symlinks/plugins/url_launcher_macos/ios"
342+
url_launcher_web:
343+
:path: ".symlinks/plugins/url_launcher_web/ios"
329344

330345
SPEC CHECKSUMS:
331346
abseil: 18063d773f5366ff8736a050fe035a28f635fd27
@@ -353,6 +368,9 @@ SPEC CHECKSUMS:
353368
leveldb-library: 55d93ee664b4007aac644a782d11da33fba316f7
354369
nanopb: 18003b5e52dab79db540fe93fe9579f399bd1ccd
355370
PromisesObjC: c119f3cd559f50b7ae681fa59dc1acd19173b7e6
371+
url_launcher: 6fef411d543ceb26efce54b05a0a40bfd74cbbef
372+
url_launcher_macos: fd7894421cd39320dce5f292fc99ea9270b2a313
373+
url_launcher_web: e5527357f037c87560776e36436bf2b0288b965c
356374

357375
PODFILE CHECKSUM: c34e2287a9ccaa606aeceab922830efb9a6ff69a
358376

lib/screens/fhir/fhir.dart

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:fhir_r4/fhir_r4.dart';
21
import 'package:flutter/material.dart';
32
import 'package:get/get.dart';
43
import 'package:symptom_tracker/services/services.dart';
@@ -7,33 +6,45 @@ import 'package:symptom_tracker/shared/shared.dart';
76
class FhirView extends StatelessWidget {
87
@override
98
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-
})
9+
return GetBuilder<FhirManager>(
10+
init: FhirManager(),
11+
builder: (data) => data.isBusy
12+
? Center(child: CircularProgressIndicator())
13+
: Column(
14+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
15+
children: [
16+
//* Aidbox FHIR calls
17+
SharedActionButton(
18+
title: 'Aidbox: Vitals',
19+
onPressed: () => data.aidboxVitals(),
20+
),
21+
22+
//* Hapi FHIR calls
23+
Row(
24+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
25+
children: <Widget>[
26+
_nameContainer(data.lastName, 'Last name'),
27+
_nameContainer(data.firstName, 'First name'),
28+
],
29+
),
30+
Row(
31+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
32+
children: <Widget>[
33+
SmallActionButton(title: 'Hapi: Search', onPressed: () => data.hapiSearch()),
34+
SmallActionButton(title: 'Hapi: Create', onPressed: () => data.hapiCreate()),
35+
],
36+
)
3137
],
3238
),
33-
));
34-
print(data);
35-
},
36-
),
3739
);
3840
}
41+
42+
Container _nameContainer(TextEditingController name, String text) => Container(
43+
width: Get.width / 3,
44+
margin: EdgeInsets.symmetric(horizontal: 8),
45+
child: TextField(
46+
controller: name,
47+
decoration: InputDecoration(hintText: text),
48+
),
49+
);
3950
}

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 renamed to lib/services/fhir/aidbox.service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'dart:convert';
33
import 'package:fhir_r4/fhir_r4.dart';
44
import 'package:http/http.dart' as http;
55

6-
class FhirService {
6+
class AidboxService {
77
Future<List<Quantity>> getResponse() async {
88
final String server = 'https://flutterfhir.aidbox.app/';
99
final Map<String, String> headers = {'Content-type': 'application/json'};

lib/services/fhir/fhir.manager.dart

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import 'package:fhir_r4/fhir_r4.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:get/get.dart';
4+
import 'package:url_launcher/url_launcher.dart';
5+
6+
import 'aidbox.service.dart';
7+
import 'hapi.service.dart';
8+
9+
class FhirManager extends GetController {
10+
AidboxService _aidbox = AidboxService();
11+
HapiService _hapi = HapiService();
12+
13+
bool isBusy = false;
14+
15+
final _lastName = TextEditingController();
16+
final _firstName = TextEditingController();
17+
18+
TextEditingController get lastName => _lastName;
19+
TextEditingController get firstName => _firstName;
20+
21+
Future aidboxVitals() async {
22+
isBusy = true;
23+
update(this);
24+
List<Quantity> data = await _aidbox.getResponse();
25+
isBusy = false;
26+
update(this);
27+
Get.defaultDialog(
28+
content: Container(
29+
height: 500,
30+
width: 300,
31+
child: ListView(
32+
shrinkWrap: true,
33+
children: <Widget>[
34+
...data.map(
35+
(f) {
36+
return Row(
37+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
38+
children: <Widget>[
39+
Text('${f.value}'),
40+
Text('${f.unit}'),
41+
],
42+
);
43+
},
44+
)
45+
],
46+
),
47+
),
48+
);
49+
}
50+
51+
Future hapiCreate() async {
52+
isBusy = true;
53+
update(this);
54+
var response = await _hapi.createPatient(_firstName.text, _lastName.text);
55+
(response.statusCode == 201)
56+
? Get.rawSnackbar(title: 'Success', message: 'Patient ${_firstName.text} ${_lastName.text} created')
57+
: Get.snackbar('Failure', 'An error occurred', snackPosition: SnackPosition.BOTTOM);
58+
isBusy = false;
59+
update(this);
60+
}
61+
62+
Future hapiSearch() async {
63+
isBusy = true;
64+
update(this);
65+
await launch('http://hapi.fhir.org/baseR4/'
66+
'Patient?given=${_firstName.text}&family=${_lastName.text}&_pretty=true');
67+
isBusy = false;
68+
update(this);
69+
}
70+
}

lib/services/fhir/hapi.service.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'dart:convert';
2+
3+
import 'package:fhir_r4/fhir_r4.dart';
4+
import 'package:http/http.dart' as http;
5+
6+
class HapiService {
7+
Future<http.Response> createPatient(String first, String last) async {
8+
var newPatient = Patient(
9+
name: [
10+
HumanName(
11+
given: [first],
12+
family: last,
13+
),
14+
],
15+
);
16+
17+
final String server = 'http://hapi.fhir.org/baseR4/';
18+
final Map<String, String> headers = {'Content-type': 'application/json'};
19+
http.Response response = await http.post(
20+
'$server/Patient?_format=json&_pretty=true',
21+
headers: headers,
22+
body: jsonEncode(
23+
newPatient.toJson(),
24+
),
25+
);
26+
return response;
27+
}
28+
}

lib/services/services.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1+
export './fhir/fhir.manager.dart';
12
export './models/models.dart';
2-
export 'fhir.service.dart';
33
export 'firebase.service.dart';
44
export 'symptom.service.dart';

lib/shared/action_button.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,22 @@ class SharedActionButton extends StatelessWidget {
1919
);
2020
}
2121
}
22+
23+
class SmallActionButton extends StatelessWidget {
24+
final String title;
25+
final void Function() onPressed;
26+
27+
const SmallActionButton({Key key, @required this.title, this.onPressed}) : super(key: key);
28+
29+
@override
30+
Widget build(BuildContext context) {
31+
return ButtonTheme.fromButtonThemeData(
32+
data: Get.theme.buttonTheme.copyWith(minWidth: Get.width / 3),
33+
child: RaisedButton(
34+
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
35+
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 24),
36+
child: Text(title),
37+
onPressed: onPressed),
38+
);
39+
}
40+
}

lib/shared/app_bar.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class SharedAppBar extends AppBar {
66
: super(
77
backgroundColor: Colors.transparent,
88
elevation: 0,
9+
centerTitle: true,
910
title: title != null
1011
? Text(
1112
title,

pubspec.lock

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ packages:
283283
name: get
284284
url: "https://pub.dartlang.org"
285285
source: hosted
286-
version: "2.0.10"
286+
version: "2.5.6"
287287
glob:
288288
dependency: transitive
289289
description:
@@ -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"

0 commit comments

Comments
 (0)