using System.Net;
using System.Text;
using System.Text.Json.Nodes;
using Azure.Core;
using BeetleX.Clients;
using BeetleX.Redis.Commands;
using EI_TestProject;
using IRaCIS.Application.Contracts;
using IRaCIS.Core.Application.Contracts;
using IRaCIS.Core.Application.ViewModel;
using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Infrastructure.Extention;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Asn1.Crmf;
using Org.BouncyCastle.Asn1.Ocsp;
using RestSharp;
using Xunit;
using Xunit.Abstractions;

public class UserApiTests : IDisposable
{
    private RestClient _client;



    public UserApiTests()
    {
        // 创建一个 RestClient 对象，并设置基本 URL
        //client = new RestClient("http://localhost:6100");

        _client = RestHelper.InitRestHelper("http://123.56.94.154:8090/api", "Admin", MD5Helper.Md5("WHxckj@2019"));
        
    }

    #region 用户  用户类型
    /// <summary>
    /// 添加系统用户
    /// </summary>
    [Fact]
    public async void Test_AddUser()
    {

        var url = $"/user/addUser";

        var jsonBody = new JObject
                {
                    { "UserName", "test_hang" },
                    { "LastName", "zhou" },
                    { "FirstName", "hang" },
                    { "Sex", 1 },
                    { "EMail", "872297557@qq.com" },
                    { "Phone", "" },
                    { "UserTypeId", "40240000-3e2c-0016-b35f-08db1895d627" },
                    { "IsZhiZhun", "" },
                    { "OrganizationName", "" },
                    { "DepartmentName", "" },
                    { "PositionName", "" },
                    { "IsTestUser", true },
                    { "UserTypeEnum", 1 },
                    { "BaseUrl", "http://123.56.94.154:8090/login" },
                    { "RouteUrl", "http://123.56.94.154:8090/email-recompose" },
                    { "RealName", string.Empty }
                };


        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<UserAddedReturnDTO>>(url, jsonBody);


        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }

    /// <summary>
    /// 更新用户
    /// </summary>
    [Fact]
    public async void Test_UpdateUser()
    {
        var url = $"/user/updateUser";

        var jsonBody = new JObject
        {
            { "CanEditUserType", false },
            { "Id", "d83f0000-3e2c-0016-2ed8-08db3f051caf" },
            { "UserName", "zhouhang" },
            { "Password", "e10adc3949ba59abbe56e057f20f883e" },
            { "RealName", "zhou / hang" },
            { "FirstName", "hang" },
            { "LastName", "zhou" },
            { "Sex", 1 },
            { "Status", 1 },
            { "Phone", "17673237815" },
            { "EMail", "872297557@qq.com" },
            { "UserTypeId", "40240000-3e2c-0016-b35f-08db1895d627" },
            { "UserCode", "U0178" },
            { "UserType", "PM (Project Manager)" },
            { "UserTypeShortName", "PM" },
            { "UserTypeEnum", 1 },
            { "IsZhiZhun", true },
            { "OrganizationName", "ExtImaging" },
            { "DepartmentName", "xx" },
            { "PositionName", "xx" },
            { "IsTestUser", false },
            { "BaseUrl", "http://123.56.94.154:8090/login" },
            { "RouteUrl", "http://123.56.94.154:8090/email-recompose" }
        };

        var result = await RestHelper.Put_JsonBodyRequestAsync<ResponseOutput<string>>(url, jsonBody);


        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }


