Skip to content

Commit

Permalink
Implement the appointment screen
Browse files Browse the repository at this point in the history
  • Loading branch information
rusiruavb committed Oct 10, 2021
1 parent 6957788 commit 45c3849
Show file tree
Hide file tree
Showing 22 changed files with 1,001 additions and 133 deletions.
Binary file added assets/images/appointment_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions lib/api_endpoints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ const RootURLPath = 'http://10.0.2.2:4000';
const GET_SEARCHED_DOCTORS = '$RootURLPath/doctor/search';
const CREATE_USER_ACCOUNT = '$RootURLPath/user/create';
const LOGIN_USER_ACCOUNT = '$RootURLPath/user/login';
const GET_USER_PROFILE = '$RootURLPath/user/';
const CREATE_APPOINTMENT = '$RootURLPath/appointment/create';
const GET_APPOINTMENTS = '$RootURLPath/appointment/';
2 changes: 1 addition & 1 deletion lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const int TEXT_SECONDARY = 0xff4a4a4a;
const int COLOR_PRIMARY = 0xffe62a29;
const int COLOR_PRIMARY_DISABLED = 0xffe95b5a;
const int COLOR_SECONDARY = 0xffe2e2e2;
const int COLOR_YELLOW = 0XFFFFB029;
const int COLOR_YELLOW = 0XFFF69B00;
const String FONT_FAMILY_PRIMARY = 'Larsseit';
const String FONT_FAMILY_SECONDARY = 'OpenSans';
const String FONT_FAMILY_DEFAULT = 'Roboto';
Expand Down
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:dialog_doc990_mobile/providers/appointment_provider.dart';
import 'package:dialog_doc990_mobile/providers/payment_provider.dart';
import 'package:dialog_doc990_mobile/providers/search_doctor_provider.dart';
import 'package:dialog_doc990_mobile/providers/sign_up_provider.dart';
import 'package:dialog_doc990_mobile/providers/user_provider.dart';
import 'package:dialog_doc990_mobile/route_generator.dart';
import 'package:dialog_doc990_mobile/screens/home/home_screen.dart';
import 'package:dialog_doc990_mobile/screens/welcome/welcome_screen.dart';
Expand All @@ -14,7 +14,7 @@ import 'constants.dart';
void main() => runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => SignUpProvider()),
ChangeNotifierProvider(create: (_) => UserProvider()),
ChangeNotifierProvider(create: (_) => SearchDoctorProvider()),
ChangeNotifierProvider(create: (_) => AppointmentProvider()),
ChangeNotifierProvider(create: (_) => PaymentProvider()),
Expand Down
97 changes: 97 additions & 0 deletions lib/models/appointment_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
class AppointmentModel {
AppointmentModel({
this.isAppointmentCancelled,
this.id,
this.time,
this.name,
this.email,
this.address,
this.phoneNumber,
this.nic,
this.city,
this.province,
this.isChargeChecked,
this.isPdfChecked,
this.referenceNo,
this.hospitalName,
this.date,
this.totalAmount,
this.specialization,
this.doctorName,
this.createdAt,
this.updatedAt,
this.v,
});

bool isAppointmentCancelled;
String id;
String time;
String name;
String email;
String address;
String phoneNumber;
String nic;
String city;
String province;
bool isChargeChecked;
bool isPdfChecked;
String referenceNo;
String hospitalName;
DateTime date;
int totalAmount;
DateTime createdAt;
DateTime updatedAt;
String doctorName;
String specialization;
int v;

factory AppointmentModel.fromJson(Map<String, dynamic> json) =>
AppointmentModel(
isAppointmentCancelled: json["isAppointmentCancelled"],
id: json["_id"],
time: json["time"],
name: json["name"],
email: json["email"],
address: json["address"],
phoneNumber: json["phoneNumber"],
nic: json["nic"],
city: json["city"],
province: json["province"],
isChargeChecked: json["isChargeChecked"],
isPdfChecked: json["isPDFChecked"],
referenceNo: json["referenceNo"],
hospitalName: json["hospitalName"],
date: DateTime.parse(json["date"]),
totalAmount: json["totalAmount"],
specialization: json["specialization"],
doctorName: json["doctorName"],
createdAt: DateTime.parse(json["createdAt"]),
updatedAt: DateTime.parse(json["updatedAt"]),
v: json["__v"],
);

Map<String, dynamic> toJson() => {
"isAppointmentCancelled": isAppointmentCancelled,
"_id": id,
"time": time,
"name": name,
"email": email,
"address": address,
"phoneNumber": phoneNumber,
"nic": nic,
"city": city,
"province": province,
"isChargeChecked": isChargeChecked,
"isPDFChecked": isPdfChecked,
"referenceNo": referenceNo,
"doctorName": doctorName,
"hospitalName": hospitalName,
"specialization": specialization,
"date":
"${date.year.toString().padLeft(4, '0')}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}",
"totalAmount": totalAmount,
"createdAt": createdAt.toIso8601String(),
"updatedAt": updatedAt.toIso8601String(),
"__v": v,
};
}
27 changes: 27 additions & 0 deletions lib/models/user_auth_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class UserAuthModel {
UserAuthModel({
this.userId,
this.name,
this.email,
this.phoneNumber,
});

String userId;
String name;
String email;
String phoneNumber;

factory UserAuthModel.fromJson(Map<String, dynamic> json) => UserAuthModel(
userId: json["user_id"],
name: json["name"],
email: json["email"],
phoneNumber: json["phoneNumber"],
);

Map<String, dynamic> toJson() => {
"user_id": userId,
"name": name,
"email": email,
"phoneNumber": phoneNumber,
};
}
59 changes: 59 additions & 0 deletions lib/models/user_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
class UserModel {
UserModel({
this.id,
this.name,
this.email,
this.phoneNumber,
this.gender,
this.password,
this.imageUrl,
this.country,
this.nic,
this.createdAt,
this.updatedAt,
this.v,
});

String id;
String name;
String email;
String phoneNumber;
String gender;
String password;
String imageUrl;
String country;
String nic;
DateTime createdAt;
DateTime updatedAt;
int v;

factory UserModel.fromJson(Map<String, dynamic> json) => UserModel(
id: json["_id"],
name: json["name"],
email: json["email"],
phoneNumber: json["phoneNumber"],
gender: json["gender"],
password: json["password"],
imageUrl: json["imageUrl"],
country: json["country"],
nic: json["nic"],
createdAt: DateTime.parse(json["createdAt"]),
updatedAt: DateTime.parse(json["updatedAt"]),
v: json["__v"],
);

Map<String, dynamic> toJson() => {
"_id": id,
"name": name,
"email": email,
"phoneNumber": phoneNumber,
"gender": gender,
"password": password,
"imageUrl": imageUrl,
"country": country,
"nic": nic,
"createdAt": createdAt.toIso8601String(),
"updatedAt": updatedAt.toIso8601String(),
"__v": v,
};
}
112 changes: 110 additions & 2 deletions lib/providers/appointment_provider.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import 'dart:convert';

