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

Joshua.documentation #72

Open
wants to merge 3 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,42 @@ import 'package:hakim_hub_mobile/features/hospital/data/models/hospital_doctor_m
import 'package:hakim_hub_mobile/features/hospital/domain/usecases/get_doctor_by_filter.dart';
import 'package:http/http.dart' as http;

/// Hospital detail remote data source.
///
/// Contains methods for retrieving hospital and doctor data from a remote API.
abstract class HospitalDetailRemoteDataSource {
Future<InstitutionDetailModel> getHospitalDetail(String hospitalID);
/// Gets the detail information for a hospital.
///
/// Fetches the hospital data from the `/InsitutionProfile/{id}` endpoint.
/// Throws a [ServerException] for all error codes.
///
/// Parameters:
/// hospitalId: The ID of the hospital to get details for.
/// Returns: The [InstitutionDetailModel] for the hospital.
Future<InstitutionDetailModel> getHospitalDetail(String hospitalId);

/// Gets doctors filtered by the provided criteria.
///
/// Calls the `/DoctorProfiles/filter` endpoint to find doctors.
/// Throws a [ServerException] for any errors.
///
/// Parameters:
/// doctorFilterModel: The filter criteria to find doctors by.
/// Returns: A list of [DoctorModel] matching the filter.
Future<List<DoctorModel>> getDoctorByFilter(
DoctorFilterModel doctorFilterModel);
}

/// Implementation of [HospitalDetailRemoteDataSource] that uses an HTTP client.
class HospitalDetailRemoteDataSoureImpl
implements HospitalDetailRemoteDataSource {
/// The HTTP client for making requests.
final http.Client client;

/// Base API URL.
String baseUrl = getBaseUrl();

/// Creates an instance with the provided [client].
HospitalDetailRemoteDataSoureImpl({required this.client});

@override
Expand All @@ -30,13 +56,14 @@ class HospitalDetailRemoteDataSoureImpl
HttpHeaders.contentTypeHeader: 'application/json',
},
);