    /// <summary>
    /// 重置密码
    /// </summary>
    [Fact]
    public async void Test_ResetPassword()
    {
        var id = Guid.Parse("d05c0000-3e2c-0016-64eb-08db617a483b");
        var url = $"/user/resetPassword/{id}";

        var result = await RestHelper.GetRequestAsync<ResponseOutput<UserAddedReturnDTO>>(url);

        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);

    }

    /// <summary>
    /// 查询系统用户
    /// </summary>
    [Fact]
    public async void Test_GetUserList()
    {
        var url = $"/user/getUserList";

        var jsonBody = new JObject
        {
           { "RealName", string.Empty }
        };

        //测试删除Api
        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<PageOutput<UserListDTO>>>(url, jsonBody);

        Assert.True(result.Data.CurrentPageData.Count >= 0);
    }



    /// <summary>
    /// 删除系统用户
    /// </summary>
    [Fact]
    public async void Test_DeleteUser()
    {
        var userId = Guid.Parse("98430000-3e2c-0016-225f-08db7612c7ae");
        var url = $"/user/deleteUser/{userId}";

        //测试删除Api
        var result = await RestHelper.DeleteRequestAsync<ResponseOutput<string>>(url);

        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }


    /// <summary>
    ///  角色
    /// </summary>
    [Fact]
    public async void Test_GetUserTypeRoleList()
    {
        var url = $"/UserTypeRole/getUserTypeRoleList";
        var jsonBody = new JObject
        {

        };

        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<List<UserTypeRoleView>>>(url, jsonBody);

        Assert.True(result.Data.Count >= 0);
    }

    #endregion


    #region 匿名化
    /// <summary>
    /// 匿名化配置   
    /// </summary>
    [Fact]
    public async void Test_getSystemAnonymizationList()
    {
        var url = $"/SystemAnonymization/getSystemAnonymizationList";

        var jsonBody = new JObject
                    {
                        { "Group", "" },
                        { "Element", "" },
                        { "TagDescription", "" },
                        { "IsAdd", false },
                        { "TagDescriptionCN", "" },
                        { "PageIndex", 1 },
                        { "PageSize", 500 }
                    };


        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<PageOutput<SystemAnonymizationView>>>(url, jsonBody);

        Assert.True(result.Data.CurrentPageData.Count >= 0);
    }



    /// <summary>
    /// 删除匿名化配置
    /// </summary>
    [Fact]
    public async void Test_DeleteSystemAnonymization()
    {
        var id = Guid.Parse("98430000-3e2c-0016-225f-08db7612c7ae");
        var url = $"/SystemAnonymization/deleteSystemAnonymization/{id}";

        //测试删除Api
        var result = await RestHelper.DeleteRequestAsync<ResponseOutput<string>>(url);

        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }


    /// <summary>
    /// 更新  匿名化配置
    /// </summary>
    [Fact]
    public async void Test_UpdateSystemAnonymization()
    {

        var url = $"/SystemAnonymization/addOrUpdateSystemAnonymization";

        var jsonBody = new JObject
                {
                    { "CreateUserId", "e2e165a0-44b0-4b16-9a4d-0b9b7a1ce362" },
                    { "UpdateTime", "2023-06-19 14:36:56" },
                    { "UpdateUserId", "e2e165a0-44b0-4b16-9a4d-0b9b7a1ce362" },
                    { "CreateTime", "2023-06-15 10:21:19" },
                    { "Id", "640a0000-3e2c-0016-ae9b-08db6d4734c9" },
                    { "Group", "1" },
                    { "Element", "2" },
                    { "TagDescription", "3" },
                    { "TagDescriptionCN", "4" },
                    { "ReplaceValue", "123" },
                    { "ValueRepresentation", "5" },
                    { "IsAdd", false },
                    { "IsEnable", true },
                    { "IsFixed", true }
                };


        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<string>>(url, jsonBody);


        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }


    /// <summary>
    /// 添加  匿名化配置
    /// </summary>
    [Fact]
    public async void Test_AddSystemAnonymization()
    {

        var url = $"/SystemAnonymization/addOrUpdateSystemAnonymization";


        var jsonBody = new JObject
                {
                    { "Group", "0010" },
                    { "Element", "0021" },
                    { "TagDescription", "test" },
                    { "TagDescriptionCN", "test" },
                    { "ValueRepresentation", "test" },
                    { "ReplaceValue", "test" },
                    { "IsEnable", false },
                    { "IsAdd", false },
                    { "IsFixed", false }
                };


        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<string>>(url, jsonBody);


        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }
    #endregion


    #region 项目

    /// 查询系项目列表
    /// </summary>
    [Fact]
    public async void Test_GetTrialList()
    {
        var url = $"/trial/getTrialList";

        var jsonBody = new JObject
                {
                    { "Code", "" },
                    { "CriterionIds", new JArray() },
                    { "SponsorId", "" },
                    { "ReviewTypeIds", new JArray() },
                    { "CROId", "" },
                    { "Expedited", "" },
                    { "Indication", "" },
                    { "Phase", "" },
                    { "ModalityIds", new JArray() },
                    { "BeginDate", "" },
                    { "EndDate", "" },
                    { "AttendedReviewerType", "" },
                    { "ResearchProgramNo", "" },
                    { "ExperimentName", "" },
                    { "PageIndex", 1 },
                    { "PageSize", 20 },
                    { "Asc", false },
                    { "SortField", "" }
                };

        //测试删除Api
        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<PageOutput<PageOutput<TrialDetailDTO>>>>(url, jsonBody);

        Assert.True(result.Data.CurrentPageData.Count >= 0);
    }



    /// <summary>
    /// 更新项目
    /// </summary>
    [Fact]
    public async void Test_UpdateTrial()
    {
        var pmclient = RestHelper.InitRestHelper("http://123.56.94.154:8090/api", "PM01", MD5Helper.Md5("WHxckj@2019"));

        var url = $"/trial/addOrUpdateTrial";

        var jsonBody = new JObject
            {
                { "Id", "20430000-3e2c-0016-aa08-08db791c6ae5" },
                { "TrialCode", "23000067" },
                { "TrialType", 1 },
                { "SponsorId", "" },
                { "CROId", "" },
                { "ReviewModeId", "" },
                { "ReviewTypeIds", new JArray() },
                { "Expedited", 0 },
                { "ModalityIds", new JArray() },
                { "Note", "" },
                { "ExpectedPatients", 0 },
                { "TimePointsPerPatient", 0 },
                { "ProjectCycle", "" },
                { "TotalReviewers", 0 },
                { "DeclarationTypeId", "742e0000-3e2c-0016-b5ca-08da6222442f" },
                { "IndicationTypeId", "437a81b3-c5ad-49fd-82a1-8f441c4ba8da" },
                { "PhaseId", "b1509dde-234a-46ce-cf13-08d9c120c961" },
                { "AttendedReviewerType", 0 },
                { "IsLocked", false },
                { "ResearchProgramNo", "111" },
                { "ExperimentName", "项目1" },
                { "MainResearchUnit", "" },
                { "HeadPI", "" },
                { "PlanSiteCount", 0 },
                { "PlanVisitCount", 0 },
                { "Indication", "肺癌" },
                { "IndicationOther", null }
            };


        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<Trial>>(url, jsonBody,restClient: pmclient);


        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }

    /// <summary>
    /// 添加项目
    /// </summary>
    /// 
    [Fact]
    public async void Test_AddTrial()
    {
        var pmclient = RestHelper.InitRestHelper("http://123.56.94.154:8090/api", "PM01", MD5Helper.Md5("WHxckj@2019"));

        var url = $"/trial/addOrUpdateTrial";

        var jsonBody = new JObject
            {
                { "Id", "" },
                { "TrialType", 1 },
                { "SponsorId", "" },
                { "CROId", "" },
                { "ReviewModeId", "" },
                { "ReviewTypeIds", new JArray() },
                { "Expedited", 0 },
                { "ModalityIds", new JArray("b44915a2-6f08-45f8-bd6c-74abad2298e1", "80480000-3e2c-0016-f090-08da6b92accd") },
                { "Note", "" },
                { "ExpectedPatients", 0 },
                { "TimePointsPerPatient", 0 },
                { "ProjectCycle", "" },
                { "TotalReviewers", 0 },
                { "DeclarationTypeId", "742e0000-3e2c-0016-b5ca-08da6222442f" },
                { "IndicationTypeId", "437a81b3-c5ad-49fd-82a1-8f441c4ba8da" },
                { "PhaseId", "b1509dde-234a-46ce-cf13-08d9c120c961" },
                { "AttendedReviewerType", 0 },
                { "IsLocked", false },
                { "ResearchProgramNo", "111" },
                { "ExperimentName", "test" },
                { "MainResearchUnit", "" },
                { "HeadPI", "zz" },
                { "PlanSiteCount", null },
                { "PlanVisitCount", null },
                { "Indication", "肺癌" },
                { "IndicationOther", null }
            };


        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<Trial>>(url, jsonBody, restClient: pmclient);


        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }

    /// <summary>
    /// 删除项目
    /// </summary>
    [Fact]
    public async void Test_DeleteTrial()
    {
        var pmclient = RestHelper.InitRestHelper("http://123.56.94.154:8090/api", "PM01", MD5Helper.Md5("WHxckj@2019"));

        var url = $"/TrialConfig/abandonTrial/dc080000-3e2c-0016-fd6b-08db8cb80e5d/true";

        var jsonBody = new JObject
        { };


        var result = await RestHelper.Put_JsonBodyRequestAsync<ResponseOutput<string>>(url, jsonBody);


        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }

    #endregion


    #region 患者

    /// <summary>
    /// 查询患者列表
    /// </summary>
    [Fact]
    public async void Test_GetSubjctList()
    {
        var url = $"/subject/getSubjectList";

        var jsonBody = new JObject
            {
                { "Code", "" },
                { "Status", "" },
                { "SiteId", "" },
                { "ShortName", "" },
                { "Sex", "" },
                { "PageIndex", 1 },
                { "PageSize", 20 },
                { "TrialId", "dc080000-3e2c-0016-64c6-08db8cb8ed81" }
            };

        //测试删除Api
        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<PageOutput<PageOutput<SubjectQueryView>>>>(url, jsonBody);

        Assert.True(result.Data.CurrentPageData.Count >= 0);
    }

    /// <summary>
    /// 添加患者
    /// </summary>
    [Fact]
    public async void Test_AddSubjet()
    {

        var url = $"/subject/addOrUpdateSubject";
        var jsonBody = new JObject
        {
            { "Id", "" },
            { "Code", "01001" },
            { "ShortName", "" },
            { "Height", "" },
            { "Weight", "" },
            { "Age", "23" },
            { "Sex", "男" },
            { "BirthDate", "" },
            { "SiteId", "db83e2f5-1f2e-408f-a45b-08d8e1dcace0" },
            { "MedicalNo", "" },
            { "Status", 1 },
            { "FirstGiveMedicineTime", "" },
            { "OutEnrollmentTime", "" },
            { "VisitOverTime", "" },
            { "Reason", "" },
            { "StudyCount", "" },
            { "SignDate", "" },
            { "IsUrgent", false },
            { "TrialId", "dc080000-3e2c-0016-64c6-08db8cb8ed81" }
        };

        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<string>>(url, jsonBody);


        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }

    /// <summary>
    /// 更新患者
    /// </summary>
    [Fact]
    public async void Test_UpdateSubject()
    {
        var url = $"/subject/addOrUpdateSubject";
        var jsonBody = new JObject
                {
                    { "Id", "20430000-3e2c-0016-a444-08db791c6dad" },
                    { "Code", "患者12" },
                    { "ShortName", "" },
                    { "Height", "" },
                    { "Weight", "" },
                    { "Age", 33 },
                    { "Sex", "" },
                    { "BirthDate", null },
                    { "SiteId", "db83e2f5-1f2e-408f-a45b-08d8e1dcace0" },
                    { "MedicalNo", "" },
                    { "Status", 1 },
                    { "FirstGiveMedicineTime", null },
                    { "OutEnrollmentTime", null },
                    { "VisitOverTime", null },
                    { "Reason", "" },
                    { "StudyCount", "" },
                    { "SignDate", null },
                    { "IsUrgent", false },
                    { "TrialId", "20430000-3e2c-0016-aa08-08db791c6ae5" }
                };

        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<string>>(url, jsonBody);


        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }

    /// <summary>
    /// 删除患者
    /// </summary>

    [Fact]
    public async void Test_DeleteSubjet()
    {
        var url = $"/subject/deleteSubject/20430000-3e2c-0016-aa08-08db791c6ae5/20430000-3e2c-0016-d10d-08db791c6ef0";

        //测试删除Api
        var result = await RestHelper.DeleteRequestAsync<ResponseOutput<string>>(url);

        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }


    #endregion


    #region 参与人员
    /// <summary>
    /// 查询参与人员列表
    /// </summary>
    [Fact]
    public async void Test_GetTrialUserList()
    {
        var url = $"/trialMaintenance/getMaintenanceUserList";

        var jsonBody = new JObject
        {
            { "UserRealName", "" },
            { "UserName", "" },
            { "UserTypeId", "" },
            { "OrganizationName", "" },
            { "IsDeleted", null },
            { "PageIndex", 1 },
            { "PageSize", 20 },
            { "TrialId", "20430000-3e2c-0016-aa08-08db791c6ae5" }
        };

        //测试删除Api
        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<PageOutput<TrialMaintenanceDTO>>>(url, jsonBody);

        Assert.True(result.Data.CurrentPageData.Count >= 0);
    }


    /// <summary>
    /// 查询参与人员列表
    /// </summary>
    [Fact]
    public async void Test_GetTrialUserScreeningList()
    {
        var url = $"/trialMaintenance/getTrialUserScreeningList";

        var jsonBody = new JObject
        {
            { "UserRealName", "" },
            { "UserName", "" },
            { "UserTypeId", "" },
            { "OrganizationName", "" },
            { "IsDeleted", null },
            { "PageIndex", 1 },
            { "PageSize", 20 },
            { "TrialId", "20430000-3e2c-0016-aa08-08db791c6ae5" }
        };

        //测试删除Api
        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<PageOutput<TrialUserScreeningDTO>>>(url, jsonBody);

        Assert.True(result.Data.CurrentPageData.Count >= 0);
    }



    /// <summary>
    /// 添加参与人员
    /// </summary>
    [Fact]
    public async void Test_AddTrialUser()
    {

        var url = $"/trialMaintenance/addTrialUsers";
        var jsonBody = new JArray
            {
                new JObject
                {
                    { "Sex", 1 },
                    { "Phone", "" },
                    { "EMail", "446322065@qq.com" },
                    { "DepartmentName", "" },
                    { "PositionName", "" },
                    { "UserName", "IR02" },
                    { "IsSelect", false },
                    { "UserTypeId", "40240000-3e2c-0016-ad69-08db18965090" },
                    { "UserType", "IR" },
                    { "UserTypeEnum", 13 },
                    { "OrganizationName", "" },
                    { "UserRealName", "IR02 / IR02" },
                    { "UserId", "9c3b0000-3e2c-0016-3606-08db706de699" },
                    { "TrialId", "e4070000-3e2c-0016-2eb5-08db373d9ae2" }
                }
            };

        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<string>>(url, jsonBody);


        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }


    /// <summary>
    /// 更新项目参与用户
    /// </summary>
    [Fact]
    public async void Test_UpdateTrialUser()
    {
        var pmclient = RestHelper.InitRestHelper("http://123.56.94.154:8090/api", "PM01", MD5Helper.Md5("WHxckj@2019"));

        var url = $"/trialMaintenance/updateTrialUser";

        var jsonBody = new JObject
            {
                { "id", "dc080000-3e2c-0016-beab-08db8cce772d" },
                { "trialId", "e4070000-3e2c-0016-2eb5-08db373d9ae2" },
                { "isDeleted", true },
                { "removeTime", "2023-07-03" },
                { "joinTime", "" }
            };

        var result = await RestHelper.Put_JsonBodyRequestAsync<ResponseOutput<string>>(url, jsonBody,restClient: pmclient);


        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }


    #endregion


    #region 任务 和阅片


    /// <summary>
    /// 阅片任务分配列表
    /// </summary>
    [Fact]
    public async void Test_GetTrialSubjectAssignAndTask()
    {
        var url = $"/VisitTask/getSubjectAssignAndTaskStatList";

        var jsonBody = new JObject
                {
                    { "PageIndex", 1 },
                    { "PageSize", 20 },
                    { "Asc", true },
                    { "SortField", "" },
                    { "TrialId", "e4070000-3e2c-0016-2eb5-08db373d9ae2" },
                    { "SiteId", null },
                    { "SubjectId", null },
                    { "SubjectCode", null },
                    { "DoctorUserId", null },
                    { "IsHaveAssigned", null },
                    { "IsAssignConfirmed", null },
                    { "TrialReadingCriterionId", "e4070000-3e2c-0016-9b99-08db373d9aed" }
                };

        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<PageOutput<SubjectAssignStat>>>(url, jsonBody);

        Assert.True(result.Data.CurrentPageData.Count >= 0);
    }

    /// <summary>
    /// 阅片任务分配给阅片人
    /// </summary>
    [Fact]
    public async void Test_batchAssignDoctorToSubject()
    {
        var url = $"/VisitTask/batchAssignDoctorToSubject";

        var jsonBody = new JObject
            {
                { "TrialId", "e4070000-3e2c-0016-2eb5-08db373d9ae2" },
                { "TrialReadingCriterionId", "e4070000-3e2c-0016-9b99-08db373d9aed" },
                { "SubjectIdList", new JArray("7c3f0000-3e2c-0016-1129-08db51c37208") },
                {
                    "DoctorArmList", new JArray(
                        new JObject
                        {
                            { "ArmEnum", 0 },
                            { "DoctorUserId", "e4070000-3e2c-0016-4e7a-08db37438068" }
                        }
                    )
                }
            };

        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<PageOutput<TrialMaintenanceDTO>>>(url, jsonBody);

        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }



    /// <summary>
    /// 获取可分配阅片人列表
    /// </summary>

    [Fact]
    public async void Test_getDoctorSelectList()
    {
        var url = $"/TaskAllocationRule/getDoctorSelectList";

        var jsonBody = new JObject
                {
                    { "TrialId", "e4070000-3e2c-0016-2eb5-08db373d9ae2" },
                    { "ReadingCategory", 2 },
                    { "TrialReadingCriterionId", "e4070000-3e2c-0016-9b99-08db373d9aed" }
                };

        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<List<TrialDoctorUserSelectView>>>(url, jsonBody);

        Assert.True(result.Data.Count >= 0);
    }


    /// <summary>
    /// 取消分配的阅片人
    /// </summary>
    [Fact]
    public async void Test_cancelSubjectAssignedDoctor()
    {
        var url = $"/VisitTask/cancelSubjectAssignedDoctor";

        var jsonBody = new JObject
            {
                {
                    "CancelList", new JArray(
                        new JObject
                        {
                            { "Id", "dc080000-3e2c-0016-616d-08db8cd1f7ba" },
                            { "SubjectId", "7c3f0000-3e2c-0016-1129-08db51c37208" },
                            { "DoctorUserId", "e4070000-3e2c-0016-4e7a-08db37438068" },
                            { "ArmEnum", 0 },
                            { "IsCancelAssign", true }
                        }
                    )
                },
                { "Note", "\n取消阅片人(IR01(张 / 航));" },
                { "TrialReadingCriterionId", "e4070000-3e2c-0016-9b99-08db373d9aed" },
                { "TrialId", "e4070000-3e2c-0016-2eb5-08db373d9ae2" }
            };

        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<List<TrialDoctorUserSelectView>>>(url, jsonBody);

        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }


    /// <summary>
    /// 患者检查列表
    /// </summary>
    [Fact]
    public async void Test_getCRCVisitList()
    {
        var url = $"/QCList/getCRCVisitList";

        var jsonBody = new JObject
            {
                { "SubjectInfo", "" },
                { "SiteId", "" },
                { "PageIndex", 1 },
                { "PageSize", 20 },
                { "VisitPlanArray", new JArray() },
                { "AuditStateArray", new JArray() },
                { "SubmitState", null },
                { "ChallengeState", null },
                { "BeginSubmitTime", null },
                { "EndSubmitTime", null },
                { "TrialId", "e4070000-3e2c-0016-2eb5-08db373d9ae2" }
            };

        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<PageOutput<QCCRCVisitViewModel>>>(url, jsonBody);

        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }

    /// <summary>
    ///阅片跟踪列表
    /// </summary>
    [Fact]
    public async void Test_getReadingTaskList()
    {
        var url = $"/VisitTask/getReadingTaskList";

        var jsonBody = new JObject
            {
                { "SubjectInfo", "" },
                { "SiteId", "" },
                { "PageIndex", 1 },
                { "PageSize", 20 },
                { "VisitPlanArray", new JArray() },
                { "AuditStateArray", new JArray() },
                { "SubmitState", null },
                { "ChallengeState", null },
                { "BeginSubmitTime", null },
                { "EndSubmitTime", null },
                { "TrialId", "e4070000-3e2c-0016-2eb5-08db373d9ae2" }
            };

        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<PageOutput<ReadingTaskView>>>(url, jsonBody);

        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }

    /// <summary>
    /// IR 待阅任务列表
    /// </summary>
    [Fact]
    public async void Test_getIRUnReadSubjectTaskList()
    {
        var url = $"/VisitTask/getIRUnReadSubjectTaskList";

        var jsonBody = new JObject
            {
                { "SubjectCode", "" },
                { "PageIndex", 1 },
                { "PageSize", 20 },
                { "TrialId", "c02a0000-3e2c-0016-cb0f-08db715ea9be" },
                { "TrialReadingCriterionId", "c02a0000-3e2c-0016-e8ae-08db715ea9e4" }
            };

        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<PageOutput<IRUnReadSubjectView>>>(url, jsonBody);

        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }


    [Fact]
    public async void Test_getIRHaveReadTaskList()
    {
        var url = $"/VisitTask/getIRHaveReadTaskList";

        var jsonBody = new JObject
            {
                { "SubjectCode", "" },
                { "SortField", "" },
                { "PageIndex", 1 },
                { "PageSize", 20 },
                { "TaskState", null },
                { "ReadingCategory", null },
                { "TrialId", "c02a0000-3e2c-0016-cb0f-08db715ea9be" },
                { "TrialReadingCriterionId", "c02a0000-3e2c-0016-e8ae-08db715ea9e4" }
            };

        var result = await RestHelper.Post_JsonBodyRequestAsync<ResponseOutput<PageOutput<IRHaveReadView>>>(url, jsonBody);

        Assert.True(result.Code != ApiResponseCodeEnum.ApiInputError && result.Code != ApiResponseCodeEnum.ProgramException);
    }


    #endregion


    public void Dispose()
    {
        // 在测试结束后释放资源（例如关闭网络连接等）
        _client?.Dispose();
    }
}