sendCollection method

void sendCollection(
  1. HCP? hcp,
  2. List<String>? rxCodes,
  3. List<String>? dxCodes,
  4. List<String>? editorialTags,
  5. Map<String, String>? event,
)

Implementation

void sendCollection(HCP? hcp, List<String>? rxCodes, List<String>? dxCodes,
    List<String>? editorialTags, Map<String, String>? event) async {
  var platformId = 0;
  List<String> installApps = <String>[];
  if(defaultTargetPlatform == TargetPlatform.android) {
    platformId = 3;
    await Utill.getInstalledApp().then((value) => installApps = value);
  }else if(defaultTargetPlatform == TargetPlatform.iOS){
    platformId = 4;
  }else if(kIsWeb){
    platformId = 2;
  }

  Header header = Header();
  Map<String, dynamic> data = {};
  CollectData platformData = CollectData();
  await header.getDeviceId().then((value) => data[platformData.udid] = value);
  data[platformData.bundleID] = header.bundle;
  data[platformData.hcpId] = hcp?.hashedHcpId;
  data[platformData.platformID] = platformId.toString();
  data[platformData.dataSource] = 2.toString();
  // data[platformData.ScreenPath] = "";
  data[platformData.editorialTags] = editorialTags;
  data[platformData.localTimestamp] = DateTimeFormat().getCurrentDateTime().toString();
  data[platformData.installedApps] = installApps;
  data[platformData.privateMode] = "0";
  data[platformData.gps] = "lat=33.961,lon=-84.220";
  data[platformData.event] = event;
  data[platformData.platformData] = getPlatformData(hcp, rxCodes, dxCodes);
  data[platformData.partnerData] = getPartnerData(hcp);
  Log(tag).i("Data Collection Call ${Network.getDataCollectionBaseUrl()}${Network.dataCollectionTrackPath}");
  Log(tag).i("Headers ${header.getHeaders().toString()}");
  List<Map<String, dynamic>> list = [];
  list.add(data);
  // String encoded = json.encode(data.toString());
  var dataCollection = DataCollection.fromJson(data);
  // Log(TAG).i("MapData ${json.encode(dataCollection)}");
  // Log(TAG).i("MapData ${dataCollection}");
  var response = await http.post(
    Uri.parse(Network.getDataCollectionBaseUrl()+Network.dataCollectionTrackPath),
    headers: header.getHeaders(),
    body: json.encode(dataCollection),
  );

  if(response.statusCode == 201 || response.statusCode == 200){
    Log(tag).i("Data Collecton Success");
  }else{
    Log(tag).i("Data Collection Error ${response.statusCode} : ${response.body}");
  }
}