From 9eb9f01dbdbf4286138cd54b2098888ebeb952a3 Mon Sep 17 00:00:00 2001 From: Haroon Amjad Date: Sun, 19 Jul 2020 20:20:32 +0300 Subject: [PATCH] Get Clinic List API Implemented, Architecture for HTTP requests implemented --- lib/config/config.dart | 28 ++++++- .../Appointments/getClinicsRequest.dart | 0 lib/models/Clinics/ClinicListResponse.dart | 77 +++++++++++++++++++ lib/models/Request.dart | 33 ++++++++ .../components/SearchByClinic.dart | 52 +++++++++++-- .../MyAppointments/models/BookedButtons.dart | 6 +- lib/pages/ToDoList/widgets/upcomingCard.dart | 5 +- .../clinic_services/get_clinic_service.dart | 37 +++++++++ 8 files changed, 225 insertions(+), 13 deletions(-) create mode 100644 lib/models/Appointments/getClinicsRequest.dart create mode 100644 lib/models/Clinics/ClinicListResponse.dart create mode 100644 lib/models/Request.dart create mode 100644 lib/services/clinic_services/get_clinic_service.dart diff --git a/lib/config/config.dart b/lib/config/config.dart index 753fcd01..25508b33 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -1,9 +1,35 @@ +import 'dart:io'; +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; +import 'package:diplomaticquarterapp/models/Request.dart'; +import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; const MAX_SMALL_SCREEN = 660; -const BASE_URL = ''; +const BASE_URL = 'https://hmgwebservices.com/'; // Production Environment +//const BASE_URL = 'https://uat.hmgwebservices.com/'; // UAT Environment + + +//URL to get clinic list +const GET_CLINICS_LIST_URL = "Services/lists.svc/REST/GetClinicCentralized"; class AppGlobal { static var context; + AppSharedPreferences sharedPref = AppSharedPreferences(); + + Request getPublicRequest() { + Request request = new Request(); + request.VersionID = 5.3; //3.6; + request.Channel = 3; +// request.LanguageID = await sharedPref.getString(APP_LANGUAGE); + request.IPAdress = "10.20.10.20"; + request.generalid = 'Cs2020@2016\$2958'; + request.PatientOutSA = 0; + request.SessionID = null; + request.isDentalAllowedBackend = false; + request.DeviceTypeID = Platform.isIOS ? 1 : 2; + + return request; + } + } diff --git a/lib/models/Appointments/getClinicsRequest.dart b/lib/models/Appointments/getClinicsRequest.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/models/Clinics/ClinicListResponse.dart b/lib/models/Clinics/ClinicListResponse.dart new file mode 100644 index 00000000..cabb47b2 --- /dev/null +++ b/lib/models/Clinics/ClinicListResponse.dart @@ -0,0 +1,77 @@ +class ListClinicCentralized { + int clinicID; + String clinicDescription; + Null clinicDescriptionN; + int age; + int gender; + bool isLiveCareClinicAndOnline; + int liveCareClinicID; + int liveCareServiceID; + + ListClinicCentralized( + {this.clinicID, + this.clinicDescription, + this.clinicDescriptionN, + this.age, + this.gender, + this.isLiveCareClinicAndOnline, + this.liveCareClinicID, + this.liveCareServiceID}); + + ListClinicCentralized.fromJson(Map json) { + clinicID = json['ClinicID']; + clinicDescription = json['ClinicDescription']; + clinicDescriptionN = json['ClinicDescriptionN']; + age = json['Age']; + gender = json['Gender']; + isLiveCareClinicAndOnline = json['IsLiveCareClinicAndOnline']; + liveCareClinicID = json['LiveCareClinicID']; + liveCareServiceID = json['LiveCareServiceID']; + } + + Map toJson() { + final Map data = new Map(); + data['ClinicID'] = this.clinicID; + data['ClinicDescription'] = this.clinicDescription; + data['ClinicDescriptionN'] = this.clinicDescriptionN; + data['Age'] = this.age; + data['Gender'] = this.gender; + data['IsLiveCareClinicAndOnline'] = this.isLiveCareClinicAndOnline; + data['LiveCareClinicID'] = this.liveCareClinicID; + data['LiveCareServiceID'] = this.liveCareServiceID; + return data; + } +} + +class ListGetBookScheduleConfigsList { + int iD; + String description; + Null descriptionN; + bool value; + bool isActive; + + ListGetBookScheduleConfigsList( + {this.iD, + this.description, + this.descriptionN, + this.value, + this.isActive}); + + ListGetBookScheduleConfigsList.fromJson(Map json) { + iD = json['ID']; + description = json['Description']; + descriptionN = json['DescriptionN']; + value = json['Value']; + isActive = json['IsActive']; + } + + Map toJson() { + final Map data = new Map(); + data['ID'] = this.iD; + data['Description'] = this.description; + data['DescriptionN'] = this.descriptionN; + data['Value'] = this.value; + data['IsActive'] = this.isActive; + return data; + } +} diff --git a/lib/models/Request.dart b/lib/models/Request.dart new file mode 100644 index 00000000..03aa7760 --- /dev/null +++ b/lib/models/Request.dart @@ -0,0 +1,33 @@ +class Request { + var ClinicID; + var PatientOutSA; + var PatientID; + var ProjectID; + var LanguageID; + var DeviceTypeID; + var AppointmentNo; + var IPAdress; + var VersionID; + var Channel; + var PatientTypeID; + var PatientType; + var isDentalAllowedBackend; + var IsIrisPrescription; + var TokenID; + var SessionID; + var PatientIdentificationID; + var PatientMobileNumber; + var BookedBy; + var Latitude; + var Longitude; + var OutSA; + var Note; + var IsActiveAppointment; + var RequestType; + var InvoiceNo; + var EncounterType; + var generalid; + var ServiceID; + var StrAppointmentDate; + var SKU; +} \ No newline at end of file diff --git a/lib/pages/BookAppointment/components/SearchByClinic.dart b/lib/pages/BookAppointment/components/SearchByClinic.dart index c1fb14c4..366f45bf 100644 --- a/lib/pages/BookAppointment/components/SearchByClinic.dart +++ b/lib/pages/BookAppointment/components/SearchByClinic.dart @@ -1,3 +1,6 @@ +import 'package:diplomaticquarterapp/models/Clinics/ClinicListResponse.dart'; +import 'package:diplomaticquarterapp/pages/BookAppointment/Search.dart'; +import 'package:diplomaticquarterapp/services/clinic_services/get_clinic_service.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:flutter/material.dart'; @@ -8,7 +11,15 @@ class SearchByClinic extends StatefulWidget { class _SearchByClinicState extends State { bool nearestAppo = false; - String dropdownValue = 'Select Clinic'; + String dropdownValue = null; + List clinicsList = []; + + @override + void initState() { + // TODO: implement initState + getClinicsList(); + super.initState(); + } @override Widget build(BuildContext context) { @@ -47,16 +58,18 @@ class _SearchByClinicState extends State { width: MediaQuery.of(context).size.width, child: DropdownButtonHideUnderline( child: DropdownButton( + hint: new Text("Select Clinic"), value: dropdownValue, - items: ['Select Clinic', 'A', 'B', 'C', 'D'] - .map((String value) { + items: clinicsList + .map((ListClinicCentralized clinicSelected) { return new DropdownMenuItem( - value: value, - child: new Text(value), +// value: dropdownValue, + child: new Text(clinicSelected.clinicDescription), ); }).toList(), - onChanged: (String newValue) { + onChanged: (newValue) { setState(() { + print(newValue); dropdownValue = newValue; }); }, @@ -66,4 +79,31 @@ class _SearchByClinicState extends State { ), ); } + + getClinicsList() { + ClinicListService service = new ClinicListService(); + service.getClinicsList().then((res) { + if (res['MessageStatus'] == 1) { + setState(() { + res['ListClinicCentralized'].forEach((v) { + clinicsList.add(new ListClinicCentralized.fromJson(v)); + }); + clinicsList.forEach((v) { + print(v.clinicID); + }); + }); + } else { + // handel error + setState(() { +// projectsList = ListProject; + }); + } + }).catchError((err) { + setState(() { +// projectsList = ListProject; + }); + print(err); + }); + } + } diff --git a/lib/pages/MyAppointments/models/BookedButtons.dart b/lib/pages/MyAppointments/models/BookedButtons.dart index a9f06cc8..f10d0a09 100644 --- a/lib/pages/MyAppointments/models/BookedButtons.dart +++ b/lib/pages/MyAppointments/models/BookedButtons.dart @@ -54,7 +54,7 @@ class BookedButtons { } ]; -// static getContext(context) { -// BookedButtons.context = context; -// } + static setContext(context) { + BookedButtons.context = context; + } } diff --git a/lib/pages/ToDoList/widgets/upcomingCard.dart b/lib/pages/ToDoList/widgets/upcomingCard.dart index d4358dc5..e6c7fa84 100644 --- a/lib/pages/ToDoList/widgets/upcomingCard.dart +++ b/lib/pages/ToDoList/widgets/upcomingCard.dart @@ -23,7 +23,7 @@ class _TodoListCardState extends State { padding: EdgeInsets.all(10.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, + mainAxisSize: MainAxisSize.max, children: [ Row( children: [ @@ -72,7 +72,6 @@ class _TodoListCardState extends State { child: Container( margin: EdgeInsets.only(top: 20.0, left: 20.0, right: 20.0), - height: MediaQuery.of(context).size.height * 0.1, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -113,7 +112,7 @@ class _TodoListCardState extends State { Expanded( flex: 1, child: Container( - height: MediaQuery.of(context).size.height * 0.1, +// height: MediaQuery.of(context).size.height * 0.12, margin: EdgeInsets.only(top: 20.0), child: Column( children: [ diff --git a/lib/services/clinic_services/get_clinic_service.dart b/lib/services/clinic_services/get_clinic_service.dart new file mode 100644 index 00000000..5aaaab3b --- /dev/null +++ b/lib/services/clinic_services/get_clinic_service.dart @@ -0,0 +1,37 @@ +import 'package:diplomaticquarterapp/client/base_app_client.dart'; +import 'package:diplomaticquarterapp/config/config.dart'; +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; +import 'package:diplomaticquarterapp/models/Request.dart'; +import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; + +class ClinicListService { + AppSharedPreferences sharedPref = AppSharedPreferences(); + AppGlobal appGlobal = new AppGlobal(); + + Future getClinicsList() async { + Map request; + var languageID = await sharedPref.getString(APP_LANGUAGE); + Request req = appGlobal.getPublicRequest(); + request = { + "LanguageID": languageID == 'ar' ? 1 : 2, + "IPAdress": "10.20.10.20", + "VersionID": req.VersionID, + "Channel": req.Channel, + "generalid": 'Cs2020@2016\$2958', + "PatientOutSA": 0, + "TokenID": "", + "DeviceTypeID": req.DeviceTypeID, + "SessionID": null + }; + + dynamic localRes; + + await BaseAppClient.post(GET_CLINICS_LIST_URL, + onSuccess: (response, statusCode) async { + localRes = response; + }, onFailure: (String error, int statusCode) { + throw error; + }, body: request); + return Future.value(localRes); + } +}