if (response.statusCode == 200) {
final responseBody = response.body;

if (responseBody.isNotEmpty) {
final Map<String, dynamic> json = jsonDecode(responseBody)["value"];
InstitutionDetailModel institutionDetailModel =
InstitutionDetailModel.fromJson(json);
return institutionDetailModel;

return InstitutionDetailModel.fromJson(json);
} else {
throw ServerException();
}
Expand Down Expand Up @@ -73,8 +100,6 @@ class HospitalDetailRemoteDataSoureImpl
throw ServerException();
}
} catch (e) {
print(e.toString());

throw ServerException();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


import 'dart:convert';
import 'dart:io';

Expand All @@ -10,52 +8,83 @@ import 'package:http/http.dart' as http;

import '../models/hospital_search_model.dart';


/// Remote data source for searching hospitals.
///
/// Provides methods for searching for hospitals by different criteria.
abstract class HospitalSearchRemoteDataSource {
/// Searches for hospitals matching the filter criteria.
///
/// Calls the `/InsitutionProfile/search-institutions` endpoint to find hospitals.
/// Throws a [ServerException] on any error.
///
/// Parameters:
/// filterHospitalModel: Filter criteria to search by.
/// Returns: List of [InstitutionSearchModel] matching the filter.
Future<List<InstitutionSearchModel>> searchByFilterHospitals(
FilterHospitalModel filterHospitalModel);

Future<List<InstitutionSearchModel>> searchByNameHospitals(
String name);
/// Searches hospitals by name.
///
/// Calls `/InsitutionProfile/search-by-name` to find hospitals.
/// Throws a [ServerException] on any error.
///
/// Parameters:
/// name: Name to search hospitals by.
/// Returns: List of [InstitutionSearchModel] matching the name.
Future<List<InstitutionSearchModel>> searchByNameHospitals(String name);

/// Gets all hospitals.
///
/// Calls `/InsitutionProfile` to retrieve all hospitals.
/// Throws a [ServerException] on any error.
///
/// Returns: List of all [InstitutionSearchModel] hospitals.
Future<List<InstitutionSearchModel>> getAllHospitals();
}

class HospitalSearchRemoteDataSourceImpl implements HospitalSearchRemoteDataSource {
/// Implementation of [HospitalSearchRemoteDataSource] using HTTP client.
class HospitalSearchRemoteDataSourceImpl
implements HospitalSearchRemoteDataSource {
/// HTTP client for making requests.
final http.Client client;

/// Base API URL.
String baseUrl = getBaseUrl();

/// Creates an instance with the provided HTTP [client].
HospitalSearchRemoteDataSourceImpl({required this.client});

@override
Future<List<InstitutionSearchModel>> searchByFilterHospitals(FilterHospitalModel filterHospitalModel) async {

Future<List<InstitutionSearchModel>> searchByFilterHospitals(
FilterHospitalModel filterHospitalModel) async {
try {

final response = await client.post(

Uri.parse(baseUrl + '/InsitutionProfile/search-institutions?operationYears=${filterHospitalModel.operationYears}&openStatus=${filterHospitalModel.openStatus}'),
Uri.parse(baseUrl +
'/InsitutionProfile/search-institutions?operationYears=${filterHospitalModel.operationYears}&openStatus=${filterHospitalModel.openStatus}'),
headers: {
HttpHeaders.contentTypeHeader: 'application/json',
},
body: json.encode(filterHospitalModel.services),
);

if (response.statusCode == 200) {

List<dynamic> returned = json.decode(response.body)["value"];

List<InstitutionSearchModel> hospitals = returned.map((data) => InstitutionSearchModel.fromJson(data)).toList();
List<InstitutionSearchModel> hospitals = returned
.map((data) => InstitutionSearchModel.fromJson(data))
.toList();
return hospitals;
} else {
throw ServerException();
}

} catch (e) {
throw ServerException();
}
}

@override
Future<List<InstitutionSearchModel>> searchByNameHospitals(String name) async {
Future<List<InstitutionSearchModel>> searchByNameHospitals(
String name) async {
try {
final response = await client.get(
Uri.parse(baseUrl + '/InsitutionProfile/search-by-name?Name=$name'),
Expand All @@ -65,46 +94,42 @@ class HospitalSearchRemoteDataSourceImpl implements HospitalSearchRemoteDataSour
);

if (response.statusCode == 200) {

List<dynamic> returned = json.decode(response.body)["value"];

List<InstitutionSearchModel> hospitals = returned.map((data) => InstitutionSearchModel.fromJson(data)).toList();
List<InstitutionSearchModel> hospitals = returned
.map((data) => InstitutionSearchModel.fromJson(data))
.toList();
return hospitals;
} else {
throw ServerException();
}

} catch (e) {
throw ServerException();
}
}

@override
Future<List<InstitutionSearchModel>> getAllHospitals() async {

try {
final response = await client.get(
Uri.parse(baseUrl + '/InsitutionProfile'),
headers: {
HttpHeaders.contentTypeHeader: 'application/json',
},
);


if (response.statusCode == 200) {

List<dynamic> returned = json.decode(response.body)["value"];

List<InstitutionSearchModel> hospitals = returned.map((data) => InstitutionSearchModel.fromJson(data)).toList();
List<InstitutionSearchModel> hospitals = returned
.map((data) => InstitutionSearchModel.fromJson(data))
.toList();
return hospitals;
} else {

throw ServerException();
}

} catch (e) {
throw ServerException();
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import 'package:hakim_hub_mobile/features/hospital/domain/entities/educational_institute.dart';

/// Model representing an educational institution.
class EducationInstituteModel extends EductationalInstitutionDomain {
/// Name of the educational institution.
String institutionName;

/// URL of the institution's logo.
String logoUrl;

/// Unique ID for the institution.
String id;

/// Create an instance from the provided data.
EducationInstituteModel({
required this.institutionName,
required this.logoUrl,
required this.id,
}) : super(id: id, institutionName: institutionName, logoUrl: logoUrl);

/// Construct an instance from a JSON map.
factory EducationInstituteModel.fromJson(Map<String, dynamic> json) {
return EducationInstituteModel(
institutionName: json['institutionName'] ?? " ",
logoUrl: json['logoUrl'] ?? " ",
id: json['id'] ?? " ",
);
}

/// Convert an instance to a JSON map.
Map<String, dynamic> toJson() {
return {
'institutionName': institutionName,
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import 'package:hakim_hub_mobile/features/hospital/domain/entities/filter_doctor_domain.dart';

/// Model for filtering doctors.
class DoctorFilterModel extends DoctorFilterDomain {
/// ID of the institution to filter by.
String institutionId;

/// Years of experience to filter by.
String experienceYears;

/// Educational institution name to filter by.
String educationalName;

/// List of specialities to filter by.
List<String> specialities;

/// Create an instance from provided data.
DoctorFilterModel({
required this.institutionId,
required this.experienceYears,
required this.educationalName,
required this.specialities,
}) : super(
educationalName: educationalName,
experienceYears: experienceYears,
specialities: specialities,
institutionId: institutionId);
educationalName: educationalName,
experienceYears: experienceYears,
specialities: specialities,
institutionId: institutionId,
);

/// Convert to a JSON map.
Map<String, dynamic> toJson() {
return {
'institutionId': institutionId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import 'package:hakim_hub_mobile/features/hospital/domain/entities/filter_hospital_domain.dart';

/// Model for filtering hospitals.
class FilterHospitalModel extends FilterHospitalDomain {
/// Number of years the hospital has been active.
int activeFor;

import 'package:hakim_hub_mobile/features/hospital/domain/entities/filter_hospital_domain.dart';
/// Whether the hospital is open now.
bool openNow;

/// List of services offered by the hospital.
List<String> services;

class FilterHospitalModel extends FilterHospitalDomain{

/// Create an instance with provided filter criteria.
FilterHospitalModel(
{required this.activeFor, required this.openNow, required this.services})
: super(
operationYears: activeFor, openStatus: openNow, services: services);

FilterHospitalModel({required int activeFor, required bool openNow, required List<String> services}):super(operationYears : activeFor, openStatus: openNow, services: services);

/// Convert to JSON map.
toJson() {
return {
'openNow': openStatus,
'activeFor': operationYears,
'services': services
};
}
}
}
Loading