123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- import 'dart:convert';
- import 'dart:html';
- import 'dart:js_util';
- import 'package:get_it/get_it.dart';
- import 'package:http/http.dart' as http;
- import 'package:localstorage/localstorage.dart';
- import 'package:sprintf/sprintf.dart';
- import 'package:ustest/ConsultationList.dart';
- import 'package:ustest/Services/LocalStorageService.dart';
- import 'dart:typed_data';
- import 'package:web_socket_channel/web_socket_channel.dart';
- import 'AppSettings.dart';
- import 'UserService.dart';
- import 'package:intl/intl.dart';
- import 'package:event/event.dart';
- class NotificationReceivedArgs extends EventArgs {
- dynamic jsonMessage;
- NotificationReceivedArgs(this.jsonMessage);
- }
- class ConsultationService {
- Event<NotificationReceivedArgs> NotificationReceived =
- Event<NotificationReceivedArgs>();
- RaiseConsultationNotificationReceived(dynamic jsonMessage) {
- NotificationReceived.broadcast(NotificationReceivedArgs(jsonMessage));
- }
- Future<AppConsultationDataModel> LoadDataAsync() async {
- var userService = GetIt.instance.get<UserService>();
- final user = userService.getCurrentUser();
- final token = user?.accessToken;
- final orgCode = user?.organizationCode;
- var client = http.Client();
- var body =
- '{"jsonrpc": "2.0", "method": "GetPersonDeviceDropdownListAsync", "params": [{"Token": "$token"}], "id": 1 }';
- print('QueryExam http.Client()' + body);
- var response = await client
- .post(Uri.parse(AppSettings.host + '/IDeviceService'), body: body);
- var parsed = decodeResponseBody(
- 'GetPersonDeviceDropdownListAsync', response.bodyBytes);
- var datas = parsed['result'];
- final devices = datas.map<Device>((json) => Device.fromJson(json)).toList();
- body =
- '{"jsonrpc": "2.0", "method": "FindOrganizationExpertsAsync", "params": [{"Token": "$token", "OrganizationCode": "$orgCode"}], "id": 1 }';
- print('QueryExam http.Client()' + body);
- response = await client.post(
- Uri.parse(AppSettings.host + '/ILiveConsultationService'),
- body: body);
- //final response = await post(client, "ILiveConsultationService",
- // "FindOrganizationExpertsAsync", args);
- print('FindOrganizationExpertsAsync response.body' + response.body);
- parsed = jsonDecode(response.body);
- datas = parsed['result'];
- final experts = datas.map<Expert>((json) => Expert.fromJson(json)).toList()
- as List<Expert>;
- body =
- '{"jsonrpc": "2.0", "method": "FindScanPositionsAsync", "params": [{"Token": "$token"}], "id": 1 }';
- print('FindScanPositionsAsync http.Client()' + body);
- response = await client.post(
- Uri.parse(AppSettings.host + '/ILiveConsultationService'),
- body: body);
- parsed = decodeResponseBody('FindScanPositionsAsync', response.bodyBytes);
- //var data = jsonDecode(parsed['result']);
- var organSource = parsed['result'];
- var organs = organSource.map<String>((json) => json.toString()).toList()
- as List<String>;
- body =
- '{"jsonrpc": "2.0", "method": "GetUserListAsync", "params": [{"Token": "$token", "OrganizationCode": "$orgCode","OrganizationQueryType":3,"ExceptSelf":true}], "id": 1 }';
- print('GetUserListAsync http.Client()' + body);
- response = await client.post(Uri.parse(AppSettings.host + '/IUserService'),
- body: body);
- print('GetUserListAsync response.body' + response.body);
- parsed = jsonDecode(response.body);
- datas = parsed['result'];
- final users = datas.map<Expert>((json) => Expert.fromJson(json)).toList()
- as List<Expert>;
- var model = new AppConsultationDataModel(experts, devices, organs, users);
- return model;
- }
- decodeResponseBody(String logTag, Uint8List bodyBytes) {
- var utfString = utf8.decode(bodyBytes);
- print('$logTag response.body' + utfString);
- final parsed = jsonDecode(utfString);
- return parsed;
- }
- Future<List<Consultation>> FindConsultationsByPageAsync(
- String id, int? selectedType) async {
- try {
- var userService = GetIt.instance.get<UserService>();
- var user = userService.getCurrentUser();
- var token = user?.accessToken;
- var client = http.Client();
- var body =
- '{"jsonrpc": "2.0", "method": "FindConsultationsByPageAsync", "params": [{"Token": "$token", "PageIndex": 1, "PageSize": 10,"ConsultationQueryType": $selectedType}], "id": 1 }';
- print('GetRecordInfoPagesAsync http.Client()' + body);
- final response = await client.post(
- Uri.parse(AppSettings.host + '/ILiveConsultationService'),
- body: body);
- print('FindConsultationsByPageAsync response.body' + response.body);
- final parsed = jsonDecode(response.body);
- var datas = parsed['result']['PageData'];
- var list = datas
- .map<Consultation>((json) => Consultation.fromJson(json))
- .toList();
- return list;
- } catch (ex) {
- print('FindConsultationsByPageAsync.to ex' + ex.toString());
- }
- return List.empty();
- }
- dynamic post(
- http.Client client, String interface, String method, String args) async {
- final body = sprintf(
- '{"jsonrpc": "2.0", "method": "$method", "params": %s, "id": 1 }',
- args);
- final response = await client
- .post(Uri.parse(AppSettings.host + '/$interface'), body: body);
- print('GetUserInfoAsync response.body' + response.body);
- var parsed = jsonDecode(response.body);
- }
- Future<bool> ApplyConsultationAsync(
- String expertCode, String deviceCode, String organ, DateTime time) async {
- var userService = GetIt.instance.get<UserService>();
- var user = userService.getCurrentUser();
- var token = user?.accessToken;
- var client = http.Client();
- var patientCode = "2D6DA689ECC54F52A17F20A05BDF5C27"; //TODO should from UI
- var organizationCode = "Organization_20221020115006aAjF6l";
- DateFormat inputFormat = DateFormat("yyyy-MM-ddTHH:mm:ss");
- var utcTime = inputFormat.format(time.toUtc()).toString();
- var body =
- '{"jsonrpc": "2.0", "method": "FindPatientByCodeAsync", "params": [{"Token": "$token", "Code":"$patientCode"}], "id": 1 }';
- print('FindPatientByCodeAsync http.Client()' + body);
- var response = await client
- .post(Uri.parse(AppSettings.host + '/IPatientService'), body: body);
- var parsed =
- decodeResponseBody('FindPatientByCodeAsync', response.bodyBytes);
- var data = parsed['result']['PatientData'];
- var list =
- data.map<DataItemDTO>((json) => DataItemDTO.fromJson(json)).toList();
- var patientDatas = jsonEncode(list);
- body =
- '{"jsonrpc": "2.0", "method": "ApplyConsultationAsync", "params": [{"Token": "$token","ApplyUserCode":"3C135B470E6448F6854974D46022F7FD", "PatientCode":"$patientCode", "ExpertOrganizationCode":"$organizationCode", "PatientDatas":$patientDatas, "ExpertUserCode": "$expertCode", "DeviceCode": "$deviceCode", "ScanPosition": "$organ", "ConsultationTime":"$utcTime"}], "id": 1 }';
- print('ApplyConsultationAsync http.Client()' + body);
- response = await client.post(
- Uri.parse(AppSettings.host + '/ILiveConsultationService'),
- body: body);
- parsed = decodeResponseBody('ApplyConsultationAsync', response.bodyBytes);
- return true;
- }
- Future<dynamic> InitiateLiveConsultationAsync(String consultationCode) async {
- var userService = GetIt.instance.get<UserService>();
- var user = userService.getCurrentUser();
- var token = user?.accessToken;
- var client = http.Client();
- var body =
- '{"jsonrpc": "2.0", "method": "InitiateLiveConsultationAsync", "params": [{"Token": "$token", "ConsultationCode":"$consultationCode"}], "id": 1 }';
- print('InitiateLiveConsultationAsync http.Client()' + body);
- final response = await client.post(
- Uri.parse(AppSettings.host + '/ILiveConsultationService'),
- body: body);
- var parsed =
- decodeResponseBody('InitiateLiveConsultationAsync', response.bodyBytes);
- var data = parsed['result'];
- print("begin RaiseConsultationNotificationReceived");
- RaiseConsultationNotificationReceived(data);
- print("end RaiseConsultationNotificationReceived");
- return data;
- }
- Future<dynamic> AcceptLiveConsultationAsync(String consultationCode) async {
- var userService = GetIt.instance.get<UserService>();
- var user = userService.getCurrentUser();
- var token = user?.accessToken;
- var client = http.Client();
- var body =
- '{"jsonrpc": "2.0", "method": "AcceptLiveConsultationAsync", "params": [{"Token": "$token", "ConsultationCode":"$consultationCode"}], "id": 1 }';
- print('AcceptLiveConsultationAsync http.Client()' + body);
- final response = await client.post(
- Uri.parse(AppSettings.host + '/ILiveConsultationService'),
- body: body);
- var parsed =
- decodeResponseBody('AcceptLiveConsultationAsync', response.bodyBytes);
- var data = parsed['result'];
- return data;
- }
- Future<dynamic> RejectLiveConsultationAsync(String consultationCode) async {
- var userService = GetIt.instance.get<UserService>();
- var user = userService.getCurrentUser();
- var token = user?.accessToken;
- var client = http.Client();
- var body =
- '{"jsonrpc": "2.0", "method": "RejectLiveConsultationAsync", "params": [{"Token": "$token", "ConsultationCode":"$consultationCode"}], "id": 1 }';
- print('RejectLiveConsultationAsync http.Client()' + body);
- final response = await client.post(
- Uri.parse(AppSettings.host + '/ILiveConsultationService'),
- body: body);
- var parsed =
- decodeResponseBody('RejectLiveConsultationAsync', response.bodyBytes);
- var data = parsed['result'];
- return data;
- }
- Future<bool> ApprovalConsultationAsync(
- ApprovalConsultationRequest model) async {
- String consultationCode = model.consultationCode;
- String expertUserCode = model.expertUserCode;
- DateTime consultationTime = model.consultationTime;
- List<String> consultationMemberCodes = <String>[];
- model.consultationMemberCodes.forEach((element) {
- consultationMemberCodes.add('"' + element + '"');
- });
- var userService = GetIt.instance.get<UserService>();
- var user = userService.getCurrentUser();
- var token = user?.accessToken;
- var client = http.Client();
- DateFormat inputFormat = DateFormat("yyyy-MM-ddTHH:mm:ss");
- var utcTime = inputFormat.format(consultationTime.toUtc()).toString();
- var body =
- '{"jsonrpc": "2.0", "method": "ApprovalConsultationAsync", "params": [{"Token": "$token","ConsultationCode":"$consultationCode", "ExpertUserCode":"$expertUserCode", "ConsultationTime":"$utcTime", "ConsultationMemberCodes":$consultationMemberCodes }], "id": 1 }';
- print('ApprovalConsultationAsync http.Client()' + body);
- var response = await client.post(
- Uri.parse(AppSettings.host + '/ILiveConsultationService'),
- body: body);
- var parsed =
- decodeResponseBody('ApprovalConsultationAsync', response.bodyBytes);
- var data = parsed['result'];
- return data;
- }
- }
- class AppConsultationDataModel {
- final List<Expert> experts;
- final List<Device> devices;
- final List<String> organs;
- final List<Expert> users;
- AppConsultationDataModel(this.experts, this.devices, this.organs, this.users);
- }
- class TokenRequest {
- String token;
- TokenRequest(this.token);
- }
- class DataItemDTO {
- final String key;
- final String value;
- DataItemDTO({required this.key, required this.value});
- factory DataItemDTO.fromJson(Map<String, dynamic> json) {
- return DataItemDTO(
- key: json['Key'] as String,
- value: json['Value'] as String,
- );
- }
- Map<String, dynamic> toJson() => {
- "Key": key,
- "Value": value,
- };
- }
- class ApplyConsultationRequest extends TokenRequest {
- String expertUserCode;
- String deviceCode;
- String scanPosition;
- DateTime consultationTime;
- List<DataItemDTO> patientDatas;
- String patientCode;
- ApplyConsultationRequest(
- this.expertUserCode,
- this.deviceCode,
- this.scanPosition,
- this.consultationTime,
- this.patientDatas,
- this.patientCode,
- String token)
- : super(token);
- }
- class Expert {
- final String code;
- final String userName;
- Expert({required this.code, required this.userName});
- @override
- bool operator ==(Object other) => other is Expert && other.code == code;
- factory Expert.fromJson(Map<String, dynamic> json) {
- return Expert(
- code: json['UserCode'] as String,
- userName: json['UserName'] as String,
- );
- }
- Map<String, dynamic> toJson() => {
- "UserCode": code,
- "UserName": userName,
- };
- }
- class Device {
- final String code;
- final String deviceName;
- Device({required this.code, required this.deviceName});
- bool operator ==(Object other) => other is Device && other.code == code;
- factory Device.fromJson(Map<String, dynamic> json) {
- return Device(
- code: json['Key'] as String,
- deviceName: json['Value'] as String,
- );
- }
- Map<String, dynamic> toJson() => {
- "Key": code,
- "Value": deviceName,
- };
- }
- class Organ {
- final String code;
- final String orgName;
- Organ({required this.code, required this.orgName});
- factory Organ.fromJson(Map<String, dynamic> json) {
- return Organ(
- code: json['Key'] as String,
- orgName: json['Value'] as String,
- );
- }
- Map<String, dynamic> toJson() => {
- "Key": code,
- "Value": orgName,
- };
- }
- class ApprovalConsultationRequest extends TokenRequest {
- String consultationCode;
- String expertUserCode;
- DateTime consultationTime;
- List<String> consultationMemberCodes;
- ApprovalConsultationRequest(this.consultationCode, this.expertUserCode,
- this.consultationTime, this.consultationMemberCodes, String token)
- : super(token);
- @override
- String toString() {
- // TODO: implement toString
- return 'consultationCode: $consultationCode,expertUserCode:$expertUserCode,consultationTime:$consultationTime,consultationMemberCodes:$consultationMemberCodes';
- }
- }
|