KonectarApp/lib/viewmodel/hcpprofprovider.dart

114 lines
3.7 KiB
Dart
Raw Normal View History

2024-09-06 06:30:31 +00:00
import 'dart:async';
2024-12-03 05:59:45 +00:00
2024-09-06 06:30:31 +00:00
import 'dart:math';
import 'package:flutter/cupertino.dart';
import 'package:hive_flutter/hive_flutter.dart';
2024-12-03 05:59:45 +00:00
import 'package:konectar_events/model/events_speakers_k1.dart';
2024-09-06 06:30:31 +00:00
import 'package:konectar_events/model/eventsdetailmodel.dart';
2024-11-19 12:57:30 +00:00
import 'package:konectar_events/model/eventspeakers.dart';
2024-09-06 06:30:31 +00:00
import 'package:konectar_events/model/sessionnotesmodel.dart';
2024-12-03 05:59:45 +00:00
import 'package:konectar_events/model/sessionstopics_model.dart';
2024-09-06 06:30:31 +00:00
import 'package:konectar_events/model/topics_cloud_model.dart';
import 'package:konectar_events/utils/apicall.dart';
import 'package:konectar_events/widgets/word_cloud.dart';
class HcpProfileProvider extends ChangeNotifier {
List<SessionNotesModel> sessionNotesList = [];
List<SessionNotesModel> allSessionNotesList = [];
int totalTopics = 0;
int totalSessions = 0;
int totalNotes = 0;
2024-12-03 05:59:45 +00:00
List<SessionsTopicsData> sessionTopics = [];
2024-09-06 06:30:31 +00:00
late Box<SessionNotesModel> box;
2024-12-03 05:59:45 +00:00
Future<void> getSessionTopics(EventSpeakersData detail) async {
sessionTopics = await ApiCall().getSessionsTopics(detail.eid!,
detail.kolId == "0" ? detail.hcpPinAlias! : detail.kolId!, detail.kId!);
totalSessions = sessionTopics.length;
notifyListeners();
}
Future<dynamic> submitSessionNotes(EventSpeakersData detail,
SessionsTopicsData sessionsTopicsData, String notes) async {
var data = await ApiCall().addSessionNotes(
sessionsTopicsData.kolEventsId!,
detail.kolId == "0" ? detail.hcpPinAlias! : detail.kolId!,
detail.eventAttendeesId!,
detail.kId!,
notes);
return data;
}
2024-09-06 06:30:31 +00:00
getCounts(Eventsdetail eventsdetail) {
List<String> topics = eventsdetail.eventTopics!.split("|");
totalTopics = topics.length;
totalSessions = int.parse(eventsdetail.numSess ?? "1");
totalNotes = sessionNotesList.length;
notifyListeners();
}
addSessionNotes(SessionNotesModel sessionNotesModel) async {
// sessionNotesList.add(sessionNotesModel);
await saveSessionData(sessionNotesModel);
notifyListeners();
}
List<SessionNotesModel> getSessionNotesList(
2024-12-03 05:59:45 +00:00
String eid, EventSpeakersData eventsdetail) {
2024-09-06 06:30:31 +00:00
print("Check hcp id");
2024-12-03 05:59:45 +00:00
print("$eid,${eventsdetail.id}");
2024-09-06 06:30:31 +00:00
sessionNotesList = sessionNotesList
.where(
(element) => element.eventid == eid,
)
.toList();
sessionNotesList = sessionNotesList.where((element) {
print("Check hcp id each");
print("${element.hcpid}");
if (element.hcpid == null) {
print("search");
String fname = element.hcpname!.split(" ")[0];
String lname = element.hcpname!.split(" ").last;
print("${element.hcpname}");
2024-12-03 05:59:45 +00:00
return fname.toLowerCase() == eventsdetail.kolFullName!.toLowerCase() &&
lname.toLowerCase() == eventsdetail.kolFullName!.toLowerCase();
2024-09-06 06:30:31 +00:00
} else {
2024-12-03 05:59:45 +00:00
return element.hcpid == eventsdetail.id;
2024-09-06 06:30:31 +00:00
}
}).toList();
totalNotes = sessionNotesList.length;
return sessionNotesList;
}
getAllSessionNotesList(String eid) async {
print("Check hcp id");
// print("$eid,$hcpid");
await getSessionData();
allSessionNotesList =
sessionNotesList.where((element) => element.eventid == eid).toList();
notifyListeners();
}
FutureOr saveSessionData(SessionNotesModel notesModel) async {
box = await Hive.openBox<SessionNotesModel>('SessionNotesModelBox');
box.add(notesModel);
await getSessionData();
notifyListeners();
}
FutureOr getSessionData() async {
box = await Hive.openBox<SessionNotesModel>('SessionNotesModelBox');
Iterable<SessionNotesModel> data = box.values;
sessionNotesList = data.toList();
notifyListeners();
// for (var obj in data) {
// sessionNotesList = new.fromJson(obj.toJson());
// }
}
}