Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions lib/screens/fhir/create.patient.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// class FhirView extends StatelessWidget {
// @override
// Widget build(BuildContext context) {
// return Center(
// child: SharedActionButton(
// title: 'Get FHIR data',
// onPressed: () async {
// List<Quantity> data = await FhirService().getResponse();
// Get.defaultDialog(
// content: Container(
// height: 500,
// width: 300,
// child: ListView(
// shrinkWrap: true,
// children: <Widget>[
// ...data.map((f) {
// return Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: <Widget>[
// Text('${f.value}'),
// Text('${f.unit}'),
// ],
// );
// })
// ],
// ),
// ));
// print(data);
// },
// ),
// );
// }
// }
111 changes: 84 additions & 27 deletions lib/screens/fhir/fhir.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,94 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:symptom_tracker/services/services.dart';
import 'package:symptom_tracker/shared/shared.dart';
import 'package:url_launcher/url_launcher.dart';

class FhirView extends StatelessWidget {
final lastName = TextEditingController(text: '');
final firstName = TextEditingController(text: '');

@override
void dispose() {
lastName.dispose();
firstName.dispose();
}

@override
Widget build(BuildContext context) {
return Center(
child: SharedActionButton(
title: 'Get FHIR data',
onPressed: () async {
List<Quantity> data = await FhirService().getResponse();
Get.defaultDialog(
content: Container(
height: 500,
width: 300,
child: ListView(
shrinkWrap: true,
children: <Widget>[
...data.map((f) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('${f.value}'),
Text('${f.unit}'),
],
);
})
],
),
));
print(data);
},
),
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
children: <Widget>[
_nameContainer(lastName, 'Last name'),
_nameContainer(firstName, 'First name'),
],
),
_linkContainer(firstName, lastName),
_patient(firstName, lastName),
_fhir,
],
);
}
}

Container _linkContainer(
TextEditingController first, TextEditingController last) =>
Container(
child: InkWell(
child: Text(
'Click to see new patient',
style: TextStyle(
color: Colors.purple,
fontSize: 18,
decoration: TextDecoration.underline,
),
),
onTap: () async => await launch('http://hapi.fhir.org/baseR4/'
'Patient?given=${first.text}&family=${last.text}&_pretty=true'),
),
);

Container _nameContainer(TextEditingController name, String text) => Container(
width: 200,
child: TextField(
controller: name,
decoration: InputDecoration(hintText: text),
),
);

SharedActionButton _patient(
TextEditingController first, TextEditingController last) =>
SharedActionButton(
title: 'Create Patient',
onPressed: () async {
await FhirService().createPatient(first.text, last.text);
},
);

SharedActionButton _fhir = SharedActionButton(
title: 'Get FHIR data',
onPressed: () async {
List<Quantity> data = await FhirService().getResponse();
Get.defaultDialog(
content: Container(
height: 500,
width: 300,
child: ListView(
shrinkWrap: true,
children: <Widget>[
...data.map((f) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('${f.value}'),
Text('${f.unit}'),
],
);
})
],
),
));
print(data);
},
);
4 changes: 3 additions & 1 deletion lib/screens/fhir/fhir.screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class FhirScreen extends StatelessWidget {
appBar: SharedAppBar(
title: 'FHIR',
actions: [
IconButton(icon: Icon(Icons.close), onPressed: () => Get.offAll(HomeScreen())),
IconButton(
icon: Icon(Icons.close),
onPressed: () => Get.offAll(HomeScreen())),
],
),
body: _buildBody(),
Expand Down
25 changes: 22 additions & 3 deletions lib/services/fhir.service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ class FhirService {
final String identifier = 'test-client';
final String secret = 'verysecret';
final String grantType = 'client_credentials';
var response1 = await http
.post('$server/auth/token?client_id=$identifier&grant_type=$grantType&client_secret=$secret', headers: headers);
var response1 = await http.post(
'$server/auth/token?client_id=$identifier&grant_type=$grantType&client_secret=$secret',
headers: headers);
if (response1.statusCode == 200) {
var parsedbody = json.decode(response1.body);

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

Expand Down Expand Up @@ -66,4 +69,20 @@ class FhirService {
}
return data;
}

Future<void> createPatient(String first, String last) async {
var newPatient = Patient(
name: [
HumanName(
given: [first],
family: last,
),
],
);

final String server = 'http://hapi.fhir.org/baseR4/';
final Map<String, String> headers = {'Content-type': 'application/json'};
await http.post('$server/Patient?_format=json&_pretty=true',
headers: headers, body: jsonEncode(newPatient.toJson()));
}
}
30 changes: 29 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,34 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
url_launcher:
dependency: "direct main"
description:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "5.4.7"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+5"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.7"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1+5"
vector_math:
dependency: transitive
description:
Expand Down Expand Up @@ -599,4 +627,4 @@ packages:
version: "2.2.1"
sdks:
dart: ">=2.7.0 <3.0.0"
flutter: ">=1.12.13+hotfix.4 <2.0.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies:
fhir_r4:
git:
url: git://github.com/Dokotela/fhir_r4.git
url_launcher: ^5.4.7

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