瀏覽代碼

update test tool

arthur.wu 2 年之前
父節點
當前提交
dfbfffbf83

+ 12 - 20
Tools/TestTools/client/lib/ConsultationList.dart

@@ -6,6 +6,8 @@ import 'package:get_it/get_it.dart';
 import 'package:sprintf/sprintf.dart';
 import 'package:http/http.dart' as http;
 
+import 'Services/ConsultationService.dart';
+
 class ConsultationList extends StatefulWidget {
   ConsultationList({Key? key, required this.token, required this.consultations})
       : super();
@@ -74,7 +76,9 @@ class _ConsultationListState extends State<ConsultationList> {
                                 Container(
                                     child: TextButton(
                                         child: Text("Start"),
-                                        onPressed: OnStartLiveConsultation))
+                                        onPressed: (() =>
+                                            OnStartLiveConsultation(widget
+                                                .consultations[index].id))))
                               ],
                             ),
                           )),
@@ -88,30 +92,18 @@ class _ConsultationListState extends State<ConsultationList> {
     ));
   }
 
-  void onTabPatient(String id) async {
-    try {
-      var client = http.Client();
-
-      var body = sprintf(
-          '{"jsonrpc": "2.0", "method": "GetRecordInfoPagesAsync", "params": [{"Token": "%s",  "PageIndex": 1, "PageSize": 10, "PatientCode": "%s"}], "id": 1 }',
-          [widget.token, id]);
-      print('GetRecordInfoPagesAsync http.Client()' + body);
-      final response = await client.post(
-          Uri.parse('http://192.168.6.80:8303/IRecordInfoService'),
-          body: body);
-      print('GetRecordInfoPagesAsync response.body' + response.body);
-      final parsed = jsonDecode(response.body);
-      var datas = parsed['result']['PageData'];
+  void onTabPatient(String id) async {}
 
-      setState(() {});
-      //client.close();
+  void OnStartLiveConsultation(id) async {
+    try {
+      var service = GetIt.instance.get<ConsultationService>();
 
+      var result = await service.InitiateLiveConsultationAsync(id);
+      print("InitiateLiveConsultationAsync");
     } catch (ex) {
-      print('GetRecordInfoPagesAsync.to ex' + ex.toString());
+      print('OnStartLiveConsultation.to ex' + ex.toString());
     }
   }
-
-  void OnStartLiveConsultation() {}
 }
 
 class Consultation {

+ 57 - 18
Tools/TestTools/client/lib/Services/ConsultationService.dart

@@ -21,11 +21,11 @@ class ConsultationService {
     var date = DateTime.utc(
         now.year, now.month, now.day, now.hour, now.minute, now.second);
     var data = new List<DataItemDTO>.empty();
-    data.add(new DataItemDTO("key", "value"));
+    //data.add(new DataItemDTO("key", "value"));
     var requet = new ApplyConsultationRequest(
         "expertusercode", "d", "s", date, data, "", "");
     var body = sprintf(
-        '{"jsonrpc": "2.0", "method": "CommonLoginAsync", "params": [{"AnyAccount": "%s", "AnyCode": "", "Password": "%s" }], "id": 1 }',
+        '{"jsonrpc": "2.0", "method": "CommonLoginAsync", "params": [{"AnyAccount": "%s", "AnyCode": "", "Password": "%s", }], "id": 1 }',
         [userName, password]);
     final response = await client
         .post(Uri.parse(AppSettings.host + '/ILoginService'), body: body);
@@ -72,16 +72,14 @@ class ConsultationService {
         as List<Expert>;
 
     body =
-        '{"jsonrpc": "2.0", "method": "GetOrganizationSettingAsync", "params": [{"Token": "$token",  "SettingType": 2, "Version": "0.0"}], "id": 1 }';
-    print('GetOrganizationSettingAsync http.Client()' + body);
+        '{"jsonrpc": "2.0", "method": "FindScanPositionsAsync", "params": [{"Token": "$token"}], "id": 1 }';
+    print('FindScanPositionsAsync http.Client()' + body);
     response = await client.post(
-        Uri.parse(AppSettings.host + '/IOrganizationService'),
+        Uri.parse(AppSettings.host + '/ILiveConsultationService'),
         body: body);
-    parsed =
-        decodeResponseBody('GetOrganizationSettingAsync', response.bodyBytes);
-    var data = jsonDecode(parsed['result']['SettingData']);
-    var organSource =
-        data['ConsultationInfo']['Booking']['ScanPosition']['Source'];
+    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>;
@@ -141,19 +139,48 @@ class ConsultationService {
     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": "ApplyConsultationAsync", "params": [{"Token": "$token", "PatientCode":"$patientCode", "ExpertUserCode": "$expertCode", "DeviceCode": "$deviceCode", "ScanPosition": "$organ", "ConsultationTime":"$utcTime"}], "id": 1 }';
+        '{"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);
-    final response = await client.post(
+    response = await client.post(
         Uri.parse(AppSettings.host + '/ILiveConsultationService'),
         body: body);
-    print('ApplyConsultationAsync response.body' + response.body);
-    final parsed = jsonDecode(response.body);
-    var datas = parsed['result'];
+    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'];
+    return data;
+  }
 }
 
 class AppConsultationDataModel {
@@ -170,9 +197,21 @@ class TokenRequest {
 }
 
 class DataItemDTO {
-  String key;
-  String value;
-  DataItemDTO(this.key, this.value);
+  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 {

+ 8 - 2
Tools/TestTools/client/lib/Services/UserService.dart

@@ -15,9 +15,9 @@ class UserService {
   late User currentUser;
   final String UserStroageKey = "CurrentUser";
   final LocalStorage storage = new LocalStorage('UserStroage');
-  final WebSocketChannel Channel = WebSocketChannel.connect(
+  late WebSocketChannel? Channel = WebSocketChannel.connect(
     Uri.parse('ws://192.168.6.80:9301?token=F97952F53B7C428C8EFE0659F8CF38F6'),
-  );
+  ); //TODO
   User? getCurrentUser() {
     //if (currentUser != null) //TODO workaround
     //{
@@ -74,6 +74,12 @@ class UserService {
 
         this.storage.setItem(UserStroageKey, jsonUser);
         print('jsonUser:' + jsonUser.toString());
+        var url = Uri.parse(AppSettings.host);
+        print("object" + url.host);
+        Channel = WebSocketChannel.connect(
+          Uri.parse(
+              'ws://192.168.6.80:9301?token=F97952F53B7C428C8EFE0659F8CF38F6'),
+        );
 
         return true;
       }

+ 53 - 49
Tools/TestTools/client/lib/UserView.dart

@@ -7,7 +7,6 @@ import 'package:get_it/get_it.dart';
 import 'package:sprintf/sprintf.dart';
 import 'package:ustest/ConsultationList.dart';
 import 'package:ustest/Services/UserService.dart';
-import 'package:http/http.dart' as http;
 
 import 'Services/ConsultationService.dart';
 
@@ -57,7 +56,7 @@ class UserView extends StatelessWidget {
             Expanded(
                 child: Center(
               child: FutureBuilder<List<Consultation>>(
-                future: fetchPatients(),
+                future: fetchConsultations(),
                 builder: (context, snapshot) {
                   if (snapshot.hasError) {
                     return const Center(
@@ -74,52 +73,57 @@ class UserView extends StatelessWidget {
                 },
               ),
             )),
-            StreamBuilder(
-              stream: service.Channel.stream,
-              builder: (context, snapshot) {
-                var message = "";
-                // var message =
-                //     snapshot.hasData ? '${snapshot.data}' : 'no message';
-                if (snapshot.hasData) {
-                  var uint8Array =
-                      Uint8List.fromList(snapshot.data as List<int>);
-                  var byteData = uint8Array.buffer.asByteData();
-                  var byteDataLength = byteData.lengthInBytes;
-                  var messageConentList =
-                      Uint8List.view(uint8Array.buffer, 0, byteDataLength);
-                  var messageConentLength = messageConentList.length;
-                  var messageConent = Uint8List.fromList(messageConentList);
-                  var messageText = Utf8Decoder().convert(messageConent);
-                  Map<String, dynamic> messageObject = jsonDecode(messageText);
-                  //通知类型区分
-                  if (messageObject["NotificationType"] as int ==
-                      NotificationTypeEnum.ConnectionNotification.index) {
-                    var connectionNotification =
-                        ConnectionNotification.fromJson(messageObject);
-                    print(
-                        "connectionNotification.NotificationType:${connectionNotification.notificationType}");
-                  } else if (messageObject["NotificationType"] as int ==
-                      NotificationTypeEnum.DisconnectNotification.index) {
-                    var disconnectNotification =
-                        DisconnectNotification.fromJson(messageObject);
-                    print(
-                        "disconnectNotification.NotificationType:${disconnectNotification.notificationType}");
-                  } else if (messageObject["NotificationType"] as int ==
-                      NotificationTypeEnum.FinishNotifyRecordsMessage.index) {
-                    var disconnectNotification =
-                        FinishNotifyRecordsMessage.fromJson(messageObject);
-                    print(
-                        "FinishNotifyRecordsMessage.NotificationType:${disconnectNotification.notificationType},  ${disconnectNotification.codes}");
-                  }
-
-                  message = messageText;
-                }
-                return new Padding(
-                  padding: const EdgeInsets.symmetric(vertical: 24.0),
-                  child: new Text(message),
-                );
-              },
-            )
+            service.Channel != null
+                ? StreamBuilder(
+                    stream: service.Channel!.stream,
+                    builder: (context, snapshot) {
+                      var message = "";
+                      // var message =
+                      //     snapshot.hasData ? '${snapshot.data}' : 'no message';
+                      if (snapshot.hasData) {
+                        var uint8Array =
+                            Uint8List.fromList(snapshot.data as List<int>);
+                        var byteData = uint8Array.buffer.asByteData();
+                        var byteDataLength = byteData.lengthInBytes;
+                        var messageConentList = Uint8List.view(
+                            uint8Array.buffer, 0, byteDataLength);
+                        var messageConentLength = messageConentList.length;
+                        var messageConent =
+                            Uint8List.fromList(messageConentList);
+                        var messageText = Utf8Decoder().convert(messageConent);
+                        Map<String, dynamic> messageObject =
+                            jsonDecode(messageText);
+                        //通知类型区分
+                        if (messageObject["NotificationType"] as int ==
+                            NotificationTypeEnum.ConnectionNotification.index) {
+                          var connectionNotification =
+                              ConnectionNotification.fromJson(messageObject);
+                          print(
+                              "connectionNotification.NotificationType:${connectionNotification.notificationType}");
+                        } else if (messageObject["NotificationType"] as int ==
+                            NotificationTypeEnum.DisconnectNotification.index) {
+                          var disconnectNotification =
+                              DisconnectNotification.fromJson(messageObject);
+                          print(
+                              "disconnectNotification.NotificationType:${disconnectNotification.notificationType}");
+                        } else if (messageObject["NotificationType"] as int ==
+                            NotificationTypeEnum
+                                .FinishNotifyRecordsMessage.index) {
+                          var disconnectNotification =
+                              FinishNotifyRecordsMessage.fromJson(
+                                  messageObject);
+                          print(
+                              "FinishNotifyRecordsMessage.NotificationType:${disconnectNotification.notificationType},  ${disconnectNotification.codes}");
+                        }
+
+                        message = messageText;
+                      }
+                      return new Padding(
+                        padding: const EdgeInsets.symmetric(vertical: 24.0),
+                        child: new Text(message),
+                      );
+                    })
+                : Text('no notification')
           ],
         ),
       ),
@@ -132,7 +136,7 @@ class UserView extends StatelessWidget {
     });
   }
 
-  Future<List<Consultation>> fetchPatients() async {
+  Future<List<Consultation>> fetchConsultations() async {
     try {
       var service = GetIt.instance.get<ConsultationService>();