Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab Test Information #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'dart:async';
import 'package:bloc/bloc.dart';

import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:medi_app/network/lab_test_api.dart';

part 'lab_test_list_event.dart';
part 'lab_test_list_state.dart';

class LabTestList extends Bloc<LabTestListEvent, LabTestListState> {
LabTestInformation labTestInformation;
LabTestList(this.labTestInformation) : super(LoadingLabTestDataState());

late List<List<dynamic>> labTestData;
late List<List<dynamic>> filterLabTestData;

@override
Stream<LabTestListState> mapEventToState(
LabTestListEvent event,
) async* {
if (event is GetLabTestData) {
yield LoadingLabTestDataState();

try {
labTestData = await labTestInformation.getListOfLabTest();
filterLabTestData = labTestData;
yield LoadedListState(labTestData);
} catch (e) {
yield ShowSnackBar(e.toString());
yield ErrorState(e.toString());
}
} else if (event is SearchTestData) {
try {
List<List<dynamic>> copyList = labTestData;

// hospitalCompareData = copyList;
filterLabTestData = [];

for (var element in copyList) {
if (element[0].toLowerCase().contains(event.query)) {
filterLabTestData.add(element);
}
}

if (filterLabTestData.isEmpty) {
yield ErrorState('No Result Found');
} else {
yield LoadedListState(filterLabTestData);
}
} catch (e) {
yield ErrorState('something wrong');
}
}
}
}

class LabTestInformation {
Future getListOfLabTest() async {
LabTestAPIClient labTestApiClient = LabTestAPIClient();

return labTestApiClient.fetchLabTestFromAssets();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
part of 'lab_test_list_bloc.dart';

abstract class LabTestListEvent extends Equatable {
const LabTestListEvent();
}

class GetLabTestData extends LabTestListEvent {
@override
List<Object> get props => [];
}

class SearchTestData extends LabTestListEvent {
final String query;

SearchTestData(this.query);
@override
List<Object> get props => [query];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
part of 'lab_test_list_bloc.dart';

abstract class LabTestListState extends Equatable {
const LabTestListState();
}

class LoadingLabTestDataState extends LabTestListState {
@override
// TODO: implement props
List<Object> get props => [];
}

class ErrorState extends LabTestListState {
final String message;
@override
// TODO: implement props
List<Object> get props => [message];

ErrorState(this.message);
}

class ShowSnackBar extends LabTestListState {
final String message;
ShowSnackBar(this.message);
@override
// TODO: implement props
List<Object> get props => [];
}

class LoadedListState extends LabTestListState {
final List<List<dynamic>> labTestListData;

LoadedListState(this.labTestListData);

@override
List<Object> get props => [labTestListData];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
part of 'medicine_list_bloc.dart';

abstract class MedicineListState extends Equatable {
const MedicineListState();
}

class LoadingMedicineDataState extends MedicineListState {
@override
// TODO: implement props
List<Object> get props => [];
}

class ErrorState extends MedicineListState {
final String message;
@override
// TODO: implement props
List<Object> get props => [message];

ErrorState(this.message);
}

class ShowSnackBar extends MedicineListState {
final String message;
ShowSnackBar(this.message);
@override
// TODO: implement props
List<Object> get props => [];
}

class LoadedListState extends MedicineListState {
final List<List<dynamic>> medicineListData;

LoadedListState(this.medicineListData);

@override
List<Object> get props => [medicineListData];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'dart:async';
import 'package:bloc/bloc.dart';

import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:medi_app/network/medicines_api.dart';
part 'medicine_list_event.dart';
part 'medecine_list_state.dart';

class MedicineListBloc extends Bloc<MedicineListEvent, MedicineListState> {
MedicineInformation medicineInformation;
MedicineListBloc(this.medicineInformation)
: super(LoadingMedicineDataState());

late List<List<dynamic>> medicineData;
late List<List<dynamic>> filterMedicineData;

@override
Stream<MedicineListState> mapEventToState(
MedicineListEvent event,
) async* {
if (event is GetMedicineData) {
yield LoadingMedicineDataState();

try {
medicineData = await medicineInformation.getListOfMedicines();
filterMedicineData = medicineData;
yield LoadedListState(medicineData);
} catch (e) {
yield ShowSnackBar(e.toString());
yield ErrorState(e.toString());
}
} else if (event is SearchTestData) {
try {
List<List<dynamic>> copyList = medicineData;

// hospitalCompareData = copyList;
filterMedicineData = [];

for (var element in copyList) {
if (element[0].toLowerCase().contains(event.query)) {
filterMedicineData.add(element);
}
}

if (filterMedicineData.isEmpty) {
yield ErrorState('No Result Found');
} else {
yield LoadedListState(filterMedicineData);
}
} catch (e) {
yield ErrorState('something wrong');
}
}
}
}

class MedicineInformation {
Future getListOfMedicines() async {
MedicinesApiClient medicineAPIClient = MedicinesApiClient();

return medicineAPIClient.fetchMedicinesFromAssets();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
part of 'medicine_list_bloc.dart';

abstract class MedicineListEvent extends Equatable {
const MedicineListEvent();
}

class GetMedicineData extends MedicineListEvent {
@override
List<Object> get props => [];
}

class SearchTestData extends MedicineListEvent {
final String query;

SearchTestData(this.query);
@override
List<Object> get props => [query];
}

// class UpdateTestToGetInformation extends LabTestListEvent {
// final int index;
// // final bool filteredlist;
// UpdateTestToGetInformation(this.index);
// @override
// List<Object> get props => [index];
// }

// class SelectedTheTestToGetInformation extends LabTestListEvent {
// final LabInformationScreenBloc labInformationScreenBloc;
// final int index;
// SelectedTheTestToGetInformation(this.labInformationScreenBloc, this.index);
// @override
// List<Object> get props => [labInformationScreenBloc, index];
// }
30 changes: 30 additions & 0 deletions lib/network/lab_test_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;

class LabTestAPIClient {
Future fetchLabTestFromAssets() async {
final myData =
await rootBundle.loadString("assets/data/Lab_Test_Information.csv");
List<dynamic> myDataList = myData.split("\n");
List<List<dynamic>> rowsAsListOfValues = [];
myDataList.forEach((element) {
List<dynamic> values = [];
element.split(",").forEach((elementValue) {
values.add(elementValue);
});

if (values.length > 2 &&
values[0] != null &&
values[0] != '''"''' &&
values[0].toString().length <= 35 &&
"${values[0]}".isNotEmpty) {
rowsAsListOfValues.add(values);
}
});
rowsAsListOfValues.sort((a, b) {
return a[0].toLowerCase().compareTo(b[0].toLowerCase());
});

return rowsAsListOfValues;
}
}
Loading