Address Added Successfully

merge-update-with-lab-changes
Elham Rababah 5 years ago
parent ed56476d81
commit 68e4b92717

@ -8,6 +8,7 @@ import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealth
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/get_order_detail_by_order_iD_response_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/patient_er_insert_pres_order_request_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/update_pres_oreder_request_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/add_new_address_Request_Model.dart';
import '../base_service.dart';
@ -93,6 +94,22 @@ class HomeHealthCareService extends BaseService {
}, body: order.toJson());
}
Future addAddressInfo({ AddNewAddressRequestModel
addNewAddressRequestModel }) async {
hasError = false;
await baseAppClient.post("https://mdlaboratories.com/exacartapi/api/addcustomeraddress",
onSuccess: (dynamic response, int statusCode) {
addressesList.clear();
response["customers"][0]["addresses"].forEach((data) {
addressesList
.add(AddressInfo.fromJson(data));
});
}, onFailure: (String error, int statusCode) {
hasError = true;
super.error = error;
}, body: addNewAddressRequestModel.toJson(), isExternal: true, isAllowAny: true);
}
Future getCustomerAddresses() async {
Map<String, String> queryParams = {
'fields':'addresses'

@ -31,74 +31,81 @@ class BaseAppClient {
{Map<String, dynamic> body,
Function(dynamic response, int statusCode) onSuccess,
Function(String error, int statusCode) onFailure,
bool isAllowAny = false}) async {
String url = BASE_URL + endPoint;
bool isAllowAny = false, bool isExternal = false}) async {
String url;
if(isExternal) {
url = endPoint;
}else{
url = BASE_URL + endPoint;
}
try {
//Map profile = await sharedPref.getObj(DOCTOR_PROFILE);
String token = await sharedPref.getString(TOKEN);
var languageID =
await sharedPref.getString(APP_LANGUAGE);
var user = await sharedPref.getObject(USER_PROFILE);
if (body.containsKey('SetupID')) {
body['SetupID'] = body.containsKey('SetupID')
? body['SetupID'] != null
? body['SetupID']
: SETUP_ID
: SETUP_ID;
}
body['VersionID'] = VERSION_ID;
body['Channel'] = CHANNEL;
body['LanguageID'] = body.containsKey('LanguageID')
? body['LanguageID'] != null
? body['LanguageID']
: languageID == 'ar'
? 1
: 2
: languageID == 'ar'
? 1
: 2;
body['IPAdress'] = IP_ADDRESS;
body['generalid'] = GENERAL_ID;
body['PatientOutSA'] = body.containsKey('PatientOutSA')
? body['PatientOutSA'] != null
? body['PatientOutSA']
: PATIENT_OUT_SA
: PATIENT_OUT_SA;
if (body.containsKey('isDentalAllowedBackend')) {
body['isDentalAllowedBackend'] =
body.containsKey('isDentalAllowedBackend')
? body['isDentalAllowedBackend'] != null
? body['isDentalAllowedBackend']
: IS_DENTAL_ALLOWED_BACKEND
: IS_DENTAL_ALLOWED_BACKEND;
}
if (!isExternal) {
String token = await sharedPref.getString(TOKEN);
var languageID =
await sharedPref.getString(APP_LANGUAGE);
var user = await sharedPref.getObject(USER_PROFILE);
if (body.containsKey('SetupID')) {
body['SetupID'] = body.containsKey('SetupID')
? body['SetupID'] != null
? body['SetupID']
: SETUP_ID
: SETUP_ID;
}
body['VersionID'] = VERSION_ID;
body['Channel'] = CHANNEL;
body['LanguageID'] = body.containsKey('LanguageID')
? body['LanguageID'] != null
? body['LanguageID']
: languageID == 'ar'
? 1
: 2
: languageID == 'ar'
? 1
: 2;
body['IPAdress'] = IP_ADDRESS;
body['generalid'] = GENERAL_ID;
body['PatientOutSA'] = body.containsKey('PatientOutSA')
? body['PatientOutSA'] != null
? body['PatientOutSA']
: PATIENT_OUT_SA
: PATIENT_OUT_SA;
if (body.containsKey('isDentalAllowedBackend')) {
body['isDentalAllowedBackend'] =
body.containsKey('isDentalAllowedBackend')
? body['isDentalAllowedBackend'] != null
? body['isDentalAllowedBackend']
: IS_DENTAL_ALLOWED_BACKEND
: IS_DENTAL_ALLOWED_BACKEND;
}
body['DeviceTypeID'] = DeviceTypeID;
if (!body.containsKey('IsPublicRequest')) {
body['PatientType'] = body.containsKey('PatientType')
? body['PatientType'] != null
? body['PatientType']
: user['PatientType'] != null
? user['PatientType']
: PATIENT_TYPE
: PATIENT_TYPE;
body['PatientTypeID'] = body.containsKey('PatientTypeID')
? body['PatientTypeID'] != null
? body['PatientTypeID']
:user['PatientType'] != null
? user['PatientType']
: PATIENT_TYPE_ID
: PATIENT_TYPE_ID;
if (user != null) {
body['TokenID'] = token;
body['PatientID'] =
body['PatientID'] != null ? body['PatientID'] : user['PatientID'];
body['PatientOutSA'] = user['OutSA'];
body['SessionID'] = SESSION_ID; //getSessionId(token);
body['DeviceTypeID'] = DeviceTypeID;
if (!body.containsKey('IsPublicRequest')) {
body['PatientType'] = body.containsKey('PatientType')
? body['PatientType'] != null
? body['PatientType']
: user['PatientType'] != null
? user['PatientType']
: PATIENT_TYPE
: PATIENT_TYPE;
body['PatientTypeID'] = body.containsKey('PatientTypeID')
? body['PatientTypeID'] != null
? body['PatientTypeID']
:user['PatientType'] != null
? user['PatientType']
: PATIENT_TYPE_ID
: PATIENT_TYPE_ID;
if (user != null) {
body['TokenID'] = token;
body['PatientID'] =
body['PatientID'] != null ? body['PatientID'] : user['PatientID'];
body['PatientOutSA'] = user['OutSA'];
body['SessionID'] = SESSION_ID; //getSessionId(token);
}
}
}

@ -0,0 +1,136 @@
class AddNewAddressRequestModel {
Customer customer;
AddNewAddressRequestModel({this.customer});
AddNewAddressRequestModel.fromJson(Map<String, dynamic> json) {
customer = json['customer'] != null
? new Customer.fromJson(json['customer'])
: null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.customer != null) {
data['customer'] = this.customer.toJson();
}
return data;
}
}
class Customer {
List<Addresses> addresses;
int id;
String email;
List<int> roleIds;
Customer({this.addresses, this.id, this.email, this.roleIds});
Customer.fromJson(Map<String, dynamic> json) {
if (json['addresses'] != null) {
addresses = new List<Addresses>();
json['addresses'].forEach((v) {
addresses.add(new Addresses.fromJson(v));
});
}
id = json['id'];
email = json['email'];
roleIds = json['role_ids'].cast<int>();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.addresses != null) {
data['addresses'] = this.addresses.map((v) => v.toJson()).toList();
}
data['id'] = this.id;
data['email'] = this.email;
data['role_ids'] = this.roleIds;
return data;
}
}
class Addresses {
int id;
String firstName;
String lastName;
String email;
Null company;
int countryId;
String country;
Null stateProvinceId;
String city;
String address1;
String address2;
String zipPostalCode;
String phoneNumber;
Null faxNumber;
String customerAttributes;
String createdOnUtc;
Null province;
String latLong;
Addresses(
{this.id,
this.firstName,
this.lastName,
this.email,
this.company,
this.countryId,
this.country,
this.stateProvinceId,
this.city,
this.address1,
this.address2,
this.zipPostalCode,
this.phoneNumber,
this.faxNumber,
this.customerAttributes,
this.createdOnUtc,
this.province,
this.latLong});
Addresses.fromJson(Map<String, dynamic> json) {
id = json['id'];
firstName = json['first_name'];
lastName = json['last_name'];
email = json['email'];
company = json['company'];
countryId = json['country_id'];
country = json['country'];
stateProvinceId = json['state_province_id'];
city = json['city'];
address1 = json['address1'];
address2 = json['address2'];
zipPostalCode = json['zip_postal_code'];
phoneNumber = json['phone_number'];
faxNumber = json['fax_number'];
customerAttributes = json['customer_attributes'];
createdOnUtc = json['created_on_utc'];
province = json['province'];
latLong = json['lat_long'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['first_name'] = this.firstName;
data['last_name'] = this.lastName;
data['email'] = this.email;
data['company'] = this.company;
data['country_id'] = this.countryId;
data['country'] = this.country;
data['state_province_id'] = this.stateProvinceId;
data['city'] = this.city;
data['address1'] = this.address1;
data['address2'] = this.address2;
data['zip_postal_code'] = this.zipPostalCode;
data['phone_number'] = this.phoneNumber;
data['fax_number'] = this.faxNumber;
data['customer_attributes'] = this.customerAttributes;
data['created_on_utc'] = this.createdOnUtc;
data['province'] = this.province;
data['lat_long'] = this.latLong;
return data;
}
}

@ -10,8 +10,10 @@ import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealth
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/update_pres_oreder_request_model.dart';
import 'package:diplomaticquarterapp/core/service/AlHabibMedicalService/home_health_care_service.dart';
import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart';
import 'package:intl/intl.dart';
import '../../../locator.dart';
import 'add_new_address_Request_Model.dart';
class HomeHealthCareViewModel extends BaseViewModel {
HomeHealthCareService _homeHealthCareService =
@ -121,5 +123,32 @@ class HomeHealthCareViewModel extends BaseViewModel {
}
}
Future addAddressInfo(
{AddNewAddressRequestModel addNewAddressRequestModel}) async {
addNewAddressRequestModel.customer.email = _homeHealthCareService.customerInfo.email;
addNewAddressRequestModel.customer.id = _homeHealthCareService.customerInfo.customerId;
addNewAddressRequestModel.customer.roleIds = [3];
addNewAddressRequestModel.customer.addresses[0].email = _homeHealthCareService.customerInfo.email;
addNewAddressRequestModel.customer.addresses[0].phoneNumber = _homeHealthCareService.customerInfo.mobileNumber;
addNewAddressRequestModel.customer.addresses[0].firstName = user.firstName;
addNewAddressRequestModel.customer.addresses[0].lastName = user.lastName;
addNewAddressRequestModel.customer.addresses[0].countryId = 69;
var f = DateFormat('E, d MMM yyyy HH:mm:ss');
var date = f.format(DateTime.now().toUtc()) + " GMT";
addNewAddressRequestModel.customer.addresses[0].createdOnUtc = date;
setState(ViewState.Busy);
await _homeHealthCareService.addAddressInfo(
addNewAddressRequestModel: addNewAddressRequestModel
);
if (_homeHealthCareService.hasError) {
error = _homeHealthCareService.error;
setState(ViewState.ErrorLocal);
} else {
setState(ViewState.Idle);
}
}
}

@ -1,8 +1,11 @@
import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/patient_er_insert_pres_order_request_model.dart';
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/add_new_address_Request_Model.dart';
import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/home_health_care_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
@ -16,12 +19,7 @@ class LocationPage extends StatefulWidget {
final double latitude;
final double longitude;
const LocationPage(
{Key key,
this.onPick,
this.latitude,
this.longitude,
})
const LocationPage({Key key, this.onPick, this.latitude, this.longitude})
: super(key: key);
@override
@ -46,20 +44,23 @@ class _LocationPageState
@override
Widget build(BuildContext context) {
ProjectViewModel projectViewModel = Provider.of(context);
return AppScaffold(
isShowDecPage: false,
isShowAppBar: true,
body: PlacePicker(
apiKey: GOOGLE_API_KEY,
enableMyLocationButton: true,
automaticallyImplyAppBarLeading: false,
autocompleteOnTrailingWhitespace: true,
selectInitialPosition: true,
autocompleteLanguage: projectViewModel.currentLanguage,
enableMapTypeButton: true,
searchForInitialValue: false,
onPlacePicked: (PickResult result) {
print(result.adrAddress);
return BaseView<HomeHealthCareViewModel>(
onModelReady: (model) {},
builder: (_, model, widget) => AppScaffold(
isShowDecPage: false,
isShowAppBar: true,
baseViewModel: model,
body: PlacePicker(
apiKey: GOOGLE_API_KEY,
enableMyLocationButton: true,
automaticallyImplyAppBarLeading: false,
autocompleteOnTrailingWhitespace: true,
selectInitialPosition: true,
autocompleteLanguage: projectViewModel.currentLanguage,
enableMapTypeButton: true,
searchForInitialValue: false,
onPlacePicked: (PickResult result) {
print(result.adrAddress);
},
selectedPlaceWidgetBuilder:
@ -82,27 +83,63 @@ class _LocationPageState
SecondaryButton(
color: Colors.grey[800],
textColor: Colors.white,
onTap: () {
onTap: () async {
print(selectedPlace);
// setState(() {
// widget.patientERInsertPresOrderRequestModel
// .latitude =
// selectedPlace.geometry.location.lat;
// widget.patientERInsertPresOrderRequestModel
// .longitude =
// selectedPlace.geometry.location.lng;
// });
AddNewAddressRequestModel
addNewAddressRequestModel =
new AddNewAddressRequestModel(
customer: Customer(addresses: [
Addresses(
address1:
selectedPlace.formattedAddress,
address2: selectedPlace
.formattedAddress,
customerAttributes: "",
city: "",
createdOnUtc: "",
id: 0,
latLong: "$latitude,$longitude",
email: "")
]),
);
selectedPlace.addressComponents.forEach((e) {
if (e.types.contains("country")) {
addNewAddressRequestModel.customer
.addresses[0].country = e.longName;
}
if (e.types.contains("postal_code")) {
addNewAddressRequestModel.customer
.addresses[0].zipPostalCode =
e.longName;
}
if (e.types.contains("locality")) {
addNewAddressRequestModel.customer
.addresses[0].city =
e.longName;
}
});
await model.addAddressInfo(
addNewAddressRequestModel: addNewAddressRequestModel);
if (model.state == ViewState.ErrorLocal) {
Utils.showErrorToast(model.error);
} else {
AppToast.showSuccessToast(
message: "Address Added Successfully");
}
Navigator.of(context).pop();
},
label: " Add New Address ",
),
],
),
),
);
),
);
},
initialPosition: LatLng(latitude, longitude),
useCurrentLocation: false,
),
);
initialPosition: LatLng(latitude, longitude),
useCurrentLocation: false,
),
));
}
}

@ -47,7 +47,6 @@ class _NewHomeHealthCareStepTowPageState
@override
void initState() {
print(widget.model.addressesList);
if (widget.patientERInsertPresOrderRequestModel.latitude == null) {
setLatitudeAndLongitude();
} else {
@ -110,12 +109,17 @@ class _NewHomeHealthCareStepTowPageState
color: Colors.grey[800],
textColor: Colors.white,
onTap: () {
Navigator.pushReplacement(
context, MaterialPageRoute(
builder: (BuildContext context) =>
LocationPage(latitude: latitude,
longitude: longitude,)));
},
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
LocationPage(
latitude: latitude,
longitude: longitude,
),
),
);
},
label: " Add New Address ",
),
SizedBox(height: 10,),

Loading…
Cancel
Save