DiscoverModule/lib/service.dart/service.dart

170 lines
5.1 KiB
Dart
Raw Normal View History

2024-06-27 08:38:43 +00:00
import 'dart:convert';
import 'package:dio/dio.dart';
2024-07-05 08:48:29 +00:00
import 'package:discover_module/constants.dart';
2024-06-27 08:38:43 +00:00
import 'package:discover_module/hive_fun.dart';
import 'package:hive_flutter/hive_flutter.dart';
2024-07-05 08:48:29 +00:00
const String curl = Constants.url;
2024-06-27 08:38:43 +00:00
class Callapi {
getallhcpdata() async {
// const url = 'http://127.0.0.1:8000/api/users';
2024-07-05 08:48:29 +00:00
// 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';
2024-06-27 08:38:43 +00:00
final response = await Dio().get(url);
final jsonresponse = response.data;
2024-06-28 08:14:42 +00:00
final apihcpdata = Hive.box("hcpdata");
2024-06-27 08:38:43 +00:00
// if (apihcpdata.isNotEmpty) {
// apihcpdata.clear();
// }
2024-06-28 08:14:42 +00:00
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'],
});
}
2024-06-27 08:38:43 +00:00
}
return jsonresponse;
}
getsinglehcpdata() async {
// const url = 'http://127.0.0.1:8000/api/users/1';
2024-07-05 08:48:29 +00:00
// 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';
2024-06-27 08:38:43 +00:00
final responsehcp = await Dio().post(url);
final jsonresponse1 = responsehcp.data;
// final List<dynamic> Json = json.decode(responsehcp.data);
print("Singlejsondata : ${jsonresponse1}");
return jsonresponse1;
}
2024-07-05 08:48:29 +00:00
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;
}
2024-07-24 08:23:02 +00:00
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;
}
2024-06-27 08:38:43 +00:00
}