Skip to content

Commit 6843fd2

Browse files
committed
separate aidbox/hapi FHIR calls
manager accesses different services minor change to title formatting
1 parent 6a683e9 commit 6843fd2

File tree

11 files changed

+181
-143
lines changed

11 files changed

+181
-143
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/create.patient.dart

Lines changed: 0 additions & 33 deletions
This file was deleted.

lib/screens/fhir/fhir.dart

Lines changed: 38 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,50 @@
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';
54
import 'package:symptom_tracker/shared/shared.dart';
6-
import 'package:url_launcher/url_launcher.dart';
75

86
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-
187
@override
198
Widget build(BuildContext context) {
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-
],
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+
)
37+
],
38+
),
3339
);
3440
}
35-
}
3641

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-
),
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),
4848
),
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-
);
49+
);
50+
}

lib/services/fhir.service.dart renamed to lib/services/fhir/aidbox.service.dart

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,23 @@ 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'};
1010
final String identifier = 'test-client';
1111
final String secret = 'verysecret';
1212
final String grantType = 'client_credentials';
13-
var response1 = await http.post(
14-
'$server/auth/token?client_id=$identifier&grant_type=$grantType&client_secret=$secret',
15-
headers: headers);
13+
var response1 = await http
14+
.post('$server/auth/token?client_id=$identifier&grant_type=$grantType&client_secret=$secret', headers: headers);
1615
if (response1.statusCode == 200) {
1716
var parsedbody = json.decode(response1.body);
1817

1918
print('parsedbody: $parsedbody');
2019
var token = parsedbody['token_type'] + ' ' + parsedbody['access_token'];
2120
headers.putIfAbsent('Authorization', () => token);
2221
}
23-
var response2 = await http.get(
24-
'$server/fhir/Observation?patient=test123&category=vital-signs',
25-
headers: headers);
22+
var response2 = await http.get('$server/fhir/Observation?patient=test123&category=vital-signs', headers: headers);
2623
Bundle vitalsBundle = Bundle.fromJson(json.decode(response2.body));
2724
print('vitalsBundle: $vitalsBundle');
2825

@@ -69,20 +66,4 @@ class FhirService {
6966
}
7067
return data;
7168
}
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-
}
8869
}

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+
}

0 commit comments

Comments
 (0)