import 'package:dialog_doc990_mobile/api_endpoints.dart';
import 'package:dialog_doc990_mobile/models/appointment_model.dart';
import 'package:dialog_doc990_mobile/providers/payment_provider.dart';
import 'package:dialog_doc990_mobile/providers/search_doctor_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:http/http.dart' as http;
import 'package:provider/provider.dart';
import 'package:uuid/uuid.dart';

class AppointmentProvider extends ChangeNotifier {
// PATIENT INFORMATION
// Patient Information
String selectTime;
String patientName;
String patientTitle;
Expand All @@ -21,12 +29,112 @@ class AppointmentProvider extends ChangeNotifier {
bool isServiceChargeChecked = false;
bool isPDFReceiptChecked = false;

// constants
// Constants
final double hospitalPrice = 400.0;
final double refundChage = 250.0;
final double bookingCharge = 99.0;
double doctorCharge;

List<AppointmentModel> appointments = [];
int noOfAppointments = 0;

void createAppointment(BuildContext context) async {
final paymentProvider =
Provider.of<PaymentProvider>(context, listen: false);
final doctorProvider =
Provider.of<SearchDoctorProvider>(context, listen: false);

if (selectTime != null &&
patientName != null &&
patientTitle != null &&
email != null &&
phoneNumber != null &&
nic != null &&
address != null &&
city != null &&
province != null &&
referenceNo != null &&
hospitalName != null &&
date != null &&
paymentProvider.enteredCardNumber != null &&
paymentProvider.enteredExpireDate != null &&
doctorProvider.selectedDoctor.name != null &&
doctorProvider.selectedDoctor.specialization != null) {
final response = await http.post(
Uri.parse(CREATE_APPOINTMENT),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8'
},
body: jsonEncode(
<String, dynamic>{
"time": selectTime,
"name": patientName,
"email": email,
"address": address,
"city": city,
"province": province,
"phoneNumber": phoneNumber,
"nic": nic,
"isChargeChecked": isServiceChargeChecked,
"isPDFChecked": isPDFReceiptChecked,
"referenceNo": referenceNo,
"hospitalName": hospitalName,
"date": date,
"totalAmount": calculateTotalPrice(),
"cardNumber": paymentProvider.enteredCardNumber,
"cardExpireDate": paymentProvider.enteredExpireDate,
"doctorName": doctorProvider.selectedDoctor.name,
"specialization": doctorProvider.selectedDoctor.specialization,
},
),
);

if (response.statusCode == 200) {
Fluttertoast.showToast(msg: 'Appointment created succussfully');
await FlutterSecureStorage().delete(key: 'phoneNumber');
await FlutterSecureStorage()
.write(key: 'phoneNumber', value: phoneNumber);
notifyListeners();
Navigator.pushNamed(context, '/home');
} else {
Fluttertoast.showToast(msg: 'Error with create appointment');
notifyListeners();
}
} else {
Fluttertoast.showToast(msg: 'Please provide necessary infromation');
notifyListeners();
}
}

Future<List<AppointmentModel>> getUserAppointments() async {
appointments.clear();
final phoneNumber = await FlutterSecureStorage().read(key: 'phoneNumber');

if (phoneNumber != null) {
final response = await http.get(
Uri.parse(GET_APPOINTMENTS),
headers: {'phonenumber': phoneNumber},
);

if (response.statusCode == 200) {
final data = jsonDecode(response.body) as List;
noOfAppointments = data.length;
for (Map<String, dynamic> appointment in data) {
appointments.add(AppointmentModel.fromJson(appointment));
}
return appointments;
} else {
Fluttertoast.showToast(msg: 'Error with fetch appointments');
notifyListeners();
return null;
}
} else {
Fluttertoast.showToast(msg: 'Please Login');
notifyListeners();
return null;
}
}

double calculateTotalPrice() {
if (doctorCharge != null) {
totalPrice = hospitalPrice + refundChage + bookingCharge + doctorCharge;
Expand Down
Loading

0 comments on commit 45c3849

Please sign in to comment.