DiscoverModule/lib/service.dart/service.dart

170 lines
5.1 KiB
Dart

import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:discover_module/constants.dart';
import 'package:discover_module/hive_fun.dart';
import 'package:hive_flutter/hive_flutter.dart';
const String curl = Constants.url;
class Callapi {
getallhcpdata() async {
// const url = 'http://127.0.0.1:8000/api/users';
// const url = 'http://192.168.2.143:8082/api/users';
// const url = 'http://192.168.172.50:8082/api/users';
// const url = 'http://192.168.172.50:8081/api/users';
const url = '$curl/users';
final response = await Dio().get(url);
final jsonresponse = response.data;
final apihcpdata = Hive.box("hcpdata");
// if (apihcpdata.isNotEmpty) {
// apihcpdata.clear();
// }
if (apihcpdata.isEmpty) {
print("alldata_is: , ${jsonresponse} ${jsonresponse.length}");
for (int i = 0; i < jsonresponse.length; i++) {
print("hcp:data_is: , ${jsonresponse[i]['email']}");
HiveFunctions.storehcpdata({
"id": jsonresponse[i]['id'],
"name": jsonresponse[i]['name'],
"email": jsonresponse[i]['email'],
"sumry": jsonresponse[i]['summarry'],
"addr": jsonresponse[i]['addr'],
"licno": jsonresponse[i]['license_no'],
"suffix": jsonresponse[i]['p_suffix'],
"spl": jsonresponse[i]['speciality'],
"sub_sp": jsonresponse[i]['sub_speciality'],
"phone_no": jsonresponse[i]['phone_no'],
"rank": jsonresponse[i]['rank'],
"score": jsonresponse[i]['score'],
"events_count": jsonresponse[i]['events_count'],
"affiliations_count": jsonresponse[i]['affiliations_count'],
"publications_count": jsonresponse[i]['publications_count'],
});
}
}
return jsonresponse;
}
getsinglehcpdata() async {
// const url = 'http://127.0.0.1:8000/api/users/1';
// const url = 'http://192.168.2.143:8082/api/users/1';
// const url = 'http://192.168.172.50:8081/api/users/1';
const url = '$curl/users/1';
final responsehcp = await Dio().post(url);
final jsonresponse1 = responsehcp.data;
// final List<dynamic> Json = json.decode(responsehcp.data);
print("Singlejsondata : ${jsonresponse1}");
return jsonresponse1;
}
getaffiliationsdata() async {
// const url = 'http://192.168.2.143:8082/api/affiliations';
// const url = 'http://192.168.172.50:8081/api/affiliations';
const url = '$curl/affiliations';
final affiliationres = await Dio().get(url);
final jsonresponse2 = affiliationres.data.take(2).toList();
return jsonresponse2;
}
getpublicationsdata() async {
//const url = 'http://192.168.2.143:8082/api/publications';
// const url = 'http://192.168.172.50:8081/api/publications';
const url = '$curl/publications';
final affiliationres = await Dio().get(url);
final jsonresponse2 = affiliationres.data.take(2).toList();
return jsonresponse2;
}
geteventsdata() async {
// const url = 'http://192.168.2.143:8082/api/events';
// const url = 'http://192.168.172.50:8081/api/events';
const url = '$curl/events';
final events = await Dio().get(url);
// final jsonEvent = events.data;
final jsonEvent = events.data;
print("All_event: $jsonEvent");
final jsonEvent1 = events.data.take(2).toList();
print("only few : $jsonEvent1");
return jsonEvent1;
}
getallaffiliationsdata() async {
// const url = 'http://192.168.2.143:8082/api/affiliations';
//const url = 'http://192.168.172.50:8081/api/affiliations';
const url = '$curl/affiliations';
final events = await Dio().get(url);
// final jsonEvent = events.data;
final jsonEvent = events.data;
print("All_event: $jsonEvent");
return jsonEvent;
}
getallpublicationsdata() async {
// const url = 'http://192.168.2.143:8082/api/publications';
//const url = 'http://192.168.172.50:8081/api/publications';
const url = '$curl/publications';
final events = await Dio().get(url);
// final jsonEvent = events.data;
final jsonEvent = events.data;
print("All_event: $jsonEvent");
return jsonEvent;
}
allgeteventsdata() async {
//const url = 'http://192.168.2.143:8082/api/events';
//const url = 'http://192.168.172.50:8081/api/events';
const url = '$curl/events';
final events = await Dio().get(url);
// final jsonEvent = events.data;
final jsonEvent = events.data;
print("All_event: $jsonEvent");
return jsonEvent;
}
getalltrials() async {
// const url = 'http://192.168.2.143:8082/api/trails';
const url = '$curl/trails';
final trials = await Dio().get(url);
final jsontrials = trials.data;
print("All_trialsss: $jsontrials");
return jsontrials;
}
getallMedicalInsightdata() async {
// const url = 'http://127.0.0.1:8000/api/users';
// const url = 'http://192.168.2.143:8082/api/users';
// const url = 'http://192.168.172.50:8082/api/users';
// const url = 'http://192.168.172.50:8081/api/users';
const url = '$curl/medicalinsight';
final response = await Dio().get(url);
final jsonresponse = response.data;
return jsonresponse;
}
}