-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3907ecb
commit a90caf8
Showing
51 changed files
with
2,336 additions
and
572 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:google_fonts/google_fonts.dart'; | ||
import 'package:happy_care/core/themes/colors.dart'; | ||
import 'package:sizer/sizer.dart'; | ||
|
||
showConfirmDialog(BuildContext context, | ||
{required String title, | ||
required String contentDialog, | ||
required void Function() confirmFunction}) async { | ||
return await showDialog( | ||
context: context, | ||
builder: (context) => AlertDialog( | ||
title: Text( | ||
title, | ||
style: GoogleFonts.openSans(fontWeight: FontWeight.w600), | ||
), | ||
content: Text( | ||
contentDialog, | ||
), | ||
actions: [ | ||
TextButton( | ||
onPressed: confirmFunction, | ||
child: Text( | ||
"Xác nhận", | ||
style: GoogleFonts.openSans(color: kMainColor), | ||
), | ||
), | ||
TextButton( | ||
onPressed: () => Get.back(result: false), | ||
child: Text( | ||
"Không", | ||
style: GoogleFonts.openSans(color: kMainColor), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
|
||
showLoadingDialog(BuildContext context, {required String contentDialog}) { | ||
return showDialog( | ||
barrierDismissible: false, | ||
context: context, | ||
builder: (context) { | ||
return Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
CircularProgressIndicator( | ||
color: kMainColor, | ||
), | ||
SizedBox( | ||
height: 1.2.h, | ||
), | ||
Text(contentDialog, | ||
style: GoogleFonts.openSans( | ||
color: Colors.white, fontWeight: FontWeight.w700)), | ||
], | ||
), | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter_dotenv/flutter_dotenv.dart'; | ||
import 'package:http/http.dart'; | ||
|
||
class DrugApi { | ||
final Client http; | ||
|
||
DrugApi(this.http); | ||
|
||
Future<String> getAllDrug() async { | ||
var response = await http | ||
.get( | ||
// Uri.parse("${dotenv.env['BASE_URL']}$path"), | ||
Uri.parse("${dotenv.env['BASE_URL']}/api/drugs"), | ||
) | ||
.timeout(Duration(minutes: 1), onTimeout: () { | ||
throw TimeoutException("Time out exception"); | ||
}); | ||
if (response.statusCode == 200) { | ||
print("=======GET_DRUG======\n" + response.body); | ||
return response.body; | ||
} else { | ||
throw Exception(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter_dotenv/flutter_dotenv.dart'; | ||
import 'package:http/http.dart'; | ||
|
||
class PrescriptionApi { | ||
final Client http; | ||
|
||
PrescriptionApi(this.http); | ||
|
||
Future<String> getMyPrescription(String token) async { | ||
final header = { | ||
'Authorization': 'Bearer $token', | ||
}; | ||
|
||
var response = await http | ||
.get(Uri.parse("${dotenv.env['BASE_URL']}/api/prescriptions/me"), | ||
headers: header) | ||
.timeout(Duration(minutes: 1), onTimeout: () { | ||
throw TimeoutException("Time out exception"); | ||
}); | ||
|
||
if (response.statusCode == 200) { | ||
print("=======GET_PRESCRIPTION======\n" + response.body); | ||
return response.body; | ||
} else { | ||
print("=======GET_PRESCRIPTION_ERROR======"); | ||
throw Exception(); | ||
} | ||
} | ||
|
||
Future<String> createNewPrescription( | ||
String token, Map<String, dynamic> body) async { | ||
final headers = { | ||
'Authorization': 'Bearer $token', | ||
'Content-Type': 'application/json', | ||
}; | ||
print(body); | ||
var response = await http | ||
.post(Uri.parse("${dotenv.env['BASE_URL']}/api/prescriptions"), | ||
headers: headers, body: jsonEncode(body)) | ||
.timeout(Duration(minutes: 1), onTimeout: () { | ||
throw TimeoutException("Het gio roi thang l"); | ||
}); | ||
|
||
if (response.statusCode == 200) { | ||
print("Up don thuoc thanh cong"); | ||
return response.body; | ||
} else { | ||
print("Up don thuoc deo thanh cong"); | ||
print(response.body); | ||
throw Exception(); | ||
} | ||
} | ||
|
||
Future<String> updatePrescription( | ||
String token, String id ,Map<String, dynamic> body) async { | ||
final headers = { | ||
'Authorization': 'Bearer $token', | ||
'Content-Type': 'application/json', | ||
}; | ||
print(body); | ||
var response = await http | ||
.patch(Uri.parse("${dotenv.env['BASE_URL']}/api/prescriptions/$id"), | ||
headers: headers, body: jsonEncode(body)) | ||
.timeout(Duration(minutes: 1), onTimeout: () { | ||
throw TimeoutException("Het gio roi thang l"); | ||
}); | ||
|
||
if (response.statusCode == 200) { | ||
print("Update don thuoc thanh cong"); | ||
return response.body; | ||
} else { | ||
print("Update don thuoc deo thanh cong"); | ||
print(response.body); | ||
throw Exception(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class Drug { | ||
String? id; | ||
String? name; | ||
String? description; | ||
|
||
|
||
Drug({this.id, this.name, this.description}); | ||
|
||
@override | ||
String toString() { | ||
return 'Drug(id: $id, name: $name, description: $description)'; | ||
} | ||
|
||
factory Drug.fromJson(Map<String, dynamic> json) => Drug( | ||
id: json['_id'] as String?, | ||
name: json['name'] as String?, | ||
description: json['description'] as String?, | ||
); | ||
|
||
Map<String, dynamic> toJson() => { | ||
'_id': id, | ||
'name': name, | ||
'description': description, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:happy_care/data/api/drug_api.dart'; | ||
import 'package:happy_care/data/models/drug.dart'; | ||
|
||
class DrugRepository { | ||
final DrugApi? drugApi; | ||
|
||
DrugRepository({this.drugApi}); | ||
|
||
Future<List<Drug>> getAllDrug() async { | ||
String response = await drugApi!.getAllDrug(); | ||
var converted = jsonDecode(response); | ||
Iterable list = converted['data']['drugs']; | ||
return list.map((data) => Drug.fromJson(data)).toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:happy_care/core/utils/shared_pref.dart'; | ||
import 'package:happy_care/data/api/prescription_api.dart'; | ||
import 'package:happy_care/data/models/prescription/medicine.dart'; | ||
import 'package:happy_care/data/models/prescription/prescription.dart'; | ||
|
||
class PrescriptionRepository { | ||
final PrescriptionApi? prescriptionApi; | ||
|
||
PrescriptionRepository({this.prescriptionApi}); | ||
|
||
Future<List<Prescription>> getMyPrescription() async { | ||
try { | ||
String token = await SharedPrefUtils.getStringKey('token'); | ||
String response = await prescriptionApi!.getMyPrescription(token); | ||
var converted = jsonDecode(response); | ||
Iterable list = converted['data']['prescriptions']; | ||
return list.map((e) => Prescription.fromJson(e)).toList(); | ||
} catch (_) { | ||
throw Exception(); | ||
} | ||
} | ||
|
||
Future<String> createNewPrescription( | ||
{required String diagnose, | ||
required String memberId, | ||
required String doctorId, | ||
required List<Medicine> medicines, | ||
String? note}) async { | ||
try { | ||
String token = await SharedPrefUtils.getStringKey('token'); | ||
final body = { | ||
'diagnose': diagnose, | ||
'member': memberId, | ||
'doctor': doctorId, | ||
'medicines': medicines.map((e) => e.toJsonNoId()).toList(), | ||
'note': note, | ||
}; | ||
String response = | ||
await prescriptionApi!.createNewPrescription(token, body); | ||
var converted = jsonDecode(response); | ||
return converted['data']['prescriptionId']; | ||
} catch (_) { | ||
throw Exception(); | ||
} | ||
} | ||
|
||
Future<void> updatePrescription({ | ||
required String prescriptionId, | ||
required String diagnose, | ||
required List<Medicine> medicines, | ||
String? note, | ||
}) async { | ||
try { | ||
String token = await SharedPrefUtils.getStringKey('token'); | ||
final body = { | ||
'diagnose': diagnose, | ||
'medicines': medicines.map((e) => e.toJsonNoId()).toList(), | ||
'note': note, | ||
}; | ||
await prescriptionApi!.updatePrescription(token, prescriptionId, body); | ||
} catch (_) { | ||
throw Exception(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.