DiscoverModule/lib/contacts_module/service.dart/k2_service/Apicall_k2.dart

637 lines
18 KiB
Dart
Raw Permalink Normal View History

2024-10-07 12:41:28 +00:00
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:discover_module/contacts_module/constants.dart';
import 'package:discover_module/contacts_module/model_class/k2_api_model/kol_Certificate_k2.dart';
import 'package:discover_module/contacts_module/model_class/k2_api_model/kol_aff_k2.dart';
import 'package:discover_module/contacts_module/model_class/k2_api_model/kol_awards_k2.dart';
import 'package:discover_module/contacts_module/model_class/k2_api_model/kol_education_k2.dart';
import 'package:discover_module/contacts_module/model_class/k2_api_model/kol_email_k2.dart';
import 'package:discover_module/contacts_module/model_class/k2_api_model/kol_event_k2.dart';
2024-11-22 10:38:43 +00:00
import 'package:discover_module/contacts_module/model_class/k2_api_model/kol_fetchnotes_k2.dart';
2024-10-07 12:41:28 +00:00
import 'package:discover_module/contacts_module/model_class/k2_api_model/kol_location_k2.dart';
import 'package:discover_module/contacts_module/model_class/k2_api_model/kol_pno_k2.dart';
import 'package:discover_module/contacts_module/model_class/k2_api_model/kol_training_k2.dart';
import 'package:discover_module/contacts_module/model_class/k2_api_model/kolcontact_list_k2.dart';
import 'package:discover_module/contacts_module/model_class/nih_model.dart';
import 'package:discover_module/contacts_module/model_class/patent_model.dart';
import 'package:discover_module/contacts_module/model_class/procedure_model.dart';
import 'package:discover_module/contacts_module/model_class/publication_model.dart';
import 'package:discover_module/contacts_module/model_class/speaker.dart';
import 'package:discover_module/contacts_module/model_class/trials.dart';
const String curl = Constants.k2url;
class CallK2api {
getallhcpdata() async {
const url = '$curl/contacts/v2/en/fetch_kols';
print("K2_Urll: $url");
final response = await Dio().post(url,
data: {"page": 1, "limit": 100},
options: Options(headers: {
"Authorization":
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
}));
print("ResponseeeeK2: ${response.statusCode}");
if (response.statusCode == 200) {
List<Datum> users = (response.data['data'] as List)
.map((userJson) => Datum.fromJson(userJson))
.toList();
return users;
}
}
getsinglehcpdata() async {
const url = '$curl/users/1';
final responsehcp = await Dio().post(url);
final jsonresponse1 = responsehcp.data;
print("Singlejsondata : ${jsonresponse1}");
return jsonresponse1;
}
Future<List<AffList>?> getaffiliationsdata(id) async {
print("Affiliation_iddd: ${id}");
var url = '$curl/affiliations/v1/en/fetch';
final affiliationres = await Dio().post(url,
data: {"page": 1, "limit": 100},
options: Options(headers: {
"Authorization":
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
}));
if (affiliationres.statusCode == 200) {
DataAffiliations dataaff = DataAffiliations.fromJson(affiliationres.data);
List<AffList> afflist = dataaff.data!;
return afflist;
}
}
getpublicationsdata(id) async {
print("getpublicationsdata_iddd: ${id}");
var url = '$curl/publications/$id';
final publicationres = await Dio().get(url);
String arrayText = '''[$publicationres]''';
final jsonresponse2 = json.decode(arrayText);
return jsonresponse2
.map((doctor) => Publications.fromJson(doctor))
.toList();
}
Future<List<EventList>?> geteventsdata(id) async {
var url = '$curl/events/v1/en/fetch';
final events = await Dio().post(url,
2024-11-22 10:38:43 +00:00
data: {"page": 1, "limit": 10},
2024-10-07 12:41:28 +00:00
options: Options(headers: {
"Authorization":
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
}));
if (events.statusCode == 200) {
DataEvent dataeve = DataEvent.fromJson(events.data);
List<EventList> evelist = dataeve.data!;
return evelist;
}
2024-11-22 10:38:43 +00:00
}
2024-10-07 12:41:28 +00:00
2024-11-22 10:38:43 +00:00
Future<List<EventList>?> geteventsdatawithid(id) async {
var url = '$curl/events/v1/en/fetch';
final events = await Dio().post(url,
data: {"page": 1, "limit": 10},
options: Options(headers: {
"Authorization":
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
}));
if (events.statusCode == 200) {
DataEvent dataeve = DataEvent.fromJson(events.data);
List<EventList> evelist = dataeve.data!;
return evelist;
}
2024-10-07 12:41:28 +00:00
}
getallaffiliationsdata() async {
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 = '$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 = '$curl/events';
final events = await Dio().get(url);
final jsonEvent = events.data;
print("All_event: $jsonEvent");
return jsonEvent;
}
getalltrials(id) async {
print("TrialsssssAPIIIIIIIIII: $id");
2024-11-22 10:38:43 +00:00
2024-10-07 12:41:28 +00:00
var url = '$curl/trails/1';
final trials = await Dio().get(url);
String dataa = "[${trials}]";
final jsontrials = jsonDecode(dataa);
print("All_trialsss: $jsontrials");
if (jsontrials.isEmpty) {
print("notnulllllll: $jsontrials");
} else {
return jsontrials.map((doctor) => Trials.fromJson(doctor)).toList();
}
}
getallMedicalInsightdata() async {
const url = '$curl/medicalinsight';
final response = await Dio().get(url);
final jsonresponse = response.data;
return jsonresponse;
}
getSpeakerdata() async {
var url = '$curl/speaker/1';
final speaker = await Dio().get(url);
print("Checkkkkk: Speakerrr: $speaker");
final List jsonspe = speaker.data; // Directly use the data
return jsonspe.map((location) => Speaker.fromJson(location)).toList();
}
getEngdata() async {
final String response = await Constants.response;
final Engagement = await json.decode(response);
final List<dynamic> eng = Engagement['Engagement'];
print("engData_isss: $eng");
return eng;
}
2024-11-22 10:38:43 +00:00
// getlocationsdata($id) async {
// var url = '$curl/location/1';
2024-10-07 12:41:28 +00:00
2024-11-22 10:38:43 +00:00
// final location = await Dio().get(url);
// print("All_locDataa: ${location.data}");
2024-10-07 12:41:28 +00:00
2024-11-22 10:38:43 +00:00
// final List jsonEvent = location.data; // Directly use the data
2024-10-07 12:41:28 +00:00
2024-11-22 10:38:43 +00:00
// print("All_locDataa123: ${jsonEvent}");
// return jsonEvent.map((location) => Loc.fromJson(location)).toList();
// }
getlocationsdata($id) async {
var url = '$curl/contacts/v2/en/kol_location_fetch';
// const url =
// 'http://192.168.2.64:8000/api/contacts/v2/en/kol_location_fetch';
2024-10-07 12:41:28 +00:00
final location = await Dio().post(url,
data: {
2024-11-22 10:38:43 +00:00
"page": $id,
2024-10-07 12:41:28 +00:00
"limit": 100,
"kol_id": "b470ae0ac9ff5cf81e2d44b8fbfe32b1"
},
options: Options(headers: {
"Authorization":
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
2024-11-22 10:38:43 +00:00
// "Bearer SIIjhONRRt8jyYqEIKb4PZYfEmKCnuSKrTU4Sdhse5c936ae"
2024-10-07 12:41:28 +00:00
}));
final List jsonEvent = location.data["data"]; // Directly use the data
if (location.statusCode == 200) {
List<Data> kolLocation = jsonEvent.map((e) => Data.fromJson(e)).toList();
print("All_locDataaK22: ${kolLocation}");
return kolLocation;
}
}
2024-11-22 10:38:43 +00:00
getphonedata($id) async {
2024-10-07 12:41:28 +00:00
var url = '$curl/contacts/v2/en/kol_phoneno_fetch';
2024-11-22 10:38:43 +00:00
//const url = 'http://192.168.2.64:8000/api/contacts/v2/en/kol_phoneno_fetch';
2024-10-07 12:41:28 +00:00
// final phoneno = await Dio().get(url);
final phoneno = await Dio().post(url,
data: {
"page": 1,
"limit": 100,
"kol_id": "b470ae0ac9ff5cf81e2d44b8fbfe32b1"
},
options: Options(headers: {
"Authorization":
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
2024-11-22 10:38:43 +00:00
// "Bearer 244|SIIjhONRRt8jyYqEIKb4PZYfEmKCnuSKrTU4Sdhse5c936ae"
2024-10-07 12:41:28 +00:00
}));
2024-11-22 10:38:43 +00:00
// if (phoneno.statusCode == 200) {
// final List jsonpno = phoneno.data["data"]; // Directly use the data
// print("All_locDataaphone_pnos: ${jsonpno}");
// DataaPnoresponse dataPno = DataaPnoresponse.fromJson(phoneno.data);
// List<DataPhno>? datalist = dataPno.data;
// print("All_kol_pnoDataa123: ${datalist}");
// return datalist;
// }
final List jsonEvent = phoneno.data["data"]; // Directly use the data
2024-10-07 12:41:28 +00:00
if (phoneno.statusCode == 200) {
2024-11-22 10:38:43 +00:00
List<DataPhno> kolPno =
jsonEvent.map((e) => DataPhno.fromJson(e)).toList();
print("All_locDataaK22: ${kolPno}");
return kolPno;
}
}
getemaildata($id) async {
var url = '$curl/contacts/v2/en/kol_email_fetch';
//const url = 'http://192.168.2.64:8000/api/contacts/v2/en/kol_email_fetch';
final email = await Dio().post(url,
data: {
"page": 1,
"limit": 100,
"kol_id": "b470ae0ac9ff5cf81e2d44b8fbfe32b1"
},
options: Options(headers: {
"Authorization":
// "Bearer 244|SIIjhONRRt8jyYqEIKb4PZYfEmKCnuSKrTU4Sdhse5c936ae"
2024-10-07 12:41:28 +00:00
2024-11-22 10:38:43 +00:00
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
}));
2024-10-07 12:41:28 +00:00
2024-11-22 10:38:43 +00:00
print("All_locDataaEmaillK22: ${email.data}");
final List jsonEvent = email.data["data"]; // Directly use the data
if (email.statusCode == 200) {
List<EmailData> emailinfo =
jsonEvent.map((e) => EmailData.fromJson(e)).toList();
2024-10-07 12:41:28 +00:00
2024-11-22 10:38:43 +00:00
print("All_EmailllllDataaK22: ${emailinfo}");
2024-10-07 12:41:28 +00:00
2024-11-22 10:38:43 +00:00
return emailinfo;
2024-10-07 12:41:28 +00:00
}
2024-11-22 10:38:43 +00:00
// if (email.statusCode == 200) {
// DataEmail email1 = DataEmail.fromJson(email.data);
// List<EmailData>? emailinfo = email1.data;
// return emailinfo;
// }
// final List jsonEvent = phoneno.data["data"]; // Directly use the data
// if (phoneno.statusCode == 200) {
// List<DataPhno> kolPno =
// jsonEvent.map((e) => DataPhno.fromJson(e)).toList();
// print("All_locDataaK22: ${kolPno}");
// return kolPno;
// }
2024-10-07 12:41:28 +00:00
}
2024-11-22 10:38:43 +00:00
Future<List<EmailData>?> oldgetemaildata($id) async {
2024-10-07 12:41:28 +00:00
var url = '$curl/contacts/v2/en/kol_email_fetch';
2024-11-22 10:38:43 +00:00
//const url = 'http://192.168.2.64:8000/api/contacts/v2/en/kol_email_fetch';
2024-10-07 12:41:28 +00:00
final email = await Dio().post(url,
data: {
"page": 1,
"limit": 100,
"kol_id": "b470ae0ac9ff5cf81e2d44b8fbfe32b1"
},
options: Options(headers: {
"Authorization":
2024-11-22 10:38:43 +00:00
// "Bearer 244|SIIjhONRRt8jyYqEIKb4PZYfEmKCnuSKrTU4Sdhse5c936ae"
2024-10-07 12:41:28 +00:00
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
}));
print("All_locDataaEmaillK22: ${email.data}");
if (email.statusCode == 200) {
DataEmail email1 = DataEmail.fromJson(email.data);
List<EmailData>? emailinfo = email1.data;
return emailinfo;
}
}
getpatentdata(id) async {
var url = '$curl/patent/1';
final patent = await Dio().get(url);
print("All_locDataa: ${patent.data}");
final List jsonEvent = patent.data; // Directly use the data
print("All_locDataa123: ${jsonEvent}");
return jsonEvent.map((email) => Patent.fromJson(email)).toList();
}
Future<List<CertificateList>?> getcerlistdata(id) async {
var url = '$curl/contacts/v2/en/kol_certification_fetch';
2024-11-22 10:38:43 +00:00
// const url =
// 'http://192.168.2.64:8000/api/contacts/v2/en/kol_certification_fetch';
2024-10-07 12:41:28 +00:00
final cer = await Dio().post(url,
data: {
"page": 1,
"limit": 100,
"kol_id": "b470ae0ac9ff5cf81e2d44b8fbfe32b1"
},
options: Options(headers: {
"Authorization":
2024-11-22 10:38:43 +00:00
// "Bearer 244|SIIjhONRRt8jyYqEIKb4PZYfEmKCnuSKrTU4Sdhse5c936ae"
2024-10-07 12:41:28 +00:00
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
}));
print("All_locDataa: ${cer.data}");
if (cer.statusCode == 200) {
DataCertificate datacer = DataCertificate.fromJson(cer.data);
List<CertificateList>? cerlist = datacer.data;
return cerlist;
}
}
Future<List<EducationList>?> getedulistdata($id) async {
var url = '$curl/contacts/v2/en/kol_education_fetch';
2024-11-22 10:38:43 +00:00
// const url =
// 'http://192.168.2.64:8000/api/contacts/v2/en/kol_education_fetch';
2024-10-07 12:41:28 +00:00
final edu = await Dio().post(url,
data: {
"page": 1,
"limit": 100,
"kol_id": "b470ae0ac9ff5cf81e2d44b8fbfe32b1"
},
options: Options(headers: {
"Authorization":
2024-11-22 10:38:43 +00:00
// "Bearer 244|SIIjhONRRt8jyYqEIKb4PZYfEmKCnuSKrTU4Sdhse5c936ae"
2024-10-07 12:41:28 +00:00
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
}));
print("All_locDataa: ${edu.data}");
if (edu.statusCode == 200) {
DataEducation dataedu = DataEducation.fromJson(edu.data);
List<EducationList>? edulist = dataedu.data;
return edulist;
}
}
Future<List<AwardsList>?> getawarddata(id) async {
var url = '$curl/contacts/v2/en/kol_awards_fetch';
final awa = await Dio().post(url,
data: {
"page": 1,
"limit": 100,
"kol_id": "b470ae0ac9ff5cf81e2d44b8fbfe32b1"
},
options: Options(headers: {
"Authorization":
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
}));
print("All_locDataa: ${awa.data}");
if (awa.statusCode == 200) {
DataAwards awardss = DataAwards.fromJson(awa.data);
List<AwardsList> awalist = awardss.data!;
return awalist;
}
}
Future<List<TrainingList>?> gettrainingdata(id) async {
var url = '$curl/contacts/v2/en/kol_training_fetch';
2024-11-22 10:38:43 +00:00
// const url =
// 'http://192.168.2.64:8000/api/contacts/v2/en/kol_training_fetch';
2024-10-07 12:41:28 +00:00
final training = await Dio().post(url,
data: {
"page": 1,
"limit": 100,
"kol_id": "b470ae0ac9ff5cf81e2d44b8fbfe32b1"
},
options: Options(headers: {
"Authorization":
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
2024-11-22 10:38:43 +00:00
// "Bearer 244|SIIjhONRRt8jyYqEIKb4PZYfEmKCnuSKrTU4Sdhse5c936ae"
2024-10-07 12:41:28 +00:00
}));
print("All_locDataa:Training: ${training.data}");
if (training.statusCode == 200) {
DataTraining trainingdata = DataTraining.fromJson(training.data);
List<TrainingList>? traininglist = trainingdata.data;
return traininglist;
}
}
getnihdata(id) async {
var url = '$curl/nih/1';
final nih = await Dio().get(url);
print("All_locDataa: ${nih.data}");
final List jsonEvent = nih.data; // Directly use the data
print("All_locDataa123: ${jsonEvent}");
return jsonEvent.map((awards) => Nih.fromJson(awards)).toList();
}
getprodata(id) async {
var url = '$curl/pro/1';
final pro = await Dio().get(url);
print("All_locDataa: ${pro.data}");
final List jsonEvent = pro.data; // Directly use the data
print("All_locDataa123: ${jsonEvent}");
return jsonEvent.map((awards) => Pro.fromJson(awards)).toList();
}
2024-11-22 10:38:43 +00:00
// geteventsdatapagelimit(int page, int limit) {}
Future<List<EventList>?> geteventsdatapagelimit(int page, int limit) async {
var url = '$curl/events/v1/en/fetch';
final events = await Dio().post(url,
data: {"page": page, "limit": limit},
options: Options(headers: {
"Authorization":
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
}));
if (events.statusCode == 200) {
DataEvent dataeve = DataEvent.fromJson(events.data);
List<EventList> evelist = dataeve.data!;
return evelist;
}
return null;
}
Future<List<HcpNotes>?> getallnotes(int page, int limit) async {
var url = '$curl/contacts/v2/en/kol_note_fetch';
final allnotes = await Dio().post(url,
data: {
"page": page,
"limit": limit,
"kol_id": "b470ae0ac9ff5cf81e2d44b8fbfe32b1"
},
options: Options(headers: {
"Authorization":
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
}));
if (allnotes.statusCode == 200) {
FetchNotes notes = FetchNotes.fromJson(allnotes.data);
List<HcpNotes> noteslist = notes.data!;
print("GetAllNotesss: $noteslist");
return noteslist;
}
return null;
}
addnotesapi(String data, [uniqueId]) async {
try {
var url = '$curl/contacts/v2/en/kol_note_upsert';
Map<String, dynamic> requestData = {
"note": data,
"kol_id": "b470ae0ac9ff5cf81e2d44b8fbfe32b1"
};
// If `id` is provided, add it to the request data for update
if (uniqueId != null && uniqueId.isNotEmpty) {
requestData["id"] = uniqueId;
}
print("I_amRequesting_Daataa_issss: $requestData");
final allnotes = await Dio().post(url,
data: requestData,
// {
// "note": data,
// "kol_id": "b470ae0ac9ff5cf81e2d44b8fbfe32b1"
// // "id": "adc0724ea70c51ff2bf01bfd37b43f09"
// },
options: Options(headers: {
"Authorization":
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
}));
if (allnotes.statusCode == 200) {
// String response = "[${allnotes.data}]";
// print("RREESSPPOONNSSEE: ${allnotes.data}");
// List<dynamic> jsonList = jsonDecode(response);
// return jsonList;
List<Map<String, dynamic>> jsonList = [allnotes.data];
return jsonList;
// FetchNotes notes = FetchNotes.fromJson(allnotes.data);
// List<HcpNotes> noteslist = notes.data!;
// print("GetAllNotesss: $noteslist");
// return noteslist;
} else {
return allnotes.data;
}
} catch (e) {
print("Error occurred: $e");
}
}
deletenotesapi(uniqueId) async {
var url = '$curl/contacts/v2/en/kol_note_delete';
final allnotes = await Dio().post(url,
data: {"id": uniqueId},
options: Options(headers: {
"Authorization":
"Bearer 245|J1GeqJKw33m4YhCOfiMNyQm2U8jbx8rf1JkC567ffcb2f9bd"
}));
if (allnotes.statusCode == 200) {
// FetchNotes notes = FetchNotes.fromJson(allnotes.data);
// List<HcpNotes> noteslist = notes.data!;
// print("GetAllNotesss: $noteslist");
// return noteslist;
List<Map<String, dynamic>> jsonList = [allnotes.data];
print("DELETE_List_isss: ${jsonList}");
return jsonList;
}
return null;
}
2024-10-07 12:41:28 +00:00
}