You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/pages/Covid-DriveThru/covid-dirvethru-questions.dart

183 lines
8.8 KiB
Dart

import 'dart:convert';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/models/CovidDriveThru/CovidPaymentInfoResponse.dart';
import 'package:diplomaticquarterapp/models/CovidDriveThru/CovidTestProceduresResponse.dart';
import 'package:diplomaticquarterapp/pages/medical/labs/passport_update_page.dart';
import 'package:diplomaticquarterapp/services/covid-drivethru/covid-drivethru.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
3 years ago
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'covid-payment-details.dart';
class CovidDirveThruQuestions extends StatefulWidget {
final String projectId;
final List<CovidTestProceduresResponse> proceduresList;
CovidDirveThruQuestions({@required this.projectId, @required this.proceduresList});
@override
CovidDirveThruQuestionsState createState() => CovidDirveThruQuestionsState();
}
class CovidDirveThruQuestionsState extends State<CovidDirveThruQuestions> {
List qa;
ProjectViewModel projectViewModel;
@override
void initState() {
super.initState();
qa = getQuestionsFromJson();
}
@override
Widget build(BuildContext context) {
projectViewModel = Provider.of(context);
var isArabic = projectViewModel.isArabic;
return AppScaffold(
appBarTitle: TranslationBase.of(context).covidTest,
isShowAppBar: true,
3 years ago
showNewAppBar: true,
showNewAppBarTitle: true,
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: MediaQuery.of(context).size.width * 0.9,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15.0),
),
margin: EdgeInsets.fromLTRB(18.0, 10.0, 18.0, 10.0),
padding: EdgeInsets.fromLTRB(8.0, 10.0, 8.0, 10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(TranslationBase.of(context).covidBookAppo, style: TextStyle(fontSize: 18, letterSpacing: 1, fontWeight: FontWeight.bold)),
Text(TranslationBase.of(context).patientName.toString() + ": " + projectViewModel.user.firstName + " " + projectViewModel.user.lastName, style: TextStyle(fontSize: 14, letterSpacing: 1)),
Text(TranslationBase.of(context).fileNo.toString() + ": " + projectViewModel.user.patientID.toString(), style: TextStyle(fontSize: 14, letterSpacing: 1)),
],
),
),
Padding(
3 years ago
padding: const EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
child: Text(TranslationBase.of(context).covidQuestionnaire, style: TextStyle(fontSize: 17, letterSpacing: 1, fontWeight: FontWeight.bold)),
),
Expanded(
child: ListView.separated(
padding: EdgeInsets.symmetric(horizontal: 20),
itemCount: qa.length,
itemBuilder: (ctx, idx) {
var obj = qa[idx];
var qtext = isArabic ? obj["questionAR"] : obj["questionEN"];
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(qtext, style: TextStyle(fontSize: 15, letterSpacing: 1.5)),
Row(
children: [
Radio<int>(
value: 1,
groupValue: obj["ans"],
onChanged: (newValue) {
setState(() {
obj["ans"] = newValue;
});
}),
Text(TranslationBase.of(context).yes),
],
),
Row(
children: [
Radio<int>(
value: 0,
groupValue: obj["ans"],
onChanged: (newValue) {
setState(() {
obj["ans"] = newValue;
});
}),
Text(TranslationBase.of(context).no),
],
)
],
),
);
},
separatorBuilder: (ctx, idx) => Divider(height: 0.25, color: Colors.grey.withOpacity(0.5)),
)),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
child: FractionallySizedBox(
widthFactor: 1,
child: DefaultButton(TranslationBase.of(context).next, () {
3 years ago
next();
}),
),
),
],
));
}
next() async {
bool all = true;
qa.forEach((element) {
all = all && (element["ans"] == 1 || element["ans"] == 0);
});
if (all) if (qa[0]["ans"] == 1) {
openPassportUpdatePage();
} else {
getPaymentInfo(context, widget.projectId);
}
else
AppToast.showErrorToast(message: TranslationBase.of(context).pleaseSelectAllQuestionToContinue);
}
openPassportUpdatePage() {
Navigator.push(context, FadePage(page: PassportUpdatePage())).then((value) {
print(value);
3 years ago
if (value != null && value == true) {
getPaymentInfo(context, widget.projectId);
}
});
}
List getQuestionsFromJson() {
var questionsJson = """
[{"id":1,"questionEN":"Is the test intended for travel?","questionAR":"هل تجري التحليل بغرض السفر؟","ans":2},{"id":2,"questionEN":"Coming from outside KSA within last 2 weeks?","questionAR":"هل قدمت من خارج المملكة خلال الأسبوعين الماضيين؟","ans":2},{"id":3,"questionEN":"Do you currently have fever?","questionAR":"هل تعاني حاليا من حرارة؟","ans":2},{"id":4,"questionEN":"Did you have fever in last 2 weeks?","questionAR":"هل عانيت من حرارة في الأسبوعين الماضيين؟","ans":2},{"id":5,"questionEN":"Do you have a sore throat?","questionAR":"هل لديك التهاب في الحلق؟","ans":2},{"id":6,"questionEN":"Do you have a runny nose?","questionAR":"هل لديك سيلان بالأنف؟"},{"id":7,"questionEN":"Do you have a cough?","questionAR":"هل لديك سعال؟","ans":2},{"id":8,"questionEN":"Do you have shortness of breath?","questionAR":"هل تعانين من ضيق في التنفس؟","ans":2},{"id":9,"questionEN":"Do you have nausea?","questionAR":"هل تعانين من غثيان؟","ans":2},{"id":10,"questionEN":"Do you have vomiting?","questionAR":"هل تعاني من القيء؟","ans":2},{"id":11,"questionEN":"Do you have a headache?","questionAR":"هل تعاني من صداع في الرأس؟","ans":2},{"id":12,"questionEN":"Do you have muscle pain?","questionAR":"هل تعانين من آلام عضلية؟","ans":2},{"id":13,"questionEN":"Do you have joint pain?","questionAR":"هل تعانين من آلام المفاصل؟","ans":2},{"id":14,"questionEN":"Do you have diarrhea?","questionAR":"هل لديك اسهال؟","ans":2}]""";
var map = json.decode(questionsJson) as List;
return map;
}
getPaymentInfo(BuildContext context, String projectID) {
CovidDriveThruService service = new CovidDriveThruService();
CovidPaymentInfoResponse covidPaymentInfoResponse = new CovidPaymentInfoResponse();
GifLoaderDialogUtils.showMyDialog(context);
service.getCovidPaymentInformation(context, int.parse(projectID), widget.proceduresList[0].procedureID).then((res) {
GifLoaderDialogUtils.hideDialog(context);
if (res['MessageStatus'] == 1) {
3 years ago
covidPaymentInfoResponse = CovidPaymentInfoResponse.fromJson(res['COVID19_PatientShare']);
Navigator.push(
context,
FadePage(
page: CovidPaymentDetails(
covidPaymentInfoResponse: covidPaymentInfoResponse,
projectID: int.parse(projectID),
proceduresList: widget.proceduresList,
)));
} else {}
}).catchError((err) {
print(err);
});
}
}