//Case 62: 1.3.1_CreatePatient_Exception
        public void Run_Patient_CreatePatient_Exception_Case62()
        {
            int runCount = 0;

            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Create patient");

                CheckPoint pCreate = new CheckPoint("Create Patient", "Test description");
                r.CheckPoints.Add(pCreate);
                PatientService ps = new PatientService();
                XMLParameter pa = new XMLParameter("patient");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                        pa.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                }
                XMLResult result = ps.createPatient(pa);
                if (result.IsErrorOccured)
                {
                    pCreate.Result = TestResult.Pass;
                    pCreate.Outputs.AddParameter("That's ok to create patient error:", "Create Patient", result.Message);
                }
                else
                {
                    pCreate.Result = TestResult.Fail;
                    pCreate.Outputs.AddParameter("Expect create patient error, but it is succusss", "Create Patient", result.Message);
                }
                SaveRound(r);
            }

            Output();
        }
        //Case 139: 1.2.1_CreatePatient_Normal
        public void Run_Patient_CreatePatient_Normal_Case139()
        {
            int runCount = 0;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Create patient");

                CheckPoint pCreate = new CheckPoint("Create Patient", "Test description");
                r.CheckPoints.Add(pCreate);
                PatientService ps = new PatientService();
                XMLParameter pa = new XMLParameter("patient");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                        pa.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                }
                XMLResult result = ps.createPatient(pa);
                if (result.IsErrorOccured)
                {
                    pCreate.Result = TestResult.Fail;
                    pCreate.Outputs.AddParameter("Create error:", "Create Patient", result.Message);
                }
                else
                {

                    pCreate.Outputs.AddParameter("Patient ID:", "Create Patient", result.SingleResult);

                    XMLResult getPatient = ps.getPatient(result.SingleResult);
                    if (getPatient.IsErrorOccured)
                    {
                        pCreate.Result = TestResult.Fail;
                        pCreate.Outputs.AddParameter("Get created patient fail", "Get Patient", getPatient.ResultContent);
                    }
                    else
                    {
                        pCreate.Outputs.AddParameter("Get created patient OK", "Get Patient", getPatient.ResultContent);
                        XMLResult delPatient = ps.deletePatient(result.SingleResult);
                        if (delPatient.IsErrorOccured)
                        {
                            pCreate.Result = TestResult.Fail;
                            pCreate.Outputs.AddParameter("Delete created patient fail", "Delete Patient", delPatient.ResultContent);
                        }
                        else
                        {
                            pCreate.Outputs.AddParameter("Delete created patient OK", "Delete Patient", delPatient.ResultContent);
                            pCreate.Result = TestResult.Pass;
                        }
                    }
                }
                SaveRound(r);
            }
            Output();
        }
        /// <summary>
        /// Utility_s the create patient for specific case.
        /// </summary>
        /// <param name="caseID">The case ID.</param>
        /// <returns>The patien ID</returns>
        public static string Utility_CreatePatientForSpecificCase(string caseID)
        {
            string patientUID = null;

            PatientService ps = new PatientService();
            XMLParameter pa = new XMLParameter("patient");

            pa.AddParameter("first_name", caseID);
            pa.AddParameter("last_name", caseID);
            pa.AddParameter("middle_name", caseID);

            XMLResult result = ps.createPatient(pa);

            if (!result.IsErrorOccured)
            {
                patientUID = result.SingleResult;
            }

            return patientUID;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Utility_s the create patient for specific case.
        /// </summary>
        /// <param name="caseID">The case ID.</param>
        /// <returns>The patien ID</returns>
        public static string Utility_CreatePatientForSpecificCase(string caseID)
        {
            string patientUID = null;

            PatientService ps = new PatientService();
            XMLParameter   pa = new XMLParameter("patient");

            pa.AddParameter("first_name", caseID);
            pa.AddParameter("last_name", caseID);
            pa.AddParameter("middle_name", caseID);

            XMLResult result = ps.createPatient(pa);

            if (!result.IsErrorOccured)
            {
                patientUID = result.SingleResult;
            }

            return(patientUID);
        }
Exemplo n.º 5
0
        public void Run()
        {
            Round r = this.NewRound("R1","Test round");

            CheckPoint p = new CheckPoint("Create Patient", "Test description");

            r.CheckPoints.Add(p);

            PatientService ps = new PatientService();

            XMLParameter pa = new XMLParameter("patient");
            pa.AddParameter(r.DataSet.InputParameters.GetParameter("dafsd").Value, "pid888");
            pa.AddParameter("dpmsid", "dpmsid888");
            pa.AddParameter("firstname", "Test");
            pa.AddParameter("lastname", "Test");
            pa.AddParameter("sex", "male");

            XMLResult result= ps.createPatient(pa);

            if (result.IsErrorOccured)
            {
                p.Result = TestResult.Fail;
                p.Outputs.AddParameter("Error", result.Message);
            }
            else
            {
                p.Result = TestResult.Pass;
                p.Outputs.AddParameter("New patient Id", result.SingleResult);
            }

            SaveRound(r);

            Output();

            System.Windows.Forms.MessageBox.Show("Done");
        }
        //Case 1220: 1.9.1_WorkFlow_N2_Import CS Model_GetVolumeInfo
        public void Run_3D_ImportCSModel_GetVolumeInfo_Case1220()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            bool isDeletePatient = true;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Import image");

                ImportService importSvc = new ImportService();
                XMLParameter pCreatePatient = new XMLParameter("patient");
                XMLParameter pImportImage = new XMLParameter("import");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        pCreatePatient.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "import")
                    {
                        pImportImage.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                }

                XMLParameter epGetVolumeInfo = new XMLParameter();

                for (int i = 0; i < ids.ExpectedValues.Count; i++)
                {
                    if (ids.ExpectedValues.GetParameter(i).Step == "getVolumeInfo")
                    {
                        epGetVolumeInfo.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                    }
                }

                try
                {
                    PatientService patientSvc = new PatientService();
                    if (isCreatePatient)
                    {
                        CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                        r.CheckPoints.Add(pCreate);

                        XMLResult result = patientSvc.createPatient(pCreatePatient);
                        if (!result.IsErrorOccured)
                        {
                            patientUID = result.SingleResult;
                            pCreate.Result = TestResult.Pass;
                            pCreate.Outputs.AddParameter("Create patient UID", "Create Patient", patientUID);
                        }
                        else
                        {
                            pCreate.Result = TestResult.Fail;
                            pCreate.Outputs.AddParameter("Create patient returns error", "Create Patient", result.ResultContent);
                        }
                    }

                    CheckPoint cpImport = new CheckPoint("Import Image", "Test import");
                    r.CheckPoints.Add(cpImport);

                    string filePath = string.Empty;
                    string archivePath = string.Empty;
                    bool overrideExisted = false;
                    for (int c = 0; c < pImportImage.Length; c++)
                    {
                        if (pImportImage.GetParameterName(c) == "path")
                            filePath = pImportImage.GetParameterValue(c);
                        if (pImportImage.GetParameterName(c) == "archivePath")
                            archivePath = pImportImage.GetParameterValue(c);
                        if (pImportImage.GetParameterName(c) == "move")
                        {
                            if (pImportImage.GetParameterValue(c) == "true")
                                overrideExisted = true;
                        }
                    }

                    XMLResult rtlImport = importSvc.importObject(patientUID, "", filePath, archivePath, overrideExisted, "false");

                    /**********************************************
                        import return sample:
                        - <trophy type="result" version="1.0">
                          <status code="0" message="ok" />
                        - <volume>
                          <parameter key="internal_id" value="5412d81a-c096-4b0d-ab93-524266af21b6" />
                          </volume>
                          </trophy>
                     * **********************************************/

                    if (rtlImport.IsErrorOccured)
                    {
                        cpImport.Result = TestResult.Fail;
                        cpImport.Outputs.AddParameter("Import volume fail", "Import", rtlImport.Message);
                        cpImport.Outputs.AddParameter("Import volume returns error code", "Import", rtlImport.Code.ToString());
                    }
                    else
                    {
                        // Check the return contiains image id and ps id
                        string volumeID = null;
                        volumeID = rtlImport.MultiResults[0].GetParameterValueByName("internal_id"); // image internal_id
                        if (volumeID == null || volumeID == string.Empty)
                        {
                            cpImport.Result = TestResult.Fail;
                            cpImport.Outputs.AddParameter("Import volume returns wrong volume internal id", "Import", rtlImport.ResultContent);
                        }
                        else
                        {
                            cpImport.Result = TestResult.Pass;
                            cpImport.Outputs.AddParameter("import volume returns OK", "Import", rtlImport.ResultContent);
                        }

                        #region Call getVolumeInfo to check expected key and value
                        VolumeService volumeSvc = new VolumeService();

                        XMLParameter pGetVolumeInfo = new XMLParameter("volume");
                        pGetVolumeInfo.AddParameter("internal_id", volumeID);

                        CheckPoint cpGetVolumeInfo = new CheckPoint("GetVolumeInfo", "Call GetVolumeInfo to check the return value");
                        r.CheckPoints.Add(cpGetVolumeInfo);

                        XMLResult rtGetVolumeInfo = volumeSvc.getVolumeInfo(pGetVolumeInfo);
                        if (rtGetVolumeInfo.IsErrorOccured)
                        {
                            cpGetVolumeInfo.Result = TestResult.Fail;
                            cpGetVolumeInfo.Outputs.AddParameter("Get Volume Info return error", "GetVolumeInfo", rtGetVolumeInfo.ResultContent);
                        }
                        else
                        {
                            cpGetVolumeInfo.Outputs.AddParameter("Get Volume Info return success", "GetVolumeInfo", rtGetVolumeInfo.Message);

                            //Check the return info contain the expected key and value: parameter key="XXX" value="XXX"
                            foreach (XMLParameterNode node in epGetVolumeInfo.Parameters)
                            {
                                if (!rtGetVolumeInfo.ResultContent.Contains("parameter key=\"" + node.ParameterName + "\" value=\"" + node.ParameterValue + "\""))
                                {
                                    cpGetVolumeInfo.Result = TestResult.Fail;
                                    cpGetVolumeInfo.Outputs.AddParameter("Get Volume Info returns wrong key-value info for: " + node.ParameterName, "GetVolumeInfo", rtGetVolumeInfo.ResultContent);
                                    continue;
                                }
                                else
                                {
                                    cpGetVolumeInfo.Outputs.AddParameter("Get Volume Info returns correct key-value info for: " + node.ParameterName, "GetVolumeInfo", "ok");
                                }
                            }

                            if (cpGetVolumeInfo.Result != TestResult.Fail)
                            {
                                cpGetVolumeInfo.Result = TestResult.Pass;
                                cpGetVolumeInfo.Outputs.AddParameter("Get Volume Info returns all correct info", "GetVolumeInfo", rtGetVolumeInfo.ResultContent);
                            }
                        }
                        #endregion
                    }

                    if (isDeletePatient)
                    {
                        CheckPoint cpDelete = new CheckPoint("Delete Patient", "Test delete patient");
                        r.CheckPoints.Add(cpDelete);
                        XMLResult rltDelete = patientSvc.deletePatient(patientUID);
                        if (rltDelete.IsErrorOccured)
                        {
                            cpDelete.Outputs.AddParameter("Delete created patient returns error", "Delete Patient", rltDelete.Message);
                            cpDelete.Result = TestResult.Fail;
                        }
                        else
                        {
                            cpDelete.Outputs.AddParameter("Delete created patient returns OK", "Delete Patient", rltDelete.Message);
                            cpDelete.Result = TestResult.Pass;
                        }
                    }

                    SaveRound(r);
                }
                catch (Exception ex)
                {
                    CheckPoint cp = new CheckPoint();
                    r.CheckPoints.Add(cp);
                    cp.Outputs.AddParameter("Exception thrown", "Exception Message", ex.ToString());
                    cp.Result = TestResult.Fail;
                    SaveRound(r);
                }
            }
            Output();
        }
        // Case 721: 1.3.10_ImportImage_N02_Archived image
        public void Run_Import_ArchivedImage_Case721()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            bool isDeletePatient = true;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Import image");

                ImportService ims = new ImportService();
                XMLParameter pa = new XMLParameter("patient");
                XMLParameter ia = new XMLParameter("import");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        pa.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "import")
                    {
                        ia.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                }

                XMLParameter epGetImagInfo = new XMLParameter();
                XMLParameter epGetImageDescription = new XMLParameter();

                for (int i = 0; i < ids.ExpectedValues.Count; i++)
                {
                    if (ids.ExpectedValues.GetParameter(i).Step == "getImageInfo")
                    {
                        epGetImagInfo.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                    }
                    else if (ids.ExpectedValues.GetParameter(i).Step == "getImageDescription")
                    {
                        epGetImageDescription.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                    }
                }

                try
                {
                    PatientService patientSvc = new PatientService();
                    if (isCreatePatient)
                    {
                        CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                        r.CheckPoints.Add(pCreate);

                        XMLResult result = patientSvc.createPatient(pa);
                        if (!result.IsErrorOccured)
                        {
                            patientUID = result.SingleResult;
                            pCreate.Result = TestResult.Pass;
                            pCreate.Outputs.AddParameter("Create patient UID", "Create Patient", patientUID);
                        }
                        else
                        {
                            pCreate.Result = TestResult.Fail;
                            pCreate.Outputs.AddParameter("Create patient returns error", "Create Patient", result.ResultContent);
                        }
                    }

                    CheckPoint pImport = new CheckPoint("Import Image", "Test import");
                    r.CheckPoints.Add(pImport);

                    string filePath = string.Empty;
                    string archivePath = string.Empty;
                    bool move = false;
                    for (int c = 0; c < ia.Length; c++)
                    {
                        if (ia.GetParameterName(c) == "path")
                            filePath = ia.GetParameterValue(c);
                        if (ia.GetParameterName(c) == "archivePath")
                            archivePath = ia.GetParameterValue(c);
                        if (ia.GetParameterName(c) == "move")
                        {
                            if (ia.GetParameterValue(c) == "true")
                                move = true;
                        }
                    }

                    XMLResult rslImport = ims.importObject(patientUID, "", filePath, archivePath, move, "false");

                    //import return sample:
                    //   <trophy type="result" version="1.0">
                    //           <status code="0" message="ok" />
                    //           <image><parameter key="internal_id" value="2bfb416b-037e-41e7-aaef-8d2bd08b1ae7" /></image>
                    //           <presentationstate><parameter key="internal_id" value="75675345-a164-4088-b6d3-1b2ae86b703b" /></presentationstate>
                    // </trophy>

                    if (rslImport.IsErrorOccured)
                    {
                        pImport.Result = TestResult.Fail;
                        pImport.Outputs.AddParameter("Import image fail", "Import", rslImport.Message);
                        pImport.Outputs.AddParameter("Import image returns error code", "Import", rslImport.Code.ToString());
                    }
                    else
                    {
                        // Check the return contiains image id and ps id
                        string imageID = null;
                        imageID = rslImport.MultiResults[0].GetParameterValueByName("internal_id"); // image internal_id
                        if (imageID == null || imageID == string.Empty)
                        {
                            pImport.Result = TestResult.Fail;
                            pImport.Outputs.AddParameter("Import image returns wrong image internal id", "Import", rslImport.ResultContent);
                        }

                        string psID = null;
                        psID = rslImport.MultiResults[1].GetParameterValueByName("internal_id"); // ps internal_id
                        if (psID == null || psID == string.Empty)
                        {
                            pImport.Result = TestResult.Fail;
                            pImport.Outputs.AddParameter("import image returns wrong ps internal id", "Import", rslImport.ResultContent);
                        }
                        else
                        {
                            pImport.Result = TestResult.Pass;
                            pImport.Outputs.AddParameter("import image returns OK", "Import", rslImport.ResultContent);
                        }

                        #region Call getImageInfo to check expected key and value
                        ImageService imageSvc = new ImageService();

                        XMLParameter pGetImageInfo = new XMLParameter("image");
                        pGetImageInfo.AddParameter("internal_id", imageID);

                        CheckPoint cpGetImageInfo = new CheckPoint("GetImageInfo", "Call GetImageInfo to check the dcm_anatomic_region value");
                        r.CheckPoints.Add(cpGetImageInfo);

                        XMLResult rtGetImageInfo = imageSvc.getImageInfo(pGetImageInfo);
                        if (rtGetImageInfo.IsErrorOccured)
                        {
                            cpGetImageInfo.Result = TestResult.Fail;
                            cpGetImageInfo.Outputs.AddParameter("Get Image Info return error", "getImageInfo", rtGetImageInfo.ResultContent);
                        }
                        else
                        {
                            cpGetImageInfo.Outputs.AddParameter("Get Image Info return success", "getImageInfo", rtGetImageInfo.Message);

                            //Check the return info contain the expected key and value: parameter key="XXX" value="XXX"
                            foreach (XMLParameterNode node in epGetImagInfo.Parameters)
                            {
                                if (!rtGetImageInfo.ResultContent.Contains("parameter key=\"" + node.ParameterName + "\" value=\"" + node.ParameterValue + "\""))
                                {
                                    cpGetImageInfo.Result = TestResult.Fail;
                                    cpGetImageInfo.Outputs.AddParameter("Get Image Info returns wrong key-value info for: " + node.ParameterName, "GetImageInfo", rtGetImageInfo.ResultContent);
                                    continue;
                                }
                                else
                                {
                                    cpGetImageInfo.Outputs.AddParameter("Get Image Info returns correct key-value info for: " + node.ParameterName, "GetImageInfo", "ok");
                                }
                            }

                            if (cpGetImageInfo.Result != TestResult.Fail)
                            {
                                cpGetImageInfo.Result = TestResult.Pass;
                                cpGetImageInfo.Outputs.AddParameter("Get Image Info return all correct info", "GetImageInfo", rtGetImageInfo.ResultContent);
                            }
                        }
                        #endregion

                        #region Call getImageDescription to check expected key and value
                        CheckPoint cpGetImageDescription = new CheckPoint("GetImageDescription", "Call GetImageDescription to check the info in return value");
                        r.CheckPoints.Add(cpGetImageDescription);

                        XMLResult rtGetImageDescription = imageSvc.getImageDescription(imageID);
                        if (rtGetImageDescription.IsErrorOccured)
                        {
                            cpGetImageDescription.Result = TestResult.Fail;
                            cpGetImageDescription.Outputs.AddParameter("Get Image Description returns error", "getImageDescription", rtGetImageDescription.ResultContent);
                        }
                        else
                        {
                            cpGetImageDescription.Outputs.AddParameter("Get Image Description return success", "getImageDescription", rtGetImageDescription.Message);

                            //Check the return info contain the expected key and value: parameter key="XXX" value="XXX"
                            foreach (XMLParameterNode node in epGetImageDescription.Parameters)
                            {
                                if (!rtGetImageDescription.ResultContent.Contains("parameter key=\"" + node.ParameterName + "\" value=\"" + node.ParameterValue + "\""))
                                {
                                    cpGetImageDescription.Result = TestResult.Fail;
                                    cpGetImageDescription.Outputs.AddParameter("Get Image Description returns wrong key-value info for: " + node.ParameterName, "GetImageDescription", rtGetImageDescription.ResultContent);
                                    continue;
                                }
                                else
                                {
                                    cpGetImageDescription.Outputs.AddParameter("Get Image Description returns correct key-value info for: " + node.ParameterName, "GetImageDescription", "ok");
                                }
                            }

                            if (cpGetImageDescription.Result != TestResult.Fail)
                            {
                                cpGetImageDescription.Result = TestResult.Pass;
                                cpGetImageDescription.Outputs.AddParameter("Get Image Description returns all correct info", "GetImageDescription", rtGetImageDescription.ResultContent);
                            }
                        }
                        #endregion
                    }

                    if (isDeletePatient)
                    {
                        CheckPoint cpDelete = new CheckPoint("Delete Patient", "Test delete patient");
                        r.CheckPoints.Add(cpDelete);
                        XMLResult rltDelete = patientSvc.deletePatient(patientUID);
                        if (rltDelete.IsErrorOccured)
                        {
                            cpDelete.Outputs.AddParameter("Delete created patient returns error", "Delete Patient", rltDelete.Message);
                            cpDelete.Result = TestResult.Fail;
                        }
                        else
                        {
                            cpDelete.Outputs.AddParameter("Delete created patient returns OK", "Delete Patient", rltDelete.Message);
                            cpDelete.Result = TestResult.Pass;
                        }
                    }

                    SaveRound(r);
                }
                catch (Exception ex)
                {
                    CheckPoint cp = new CheckPoint();
                    r.CheckPoints.Add(cp);
                    cp.Outputs.AddParameter("Exception thrown", "Exception Message", ex.Message);
                    cp.Result = TestResult.Fail;
                    SaveRound(r);
                }
            }
            Output();
        }
        //Case 1043: 1.3.17_workflow_ImportCeph_GetImageInfo_RadilogIsNotSaved
        public void Run_WorkFlow_ImportCeph_RadioLog_Case1043()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            bool isDeletePatient = true;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Import image");

                PatientService patientSvc = new PatientService();
                ImportService importSvc = new ImportService();
                ImageService imageSvc = new ImageService();

                string radioLogBeforeImport = string.Empty;
                string radioLogAfterImport = string.Empty;
                string imageID = null;

                XMLParameter pa = new XMLParameter("patient");
                XMLParameter ia = new XMLParameter("import");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        pa.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "import")
                    {
                        ia.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                }

                XMLParameter epGetImagInfo = new XMLParameter();
                for (int i = 0; i < ids.ExpectedValues.Count; i++)
                {
                    if (ids.ExpectedValues.GetParameter(i).Step == "getImageInfo")
                    {
                        epGetImagInfo.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                    }
                }

                try
                {
                    #region Step1: Create Image
                    if (isCreatePatient)
                    {
                        CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                        r.CheckPoints.Add(pCreate);

                        XMLResult rtCreatePatient = patientSvc.createPatient(pa);
                        if (!rtCreatePatient.IsErrorOccured)
                        {
                            patientUID = rtCreatePatient.SingleResult;
                            pCreate.Outputs.AddParameter("Create patient UID", "Create Patient", patientUID);
                            pCreate.Result = TestResult.Pass;
                        }
                    }
                    #endregion

                    #region Step2: Get patient radio log info before import
                    CheckPoint cpGetPatientBeforeImport = new CheckPoint("GetPatient", "Get Patient Info before import image");
                    r.CheckPoints.Add(cpGetPatientBeforeImport);

                    XMLResult rtGetPatientBeforeImport = patientSvc.getPatient(patientUID);
                    if (rtGetPatientBeforeImport.IsErrorOccured)
                    {
                        cpGetPatientBeforeImport.Result = TestResult.Fail;
                        cpGetPatientBeforeImport.Outputs.AddParameter("Get Patient Info before import image returns error", "GetPatient", rtGetPatientBeforeImport.ResultContent);
                    }
                    else
                    {
                        cpGetPatientBeforeImport.Result = TestResult.Pass;
                        cpGetPatientBeforeImport.Outputs.AddParameter("Get Patient Info before import image returns ok", "GetPatient", rtGetPatientBeforeImport.ResultContent);

                        radioLogBeforeImport = rtGetPatientBeforeImport.MultiResults[0].GetParameterValueByName("cumulative_dose");  //get the cumulative_dose info
                    }
                    #endregion

                    #region Step3: Import Image
                    CheckPoint pImport = new CheckPoint("Import Image", "Test import");
                    r.CheckPoints.Add(pImport);

                    string filePath = string.Empty;
                    string archivePath = string.Empty;
                    bool move = false;
                    for (int c = 0; c < ia.Length; c++)
                    {
                        if (ia.GetParameterName(c) == "path")
                        {
                            filePath = ia.GetParameterValue(c);
                        }
                        else if (ia.GetParameterName(c) == "archivePath")
                        {
                            archivePath = ia.GetParameterValue(c);
                        }
                        else if (ia.GetParameterName(c) == "move")
                        {
                            if (ia.GetParameterValue(c) == "true")
                            {
                                move = true;
                            }
                        }
                    }

                    XMLResult rtlImport = importSvc.importObject(patientUID, "", filePath, archivePath, move, "false");

                    //import return sample:
                    //   <trophy type="result" version="1.0">
                    //           <status code="0" message="ok" />
                    //           <image><parameter key="internal_id" value="2bfb416b-037e-41e7-aaef-8d2bd08b1ae7" /></image>
                    //           <presentationstate><parameter key="internal_id" value="75675345-a164-4088-b6d3-1b2ae86b703b" /></presentationstate>
                    // </trophy>

                    if (rtlImport.IsErrorOccured)
                    {
                        pImport.Result = TestResult.Fail;
                        pImport.Outputs.AddParameter("Import image fail", "Import", rtlImport.Message);
                        pImport.Outputs.AddParameter("Import image returns error code", "Import", rtlImport.Code.ToString());
                    }
                    else
                    {
                        // Check the return contiains image id and ps id
                        imageID = rtlImport.MultiResults[0].GetParameterValueByName("internal_id"); // image internal_id
                        if (imageID == null || imageID == string.Empty)
                        {
                            pImport.Result = TestResult.Fail;
                            pImport.Outputs.AddParameter("Import image returns wrong image internal id", "Import", rtlImport.ResultContent);
                        }

                        string psID = null;
                        psID = rtlImport.MultiResults[1].GetParameterValueByName("internal_id"); // ps internal_id
                        if (psID == null || psID == string.Empty)
                        {
                            pImport.Result = TestResult.Fail;
                            pImport.Outputs.AddParameter("import image returns wrong ps internal id", "Import", rtlImport.ResultContent);
                        }
                        else
                        {
                            pImport.Result = TestResult.Pass;
                            pImport.Outputs.AddParameter("import image returns OK", "Import", rtlImport.ResultContent);
                        }
                    }
                    #endregion

                    #region Step4: Call GetImageInfo to check the radio log info
                    CheckPoint cpGetImageInfo = new CheckPoint("GetImageInfo", "Get the image info of the imported image");
                    r.CheckPoints.Add(cpGetImageInfo);

                    XMLParameter pGetImageInfo = new XMLParameter("image");
                    pGetImageInfo.AddParameter("internal_id", imageID);
                    XMLResult rtGetImageInfo = imageSvc.getImageInfo(pGetImageInfo);

                    if (rtGetImageInfo.IsErrorOccured)
                    {
                        cpGetImageInfo.Result = TestResult.Fail;
                        cpGetImageInfo.Outputs.AddParameter("Get the image info of the imported image return error", "GetImageInfo", rtGetImageInfo.ResultContent);
                    }
                    else
                    {
                        cpGetImageInfo.Outputs.AddParameter("Get Image Info return success", "getImageInfo", rtGetImageInfo.Message);

                        //Check the return info contain the expected key and value: <parameter key="XXX" value="XXX" />
                        foreach (XMLParameterNode node in epGetImagInfo.Parameters)
                        {
                            if (!rtGetImageInfo.ResultContent.Contains("parameter key=\"" + node.ParameterName + "\" value=\"" + node.ParameterValue + "\""))
                            {
                                cpGetImageInfo.Result = TestResult.Fail;
                                cpGetImageInfo.Outputs.AddParameter("Get Image Info returns wrong key-value info for: " + node.ParameterName, "GetImageInfo", rtGetImageInfo.ResultContent);
                                continue;
                            }
                            else
                            {
                                cpGetImageInfo.Outputs.AddParameter("Get Image Info returns correct key-value info for: " + node.ParameterName, "GetImageInfo", "ok");
                            }
                        }

                        if (cpGetImageInfo.Result != TestResult.Fail)
                        {
                            cpGetImageInfo.Result = TestResult.Pass;
                            cpGetImageInfo.Outputs.AddParameter("Get Image Info return all correct info", "GetImageInfo", rtGetImageInfo.ResultContent);
                        }
                    }
                    #endregion

                    #region Step5: Get patient radio log info after import
                    CheckPoint cpGetPatientAfterImport = new CheckPoint("GetPatient", "Get Patient Info after import image");
                    r.CheckPoints.Add(cpGetPatientAfterImport);

                    XMLResult rtGetPatientAfterImport = patientSvc.getPatient(patientUID);
                    if (rtGetPatientAfterImport.IsErrorOccured)
                    {
                        cpGetPatientAfterImport.Result = TestResult.Fail;
                        cpGetPatientAfterImport.Outputs.AddParameter("Get Patient Info after import image returns error", "GetPatient", rtGetPatientAfterImport.ResultContent);
                    }
                    else
                    {
                        cpGetPatientAfterImport.Result = TestResult.Pass;
                        cpGetPatientAfterImport.Outputs.AddParameter("Get Patient Info after import image returns ok", "GetPatient", rtGetPatientAfterImport.ResultContent);

                        radioLogAfterImport = rtGetPatientAfterImport.MultiResults[0].GetParameterValueByName("cumulative_dose");  //get the cumulative_dose info
                    }
                    #endregion

                    #region Step6: Check the patient radio log info not changes after import image
                    CheckPoint cpPatientRadioLogInfo = new CheckPoint("Patient Radiolog Info", "Check patient radio log info not changes aftert import image");
                    r.CheckPoints.Add(cpPatientRadioLogInfo);

                    if (radioLogAfterImport == radioLogBeforeImport)
                    {
                        cpPatientRadioLogInfo.Result = TestResult.Pass;
                        cpPatientRadioLogInfo.Outputs.AddParameter("Patient radio log info not changes aftert import image", "Patient Radiolog Info", "Before import value is: " + radioLogBeforeImport + ". After import value is: " + radioLogAfterImport);
                    }
                    else
                    {
                        cpPatientRadioLogInfo.Result = TestResult.Fail;
                        cpPatientRadioLogInfo.Outputs.AddParameter("Patient radio log info  changes aftert import image", "Patient Radiolog Info", "Before import value is: " + radioLogBeforeImport + ". After import value is: " + radioLogAfterImport);
                    }
                    #endregion

                    #region Step7: Delete Patient
                    if (isDeletePatient)
                    {
                        CheckPoint cpDelete = new CheckPoint("Delete Patient", "Test delete patient");
                        r.CheckPoints.Add(cpDelete);
                        XMLResult rltDelete = patientSvc.deletePatient(patientUID);
                        if (rltDelete.IsErrorOccured)
                        {
                            cpDelete.Outputs.AddParameter("Delete created patient returns error", "Delete Patient", rltDelete.Message);
                            cpDelete.Result = TestResult.Fail;
                        }
                        else
                        {
                            cpDelete.Outputs.AddParameter("Delete created patient returns OK", "Delete Patient", rltDelete.Message);
                            cpDelete.Result = TestResult.Pass;
                        }
                    }
                    #endregion

                    SaveRound(r);
                }
                catch (Exception ex)
                {
                    CheckPoint cp = new CheckPoint();
                    r.CheckPoints.Add(cp);
                    cp.Outputs.AddParameter("Exception thrown", "Exception Message", ex.Message);
                    cp.Result = TestResult.Fail;
                    SaveRound(r);
                }
            }
            Output();
        }
        //Case 34: 1.3.1_SetPatient_Normal
        public void Run_Patient_SetPatient_Normal_Case34()
        {
            int runCount = 0;
            int matchItem = 1;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "set patient");
                CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                r.CheckPoints.Add(pCreate);
                PatientService ps = new PatientService();

                XMLParameter cpatientData = new XMLParameter("patient");
                XMLParameter spatientData = new XMLParameter("patient");

                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        cpatientData.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "set")
                    {
                        spatientData.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        matchItem++;
                    }
                }
                if (isCreatePatient)
                {
                    XMLResult rslCreate = ps.createPatient(cpatientData);
                    if (!rslCreate.IsErrorOccured)
                    {
                        patientUID = rslCreate.SingleResult;
                        pCreate.Result = TestResult.Pass;
                        pCreate.Outputs.AddParameter("create", "Create patient UID", patientUID);
                        //System.Diagnostics.Debug.Print("PAS: Create patient UID:{0}",patientUID);
                    }
                    else
                    {
                        pCreate.Result = TestResult.Fail;
                        pCreate.Outputs.AddParameter("create", "Create patient ERR", rslCreate.Message);
                        //System.Diagnostics.Debug.Print("PAS: Create patient ERR:{0}",rslCreate.Message);
                    }
                }

                CheckPoint pSet = new CheckPoint("Set Patient", "Test set");
                r.CheckPoints.Add(pSet);

                XMLResult rslSet = ps.setPatient(spatientData, patientUID);
                System.Threading.Thread.Sleep(500);

                XMLResult rslGet = ps.getPatient(patientUID);

                if (rslSet.IsErrorOccured || rslGet.IsErrorOccured)
                {
                    pSet.Result = TestResult.Fail;
                    pSet.Outputs.AddParameter("set", "Set patient ERR", patientUID);
                }

                for (int j = 0; j < rslGet.ArrayResult.Length; j++)
                {
                    for (int k = 0; k < spatientData.Length; k++)
                    {
                        if (rslGet.ArrayResult.GetParameterName(j) == spatientData.GetParameterName(k)
                          && rslGet.ArrayResult.GetParameterValue(j) == spatientData.GetParameterValue(k))
                            matchItem--;
                    }
                }
                //System.Diagnostics.Debug.Print("PAS: Get patient match:{0}",matchItem - 1);
                if (matchItem == 1)
                {
                    pSet.Outputs.AddParameter("set", "Set patient OK", patientUID);
                }
                else
                {
                    pSet.Result = TestResult.Fail;
                    pSet.Outputs.AddParameter("set", "Set patient ERR", rslSet.Message);
                }

                XMLResult delPat = ps.deletePatient(patientUID);
                if (!delPat.IsErrorOccured)
                {
                    pSet.Outputs.AddParameter("Delete created patient OK", "Delete Patient", delPat.Message);
                    pSet.Result = TestResult.Pass;
                }

                SaveRound(r);
            }
            Output();
        }
        //Case 1091: 1.3.7_WorkFlow_AcquireRVG+SetImageInfo+GetPresentationStateInfo_RadioLogInformation
        public void Run_PS_Acq_Radiolog_Case1091()
        {
            //int runCount = this.Input.Repetition;

            int runCount = 0; // this is the initial run count. Use this count to repeat different test data set.

            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Test round");

                //Mark the check point here to indicate what's the check point here
                CheckPoint p1 = new CheckPoint("createPatient", "Setup environment of createPatient");
                CheckPoint p2 = new CheckPoint("startAcquisition", "Setup environment of acquisition");
                CheckPoint p3 = new CheckPoint("getAcquisitionResult", "Setup environment of image and PS id");
                CheckPoint p4 = new CheckPoint("setImageInfo", "Setup environment of setImageInfo");
                CheckPoint p5 = new CheckPoint("getImageInfo", "Test getImageInfo");
                CheckPoint p6 = new CheckPoint("getPresentationStateInfo", "Test getPresentationStateInfo");

                r.CheckPoints.Add(p1);
                r.CheckPoints.Add(p2);
                r.CheckPoints.Add(p3);
                r.CheckPoints.Add(p4);
                r.CheckPoints.Add(p5);
                r.CheckPoints.Add(p6);

                //create required PAS service instaces here
                PatientService pats = new PatientService();
                AcquisitionService acq = new AcquisitionService();
                ImageService img = new ImageService();
                PresentationStateService ps = new PresentationStateService();

                //create input parameters here, it may include XML path type and string type value
                XMLParameter pa1 = new XMLParameter("patient");
                XMLParameter pa2 = new XMLParameter("acq_info");
                XMLParameter pa3 = new XMLParameter("getAcquisitionResult");
                XMLParameter pa4 = new XMLParameter("image");
                XMLParameter pa5 = new XMLParameter("image");
                XMLParameter pt6 = new XMLParameter("presentationstate");
                XMLParameterCollection pa6 = new XMLParameterCollection();

                try
                {

                    for (int i = 0; i < ids.InputParameters.Count; i++)
                    {
                        switch (ids.InputParameters.GetParameter(i).Step)
                        {
                            case "createPatient":
                                pa1.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                                break;
                            case "acquire":
                                pa2.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                                break;
                            case "setImageInfo":
                                pa4.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                                break;
                            default:
                                Console.WriteLine("There is no valid selection when parse input parameters.");
                                break;
                        }
                    }

                    //If we need change parameter by specific logic, please put code here

                    //Get service result
                    //Step1 result

                    XMLResult step1_result = pats.createPatient(pa1);

                    //Log step1 service output
                    if (step1_result.IsErrorOccured)
                    {
                        p1.Result = TestResult.Fail;
                        p1.Outputs.AddParameter("createPatient", "Error", step1_result.ResultContent);
                        SaveRound(r);
                        continue;
                    }

                    p1.Result = TestResult.Pass;
                    p1.Outputs.AddParameter("createPatient", "Success", step1_result.ResultContent);

                    //Change input parameter according the output of Step1
                    pa2.AddParameter("patient_internal_id", step1_result.SingleResult);

                    //Step2 result

                    //if acquireType isn't emtpy string, skip step2, here is only RVG acquisition
                    bool acqflag = true;
                    XMLResult step3_result = new XMLResult();
                    if (pa2.GetParameterValueByName("acquireType") == null || pa2.GetParameterValueByName("acquireType") == "")
                    {
                        XMLResult rslAcqRVG = acq.startAcquisition(pa2);
                        System.Threading.Thread.Sleep(3000);
                        if (rslAcqRVG.IsErrorOccured)
                        {
                            System.Diagnostics.Debug.Print("Acquire fail:");
                            p2.Result = TestResult.Fail;
                            p2.Outputs.AddParameter("acquire", "Acquire image error", rslAcqRVG.Message);
                        }
                        else
                        {
                            p2.Result = TestResult.Pass;
                            p2.Outputs.AddParameter("acquire", "Acquire session ID", rslAcqRVG.SingleResult);
                            int DORVGcount = 0;
                            do
                            {
                                System.Threading.Thread.Sleep(3000);
                                System.Diagnostics.Debug.Print("get acquire in do");
                                DORVGcount++;
                                step3_result = acq.getAcquisitionResult(rslAcqRVG.SingleResult);
                                if (!step3_result.IsErrorOccured)
                                {
                                    // move this to out of do-while loop as need check the return value is correct or not there
                                    //p3.Result = TestResult.Pass;
                                    //p3.Outputs.AddParameter("acquire", "Get acquire image", step3_result.Message);
                                    acqflag = false;
                                    break;
                                }
                                if (step3_result.Code != 501)
                                {
                                    continue;
                                }
                                else
                                {
                                    p3.Result = TestResult.Fail;
                                    p3.Outputs.AddParameter("acquire", "Get acquire image error", step3_result.Message);
                                    acqflag = false;
                                }
                                System.Diagnostics.Debug.Print("get acquireResult:" + DORVGcount);
                                if (DORVGcount > 60)
                                {
                                    p3.Result = TestResult.Fail;
                                    p3.Outputs.AddParameter("acquire", "Get acquire image error", "Acquire greate with 3 minutes, timeout!");
                                    acqflag = false;
                                    break;
                                }
                            } while (acqflag);
                        }
                    }

                    //Change input parameter according the output of Step3
                    // if step3 is skipped, step4,step5,setp6 input has no need parameter of internal_id

                    //2012-11-28/19006723: Chanege as ther getAcquisitionResult result change, need new way to get the image ID and PS ID
                    string imgInternalID = string.Empty;
                    string psInternalID = string.Empty;

                    ParseXMLContent parser = new ParseXMLContent(step3_result.ResultContent); // To parse the return XML

                    string imageID = parser.getStringWithPathAndType("trophy/object_info", "image", "value");
                    string[] imageIDs = imageID.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    int imageCount = imageIDs.Length;

                    string psID = parser.getStringWithPathAndType("trophy/object_info", "presentation_state", "value");
                    string[] psIDs = psID.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    int psCount = psIDs.Length;

                    if (imageCount == 1 && psCount == 1)
                    {
                        p3.Result = TestResult.Pass;
                        p3.Outputs.AddParameter("acquire", "getAcquisitionResult return OK", step3_result.ResultContent);

                        imgInternalID = imageIDs[0];
                        psInternalID = psIDs[0];

                        pa5.AddParameter("internal_id", imgInternalID);
                        pt6.AddParameter("internal_id", psInternalID);
                    }
                    else
                    {
                        p3.Result = TestResult.Fail;
                        p3.Outputs.AddParameter("acquire", "getAcquisitionResult return ERROR", step3_result.ResultContent);
                        SaveRound(r);
                        continue; // Not run below steps
                    }

                    //if (step3_result.MultiResults.Count > 0)
                    //{
                    //    for (int j = 0; j < step3_result.MultiResults.Count; j++)
                    //    {
                    //        for (int i = 0; i < step3_result.MultiResults[j].Parameters.Count; i++)
                    //        {
                    //            if (step3_result.MultiResults[j].Parameters[i].ParameterName == "image_internal_id")
                    //            {
                    //                imgInternalID = step3_result.MultiResults[j].Parameters[i].ParameterValue;
                    //                pa5.AddParameter("internal_id", step3_result.MultiResults[j].Parameters[i].ParameterValue);
                    //            }
                    //            if (step3_result.MultiResults[j].Parameters[i].ParameterName == "presentation_state_internal_id")
                    //            {
                    //                pt6.AddParameter("internal_id", step3_result.MultiResults[j].Parameters[i].ParameterValue);
                    //            }
                    //        }
                    //    }
                    //}

                    //Step4 result
                    XMLResult step4_result = img.setImageInfo(pa4, imgInternalID);

                    //Log step4 service output
                    if (step4_result.IsErrorOccured)
                    {
                        p4.Result = TestResult.Fail;
                        p4.Outputs.AddParameter("setImageInfo", "Error", step4_result.ResultContent);
                        SaveRound(r);
                        continue;
                    }

                    p4.Result = TestResult.Pass;
                    p4.Outputs.AddParameter("setImageInfo", "Success", step4_result.ResultContent);

                    //Step5 result
                    XMLResult step5_result = img.getImageInfo(pa5);

                    //Log step3 service output
                    //Compare the Expected parameters of getImageInfo and output result of getImageInfo
                    //count of compare matched parameters
                    int compCount = 0;
                    //count of expected parameters on getImageInfo
                    int expectedParameterCount = 0;
                    for (int index = 0; index < ids.ExpectedValues.Parameters.Count; index++)
                    {
                        if (ids.ExpectedValues.Parameters[index].Step == "getImageInfo")
                        {
                            expectedParameterCount++;
                        }
                    }

                    for (int index = 0; index < ids.ExpectedValues.Parameters.Count; index++)
                    {
                        if (ids.ExpectedValues.Parameters[index].Step == "getImageInfo" && ids.ExpectedValues.Parameters[index].Value == step5_result.DicomArrayResult.GetParameterValueByName(ids.ExpectedValues.Parameters[index].Key))
                        {
                            compCount++;
                        }
                    }

                    if (step5_result.IsErrorOccured || compCount != expectedParameterCount)
                    {
                        p5.Result = TestResult.Fail;
                        p5.Outputs.AddParameter("getImageInfo", "Error", step5_result.ResultContent);
                        SaveRound(r);
                        continue;
                    }

                    p5.Result = TestResult.Pass;
                    p5.Outputs.AddParameter("getImageInfo", "Success", step5_result.ResultContent);

                    //Change input parameter according the output of Step6

                    //generate input parameter collection of step6
                    pa6.Add(pt6);
                    //Step6 result

                    XMLResult step6_result = ps.getPresentationStateInfo(pa6);

                    //Log step6 service output
                    //Compare the Expected parameters of getPresentationStateInfo and output result of getPresentationStateInfo
                    compCount = 0;
                    //count of expected parameters on getPresentationStateInfo
                    expectedParameterCount = 0;
                    for (int index = 0; index < ids.ExpectedValues.Parameters.Count; index++)
                    {
                        if (ids.ExpectedValues.Parameters[index].Step == "getPresentationStateInfo")
                        { expectedParameterCount++; }
                    }

                    for (int index = 0; index < ids.ExpectedValues.Parameters.Count; index++)
                    {
                        if (ids.ExpectedValues.Parameters[index].Step == "getPresentationStateInfo" && ids.ExpectedValues.Parameters[index].Value == step6_result.DicomArrayResult.GetParameterValueByName(ids.ExpectedValues.Parameters[index].Key))
                        { compCount++; }
                    }

                    if (step6_result.IsErrorOccured || compCount != expectedParameterCount)
                    {
                        p6.Result = TestResult.Fail;
                        p6.Outputs.AddParameter("getPresentationStateInfo", "Error", step6_result.ResultContent);
                    }
                    else
                    {
                        p6.Result = TestResult.Pass;
                        p6.Outputs.AddParameter("getPresentationStateInfo", "Success", step6_result.ResultContent);
                    }

                    //Save data for each round
                    SaveRound(r);
                }
                catch (Exception ex)
                {
                    CheckPoint p = new CheckPoint("Excepption", "Exception thrown when case run: "+ex.ToString());
                    r.CheckPoints.Add(p);
                    SaveRound(r);
                }
            }

            //Save service log as xml file
            Output();
        }
        //Case 976: 1.3.1_GetPatient_N2_getCumulativeDose
        public void Run_Patient_GetPatient_CumulativeDose_Case976()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            string dose_value = string.Empty;
            bool isCreatePatient = false;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Cumulative Dose");

                PatientService ps = new PatientService();
                ImageService igs = new ImageService();

                XMLParameter cpatientData = new XMLParameter("patient");
                XMLParameter imageData = new XMLParameter("image");

                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        cpatientData.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "Image")
                    {
                        imageData.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        if (ids.InputParameters.GetParameter(i).Key == "area_dose_product")
                            dose_value = ids.InputParameters.GetParameter(i).Value;
                    }
                }
                if (isCreatePatient)
                {
                    CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                    r.CheckPoints.Add(pCreate);

                    XMLResult rslCreate = ps.createPatient(cpatientData);
                    if (!rslCreate.IsErrorOccured)
                    {
                        patientUID = rslCreate.SingleResult;
                        pCreate.Result = TestResult.Pass;
                        pCreate.Outputs.AddParameter("create", "Create patient UID", patientUID);
                    }
                    else
                    {
                        pCreate.Result = TestResult.Fail;
                        pCreate.Outputs.AddParameter("create", "Create patient ERR", rslCreate.Message);
                        goto CLEANUP;
                    }
                }

                if (patientUID != null)
                {
                    imageData.AddParameter("patient_internal_id", patientUID);
                    CheckPoint imageSet = new CheckPoint("Create image", "Create image");
                    r.CheckPoints.Add(imageSet);
                    XMLResult rslCreateImage = igs.createImage(imageData);
                    if (rslCreateImage.IsErrorOccured)
                    {
                        imageSet.Outputs.AddParameter("Create", "Create Image Fail", rslCreateImage.Message);
                        imageSet.Result = TestResult.Fail;
                    }
                    else
                    {
                        imageSet.Outputs.AddParameter("Create", "Create Image UID", rslCreateImage.SingleResult);
                        imageSet.Result = TestResult.Pass;

                        CheckPoint pGet = new CheckPoint("Get Patient", "Get Cumulative Dose");
                        r.CheckPoints.Add(pGet);

                        XMLResult rslGet = ps.getPatient(patientUID);
                        if (!rslGet.IsErrorOccured && rslGet.Code == 0)
                        {
                            for (int j = 0; j < rslGet.ArrayResult.Parameters.Count; j++)
                            {
                                if (rslGet.ArrayResult.Parameters[j].ParameterName == "cumulative_dose")
                                {
                                    if (double.Parse(rslGet.ArrayResult.Parameters[j].ParameterValue) == double.Parse(dose_value))
                                    {
                                        pGet.Outputs.AddParameter("Get", "Get patient OK", rslGet.ResultContent);
                                        pGet.Result = TestResult.Pass;
                                    }
                                    else
                                    {
                                        pGet.Outputs.AddParameter("Get", "Get wrong dose_value", "Expect: " + dose_value + "; actually get: " + rslGet.ArrayResult.Parameters[j].ParameterValue);
                                        pGet.Result = TestResult.Fail;
                                        goto CLEANUP;
                                    }
                                }
                            }
                        }
                        else
                        {
                            pGet.Outputs.AddParameter("Get", "Get patient Error", rslGet.ResultContent);
                            pGet.Result = TestResult.Fail;
                        }
                    }
                }

            CLEANUP:
                SaveRound(r);
                if (isCreatePatient && !string.IsNullOrEmpty(patientUID))
                {
                    ps.deletePatient(patientUID);
                }
            }
            Output();
        }
        // Case 1643: 1.1.03.12_List Objects - N10 - tag for image with logicon report
        public void Run_Patient_ListObjects_LogiconTagForImage_Case1643()
        {
            int runCount = 0;

            PatientService oldPatientSvc = new PatientService();
            ImportService ims = new ImportService();
            NewPatientService patientSvc = new NewPatientService();
            PatientListObjectsRequestType pListObjects = new PatientListObjectsRequestType();
            PatientListObjectsResponseType rtListObjects = new PatientListObjectsResponseType();
            PatientListObjectsResponseType rtListObjectsAfterProcess = new PatientListObjectsResponseType();

            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), ids.Description);

                try
                {
                    #region Initialize test data
                    XMLParameter pCreatePatient = new XMLParameter("patient");
                    string patientID = string.Empty;
                    string filePath = string.Empty;
                    string archivePath = string.Empty;
                    string imageID = string.Empty;
                    for (int i = 0; i < ids.InputParameters.Count; i++)
                    {
                        if (ids.InputParameters.GetParameter(i).Step == "createPatient")
                        {
                            pCreatePatient.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        }
                        else if (ids.InputParameters.GetParameter(i).Step == "import")
                        {
                            if (ids.InputParameters.GetParameter(i).Key == "filePath")
                            {
                                filePath = ids.InputParameters.GetParameter(i).Value;
                            }
                            else if (ids.InputParameters.GetParameter(i).Key == "archivePath")
                            {
                                archivePath = ids.InputParameters.GetParameter(i).Value;
                            }
                        }
                    }

                    string tagBeforeProcess = null;
                    string tagAfterProcess = null;
                    for (int i = 0; i < ids.ExpectedValues.Count; i++)
                    {
                        if (ids.ExpectedValues.GetParameter(i).Step == "listObjectsBeforeProcess")
                        {
                            tagBeforeProcess = ids.ExpectedValues.GetParameter(i).Value;
                        }
                        else if (ids.ExpectedValues.GetParameter(i).Step == "listObjectsAfterProcess")
                        {
                            tagAfterProcess = ids.ExpectedValues.GetParameter(i).Value;
                        }
                    }
                    #endregion

                    #region Step: Create a patient
                    CheckPoint cpCreate = new CheckPoint("Create Patient", "Create Patient");
                    r.CheckPoints.Add(cpCreate);

                    XMLResult rtCreatePatient = oldPatientSvc.createPatient(pCreatePatient);
                    if (rtCreatePatient.IsErrorOccured)
                    {
                        cpCreate.Result = TestResult.Fail;
                        cpCreate.Outputs.AddParameter("Create returns error:", "Create Patient", rtCreatePatient.Message);
                        SaveRound(r);
                        continue;
                    }
                    else
                    {
                        patientID = rtCreatePatient.SingleResult;
                        pListObjects.patientInternalId = patientID;
                        pListObjects.current = true;
                        pListObjects.currentSpecified = true;
                        cpCreate.Outputs.AddParameter("Patient ID:", "Create Patient", rtCreatePatient.SingleResult);
                        cpCreate.Result = TestResult.Pass;
                    }
                    #endregion

                    #region Step: Prepare a RVG image
                    CheckPoint cpImport = new CheckPoint("Import Image", "Test import");
                    r.CheckPoints.Add(cpImport);

                    XMLResult rtlImport = ims.importObject(patientID, "", filePath, archivePath, false, "false");
                    if (rtlImport.IsErrorOccured)
                    {
                        cpImport.Result = TestResult.Fail;
                        cpImport.Outputs.AddParameter("import", "Import image fail", rtlImport.ResultContent);
                    }
                    else
                    {
                        cpImport.Result = TestResult.Pass;
                        cpImport.Outputs.AddParameter("import", "Import image OK", rtlImport.ResultContent);
                        imageID = rtlImport.SingleResult;
                    }
                    #endregion

                    #region Step: Check the tag before do logicon processing
                    CheckPoint cpListObjects = new CheckPoint("List Object", "List Object before process");
                    r.CheckPoints.Add(cpListObjects);
                    rtListObjects = patientSvc.listObjects(pListObjects);
                    if (patientSvc.LastReturnXMLValidateResult.isValid && rtListObjects.status.code == 0)
                    {
                        cpListObjects.Result = TestResult.Pass;
                        cpListObjects.Outputs.AddParameter("List Object Return Pass", "List Object", "The web service return is OK!: " + patientSvc.LastReturnXML);
                    }
                    else
                    {
                        cpListObjects.Result = TestResult.Fail;
                        cpListObjects.Outputs.AddParameter("List Object Return Fail", "List Object", "The web service return is ERROR! : " + patientSvc.LastReturnXML);
                        goto CLEANUP;
                    }

                    CheckPoint cpLogiconTag = new CheckPoint("Tag", "Check the logicon tag before processing");
                    if (tagBeforeProcess == rtListObjects.presentationStates[0].image.tags)
                    {
                        cpLogiconTag.Outputs.AddParameter("Check Tag", "List Object", "List Object return tag as expect: " + patientSvc.LastReturnXML);
                        cpLogiconTag.Result = TestResult.Pass;
                    }
                    else
                    {
                        cpLogiconTag.Outputs.AddParameter("List Object Return Result unexpect", "List Object", "List Object return unexpected tag!" + patientSvc.LastReturnXML);
                        cpLogiconTag.Result = TestResult.Fail;
                    }
                    #endregion

                    #region Step: Do logicon processing
                    GenericInstanceService genericInstanceSvc = new GenericInstanceService();
                    genericInstanceSvc.DoLogiconProcess(r, imageID);
                    #endregion

                    #region Step: Check the tag after do logicon processing
                    CheckPoint cpListObjectsAfterProcess = new CheckPoint("List Object", "List Object after process");
                    r.CheckPoints.Add(cpListObjectsAfterProcess);
                    rtListObjectsAfterProcess = patientSvc.listObjects(pListObjects);
                    if (patientSvc.LastReturnXMLValidateResult.isValid && rtListObjectsAfterProcess.status.code == 0)
                    {
                        cpListObjectsAfterProcess.Result = TestResult.Pass;
                        cpListObjectsAfterProcess.Outputs.AddParameter("List Object Return Pass", "List Object", "The web service return is OK!");
                    }
                    else
                    {
                        cpListObjectsAfterProcess.Result = TestResult.Fail;
                        cpListObjectsAfterProcess.Outputs.AddParameter("List Object Return Fail", "List Object", "The web service return is ERROR! : " + patientSvc.LastReturnXML);
                        goto CLEANUP;
                    }

                    CheckPoint cpLogiconTagAfterProcess = new CheckPoint("Tag", "Check the logicon tag before processing");
                    if (tagAfterProcess == rtListObjectsAfterProcess.presentationStates[0].image.tags)
                    {
                        cpListObjectsAfterProcess.Outputs.AddParameter("Check Tag", "List Object", "List Object return tag as expect: " + patientSvc.LastReturnXML);
                        cpListObjectsAfterProcess.Result = TestResult.Pass;
                    }
                    else
                    {
                        cpListObjectsAfterProcess.Outputs.AddParameter("List Object Return Result unexpect", "List Object", "List Object return unexpected tag!" + patientSvc.LastReturnXML);
                        cpListObjectsAfterProcess.Result = TestResult.Fail;
                    }
                    #endregion

                    #region Delete patient
                CLEANUP:
                    CheckPoint cpDelete = new CheckPoint("Delete Patient", "Delete Patient");
                    r.CheckPoints.Add(cpDelete);

                    XMLResult rtDeletePatient = oldPatientSvc.deletePatient(patientID);
                    if (rtDeletePatient.IsErrorOccured)
                    {
                        cpDelete.Result = TestResult.Fail;
                        cpDelete.Outputs.AddParameter("Delete returns error:", "Delete Patient", rtDeletePatient.Message);
                    }
                    else
                    {
                        cpDelete.Outputs.AddParameter("Delete return success:", "Delete Patient", rtDeletePatient.Message);
                        cpDelete.Result = TestResult.Pass;
                    }
                    #endregion

                    SaveRound(r);
                }
                catch (Exception ex)
                {
                    CheckPoint cp = new CheckPoint();
                    r.CheckPoints.Add(cp);
                    cp.Outputs.AddParameter("Exception thrown", "Exception Message", ex.Message);
                    cp.Result = TestResult.Fail;
                    SaveRound(r);
                }
            }
            Output();
        }
        //Case 1570: 1.1.06.02_Import an archived FMS_Normal_contains shortcut of archived image(French FE Tool)
        public void Run_Import_ArchivedFMS_Case1570()
        {
            int runCount = 0;

            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Import FMS1");
                CheckPoint pImportFMS = new CheckPoint("Import FMS1", "Import FMS using conversiontool");
                r.CheckPoints.Add(pImportFMS);
                string patientdir = ids.InputParameters.GetParameter("patientdir").Value;
                string patient_id = ids.InputParameters.GetParameter("patient_id").Value;
                string dpms_id = ids.InputParameters.GetParameter("dpms_id").Value;

                //call conversiontool to import archivedFMS
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = System.IO.Directory.GetCurrentDirectory() + "\\ConversionTool version 1.0.4.0\\conversiontool.exe";
                p.StartInfo.Arguments = "-P\"" + patientdir + "\"";
                p.Start();
                System.Threading.Thread.Sleep(20000);
                p.Kill();

                string puid = null;
                PatientService ps = new PatientService();
                XMLParameter cInputQuery = new XMLParameter("filter");
                cInputQuery.AddParameter("dpms_id", dpms_id);
                cInputQuery.AddParameter("patient_id", patient_id);
                XMLResult rslQuery = ps.queryPatients(cInputQuery);
                if (rslQuery.IsErrorOccured)
                {
                    pImportFMS.Result = TestResult.Fail;
                    pImportFMS.Outputs.AddParameter("archiveFMS Import", "Query Fail:", rslQuery.Message);
                    SaveRound(r);
                    goto CLEANUP;
                }

                puid = rslQuery.SingleResult;
                //trigger the post import of FMS
                NewPatientService nps = new NewPatientService();
                PatientListObjectsRequestType request = new PatientListObjectsRequestType();
                request.type = PatientListObjectsType.all;
                request.currentSpecified = true;
                request.current = true;
                request.patientInternalId = puid;

                nps.listObjects(request);

                //wait the post import completed
                System.Threading.Thread.Sleep(10000);
                PatientListObjectsResponseType response = nps.listObjects(request);

                if (!nps.LastReturnXMLValidateResult.isValid)
                {
                    pImportFMS.Result = TestResult.Fail;
                    pImportFMS.Outputs.AddParameter("archiveFMS Import", "List Fail:", "Response is not complied with XML Schema");
                    SaveRound(r);
                    goto CLEANUP;
                }

                if (response.status.code != 0)
                {

                    pImportFMS.Result = TestResult.Fail;
                    pImportFMS.Outputs.AddParameter("archiveFMS Import", "List Fail:", response.status.message);
                    SaveRound(r);
                    goto CLEANUP;
                }
                if (response.fmss == null)
                {
                    pImportFMS.Result = TestResult.Fail;
                    pImportFMS.Outputs.AddParameter("archiveFMS Import", "Import Fail:", "Expected 3 fms, actual none.");
                    SaveRound(r);
                    goto CLEANUP;
                }
                else if (response.fmss.Length != 3)
                {
                    pImportFMS.Result = TestResult.Fail;
                    pImportFMS.Outputs.AddParameter("archiveFMS Import", "Import Fail:", "Expected 3 fms, actual:" + response.fmss.Length.ToString());
                    SaveRound(r);
                    goto CLEANUP;
                }

                if (response.presentationStates == null)
                {
                    pImportFMS.Result = TestResult.Fail;
                    pImportFMS.Outputs.AddParameter("archiveFMS Import", "Import Fail:", "Expected 21 PS, actual none.");
                    SaveRound(r);
                    goto CLEANUP;
                }
                else if (response.presentationStates.Length != 21)
                {
                    pImportFMS.Result = TestResult.Fail;
                    pImportFMS.Outputs.AddParameter("archiveFMS Import", "Import Fail:", "Expected 21 PS, actual:" + response.presentationStates.Length.ToString());
                    SaveRound(r);
                    goto CLEANUP;
                }

                foreach (PresentationStateType pstate in response.presentationStates)
                {
                    if (pstate.image.tags != "archived" || pstate.image.archivePath == string.Empty)
                    {
                        pImportFMS.Result = TestResult.Fail;
                        pImportFMS.Outputs.AddParameter("archiveFMS Import", "Check Fail:", "archive tag or path is not correct");
                        SaveRound(r);
                        goto CLEANUP;
                    }
                }

                pImportFMS.Result = TestResult.Pass;
                pImportFMS.Outputs.AddParameter("archiveFMS Import", "Check Success:", "OK");
                SaveRound(r);

            CLEANUP:
                if (!string.IsNullOrEmpty(puid))
                {
                    ps.deletePatient(patient_id); //delete the patient
                }
            }
            Output();
        }
 /// <summary>
 /// Utility_s the delete patient for specific case.
 /// </summary>
 /// <param name="patientID">The patient ID.</param>
 /// <returns>The Web Service Call return</returns>
 public static XMLResult Utility_DeletePatientForSpecificCase(string patientID)
 {
     PatientService ps = new PatientService();
     XMLResult result = ps.deletePatient(patientID);
     return result;
 }
        //Case 55: 1.3.6_DeleteImage_Normal
        public void Run_Image_DeleteImage_Normal_Case55()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            string imageUID = string.Empty;
            bool isCreatePatient = false;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Create image");
                CheckPoint pCreate = new CheckPoint("Create patient", "Test create");
                r.CheckPoints.Add(pCreate);
                PatientService ps = new PatientService();
                ImageService ims = new ImageService();
                XMLParameter pa = new XMLParameter("patient");
                XMLParameter ia = new XMLParameter("image");

                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        pa.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "image")
                    {
                        ia.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                }
                if (isCreatePatient)
                {
                    XMLResult result = ps.createPatient(pa);
                    if (!result.IsErrorOccured)
                    {
                        patientUID = result.SingleResult;

                        pCreate.Result = TestResult.Pass;
                        pCreate.Outputs.AddParameter("create", "Create patient UID", patientUID);
                    }
                    else
                    {
                        pCreate.Result = TestResult.Pass;
                        pCreate.Outputs.AddParameter("create", "Create patient return error: ", result.ResultContent);
                    }
                }

                CheckPoint cpCreateImage = new CheckPoint("Image create", "Test image");
                r.CheckPoints.Add(cpCreateImage);
                if (patientUID != null)
                {
                    ia.AddParameter("patient_internal_id", patientUID);
                    XMLResult imageRsl = ims.createImage(ia);
                    if (imageRsl.IsErrorOccured)
                    {
                        cpCreateImage.Result = TestResult.Fail;
                        cpCreateImage.Outputs.AddParameter("create", "Create image error", imageRsl.Message);
                    }
                    else
                    {
                        cpCreateImage.Result = TestResult.Pass;
                        cpCreateImage.Outputs.AddParameter("create", "Create image Id", imageUID);
                        imageUID = imageRsl.SingleResult;
                    }
                }
                if (imageUID != null)
                {
                    CheckPoint cpDeleteImage = new CheckPoint("Image delete", "Test image");
                    r.CheckPoints.Add(cpDeleteImage);

                    XMLParameter deletePreference = new XMLParameter("preferences");
                    deletePreference.AddParameter("completedFlag", "true");
                    XMLResult delImageRsl = ims.deleteImage(imageUID, deletePreference);
                    if (delImageRsl.IsErrorOccured)
                    {
                        cpDeleteImage.Result = TestResult.Fail;
                        cpDeleteImage.Outputs.AddParameter("delete", "delete image error", delImageRsl.Message);
                    }
                    else
                    {
                        cpDeleteImage.Result = TestResult.Pass;
                        cpDeleteImage.Outputs.AddParameter("delete", "delete image success", delImageRsl.Message);
                    }
                }

                if (!string.IsNullOrEmpty(patientUID))
                {
                    ps.deletePatient(patientUID);
                }

                SaveRound(r);
            }

            Output();
        }
        //Case 927: 1.3.3_WorkFlow_N03_CreateSetGet
        public void Run_RadioLogicalLog_WorkFlow_N03_CreateSetGet_Case927()
        {
            //int runCount = this.Input.Repetition;

            int runCount = 0; // this is the initial run count. Use this count to repeat different test data set.

            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Test round");

                //Mark the check point here to indicate what's the check point here
                CheckPoint p1 = new CheckPoint("createPatient", "Setup environment of createPatient");
                CheckPoint p2 = new CheckPoint("createRadioLogEntry", "Setup environment of createRadioLogEntry");
                CheckPoint p3 = new CheckPoint("setRadioLogEntry", "Test setRadioLogEntry");
                CheckPoint p4 = new CheckPoint("getRadioLogEntry", "Test getRadioLogEntry");

                r.CheckPoints.Add(p1);
                r.CheckPoints.Add(p2);
                r.CheckPoints.Add(p3);
                r.CheckPoints.Add(p4);

                //create required PAS service instaces here
                PatientService pats = new PatientService();
                RadiologService radios = new RadiologService();

                //create input parameters here, it may include XML path type and string type value
                XMLParameter pa1 = new XMLParameter("createPatient");
                XMLParameter pa2 = new XMLParameter("createRadioLogEntry");
                XMLParameter pa3 = new XMLParameter("setRadioLogEntry");
                XMLParameter pa4 = new XMLParameter("getRadioLogEntry");

                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    switch (ids.InputParameters.GetParameter(i).Step)
                    {
                        case "createPatient":
                            pa1.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                            break;
                        case "createRadioLogEntry":
                            pa2.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                            break;
                        case "setRadioLogEntry":
                            pa3.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                            break;
                        case "getRadioLogEntry":
                            pa4.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                            break;
                        default:
                            Console.WriteLine("There is no valid selection when parse input parameters.");
                            break;
                    }
                }

                //If we need change parameter by specific logic, please put code here

                //Get service result
                //Step1 result

                XMLResult step1_result = pats.createPatient(pa1);

                //Log step1 service output
                if (step1_result.IsErrorOccured)
                {
                    p1.Result = TestResult.Fail;
                    p1.Outputs.AddParameter("createPatient", "Error", step1_result.ResultContent);
                    SaveRound(r);
                    continue;
                }

                p1.Result = TestResult.Pass;
                p1.Outputs.AddParameter("createPatient", "Success", step1_result.ResultContent);

                //Change input parameter according the output of Step1
                pa2.AddParameter("patient_internal_id", step1_result.SingleResult);

                //Step2 result

                XMLResult step2_result = radios.createRadioLogEntry(pa2);

                //Log step2 service output
                if (step2_result.IsErrorOccured)
                {
                    p2.Result = TestResult.Fail;
                    p2.Outputs.AddParameter("createRadioLogEntry", "Error", step2_result.ResultContent);
                    SaveRound(r);
                    continue;
                }

                p2.Result = TestResult.Pass;
                p2.Outputs.AddParameter("createRadioLogEntry", "Success", step2_result.ResultContent);

                //Change input parameter according the output of Step2

                //Step3 result

                XMLResult step3_result = radios.setRadioLogEntry(pa3, step2_result.SingleResult);

                //Log step3 service output
                if (step3_result.IsErrorOccured)
                {
                    p3.Result = TestResult.Fail;
                    p3.Outputs.AddParameter("setRadioLogEntry", "Error", step3_result.ResultContent);
                    SaveRound(r);
                    continue;
                }

                p3.Result = TestResult.Pass;
                p3.Outputs.AddParameter("setRadioLogEntry", "Success", step3_result.ResultContent);

                //Change input parameter according the output of Step3

                //Step4 result

                XMLResult step4_result = radios.getRadioLogEntry(step2_result.SingleResult);

                //Log step4 service output

                //Compare the Expected parameters of getRadioLogEntry and output result of getRadioLogEntry
                int compCount = 0;

                for (int index = 0; index < ids.ExpectedValues.Parameters.Count; index++)
                {
                    if (ids.ExpectedValues.Parameters[index].Value == step4_result.ArrayResult.GetParameterValueByName(ids.ExpectedValues.Parameters[index].Key))
                    { compCount++; }
                }

                if (step4_result.IsErrorOccured || compCount != ids.ExpectedValues.Parameters.Count)
                {
                    p4.Result = TestResult.Fail;
                    p4.Outputs.AddParameter("getRadioLogEntry", "Error", step4_result.ResultContent);
                }
                else
                {
                    p4.Result = TestResult.Pass;
                    p4.Outputs.AddParameter("getRadioLogEntry", "Success", step4_result.ResultContent);
                }

                //Save data for each round
                SaveRound(r);
            }

            //Save service log as xml file
            Output();
        }
        //Case 99: 1.3.6_CreateImage_Exception
        public void Run_Image_CreateImage_Exception_Case99()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            bool isDeletePatient = false;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                isDeletePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Create image");

                PatientService patientSvc = new PatientService();
                ImageService imageSvc = new ImageService();

                XMLParameter pCreatePatient = new XMLParameter("patient");
                XMLParameter pCreateImage = new XMLParameter("image");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "createPatient")
                    {
                        pCreatePatient.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "createImage")
                    {
                        pCreateImage.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "deletePatient")
                    {
                        isDeletePatient = ids.InputParameters.GetParameter(i).Value.ToLower().Equals("true");
                    }
                }

                string epErrorCode = string.Empty;
                string epErrorMessage = string.Empty;
                for (int i = 0; i < ids.ExpectedValues.Count; i++)
                {
                    if (ids.ExpectedValues.GetParameter(i).Step == "createImage")
                    {
                        if (ids.ExpectedValues.GetParameter(i).Key == "error_code")
                        {
                            epErrorCode = ids.ExpectedValues.GetParameter(i).Value;
                        }
                        else if (ids.ExpectedValues.GetParameter(i).Key == "error_message")
                        {
                            epErrorMessage = ids.ExpectedValues.GetParameter(i).Value;
                        }
                    }
                }

                try
                {
                    #region Create Patient
                    if (isCreatePatient)
                    {
                        CheckPoint cpCreatePatient = new CheckPoint("Create Patient", "Test create patient");
                        r.CheckPoints.Add(cpCreatePatient);
                        XMLResult rtCreatePatient = patientSvc.createPatient(pCreatePatient);
                        if (rtCreatePatient.IsErrorOccured)
                        {
                            cpCreatePatient.Result = TestResult.Fail;
                            cpCreatePatient.Outputs.AddParameter("create patient returns error", "Create Patient", rtCreatePatient.ResultContent);
                            SaveRound(r);
                            break;
                        }
                        else
                        {
                            patientUID = rtCreatePatient.SingleResult;
                            cpCreatePatient.Result = TestResult.Pass;
                            cpCreatePatient.Outputs.AddParameter("create patient returns success", "Create Patient", rtCreatePatient.ResultContent);
                        }
                    }
                    #endregion

                    #region Create Image
                    CheckPoint cpCreateImage = new CheckPoint("Create Image", "Test create image");
                    r.CheckPoints.Add(cpCreateImage);
                    if (patientUID != null)
                    {
                        pCreateImage.AddParameter("patient_internal_id", patientUID);
                        XMLResult rtCreateImage = imageSvc.createImage(pCreateImage);
                        if (rtCreateImage.IsErrorOccured)
                        {
                            if (rtCreateImage.Code.ToString().Equals(epErrorCode) && rtCreateImage.Message.Contains(epErrorMessage))
                            {
                                cpCreateImage.Result = TestResult.Pass;
                                cpCreateImage.Outputs.AddParameter("Create image returns correct error message as expected", "Create Image", rtCreateImage.ResultContent);
                            }
                            else
                            {
                                cpCreateImage.Result = TestResult.Fail;
                                cpCreateImage.Outputs.AddParameter("Create image doesn't return correct error info as expected", "Create Image", rtCreateImage.ResultContent);
                            }
                        }
                        else
                        {
                            cpCreateImage.Result = TestResult.Fail;
                            cpCreateImage.Outputs.AddParameter("Create image doesn't return error as expected", "Create Image", rtCreateImage.ResultContent);
                        }
                    }
                    #endregion

                    #region Delete patient
                    if (isDeletePatient)
                    {
                        CheckPoint cpDeletePatient = new CheckPoint("DeletePatient", "Delete the created patient");
                        r.CheckPoints.Add(cpDeletePatient);

                        XMLResult rtDeletePatient = patientSvc.deletePatient(patientUID);

                        if (rtDeletePatient.IsErrorOccured)
                        {
                            cpDeletePatient.Result = TestResult.Fail;
                            cpDeletePatient.Outputs.AddParameter("delete patient returns error", "Delete Patient", rtDeletePatient.ResultContent);
                            SaveRound(r);
                            break;
                        }
                        else
                        {
                            cpDeletePatient.Result = TestResult.Pass;
                            cpDeletePatient.Outputs.AddParameter("delete patient returns success", "Delete Patient", rtDeletePatient.ResultContent);
                        }
                    }
                    #endregion

                    SaveRound(r);
                }
                catch (Exception ex)
                {
                    CheckPoint cp = new CheckPoint();
                    r.CheckPoints.Add(cp);
                    cp.Outputs.AddParameter("Exception thrown", "Exception Message", ex.Message);
                    cp.Result = TestResult.Fail;
                    SaveRound(r);
                }
            }

            Output();
        }
        //Case 44: 1.3.6_CreateImage_Normal
        public void Run_Image_CreateImage_Normal_Case44()
        {
            int runCount = 0;
            string patientUID = null;
            bool isCreatePatient = false;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Create image");

                PatientService ps = new PatientService();
                ImageService ims = new ImageService();
                XMLParameter pa = new XMLParameter("patient");
                XMLParameter ia = new XMLParameter("image");

                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        pa.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "image")
                    {
                        ia.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                }
                if (isCreatePatient)
                {
                    CheckPoint pCreate = new CheckPoint("Create patient", "Test create");
                    r.CheckPoints.Add(pCreate);

                    XMLResult result = ps.createPatient(pa);
                    if (!result.IsErrorOccured)
                    {
                        patientUID = result.SingleResult;
                        pCreate.Outputs.AddParameter("create", "Create patient UID", patientUID);
                        pCreate.Result = TestResult.Pass;
                    }
                    else
                    {
                        pCreate.Outputs.AddParameter("create", "Create patient returns error: ", result.ResultContent);
                        pCreate.Result = TestResult.Fail;
                        goto CLEANUP;
                    }
                }

                CheckPoint pImage = new CheckPoint("Image create", "Test image");
                r.CheckPoints.Add(pImage);
                if (patientUID != null)
                {
                    ia.AddParameter("patient_internal_id", patientUID);
                    XMLResult imageRsl = ims.createImage(ia);
                    if (imageRsl.IsErrorOccured)
                    {
                        pImage.Result = TestResult.Fail;
                        pImage.Outputs.AddParameter("create", "Create image error", imageRsl.Message);
                    }
                    else
                    {
                        pImage.Result = TestResult.Pass;
                        pImage.Outputs.AddParameter("create", "Create image Id", imageRsl.SingleResult);
                    }
                }

            CLEANUP:
                if (isCreatePatient && !string.IsNullOrEmpty(patientUID))
                {
                    ps.deletePatient(patientUID);
                }
                SaveRound(r);
            }

            Output();
        }
        //Case 161: 1.3.2_CreateSimpleInstance_N1_WithAllParameters
        public void Run_SimpleInstance_CreateSimpleInstance_Case161()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            string instanceUID = string.Empty;
            bool isCreatePatient = false;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Create simple instance");
                CheckPoint pCreate = new CheckPoint("Create patient", "Test create");
                r.CheckPoints.Add(pCreate);
                PatientService ps = new PatientService();
                //ImageService ims = new ImageService();
                SimpleInstanceService sis = new SimpleInstanceService();
                XMLParameter pa = new XMLParameter("patient");
                XMLParameter sia = new XMLParameter("instance");

                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        pa.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "simple")
                    {
                        sia.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }

                }
                if (isCreatePatient)
                {
                    XMLResult result = ps.createPatient(pa);
                    if (!result.IsErrorOccured)
                    {
                        patientUID = result.SingleResult;

                        pCreate.Outputs.AddParameter("create", "Create patient UID", patientUID);
                        pCreate.Result = TestResult.Pass;
                    }
                }

                CheckPoint pInstance = new CheckPoint("Simple instance create", "Test image");
                r.CheckPoints.Add(pInstance);
                if (patientUID != string.Empty)
                {
                    sia.AddParameter("patient_internal_id", patientUID);
                    XMLResult instanceRsl = sis.createSimpleInstance(sia);
                    if (instanceRsl.IsErrorOccured)
                    {

                        pInstance.Outputs.AddParameter("create", "Create SimpleInstance error", instanceRsl.Message);
                        pInstance.Result = TestResult.Fail;
                    }
                    else
                    {
                        instanceUID = instanceRsl.SingleResult;
                        pInstance.Outputs.AddParameter("create", "Create SimpleInstance Id", instanceUID);
                        pInstance.Result = TestResult.Pass;
                    }
                }

                ps.deletePatient(patientUID);

                SaveRound(r);
            }

            Output();
        }
        // Case 1048: 1.3.10_ImportImage_N05_TW5Tiff_FMS
        public void Run_Import_TW5Tiff_Case1048()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            bool isDeletePatient = true;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Import image");

                ImportService ims = new ImportService();
                XMLParameter pa = new XMLParameter("patient");
                XMLParameter ia = new XMLParameter("import");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        pa.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "import")
                    {
                        ia.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                }

                XMLParameter epImport = new XMLParameter();

                for (int i = 0; i < ids.ExpectedValues.Count; i++)
                {
                    if (ids.ExpectedValues.GetParameter(i).Step == "import")
                    {
                        epImport.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                    }
                }

                try
                {
                    PatientService patientSvc = new PatientService();
                    if (isCreatePatient)
                    {
                        CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                        r.CheckPoints.Add(pCreate);

                        XMLResult result = patientSvc.createPatient(pa);
                        if (!result.IsErrorOccured)
                        {
                            patientUID = result.SingleResult;
                            pCreate.Result = TestResult.Pass;
                            pCreate.Outputs.AddParameter("Create patient UID", "Create Patient", patientUID);
                        }
                        else
                        {
                            pCreate.Result = TestResult.Fail;
                            pCreate.Outputs.AddParameter("Create patient returns error", "Create Patient", result.ResultContent);
                        }
                    }

                    CheckPoint pImport = new CheckPoint("Import Image", "Test import");
                    r.CheckPoints.Add(pImport);

                    string filePath = string.Empty;
                    string archivePath = string.Empty;
                    bool move = false;
                    for (int c = 0; c < ia.Length; c++)
                    {
                        if (ia.GetParameterName(c) == "path")
                            filePath = ia.GetParameterValue(c);
                        if (ia.GetParameterName(c) == "archivePath")
                            archivePath = ia.GetParameterValue(c);
                        if (ia.GetParameterName(c) == "move")
                        {
                            if (ia.GetParameterValue(c) == "true")
                                move = true;
                        }
                    }

                    XMLResult rslImport = ims.importObject(patientUID, "", filePath, archivePath, move, "false");
                    /************************************************
                    import return sample:
                        - <trophy type="result" version="1.0">
                          <status code="0" message="ok" />
                        - <fms>
                          <parameter key="internal_id" value="79d96c5c-1ec5-4408-8709-622c0bd4a951" />
                          </fms>
                        - <image>
                          <parameter key="internal_id" value="1547aca3-7d98-4282-bd4c-e4e9547e126b" />
                          </image>
                        - <presentationstate>
                          <parameter key="internal_id" value="f0c4ed26-e41f-45dc-9f03-41e982d70b23" />
                          </presentationstate>
                        - <image>
                          <parameter key="internal_id" value="14831be6-ca69-417c-957f-c7f3a493cc70" />
                          </image>
                        - <presentationstate>
                          <parameter key="internal_id" value="a640fe70-7ad9-45c4-b68c-1f0ba2c503f1" />
                          </presentationstate>
                        - <image>
                          <parameter key="internal_id" value="d8b65e88-a9c7-4e7b-baac-05da4982f6be" />
                          </image>
                        - <presentationstate>
                          <parameter key="internal_id" value="18834173-1ce8-4d6e-9ce7-daf1745761e0" />
                          </presentationstate>
                        - <image>
                          <parameter key="internal_id" value="6608a41f-de96-4d0b-8391-6f16cf9fb812" />
                          </image>
                        - <presentationstate>
                          <parameter key="internal_id" value="c1b10673-a4ba-4ee9-824c-0431926b3f27" />
                          </presentationstate>
                        - <other>
                          <parameter key="total" value="4" />
                          <parameter key="success" value="4" />
                          </other>
                          </trophy>
                     * **********************************************/

                    if (rslImport.IsErrorOccured)
                    {
                        pImport.Result = TestResult.Fail;
                        pImport.Outputs.AddParameter("Import image fail", "Import", rslImport.Message);
                        pImport.Outputs.AddParameter("Import image returns error code", "Import", rslImport.Code.ToString());
                    }
                    else
                    {
                        // Check the return contiains image id and ps id
                        string fmsID = null;
                        fmsID = rslImport.MultiResults[0].GetParameterValueByName("internal_id"); // image internal_id
                        if (fmsID == null || fmsID == string.Empty)
                        {
                            pImport.Result = TestResult.Fail;
                            pImport.Outputs.AddParameter("Import image returns wrong FMS internal id", "Import", rslImport.ResultContent);
                        }

                        #region Call getImageInfo to check expected key and value

                        //Check the return info contain the expected key and value: parameter key="XXX" value="XXX"
                        foreach (XMLParameterNode node in epImport.Parameters)
                        {
                            if (!rslImport.ResultContent.Contains("parameter key=\"" + node.ParameterName + "\" value=\"" + node.ParameterValue + "\""))
                            {
                                pImport.Result = TestResult.Fail;
                                pImport.Outputs.AddParameter("Import image returns wrong key-value info for: " + node.ParameterName, "Import", rslImport.ResultContent);
                                continue;
                            }
                            else
                            {
                                pImport.Outputs.AddParameter("Import image returns correct key-value info for: " + node.ParameterName, "Import", "ok");
                            }
                        }

                        if (pImport.Result != TestResult.Fail)
                        {
                            pImport.Result = TestResult.Pass;
                            pImport.Outputs.AddParameter("Import image Info returns all correct info", "Import", rslImport.ResultContent);
                        }

                        #endregion
                    }

                    if (isDeletePatient)
                    {
                        CheckPoint cpDelete = new CheckPoint("Delete Patient", "Test delete patient");
                        r.CheckPoints.Add(cpDelete);
                        XMLResult rltDelete = patientSvc.deletePatient(patientUID);
                        if (rltDelete.IsErrorOccured)
                        {
                            cpDelete.Outputs.AddParameter("Delete created patient returns error", "Delete Patient", rltDelete.Message);
                            cpDelete.Result = TestResult.Fail;
                        }
                        else
                        {
                            cpDelete.Outputs.AddParameter("Delete created patient returns OK", "Delete Patient", rltDelete.Message);
                            cpDelete.Result = TestResult.Pass;
                        }
                    }

                    SaveRound(r);
                }
                catch (Exception ex)
                {
                    CheckPoint cp = new CheckPoint();
                    r.CheckPoints.Add(cp);
                    cp.Outputs.AddParameter("Exception thrown", "Exception Message", ex.Message);
                    cp.Result = TestResult.Fail;
                    SaveRound(r);
                }
            }
            Output();
        }
        public override void Run()
        {
            string PatientStarts = string.Empty;
            Random random = new Random(Guid.NewGuid().GetHashCode());
            PatientStarts += Convert.ToChar(random.Next(65, 91));
            PatientStarts += Convert.ToChar(random.Next(65, 91));
            PatientStarts += Convert.ToChar(random.Next(65, 91));
            PatientStarts += Convert.ToChar(random.Next(65, 91));

            PatientService ps = new PatientService();

            XMLParameter pa = new XMLParameter("patient");
            pa.AddParameter("patient_id", "$_R");
            pa.AddParameter("dpms_id", "$_R");
            pa.AddParameter("first_name", "$_R");
            pa.AddParameter("last_name", "$_R");
            pa.AddParameter("middle_name", "$_R");
            pa.AddParameter("prefix", "Mr");
            pa.AddParameter("suffix", "X");
            pa.AddParameter("birth_date", "2010-10-22");
            pa.AddParameter("sex", "female");
            pa.AddParameter("pregnancy", "not pregnant");
            pa.AddParameter("insurance_number", "1234567");
            pa.AddParameter("address", "Test address");
            pa.AddParameter("town", "test town");
            pa.AddParameter("postal_code", "female");
            pa.AddParameter("cellular_phone", "female");
            pa.AddParameter("home_phone", "female");
            pa.AddParameter("work_phone", "female");
            pa.AddParameter("comments", "user comments");
            pa.AddParameter("email", "*****@*****.**");
            pa.AddParameter("photo", "");

            string PatientInfo = pa.GenerateXML();

            for (int i = 1; i <= this.mRepeat; i++)
            {
                LogRecordType lr = new LogRecordType();
                lr.Lable = this.mLabel;
                lr.FunctionName = this.mFunctionName;

                try
                {
                    XMLResult result = new XMLResult(ps.InvokeMethod("createPatient", new object[] { PatientInfo.Replace("$_R", PatientStarts + (i + 1).ToString()) }));
                    lr.ResponseTime = ps.ResponseTime;
                    lr.Passed = !(result.IsErrorOccured);

                    if (!lr.Passed)
                    {
                        lr.Message = result.Message;
                        this.mFailed++;
                    }
                    else
                    {
                        lr.Message = result.SingleResult;
                        this.mExectuedTime += lr.ResponseTime;
                    }
                }
                catch (Exception ex)
                {
                    this.mFailed++;
                    lr.Passed = false;
                    string innerText = ex.InnerException == null ? string.Empty : ex.InnerException.Message;
                    lr.Message = ex.Message + innerText == string.Empty ? string.Empty : "(" + innerText + ")";
                }

                this.Executed = i;
                Log.AddRecord(lr);

                this.RiseSingleCallCompleteEvent(lr.ResponseTime, lr.Passed);
            }

            this.RiseTestCaseCompleteEvent();
        }
        //Case 38: 1.3.1_DeletePatient_Normal
        public void Run_Patient_DeletePatient_Normal_Case38()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "delete patient");
                CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                r.CheckPoints.Add(pCreate);
                PatientService ps = new PatientService();

                XMLParameter cpatientData = new XMLParameter("patient");

                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        cpatientData.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                }
                if (isCreatePatient)
                {
                    XMLResult rslCreate = ps.createPatient(cpatientData);
                    if (!rslCreate.IsErrorOccured)
                    {
                        patientUID = rslCreate.SingleResult;
                        pCreate.Result = TestResult.Pass;
                        pCreate.Outputs.AddParameter("create", "Create patient UID", patientUID);
                        XMLResult rslGet = ps.getPatient(patientUID);
                        if (!rslGet.IsErrorOccured && rslGet.Code == 0)
                        {
                            CheckPoint pDel = new CheckPoint("Delete Patient", "Test delete");
                            r.CheckPoints.Add(pDel);
                            XMLResult rslDel = ps.deletePatient(patientUID);
                            System.Threading.Thread.Sleep(2000);

                            if (!rslDel.IsErrorOccured)
                            {
                                rslGet = ps.getPatient(patientUID);
                                if (rslGet.IsErrorOccured && rslGet.Code == 1020)
                                {
                                    pDel.Outputs.AddParameter("Delete", "Delete patient success", patientUID);
                                    pDel.Outputs.AddParameter("Get", "Get patient ERR", rslGet.Message);
                                    pDel.Result = TestResult.Pass;
                                }
                            }
                            else
                            {
                                pDel.Result = TestResult.Fail;
                            }
                        }

                    }
                    else
                    {
                        pCreate.Result = TestResult.Fail;
                        pCreate.Outputs.AddParameter("create", "Create patient ERR", rslCreate.Message);
                    }
                }

                SaveRound(r);
            }
            Output();
        }
        // Case 1658: 1.2.3_ImportImage_SimpleInstance_large file
        public void Run_Import_SimpleInstance_LargeFile_Case1658()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            bool isDeletePatient = true;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Import image");

                string instanceID = null;

                PatientService ps = new PatientService();
                ImportService ims = new ImportService();
                XMLParameter pa = new XMLParameter("patient");
                XMLParameter ia = new XMLParameter("import");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        pa.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "import")
                    {
                        ia.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                }

                XMLParameter epGetInstanceInfo = new XMLParameter();
                for (int i = 0; i < ids.ExpectedValues.Count; i++)
                {
                    if (ids.ExpectedValues.GetParameter(i).Step == "getInstanceInfo")
                    {
                        epGetInstanceInfo.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                    }
                }

                try
                {
                    if (isCreatePatient)
                    {
                        CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                        r.CheckPoints.Add(pCreate);

                        XMLResult result = ps.createPatient(pa);
                        if (!result.IsErrorOccured)
                        {
                            patientUID = result.SingleResult;
                            pCreate.Result = TestResult.Pass;
                            pCreate.Outputs.AddParameter("Create patient UID", "Create Patient", patientUID);
                        }
                    }

                    CheckPoint pImport = new CheckPoint("Import Image", "Test import");
                    r.CheckPoints.Add(pImport);

                    string filePath = string.Empty;
                    string archivePath = string.Empty;
                    bool move = false;
                    for (int c = 0; c < ia.Length; c++)
                    {
                        if (ia.GetParameterName(c) == "path")
                            filePath = ia.GetParameterValue(c);
                        if (ia.GetParameterName(c) == "archivePath")
                            archivePath = ia.GetParameterValue(c);
                        if (ia.GetParameterName(c) == "move")
                        {
                            if (ia.GetParameterValue(c) == "true")
                                move = true;
                        }
                    }

                    XMLResult rslImport = ims.importObject(patientUID, "", filePath, archivePath, move, "false");

                    /*****************************************
                     *  import simple instance return sample:
                     * <trophy type="result" version="1.0">
                     * <status code="0" message="ok" />
                     * <instance><parameter key="internal_id" value="1f678090-2c54-4128-8d13-833645ac7483" /></instance>
                     * </trophy>
                     * ****************************************/

                    if (rslImport.IsErrorOccured)
                    {
                        pImport.Result = TestResult.Fail;
                        pImport.Outputs.AddParameter("Import simple instance fail", "Import", rslImport.Message);
                        pImport.Outputs.AddParameter("Import simple instance returns error code", "Import", rslImport.Code.ToString());
                    }
                    else
                    {
                        // Check the return contiains instance id
                        instanceID = rslImport.MultiResults[0].GetParameterValueByName("internal_id"); // image internal_id
                        if (instanceID == null || instanceID == string.Empty)
                        {
                            pImport.Result = TestResult.Fail;
                            pImport.Outputs.AddParameter("Import simple instance returns wrong instance internal id", "Import", rslImport.ResultContent);
                        }
                        else
                        {
                            pImport.Result = TestResult.Pass;
                            pImport.Outputs.AddParameter("import simple instance returns OK", "Import", rslImport.ResultContent);
                        }
                    }

                    #region Call getInstanceInfo to check expected key and value
                    SimpleInstanceService simpleInstanceSvc = new SimpleInstanceService();

                    CheckPoint cpGetInstanceInfo = new CheckPoint("GetInstanceInfo", "Call GetInstanceInfo to check the return value");
                    r.CheckPoints.Add(cpGetInstanceInfo);

                    XMLResult rtGetInstanceInfo = simpleInstanceSvc.getInstanceInfo(instanceID);
                    if (rtGetInstanceInfo.IsErrorOccured)
                    {
                        cpGetInstanceInfo.Result = TestResult.Fail;
                        cpGetInstanceInfo.Outputs.AddParameter("Get Instance Info return error", "getInstanceInfo", rtGetInstanceInfo.ResultContent);
                    }
                    else
                    {
                        cpGetInstanceInfo.Outputs.AddParameter("Get Instance Info return success", "getInstanceInfo", rtGetInstanceInfo.Message);

                        //Check the return info contain the expected key and value: parameter key="XXX" value="XXX"
                        foreach (XMLParameterNode node in epGetInstanceInfo.Parameters)
                        {
                            if (!rtGetInstanceInfo.ResultContent.Contains("parameter key=\"" + node.ParameterName + "\" value=\"" + node.ParameterValue + "\""))
                            {
                                cpGetInstanceInfo.Result = TestResult.Fail;
                                cpGetInstanceInfo.Outputs.AddParameter("Get Instance Info returns wrong key-value info for: " + node.ParameterName, "GetInstanceInfo", rtGetInstanceInfo.ResultContent);
                                continue;
                            }
                            else
                            {
                                cpGetInstanceInfo.Outputs.AddParameter("Get Instance Info returns correct key-value info for: " + node.ParameterName, "GetInstanceInfo", "ok");
                            }
                        }

                        if (cpGetInstanceInfo.Result != TestResult.Fail)
                        {
                            cpGetInstanceInfo.Result = TestResult.Pass;
                            cpGetInstanceInfo.Outputs.AddParameter("Get Instance Info return all correct info", "GetInstanceInfo", rtGetInstanceInfo.ResultContent);
                        }
                    }
                    #endregion

                    System.Threading.Thread.Sleep(10000);

                    if (isDeletePatient)
                    {
                        CheckPoint cpDelete = new CheckPoint("Delete Patient", "Test delete patient");
                        r.CheckPoints.Add(cpDelete);
                        XMLResult rltDelete = ps.deletePatient(patientUID);
                        if (rltDelete.IsErrorOccured)
                        {
                            cpDelete.Outputs.AddParameter("Delete created patient returns error", "Delete Patient", rltDelete.Message);
                            cpDelete.Result = TestResult.Fail;
                        }
                        else
                        {
                            cpDelete.Outputs.AddParameter("Delete created patient returns OK", "Delete Patient", rltDelete.Message);
                            cpDelete.Result = TestResult.Pass;
                        }
                    }

                    SaveRound(r);
                }
                catch (Exception ex)
                {
                    CheckPoint cp = new CheckPoint();
                    r.CheckPoints.Add(cp);
                    cp.Outputs.AddParameter("Exception thrown", "Exception Message", ex.Message);
                    cp.Result = TestResult.Fail;
                    SaveRound(r);
                }
            }
            Output();
        }
        //Case 981: 1.3.10_ImportImage_N01_WithNotification
        public void Run_Import_TestNotification_Case981()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            bool isDeletePatient = false;
            string stopMessageType = "teststop";
            string stopMessageContent = "teststop";
            //LaunchNotification();

            NotificationSim.ReceiveNotification rn = new NotificationSim.ReceiveNotification();
            //NotificationSim.ReceiveNotification rn = new NotificationSim.ReceiveNotification("10.112.39.167");
            System.Collections.Generic.List<string> rms = new System.Collections.Generic.List<string>();
            rms.Add("topic.patientCreated");
            rms.Add("topic.acquisitionCompleted");
            rms.Add("topic.imageCreated");
            rms.Add("topic.presentationStateModified");
            rn.startListon(rms, stopMessageType, stopMessageContent);

            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                isDeletePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Import image");
                CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                r.CheckPoints.Add(pCreate);
                PatientService ps = new PatientService();
                ImportService ims = new ImportService();
                ApplicationService ass = new ApplicationService();
                XMLParameter pa = new XMLParameter("patient");
                XMLParameter ia = new XMLParameter("import");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        pa.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "import")
                    {
                        ia.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "delete")
                    {
                        isDeletePatient = true;
                    }
                }
                if (isCreatePatient)
                {
                    XMLResult result = ps.createPatient(pa);
                    if (!result.IsErrorOccured)
                    {
                        patientUID = result.SingleResult;
                        pCreate.Result = TestResult.Pass;
                        pCreate.Outputs.AddParameter("create", "Create patient UID", patientUID);
                    }
                }
                System.Threading.Thread.Sleep(500);

                CheckPoint pImport = new CheckPoint("Import Image", "Test import");
                r.CheckPoints.Add(pImport);

                string filePath = string.Empty;
                string archivePath = string.Empty;
                for (int c = 0; c < ia.Length; c++)
                {
                    if (ia.GetParameterName(c) == "path")
                        filePath = ia.GetParameterValue(c);
                    if (ia.GetParameterName(c) == "archivepath")
                        archivePath = ia.GetParameterValue(c);
                }

                XMLResult rslImport = ims.importObject(patientUID, "", filePath, archivePath, true, "false");
                if (rslImport.IsErrorOccured)
                {
                    pImport.Result = TestResult.Fail;
                    pImport.Outputs.AddParameter("import", "Import image fail", rslImport.Message);
                    pImport.Outputs.AddParameter("import", "Import image error code", rslImport.Code.ToString());
                }
                else
                {
                    pImport.Result = TestResult.Pass;
                    pImport.Outputs.AddParameter("import", "Import image OK", rslImport.Message);
                }

                System.Threading.Thread.Sleep(500);
                ass.sendGenericNotification(stopMessageType, stopMessageContent);
                System.Threading.Thread.Sleep(500);

                int getn = rn.getNotificationNumber();

                CheckPoint pNotification = new CheckPoint("Receive Notification", "import message");
                r.CheckPoints.Add(pNotification);

                if (getn == 3)
                {
                    pNotification.Result = TestResult.Pass;
                    foreach (string mmm in rn.getNotificationContent())
                        pNotification.Outputs.AddParameter("Notification message", "Content:", mmm);
                }
                else
                {
                    pNotification.Result = TestResult.Fail;
                    pNotification.Outputs.AddParameter("Message", "Content:", "miss message on receive");
                }
                if (isDeletePatient)
                {
                    XMLResult rslDelete = ps.deletePatient(patientUID);
                    if (!rslDelete.IsErrorOccured)
                    {
                        pNotification.Outputs.AddParameter("Delete created patient", "Delete Patient", rslDelete.ResultContent);
                    }
                }
                SaveRound(r);
            }
            Output();
        }
        //Case 1016: 1.3.17_workflow_PostImportWithStompNotification
        public void Run_WorkFlow_PostImportWithStompNotification_Case1016()
        {
            int runCount = 0; // this is the initial run count. Use this count to repeat different test data set.

            //Generic notification to used to stop the notification receiver
            string stopMessageType = "Stop Receiving the Notification";
            string stopMessageContent = "Stop Receiving the Notification";

            // Stepup the notification receiver
            NotificationSim.ReceiveNotification rn = new NotificationSim.ReceiveNotification();
            //NotificationSim.ReceiveNotification rn = new NotificationSim.ReceiveNotification("10.112.39.167");
            System.Collections.Generic.List<string> rms = new System.Collections.Generic.List<string>();
            rms.Add("topic.patientCreated");
            rms.Add("topic.postImportStarted");
            rms.Add("topic.postImportCompleted");
            rms.Add("topic.fmsCreated");
            rms.Add("topic.imageCreated");
            rms.Add("topic.simpleInstanceCreated");
            rms.Add("topic.presentationStateInfoModified");
            rn.startListon(rms, stopMessageType, stopMessageContent);

            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Test round");

                //Mark the check point here to indicate what's the check point here
                CheckPoint p1 = new CheckPoint("createPatient", "Setup environment of createPatient");
                CheckPoint p2 = new CheckPoint("initListObjects", "First result of listObjects for the postImport");
                CheckPoint p3 = new CheckPoint("endListObjects", "End result of listObjects for the postImport");
                CheckPoint p4 = new CheckPoint("stompNotification", "Number of received stomp notification during postImport");

                r.CheckPoints.Add(p1);
                r.CheckPoints.Add(p2);
                r.CheckPoints.Add(p3);
                r.CheckPoints.Add(p4);

                //create required PAS service instaces here
                PatientService pats = new PatientService();
                ApplicationService ass = new ApplicationService();

                //create input parameters here, it may include XML path type and string type value
                XMLParameter pa1 = new XMLParameter("createPatient");
                XMLParameter pa2 = new XMLParameter("listObjects");

                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    switch (ids.InputParameters.GetParameter(i).Step)
                    {
                        case "createPatient":
                            pa1.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                            break;
                        case "listObjects":
                            pa2.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                            break;
                        default:
                            Console.WriteLine("There is no valid selection when parse input parameters.");
                            break;
                    }
                }

                //If we need change parameter by specific logic, please put code here

                //Get service result
                //Step1 result

                XMLResult step1_result = pats.createPatient(pa1);

                //Log step1 service output
                if (step1_result.IsErrorOccured)
                {
                    p1.Result = TestResult.Fail;
                    p1.Outputs.AddParameter("createPatient", "Error", step1_result.ResultContent);
                    SaveRound(r);
                    continue;
                }

                p1.Result = TestResult.Pass;
                p1.Outputs.AddParameter("createPatient", "Success", step1_result.ResultContent);

                //Change input parameter according the output of Step1
                pa2.AddParameter("patient_internal_id", step1_result.SingleResult);

                //Step2 result

                XMLResult step2_result = pats.listObjects(pa2);

                //Log step2 service output
                if (step2_result.Code != 800)
                {
                    p2.Result = TestResult.Fail;
                    p2.Outputs.AddParameter("initListObjects", "Error", step2_result.ResultContent);
                    SaveRound(r);
                    continue;
                }

                p2.Result = TestResult.Pass;
                p2.Outputs.AddParameter("initListObjects", "Success", step2_result.ResultContent);

                //Change input parameter according the output of Step2

                //Step3 result
                XMLResult step3_result = new XMLResult();
                int countOfListObjectsLoop = 0;

                do
                {
                    System.Threading.Thread.Sleep(30000);
                    countOfListObjectsLoop++;
                    step3_result = pats.listObjects(pa2);

                    //Log step3 service output
                    if (step3_result.Code == 0)
                    {
                        p3.Result = TestResult.Pass;
                        p3.Outputs.AddParameter("endListObjects", "Success", step3_result.ResultContent);
                        break;
                    }

                    if (step3_result.IsErrorOccured && countOfListObjectsLoop > 2)
                    {
                        p3.Result = TestResult.Fail;
                        p3.Outputs.AddParameter("endListObjects", "Error", step3_result.ResultContent);
                        SaveRound(r);
                        break;
                    }

                } while (true);

                //Change input parameter according the output of Step3

                //Step4 result

                System.Threading.Thread.Sleep(500);

                ass.sendGenericNotification(stopMessageType, stopMessageContent);

                System.Threading.Thread.Sleep(1000);

                int step4_result = rn.getNotificationNumber() - 1;

                //Log step4 service output

                if (ids.ExpectedValues.GetParameter("NumOfNotification").Value == step4_result.ToString())
                {
                    p4.Result = TestResult.Pass;
                    foreach (string notification in rn.getNotificationContent())
                    {
                        p4.Outputs.AddParameter("Received notification number and content: " + rn.getNotificationContent().IndexOf(notification), "Success", notification);
                    }
                }
                else
                {
                    p4.Result = TestResult.Fail;
                    p4.Outputs.AddParameter("Received notification number", "Error", step4_result.ToString());
                    foreach (string notification in rn.getNotificationContent())
                    {
                        p4.Outputs.AddParameter("Received notification number and content: " + rn.getNotificationContent().IndexOf(notification), "Error", notification);
                    }
                }

                //Save data for each round
                SaveRound(r);
            }

            //Save service log as xml file
            Output();
        }
        // Case 1654: 1.3.1_QueryPatients_N6_grouped by keyword in global search
        public void Run_Patient_QueryPatient_Case1654()
        {
            int runCount = 0;
            List<string> needDelete = new List<string>();

            // step 1. create listed patients.
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                bool bSkip = false; // to skip query InputDataSet
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "queryPatient")
                        bSkip = true;
                }
                if (bSkip)
                    continue;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Create patient");

                CheckPoint pCreate = new CheckPoint("Create Patient", "Test description");
                r.CheckPoints.Add(pCreate);
                PatientService ps = new PatientService();
                XMLParameter pa = new XMLParameter("patient");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "createPatient")
                        pa.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                }
                XMLResult result = ps.createPatient(pa);
                if (result.IsErrorOccured)
                {
                    pCreate.Result = TestResult.Fail;
                    pCreate.Outputs.AddParameter("Create error:", "Create Patient", result.Message);
                }
                else
                {
                    pCreate.Result = TestResult.Pass;
                    pCreate.Outputs.AddParameter("Patient ID:", "Create Patient", result.SingleResult);
                    needDelete.Add(result.SingleResult);
                }
                SaveRound(r);
            }
            // step 2. query.
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                bool bSkip = false; // to skip create patient InputDataSet
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "createPatient")
                        bSkip = true;
                }
                if (bSkip)
                    continue;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Query patient");

                CheckPoint pQuery = new CheckPoint("Query Patient", "Test description");
                r.CheckPoints.Add(pQuery);
                PatientService ps = new PatientService();
                XMLParameter query = new XMLParameter("filter");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "queryPatient")
                        query.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                }

                XMLResult queryPatient = ps.queryPatients(query); // should send global_search
                if (queryPatient.IsErrorOccured)
                {
                    pQuery.Result = TestResult.Fail;
                    pQuery.Outputs.AddParameter("Query created patient fail", "Query Patient", queryPatient.ResultContent);
                }
                else
                {
                    pQuery.Outputs.AddParameter("Query created patient OK", "Query Patient", queryPatient.ResultContent);
                    // Here should add the checker for XMLResult
                    //
                    int iTotalExpectedResult = 0;
                    foreach (Parameter p in ids.ExpectedValues.Parameters)
                    {
                        int iStep = 0;
                        if (System.Int32.TryParse(p.Step, out iStep))
                        {
                            iTotalExpectedResult = iStep > iTotalExpectedResult ? iStep : iTotalExpectedResult;
                        }
                    }

                    System.Xml.XmlDocument xmlResult = new System.Xml.XmlDocument();
                    xmlResult.LoadXml(queryPatient.ResultContent);
                    int iNodelist = 0;
                    System.Xml.XmlNodeList patientList = xmlResult.SelectNodes("trophy/patient");
                    foreach (System.Xml.XmlNode patient in patientList)
                    {
                        if (iNodelist < iTotalExpectedResult)
                        {
                            // find the pAttr Key, should check whether the key attribute value is in expected result.
                            foreach (Parameter pExpected in ids.ExpectedValues.Parameters)
                            {
                                int iStep = 0;
                                if (System.Int32.TryParse(pExpected.Step, out iStep))
                                {
                                    if (iStep == (iNodelist + 1))
                                    {
                                        bool bChecked = false;
                                        // if iNodelist is less than expected value, should check whether this is the expected value ordered by global_search
                                        System.Xml.XmlNodeList parameterList = patient.SelectNodes("parameter");
                                        foreach (System.Xml.XmlNode parameter in parameterList)
                                        {
                                            if (parameter.Attributes["key"].Value == pExpected.Key)
                                            {
                                                if (parameter.Attributes["value"].Value == pExpected.Value)
                                                {
                                                    string step = "row (" + iStep + ")" + "key (" + pExpected.Key + ") check successful";
                                                    string key = "query patient";
                                                    string value = "value (" + pExpected.Value + ")";
                                                    pQuery.Outputs.AddParameter(step, key, value);
                                                    pQuery.Result = TestResult.Pass;
                                                    bChecked = true;
                                                }
                                                else
                                                {
                                                    string step = "row (" + iStep + ")" + "key (" + pExpected.Key + ") check fail";
                                                    string key = "query patient";
                                                    string value = "value (" + pExpected.Value + ")";
                                                    pQuery.Outputs.AddParameter(step, key, value);
                                                    pQuery.Result = TestResult.Fail;
                                                    bChecked = true;
                                                }
                                                break; // find the expected key value
                                            }
                                        }
                                        if (!bChecked) // the expected value is not find in expected row
                                        {
                                            string step = "row (" + iStep + ")" + "key (" + pExpected.Key + ") check missed";
                                            string key = "query patient";
                                            string value = "value (" + pExpected.Value + ")";
                                            pQuery.Outputs.AddParameter(step, key, value);
                                            pQuery.Result = TestResult.Fail;
                                            bChecked = true;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            // here , iNodelist is greater than expected value, so this record is more than expected.
                            string step = "row (" + (iNodelist + 1) + ") is not expected";
                            string key = "query patient";
                            string value = patient.InnerXml;
                            pQuery.Outputs.AddParameter(step, key, value);
                            pQuery.Result = TestResult.Fail;
                        }
                        iNodelist++;
                    }
                    if (patientList.Count == 0)
                    {
                        string step = "no any query results";
                        string key = "query patient";
                        string value = queryPatient.ResultContent;
                        pQuery.Outputs.AddParameter(step, key, value);
                        pQuery.Result = TestResult.Fail;
                    }
                }
                SaveRound(r);
            }
            // step 3. delete listed patients.
            foreach (string delpa in needDelete)
            {
                PatientService ps = new PatientService();
                XMLParameter query = new XMLParameter("patient");
                XMLResult delPatient = ps.deletePatient(delpa);
                if (delPatient.IsErrorOccured)
                {
                    Round r = this.NewRound(runCount.ToString(), "Delete patient");
                    CheckPoint pDelete = new CheckPoint("Delete Patient", "Test description");
                    r.CheckPoints.Add(pDelete);
                    pDelete.Result = TestResult.Fail;
                    pDelete.Outputs.AddParameter("Delete created patient fail", "Delete Patient", delPatient.ResultContent);
                    SaveRound(r);
                }
            }

            Output();
        }
        //Case 980: 1.3.17_workflow_CSI select a patient, open an image and then close it
        public void Run_WorkFlow_CSIOpenImageAndClose_Case980()
        {
            // Test Case added for work flow: CSI select a patient to list all the image, click to open one of them and then save and close it.

            PatientService patientService = new PatientService();
            AcquisitionService acquisitionService = new AcquisitionService();
            PresentationStateService presentationStateService = new PresentationStateService();
            AnalysisService analysisService = new AnalysisService();

            string patientUID = null;
            XMLParameter setAsynAcqPatientInfoParam = new XMLParameter("acq_info");
            XMLParameter listObjectForPSParam = new XMLParameter("filter");
            XMLParameterCollection getPresentionStateInfoParam = new XMLParameterCollection();
            XMLParameter listObjectForVolumeParam = new XMLParameter("filter");
            XMLParameter listObjectForFMSParam = new XMLParameter("filter");
            XMLParameter listObjectForOtherParam = new XMLParameter("filter");

            XMLParameter setPresentationStateParam = new XMLParameter("presentationstate");
            XMLParameter setPresentationStateInfoParam = new XMLParameter("presentationstate");

            XMLParameter listObjectForAnalysisParam = new XMLParameter("filter");
            XMLParameter setAnalysisInfoParam = new XMLParameter("analysis");

            foreach (InputDataSet ids in this.Input.DataSets)
            {
                Round r = new Round();

                try
                {
                    for (int i = 0; i < ids.InputParameters.Count; i++)
                    {
                        if (ids.InputParameters.GetParameter(i).Step == "getPatient")
                        {
                            if (ids.InputParameters.GetParameter(i).Key == "patientInternalID")
                            {
                                patientUID = ids.InputParameters.GetParameter(i).Value;
                            }
                        }

                        if (ids.InputParameters.GetParameter(i).Step == "setAsynAcqPatientInfo")
                        {
                            setAsynAcqPatientInfoParam.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        }

                        if (ids.InputParameters.GetParameter(i).Step == "listObjectForPS")
                        {
                            listObjectForPSParam.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        }

                        if (ids.InputParameters.GetParameter(i).Step == "listObjectForVolume")
                        {
                            listObjectForVolumeParam.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        }

                        if (ids.InputParameters.GetParameter(i).Step == "listObjectForFMS")
                        {
                            listObjectForFMSParam.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        }

                        if (ids.InputParameters.GetParameter(i).Step == "listObjectForOther")
                        {
                            listObjectForOtherParam.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        }

                        if (ids.InputParameters.GetParameter(i).Step == "listObjectForAnalysis")
                        {
                            listObjectForAnalysisParam.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        }

                        if (ids.InputParameters.GetParameter(i).Step == "setPresentationStateInfo")
                        {
                            setPresentationStateInfoParam.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        }

                        if (ids.InputParameters.GetParameter(i).Step == "setAnalysisInfo")
                        {
                            setAnalysisInfoParam.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        }
                    }

                    #region Step 1: Check the specific patient exists in Database
                    CheckPoint pGetPatient = new CheckPoint("getPatient", "Step 1: Get the specific patient info");
                    r.CheckPoints.Add(pGetPatient);

                    XMLResult getPatientResult = patientService.getPatient(patientUID);

                    if (getPatientResult.IsErrorOccured)
                    {
                        pGetPatient.Result = TestResult.Fail;

                        System.Diagnostics.Debug.Print("Get the specific patient info fail:");
                        pGetPatient.Outputs.AddParameter("getPatient", "get the specific patient info", getPatientResult.Message);

                        SaveRound(r);
                        break;
                    }
                    else
                    {
                        pGetPatient.Result = TestResult.Pass;

                        System.Diagnostics.Debug.Print("Get the specific patient info succeed:");
                        pGetPatient.Outputs.AddParameter("getPatient", "get the specific patient info", getPatientResult.Message);
                    }
                    #endregion

                    // Step 2 - Step 7 are what to do after select a patient

                    #region Step 2: set asyn acq patient with the specific patient
                    CheckPoint pSetAsynAcqPatientInfo = new CheckPoint("setAsynAcqPatientInfo", "Step 2: call setAsynAcqPatientInfo to set asyn acq patient info");
                    r.CheckPoints.Add(pSetAsynAcqPatientInfo);

                    XMLResult setAsynAcqPatientInfoResult = acquisitionService.setAsynAcqPatientInfo(setAsynAcqPatientInfoParam);

                    if (setAsynAcqPatientInfoResult.IsErrorOccured)
                    {
                        pSetAsynAcqPatientInfo.Result = TestResult.Fail;

                        System.Diagnostics.Debug.Print("Set asyn acq PatientInfo fail:");
                        pSetAsynAcqPatientInfo.Outputs.AddParameter("setAsynAcqPatientInfo", "set asyn acq patient info", setAsynAcqPatientInfoResult.Message);

                        SaveRound(r);
                        break;
                    }
                    else
                    {
                        pSetAsynAcqPatientInfo.Result = TestResult.Pass;

                        System.Diagnostics.Debug.Print("Set asyn acq PatientInfo succeed:");
                        pSetAsynAcqPatientInfo.Outputs.AddParameter("setAsynAcqPatientInfo", "set asyn acq patient info", setAsynAcqPatientInfoResult.Message);
                    }
                    #endregion

                    #region Step 3: Call listObject to get the presentation state list of the patient
                    CheckPoint pListObjectForPS = new CheckPoint("listObjectForPS", "Step 3: call listObject to get PS info");
                    r.CheckPoints.Add(pListObjectForPS);

                    XMLResult listObjectForPSResult = patientService.listObjects(listObjectForPSParam);

                    if (listObjectForPSResult.IsErrorOccured)
                    {
                        pListObjectForPS.Result = TestResult.Fail;

                        System.Diagnostics.Debug.Print("Call listObject to get PS info fail:");
                        pListObjectForPS.Outputs.AddParameter("listObject", "listObject to get PS", listObjectForPSResult.Message);

                        SaveRound(r);
                        break;
                    }
                    else
                    {
                        pListObjectForPS.Result = TestResult.Pass;

                        System.Diagnostics.Debug.Print("Call listObject to get PS info succeed:");
                        pListObjectForPS.Outputs.AddParameter("listObject", "listObject to get PS", listObjectForPSResult.Message);

                    }
                    #endregion

                    #region Step 4: Call getPresentationStateInfo to get the presentationstate info according to the presentationstate internal_id

                    CheckPoint pGetPresentionStateInfo = new CheckPoint("getPresentionStateInfo", "Step 4: call getPresentationStateInfo to get presention state info");
                    r.CheckPoints.Add(pGetPresentionStateInfo);

                    foreach (XMLParameter param in listObjectForPSResult.MultiResults)
                    {
                        getPresentionStateInfoParam.Add(param);
                    }

                    XMLResult getPresentationStateInfoResult = presentationStateService.getPresentationStateInfo(getPresentionStateInfoParam);

                    if (getPresentationStateInfoResult.IsErrorOccured)
                    {
                        pGetPresentionStateInfo.Result = TestResult.Fail;

                        System.Diagnostics.Debug.Print("Call getPresentationStateInfo to get PS info fail:");
                        pGetPresentionStateInfo.Outputs.AddParameter("getPresentationStateInfo", "getPresentationStateInfo to get PS info", getPresentationStateInfoResult.Message);

                        SaveRound(r);
                        break;
                    }
                    else
                    {
                        pGetPresentionStateInfo.Result = TestResult.Pass;

                        System.Diagnostics.Debug.Print("Call getPresentationStateInfo to get PS info succeed:");
                        pGetPresentionStateInfo.Outputs.AddParameter("getPresentationStateInfo", "getPresentationStateInfo to get PS info", getPresentationStateInfoResult.Message);

                    }
                    #endregion

                    #region Step 5: Call listObject to get the volume list of the patient
                    CheckPoint pListObjectForVolume = new CheckPoint("listObjectForVolume", "Step 5: call listObject to get volume info");
                    r.CheckPoints.Add(pListObjectForVolume);

                    XMLResult listObjectForVolumeResult = patientService.listObjects(listObjectForVolumeParam);

                    if (listObjectForVolumeResult.IsErrorOccured)
                    {
                        pListObjectForVolume.Result = TestResult.Fail;

                        System.Diagnostics.Debug.Print("Call listObject to get volume info fail:");
                        pListObjectForVolume.Outputs.AddParameter("listObject", "listObject to get volume", listObjectForVolumeResult.Message);

                        SaveRound(r);
                        break;
                    }
                    else
                    {
                        pListObjectForVolume.Result = TestResult.Pass;

                        System.Diagnostics.Debug.Print("Call listObject to get volume info succeed:");
                        pListObjectForVolume.Outputs.AddParameter("listObject", "listObject to get volume", listObjectForVolumeResult.Message);

                    }
                    #endregion

                    #region Step 6: Call listObject to get the FMS list of the patient
                    CheckPoint pListObjectForFMS = new CheckPoint("listObjectForFMS", "Step 6: call listObject to get FMS info");
                    r.CheckPoints.Add(pListObjectForFMS);

                    XMLResult listObjectForFMSResult = patientService.listObjects(listObjectForFMSParam);

                    if (listObjectForFMSResult.IsErrorOccured)
                    {
                        pListObjectForFMS.Result = TestResult.Fail;

                        System.Diagnostics.Debug.Print("Call listObject to get FMS info fail:");
                        pListObjectForFMS.Outputs.AddParameter("listObject", "listObject to get FMS", listObjectForFMSResult.Message);

                        SaveRound(r);
                        break;
                    }
                    else
                    {
                        pListObjectForFMS.Result = TestResult.Pass;

                        System.Diagnostics.Debug.Print("Call listObject to get FMS info succeed:");
                        pListObjectForFMS.Outputs.AddParameter("listObject", "listObject to get FMS", listObjectForFMSResult.Message);

                    }
                    #endregion

                    #region Step 7: Call listObject to get the other info of the patient
                    CheckPoint pListObjectForOther = new CheckPoint("listObjectForOther", "Step 7: call listObject to get other info");
                    r.CheckPoints.Add(pListObjectForOther);

                    XMLResult listObjectForOtherResult = patientService.listObjects(listObjectForOtherParam);

                    if (listObjectForOtherResult.IsErrorOccured)
                    {
                        pListObjectForOther.Result = TestResult.Fail;

                        System.Diagnostics.Debug.Print("Call listObject to get other info fail:");
                        pListObjectForOther.Outputs.AddParameter("listObject", "listObject to get other", listObjectForOtherResult.Message);

                        SaveRound(r);
                        break;
                    }
                    else
                    {
                        pListObjectForOther.Result = TestResult.Pass;

                        System.Diagnostics.Debug.Print("Call listObject to get other info succeed:");
                        pListObjectForOther.Outputs.AddParameter("listObject", "listObject to get other", listObjectForOtherResult.Message);

                    }
                    #endregion

                    // After double click an image to open it, it will repeat step 3 to step 7
                    // When open image, it will call getPresentationState to get the presentation state, which can be used in setPresentationState step later
                    string presentationStateInternalID = null;
                    XMLParameterCollection setPresentationStateParamList = new XMLParameterCollection();

                    foreach (XMLParameterNode psNode in listObjectForPSResult.ArrayResult.Parameters)
                    {
                        presentationStateInternalID = psNode.ParameterValue;

                        XMLResult getPresentationStateResult = presentationStateService.getPresentationState(presentationStateInternalID);

                        setPresentationStateParam = getPresentationStateResult.ArrayResult;
                        setPresentationStateParamList.Add(setPresentationStateParam);
                    }

                    // Close the image, it will do step 8 to step 10
                    #region Step 8: Call setPresentationState to set presentation state, not change the presentation state value, just set it back
                    CheckPoint pSetPresentationState = new CheckPoint("setPresentationState", "Step 8: call setPresentationState to set the presentation state after close the image");
                    r.CheckPoints.Add(pSetPresentationState);

                    XMLResult setPresentationStateResult = new XMLResult();

                    foreach (XMLParameter presentationStateInfo in setPresentationStateParamList)
                    {
                        setPresentationStateResult = presentationStateService.setPresentationState(presentationStateInfo, presentationStateInternalID);

                        if (setPresentationStateResult.IsErrorOccured)
                        {
                            pSetPresentationState.Result = TestResult.Fail;
                            break;
                        }
                        else
                        {
                            pSetPresentationState.Result = TestResult.Pass;
                        }

                    }

                    if (pSetPresentationState.Result == TestResult.Fail)
                    {
                        System.Diagnostics.Debug.Print("Call setPresentationState to set presentation state fail:");
                        pSetPresentationState.Outputs.AddParameter("setPresentationState", "setPresentationState to set presentation state", setPresentationStateResult.Message);

                        SaveRound(r);
                        break;
                    }
                    else
                    {
                        System.Diagnostics.Debug.Print("Call setPresentationState to set presentation state succeed:");
                        pSetPresentationState.Outputs.AddParameter("setPresentationState", "setPresentationState to set presentation state", setPresentationStateResult.Message);
                    }
                    #endregion

                    #region Step 9: Call setPresentationStateInfo to set the presentation state info
                    CheckPoint pSetPresentationStateInfo = new CheckPoint("setPresentationStateInfo", "Step 9: call setPresentationStateInfo to set the presentation state info after close the image");
                    r.CheckPoints.Add(pSetPresentationStateInfo);

                    XMLResult setPresentationStateInfoResult = new XMLResult();

                    foreach (XMLParameter presentationStateInfoParam in getPresentationStateInfoResult.MultiResults)
                    {
                        presentationStateInternalID = presentationStateInfoParam.GetParameterValueByName("internal_id");

                        setPresentationStateInfoResult = presentationStateService.setPresentationStateInfo(setPresentationStateInfoParam, presentationStateInternalID);

                        if (setPresentationStateInfoResult.IsErrorOccured)
                        {
                            pSetPresentationStateInfo.Result = TestResult.Fail;
                            break;
                        }
                        else
                        {
                            pSetPresentationStateInfo.Result = TestResult.Pass;
                        }
                    }

                    if (pSetPresentationStateInfo.Result == TestResult.Fail)
                    {
                        System.Diagnostics.Debug.Print("Call setPresentationStateInfo to set presentation state info fail:");
                        pSetPresentationStateInfo.Outputs.AddParameter("setPresentationStateInfo", "setPresentationState to set presentation state info", setPresentationStateInfoResult.Message);

                        SaveRound(r);
                        break;
                    }
                    else
                    {
                        System.Diagnostics.Debug.Print("Call setPresentationStateInfo to set presentation state info succeed:");
                        pSetPresentationStateInfo.Outputs.AddParameter("setPresentationState", "setPresentationState to set presentation state info", setPresentationStateInfoResult.Message);
                    }
                    #endregion

                    #region Step 10: Call listObject to get the presentation state
                    CheckPoint pListObjectForPS2 = new CheckPoint("listObjectForPS", "Step 10: call listObject to get PS info after close image");
                    r.CheckPoints.Add(pListObjectForPS2);

                    XMLResult listObjectForPSResult2 = patientService.listObjects(listObjectForPSParam);

                    if (listObjectForPSResult2.IsErrorOccured)
                    {
                        pListObjectForPS.Result = TestResult.Fail;

                        System.Diagnostics.Debug.Print("Call listObject to get PS info fail:");
                        pListObjectForPS2.Outputs.AddParameter("listObject", "listObject to get PS", listObjectForPSResult2.Message);

                        SaveRound(r);
                        break;
                    }
                    else
                    {
                        pListObjectForPS2.Result = TestResult.Pass;

                        System.Diagnostics.Debug.Print("Call listObject to get PS info succeed:");
                        pListObjectForPS2.Outputs.AddParameter("listObject", "listObject to get PS", listObjectForPSResult2.Message);

                    }
                    #endregion

                    #region Step 11: Call getPresentationStateInfo to get the presentation state info
                    CheckPoint pGetPresentionStateInfo2 = new CheckPoint("getPresentionStateInfo", "Step 11: call getPresentationStateInfo to get presention state info after close image");
                    r.CheckPoints.Add(pGetPresentionStateInfo2);

                    XMLResult getPresentationStateInfoResult2 = presentationStateService.getPresentationStateInfo(getPresentionStateInfoParam);

                    if (getPresentationStateInfoResult2.IsErrorOccured)
                    {
                        pGetPresentionStateInfo2.Result = TestResult.Fail;

                        System.Diagnostics.Debug.Print("Call getPresentationStateInfo to get PS info fail:");
                        pGetPresentionStateInfo2.Outputs.AddParameter("getPresentationStateInfo", "getPresentationStateInfo to get PS info", getPresentationStateInfoResult2.Message);

                        SaveRound(r);
                        break;
                    }
                    else
                    {
                        pGetPresentionStateInfo2.Result = TestResult.Pass;

                        System.Diagnostics.Debug.Print("Call getPresentationStateInfo to get PS info succeed:");
                        pGetPresentionStateInfo2.Outputs.AddParameter("getPresentationStateInfo", "getPresentationStateInfo to get PS info", getPresentationStateInfoResult2.Message);

                    }
                    #endregion

                    // Close the viewer
                    #region Step 12: Call listObject to get the analysis
                    CheckPoint pListObjectForAnalysis = new CheckPoint("listObjectForAnalysis", "Step 12: call listObject to get analysis info");
                    r.CheckPoints.Add(pListObjectForAnalysis);

                    XMLResult listObjectForAnalysisResult = patientService.listObjects(listObjectForAnalysisParam);

                    if (listObjectForAnalysisResult.IsErrorOccured)
                    {
                        pListObjectForAnalysis.Result = TestResult.Fail;

                        System.Diagnostics.Debug.Print("Call listObject to get analysis info fail:");
                        pListObjectForAnalysis.Outputs.AddParameter("listObject", "listObject to get analysis", listObjectForAnalysisResult.Message);

                        SaveRound(r);
                        break;
                    }
                    else
                    {
                        pListObjectForAnalysis.Result = TestResult.Pass;

                        System.Diagnostics.Debug.Print("Call listObject to get analysis info succeed:");
                        pListObjectForAnalysis.Outputs.AddParameter("listObject", "listObject to get analysis", listObjectForAnalysisResult.Message);
                    }
                    #endregion

                    string analysisId = null;
                    analysisId = listObjectForAnalysisResult.SingleResult;

                    if (analysisId == null || analysisId == string.Empty)
                    {
                        // Below Step are excuted when there is no analysis before

                        #region Step 13: createAnalysis
                        CheckPoint pCreateAnalysis = new CheckPoint("createAnalysis", "Step 13: call createAnalysis to create new analysis");
                        r.CheckPoints.Add(pCreateAnalysis);

                        XMLResult createAnalysisResult = new XMLResult();

                        XMLParameter analysisXml = new XMLParameter("analysis");
                        XMLParameterCollection uidsXml = new XMLParameterCollection();
                        XMLParameter presentationStateUids = new XMLParameter("presentationstate");
                        XMLParameter fmsUids = new XMLParameter("fms");
                        uidsXml.Add(presentationStateUids);
                        uidsXml.Add(fmsUids);

                        createAnalysisResult = analysisService.createAnalysis(analysisXml.GenerateXML().ToString(), true, true, patientUID, null, uidsXml);
                        // public XMLResult createAnalysis(string analysisXml, bool current, bool currentSpecified, string patientInternalID, string thumbnail, XMLParameterCollection uidsXml);
                        if (createAnalysisResult.IsErrorOccured)
                        {
                            System.Diagnostics.Debug.Print("Call createAnalysis to create analysis fail:");
                            pCreateAnalysis.Outputs.AddParameter("createAnalysis", "createAnalysis to create analysis", createAnalysisResult.Message);

                            SaveRound(r);
                            break;
                        }
                        else
                        {
                            System.Diagnostics.Debug.Print("Call createAnalysis to create analysis succeed:");
                            pCreateAnalysis.Outputs.AddParameter("createAnalysis", "createAnalysis to create analysis", createAnalysisResult.Message);
                        }
                        #endregion

                        #region Step 14: Call AnalysisService.setAnalysisInfo to set the analysis info
                        CheckPoint pSetAnalysisInfo = new CheckPoint("setAnalysisInfo", "Step 14: call setAnalysisInfo to set the analysis info");
                        r.CheckPoints.Add(pSetAnalysisInfo);

                        XMLResult setAnalysisInfoResult = new XMLResult();

                        analysisId = createAnalysisResult.MultiResults[0].GetParameterValueByName("internal_id");

                        setAnalysisInfoResult = analysisService.setAnalysisInfo(analysisId, setAnalysisInfoParam);

                        if (setAnalysisInfoResult.IsErrorOccured)
                        {
                            System.Diagnostics.Debug.Print("Call setAnalysisInfo to set analysis info fail:");
                            pSetAnalysisInfo.Outputs.AddParameter("setAnalysisInfo", "setAnalysisInfo to set analysis info", setAnalysisInfoResult.Message);

                            SaveRound(r);
                            break;
                        }
                        else
                        {
                            System.Diagnostics.Debug.Print("Call setAnalysisInfo to set analysis info succeed:");
                            pSetAnalysisInfo.Outputs.AddParameter("setAnalysisInfo", "setAnalysisInfo to set analysis info", setAnalysisInfoResult.Message);
                        }
                        #endregion
                    }

                    else
                    {
                        // Below Step 15 to Step 17 are excuted when there is analysis exist before...

                        #region Step 15: Call AnalysisService.getAnalysisInfo to get the analysis info
                        CheckPoint pGetAnalysisInfo = new CheckPoint("getAnalysisInfo", "Step 15: call getAnalysisInfo to get the analysis info");
                        r.CheckPoints.Add(pGetAnalysisInfo);

                        XMLResult getAnalysisInfoResult = new XMLResult();

                        getAnalysisInfoResult = analysisService.getAnalysisInfo(analysisId);

                        if (getAnalysisInfoResult.IsErrorOccured)
                        {
                            pGetAnalysisInfo.Result = TestResult.Fail;
                            System.Diagnostics.Debug.Print("Call getAnalysisInfo to get analysis info fail:");
                            pGetAnalysisInfo.Outputs.AddParameter("getAnalysisInfo", "getAnalysisInfo to get analysis info", getAnalysisInfoResult.Message);

                            SaveRound(r);
                            break;
                        }
                        else
                        {
                            pGetAnalysisInfo.Result = TestResult.Pass;
                            System.Diagnostics.Debug.Print("Call getAnalysisInfo to get analysis info succeed:");
                            pGetAnalysisInfo.Outputs.AddParameter("getAnalysisInfo", "getAnalysisInfo to get analysis info", getAnalysisInfoResult.Message);
                        }
                        #endregion

                        #region Step 16: Call AnalysisService.setAnalysisDescription to set analysis description
                        CheckPoint pSetAnalysisDescription = new CheckPoint("setAnalysisDescription", "Step 16: call setAnalysisDescription to set the analysis description");
                        r.CheckPoints.Add(pSetAnalysisDescription);

                        XMLResult setAnalysisDescriptionResult = new XMLResult();

                        XMLParameter analysisXml = new XMLParameter("analysis");
                        XMLParameterCollection uidsXml = new XMLParameterCollection();
                        XMLParameter presentationStateUids = new XMLParameter("presentationstate");
                        XMLParameter fmsUids = new XMLParameter("fms");
                        uidsXml.Add(presentationStateUids);
                        uidsXml.Add(fmsUids);

                        setAnalysisDescriptionResult = analysisService.setAnalysisDescription(analysisId, analysisXml.GenerateXML(), false, uidsXml);

                        if (setAnalysisDescriptionResult.IsErrorOccured)
                        {
                            pSetAnalysisDescription.Result = TestResult.Fail;
                            System.Diagnostics.Debug.Print("Call setAnalysisDescription to set the analysis description fail:");
                            pSetAnalysisDescription.Outputs.AddParameter("setAnalysisDescription", "call set the analysis description", setAnalysisDescriptionResult.Message);

                            SaveRound(r);
                            break;
                        }
                        else
                        {
                            pSetAnalysisDescription.Result = TestResult.Pass;
                            System.Diagnostics.Debug.Print("Call setAnalysisDescription to set the analysis description succeed:");
                            pSetAnalysisDescription.Outputs.AddParameter("setAnalysisDescription", "call set the analysis description", setAnalysisDescriptionResult.Message);
                        }
                        #endregion

                        #region Step 17: Call AnalysisService.setAnalysisInfo to set the analysis info
                        CheckPoint pSetAnalysisInfo = new CheckPoint("setAnalysisInfo", "Step 17: call setAnalysisInfo to set the analysis info");
                        r.CheckPoints.Add(pSetAnalysisInfo);

                        XMLResult setAnalysisInfoResult = new XMLResult();

                        setAnalysisInfoResult = analysisService.setAnalysisInfo(analysisId, setAnalysisInfoParam);

                        if (setAnalysisInfoResult.IsErrorOccured)
                        {
                            pSetAnalysisInfo.Result = TestResult.Fail;
                            System.Diagnostics.Debug.Print("Call setAnalysisInfo to set analysis info fail:");
                            pSetAnalysisInfo.Outputs.AddParameter("setAnalysisInfo", "setAnalysisInfo to set analysis info", setAnalysisInfoResult.Message);

                            SaveRound(r);
                            break;
                        }
                        else
                        {
                            pSetAnalysisInfo.Result = TestResult.Pass;
                            System.Diagnostics.Debug.Print("Call setAnalysisInfo to set analysis info succeed:");
                            pSetAnalysisInfo.Outputs.AddParameter("setAnalysisInfo", "setAnalysisInfo to set analysis info", setAnalysisInfoResult.Message);
                        }
                        #endregion
                    }

                    SaveRound(r);
                }
                catch (Exception ex)
                {
                    CheckPoint cp = new CheckPoint();
                    r.CheckPoints.Add(cp);
                    cp.Outputs.AddParameter("Exception thrown", "Exception Message", ex.Message);
                    cp.Result = TestResult.Fail;
                    SaveRound(r);
                }
            }

            Output();
        }
        //Case 992: 1.3.7_GetPresentationStateDescription_N02_WhenPSNotExist
        public void Run_PS_GetPresentationStateDescription_PSNotExist_Case992()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            bool isDeletePatient = false;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                isDeletePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Import image");
                CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                r.CheckPoints.Add(pCreate);
                PatientService ps = new PatientService();
                ImportService ims = new ImportService();
                PresentationStateService pss = new PresentationStateService();

                XMLParameter pa = new XMLParameter("patient");
                XMLParameter ia = new XMLParameter("import");
                //XMLParameter psa = new XMLParameter("presentationstate");

                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        pa.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "import")
                    {
                        ia.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "delete")
                    {
                        isDeletePatient = true;
                    }
                }
                if (isCreatePatient)
                {
                    XMLResult result = ps.createPatient(pa);
                    if (!result.IsErrorOccured)
                    {
                        patientUID = result.SingleResult;
                        pCreate.Result = TestResult.Pass;
                        pCreate.Outputs.AddParameter("create", "Create patient UID", patientUID);
                    }
                }

                CheckPoint pImport = new CheckPoint("Import Image", "Test import");
                r.CheckPoints.Add(pImport);

                string filePath = string.Empty;
                string archivePath = string.Empty;
                bool move = false;
                for (int c = 0; c < ia.Length; c++)
                {
                    if (ia.GetParameterName(c) == "path")
                        filePath = ia.GetParameterValue(c);
                    if (ia.GetParameterName(c) == "archivePath")
                        archivePath = ia.GetParameterValue(c);
                    if (ia.GetParameterName(c) == "move")
                    {
                        if (ia.GetParameterValue(c) == "true")
                            move = true;
                    }
                }

                XMLResult rslImport = ims.importObject(patientUID, "", filePath, archivePath, move, "false");

                if (rslImport.IsErrorOccured)
                {
                    pImport.Result = TestResult.Fail;
                    pImport.Outputs.AddParameter("import", "Import image fail", rslImport.Message);
                    pImport.Outputs.AddParameter("import", "Import image error code", rslImport.Code.ToString());
                }
                else
                {
                    pImport.Result = TestResult.Pass;
                    pImport.Outputs.AddParameter("import", "Import image OK", rslImport.Message);

                    for (int findPs = 0; findPs < rslImport.MultiResults.Count; findPs++)
                    {
                        if (rslImport.MultiResults[findPs].Name == "presentationstate")
                        {
                            string psUID = rslImport.MultiResults[findPs].Parameters[0].ParameterValue;
                            XMLResult psreturn = pss.getPresentationState(psUID);

                            CheckPoint pGetPS = new CheckPoint("Get Presentation State", "PS Desc");
                            r.CheckPoints.Add(pGetPS);
                            if (psreturn.MultiResults.Count == 1 && !string.IsNullOrEmpty(psreturn.MultiResults[0].GetParameterValueByName("image_internal_id")) && string.IsNullOrEmpty(psreturn.MultiResults[0].GetParameterValueByName("general.xml")) && string.IsNullOrEmpty(psreturn.MultiResults[0].GetParameterValueByName("processing.xml")) && string.IsNullOrEmpty(psreturn.MultiResults[0].GetParameterValueByName("annotation.xml")))
                            {
                                pGetPS.Result = TestResult.Pass;
                                pGetPS.Outputs.AddParameter("get presentation state", "get presentation state as expect", psreturn.ResultContent);
                            }
                            else
                            {
                                pGetPS.Result = TestResult.Fail;
                                pGetPS.Outputs.AddParameter("get presentation state", "get presentation state not as expect", psreturn.ResultContent);
                            }
                        }
                    }
                }
                if (isDeletePatient)
                {
                    XMLResult rltDelete = ps.deletePatient(patientUID);
                    if (!rltDelete.IsErrorOccured)
                    {
                        pCreate.Outputs.AddParameter("Delete created patient", "Delete Patient", rltDelete.Message);
                    }
                }
                SaveRound(r);
            }
            Output();
        }
        //Case 978: 1.3.17_workflow_CSI starts up and initializes
        public void Run_WorkFlow_CSIStartsupAndInitializes_Case978()
        {
            ApplicationService applicationService = new ApplicationService();
            PatientService patientService = new PatientService();
            AcquisitionService acquisitionService = new AcquisitionService();

            XMLParameter queryPatientsParameter = new XMLParameter("filter");
            XMLParameter queryDivicesParameter = new XMLParameter("query_devices");
            XMLParameter queryLinesParameter = new XMLParameter("query_lines");
            XMLParameter setAsynAcqPatientInfoParameter = new XMLParameter("acq_info");

            CheckPoint pRegister = new CheckPoint("register", "register 2D Viewer");
            CheckPoint pQueryPatients = new CheckPoint("queryPatients", "query the patients list");
            CheckPoint pQueryDevices = new CheckPoint("queryDevices", "query installed device IDs of sensor type");
            CheckPoint pQueryLines = new CheckPoint("queryLines", "query installed line IDs of device IDs");
            CheckPoint pSetAsynAcqPatientInfo = new CheckPoint("setAsynAcqPatientInfo", "set asyn acq patient info");

            foreach (InputDataSet ids in this.Input.DataSets)
            {
                Round r = new Round();

                r.CheckPoints.Add(pRegister);
                r.CheckPoints.Add(pQueryPatients);
                r.CheckPoints.Add(pQueryDevices);
                r.CheckPoints.Add(pQueryLines);
                r.CheckPoints.Add(pSetAsynAcqPatientInfo);

                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "query_devices")
                    {
                        queryDivicesParameter.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                }

                #region Step 1: receive getType and then register 2D applciation to CSDM

                System.Threading.Thread simulator = new System.Threading.Thread(delegate()
                {
                    TwoDSim.simulator si = new TwoDSim.simulator(2010);

                    si.StartSimulater("0,2DViewer");
                    si.StopSimulator(60000);
                }); //Use simulator to simulate there is 2D running

                simulator.Start();
                System.Threading.Thread.Sleep(3000);

                XMLResult registerResult = applicationService.registerApplication("2DViewer", "localhost", 2010, true);

                try
                {
                    simulator.Join(3000);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                if (registerResult.IsErrorOccured)
                {
                    pRegister.Result = TestResult.Fail;
                    System.Diagnostics.Debug.Print("2D Viewer register fail");
                    pRegister.Outputs.AddParameter("Register", "register 2D Viewer", registerResult.Message);

                    SaveRound(r);
                    break; // There is error, end test case
                }
                else
                {
                    pRegister.Result = TestResult.Pass;
                    System.Diagnostics.Debug.Print("2D Viewer register succeed");
                    pRegister.Outputs.AddParameter("registerApplication", "Register 2D Viewer", registerResult.Message);
                }
                #endregion

                #region Step 2: call queryPatients to get the patient list
                XMLResult queryPatientsResult = patientService.queryPatients(queryPatientsParameter);

                if (queryPatientsResult.IsErrorOccured)
                {
                    pQueryPatients.Result = TestResult.Fail;
                    System.Diagnostics.Debug.Print("query the patients list fail:");
                    pQueryPatients.Outputs.AddParameter("queryPatients", "query the patients list", queryPatientsResult.Message);

                    SaveRound(r);
                    break; // There is error, end test case
                }
                else
                {
                    pQueryPatients.Result = TestResult.Pass;
                    System.Diagnostics.Debug.Print("query the patients list succeed:");
                    pQueryPatients.Outputs.AddParameter("queryPatients", "query the patients list", queryPatientsResult.Message);
                }
                #endregion

                #region Step 3: call queryDevices to query installed device IDs of sensor type
                XMLResult queryDevicesResult = acquisitionService.queryDevices(queryDivicesParameter);

                if (queryDevicesResult.IsErrorOccured)
                {
                    pQueryDevices.Result = TestResult.Fail;
                    System.Diagnostics.Debug.Print("query installed device IDs of sensor type fail:");
                    pQueryDevices.Outputs.AddParameter("queryDevices", "query installed device IDs of sensor type", queryDevicesResult.Message);

                    SaveRound(r);
                    break; // There is error, end test case
                }
                else
                {
                    pQueryDevices.Result = TestResult.Pass;
                    System.Diagnostics.Debug.Print("query installed device IDs of sensor type succeed:");
                    pQueryDevices.Outputs.AddParameter("queryDevices", "query installed device IDs of sensor type", queryDevicesResult.Message);
                }
                #endregion

                #region Step 4: call queryLines to query installed line IDs of device IDs
                // Get the line ID sub strings from queryDevicesResult, e.g: <device id="AcqCR7400.dll">
                string pattern = "<device id=\"\\S*\">";
                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(pattern);
                System.Text.RegularExpressions.MatchCollection matches = regex.Matches(queryDevicesResult.ResultContent);

                foreach (System.Text.RegularExpressions.Match match in matches)
                {
                    // Get the exact device ID from the result, e.g: from <device id="AcqCR7400.dll"> to AcqCR7400.dll
                    string deviceID = match.Value;
                    deviceID = deviceID.Replace("<device id=\"", "");
                    deviceID = deviceID.Replace("\">", "");

                    queryLinesParameter.AddParameter("id", deviceID);
                }

                XMLResult queryLinesResult = acquisitionService.queryLines(queryLinesParameter);

                if (queryLinesResult.IsErrorOccured)
                {
                    pQueryLines.Result = TestResult.Fail;
                    System.Diagnostics.Debug.Print("query installed line IDs of device IDs fail:");
                    pQueryLines.Outputs.AddParameter("queryLines", "query installed line IDs of device IDs", queryLinesResult.Message);

                    SaveRound(r);
                    break; // There is error, end test case
                }
                else
                {
                    pQueryLines.Result = TestResult.Pass;
                    System.Diagnostics.Debug.Print("query installed line IDs of device IDs succeed:");
                    pQueryLines.Outputs.AddParameter("queryLines", "query installed line IDs of device IDs", queryLinesResult.Message);
                }
                #endregion

                #region Step 5: setAsynAcqPatientInfo with empty patient
                setAsynAcqPatientInfoParameter.AddParameter("patient_internal_id", "");
                XMLResult setAsynAcqPatientInfoResult = acquisitionService.setAsynAcqPatientInfo(setAsynAcqPatientInfoParameter);

                if (setAsynAcqPatientInfoResult.IsErrorOccured)
                {
                    pSetAsynAcqPatientInfo.Result = TestResult.Fail;

                    System.Diagnostics.Debug.Print("Set AsynAcq PatientInfo fail:");
                    pSetAsynAcqPatientInfo.Outputs.AddParameter("setAsynAcqPatientInfo", "Set AsynAcq PatientInfo", setAsynAcqPatientInfoResult.Message);

                    SaveRound(r);
                    break; // There is error, end test case
                }
                else
                {
                    pSetAsynAcqPatientInfo.Result = TestResult.Pass;

                    System.Diagnostics.Debug.Print("Set AsynAcq PatientInfo succeed:");
                    pSetAsynAcqPatientInfo.Outputs.AddParameter("setAsynAcqPatientInfo", "Set AsynAcq PatientInfo", setAsynAcqPatientInfoResult.Message);
                }
                #endregion

                SaveRound(r);

            }

            Output();
        }
        //Case 1094: 1.3.7_WorkFlow_ImportDICOMImage+GetPresentationStateInfo_RadioLogInformation
        public void Run_PS_ImportDicom_RadioLog_Case1094()
        {
            //int runCount = this.Input.Repetition;

            int runCount = 0; // this is the initial run count. Use this count to repeat different test data set.

            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Test round");

                //Mark the check point here to indicate what's the check point here
                CheckPoint p1 = new CheckPoint("createPatient", "Setup environment of createPatient");
                CheckPoint p2 = new CheckPoint("importObject", "Setup environment of importObject");
                CheckPoint p3 = new CheckPoint("getImageInfo", "Test getImageInfo");
                CheckPoint p4 = new CheckPoint("getPresentationStateInfo", "Test getPresentationStateInfo");

                r.CheckPoints.Add(p1);
                r.CheckPoints.Add(p2);
                r.CheckPoints.Add(p3);
                r.CheckPoints.Add(p4);

                //create required PAS service instaces here
                PatientService pats = new PatientService();
                ImportService ims = new ImportService();
                ImageService img = new ImageService();
                PresentationStateService ps = new PresentationStateService();

                //create input parameters here, it may include XML path type and string type value
                XMLParameter pa1 = new XMLParameter("patient");
                XMLParameter pa2 = new XMLParameter("importObject");
                XMLParameter pa3 = new XMLParameter("image");
                XMLParameter ps4 = new XMLParameter("presentationstate");
                XMLParameterCollection pa4 = new XMLParameterCollection();

                try
                {
                    for (int i = 0; i < ids.InputParameters.Count; i++)
                    {
                        switch (ids.InputParameters.GetParameter(i).Step)
                        {
                            case "createPatient":
                                pa1.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                                break;
                            case "importObject":
                                pa2.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                                break;
                            default:
                                Console.WriteLine("There is no valid selection when parse input parameters.");
                                break;
                        }
                    }

                    //If we need change parameter by specific logic, please put code here

                    //Get service result
                    //Step1 result

                    XMLResult step1_result = pats.createPatient(pa1);

                    //Log step1 service output
                    if (step1_result.IsErrorOccured)
                    {
                        p1.Result = TestResult.Fail;
                        p1.Outputs.AddParameter("Step 1: createPatient", "Error", step1_result.ResultContent);
                        SaveRound(r);
                        continue;
                    }

                    p1.Result = TestResult.Pass;
                    p1.Outputs.AddParameter("Step 1: createPatient", "Success", step1_result.ResultContent);

                    //Change input parameter according the output of Step1
                    pa2.AddParameter("patientInternalId", step1_result.SingleResult);

                    //Step2 result

                    //if objectFileFullPath is empty string, skip step2
                    if (pa2.GetParameterValueByName("objectFileFullPath") != null && pa2.GetParameterValueByName("objectFileFullPath") != "")
                    {
                        XMLResult step2_result = ims.importObject(pa2.GetParameterValueByName("patientInternalId"), "", pa2.GetParameterValueByName("objectFileFullPath"), "", false, "");

                        //Log step2 service output
                        if (step2_result.IsErrorOccured)
                        {
                            p2.Result = TestResult.Fail;
                            p2.Outputs.AddParameter("Step 2: importObject", "Error", step2_result.ResultContent);
                            SaveRound(r);
                            continue;
                        }

                        p2.Result = TestResult.Pass;
                        p2.Outputs.AddParameter("Step 2: importObject", "Success", step2_result.ResultContent);

                        //Change input parameter according the output of Step2
                        // if step2 is skipped, step3 input has no need parameter of internal_id

                        for (int i = 0; i < step2_result.MultiResults.Count; i++)
                        {
                            if (step2_result.MultiResults[i].Name == "image")
                            {
                                pa3.AddParameter("internal_id", step2_result.MultiResults[i].GetParameterValueByIndex(i));
                            }
                            if (step2_result.MultiResults[i].Name == "presentationstate")
                            {
                                pa4.Add(step2_result.MultiResults[i]);
                            }
                        }
                    }

                    //Step3 result
                    XMLResult step3_result = img.getImageInfo(pa3);

                    if (step3_result.IsErrorOccured)
                    {
                        p3.Result = TestResult.Fail;
                        p3.Outputs.AddParameter("Step 3: getImageInfo", "The call 'getImageInfo' returns error: ", step3_result.Message);
                        SaveRound(r);
                        continue;
                    }
                    else
                    {
                        p3.Result = TestResult.Pass; // Assume test pass at first, check the details later to update this
                    }

                    //Log step3 service output
                    int expectedParameterCount = 0;
                    for (int index = 0; index < ids.ExpectedValues.Parameters.Count; index++)
                    {
                        if (ids.ExpectedValues.Parameters[index].Step == "getImageInfo")
                        {
                            expectedParameterCount++;
                        }
                    }

                    string dicom_info_getImageInfo = step3_result.DicomArrayResult.GetParameterValueByName("dicom_info");

                    for (int index = 0; index < ids.ExpectedValues.Parameters.Count; index++)
                    {
                        if (ids.ExpectedValues.Parameters[index].Step == "getImageInfo")
                        {
                            // The dicom_info in return does not match the expected key and value
                            if (false == dicom_info_getImageInfo.Contains("<parameter key=\"" + ids.ExpectedValues.Parameters[index].Key + "\" value=\"" + ids.ExpectedValues.Parameters[index].Value + "\" />"))
                            {
                                p3.Result = TestResult.Fail;
                                p3.Outputs.AddParameter("Step 3: getImageInfo", "Error: the expect value does not match: " + ids.ExpectedValues.Parameters[index].Key + ". Actually get dicom_Info: ", dicom_info_getImageInfo);
                                break;
                            }
                        }
                    }
                    if (p3.Result == TestResult.Pass)
                    {
                        p3.Outputs.AddParameter("Step 3: getImageInfo", "The dicom info all match the expected value", dicom_info_getImageInfo);
                    }

                    //Step4 result
                    XMLResult step4_result = ps.getPresentationStateInfo(pa4);

                    if (step4_result.IsErrorOccured)
                    {
                        p4.Result = TestResult.Fail;
                        p4.Outputs.AddParameter("Step 4: getPresentationStateInfo", "The call 'getPresentationStateInfo' returns error: ", step4_result.Message);
                        SaveRound(r);
                        continue;
                    }
                    else
                    {
                        p4.Result = TestResult.Pass;
                    }

                    expectedParameterCount = 0;  //count of expected parameters on getPresentationStateInfo
                    for (int index = 0; index < ids.ExpectedValues.Parameters.Count; index++)
                    {
                        if (ids.ExpectedValues.Parameters[index].Step == "getPresentationStateInfo")
                        {
                            expectedParameterCount++;
                        }
                    }

                    string dicom_info_getPSInfo = step4_result.DicomArrayResult.GetParameterValueByName("dicom_info");

                    for (int index = 0; index < ids.ExpectedValues.Parameters.Count; index++)
                    {
                        if (ids.ExpectedValues.Parameters[index].Step == "getPresentationStateInfo")
                        {
                            if (false == dicom_info_getPSInfo.Contains("<parameter key=\"" + ids.ExpectedValues.Parameters[index].Key + "\" value=\"" + ids.ExpectedValues.Parameters[index].Value + "\" />"))
                            {
                                p4.Result = TestResult.Fail;
                                p4.Outputs.AddParameter("Step 4: getPresentationStateInfo", "Error: the expect dicom value does not match: " + ids.ExpectedValues.Parameters[index].Key + ". Actually get dicom_Info: ", dicom_info_getPSInfo);
                                break;
                            }
                        }
                    }

                    if (p4.Result == TestResult.Pass)
                    {
                        p4.Outputs.AddParameter("Step 4: getPresentationStateInfo", "Success: the expect dicom value all match the expected", dicom_info_getPSInfo);
                    }

                    SaveRound(r);

                }
                catch (Exception ex)
                {
                    CheckPoint cp = new CheckPoint();
                    r.CheckPoints.Add(cp);
                    cp.Outputs.AddParameter("Exception thrown", "Exception Message: ", ex.Message);
                    cp.Result = TestResult.Fail;
                    SaveRound(r);
                }
            }

            //Save service log as xml file
            Output();
        }
        //Case 512: 1.2.3_ImportZip_Normal
        public void Run_Import_Zip_Case512()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            bool isDeletePatient = false;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                isDeletePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Import image");
                CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                r.CheckPoints.Add(pCreate);
                PatientService ps = new PatientService();
                ImportService ims = new ImportService();
                PresentationStateService pss = new PresentationStateService();

                XMLParameter pa = new XMLParameter("patient");
                XMLParameter ia = new XMLParameter("import");
                XMLParameter ObjFilter = new XMLParameter("filter");
                for (int i = 0; i < ids.InputParameters.Count; i++)
                {
                    if (ids.InputParameters.GetParameter(i).Step == "create")
                    {
                        pa.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        isCreatePatient = true;
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "import")
                    {
                        ia.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "delete")
                    {
                        isDeletePatient = true;
                    }
                }
                if (isCreatePatient)
                {
                    XMLResult result = ps.createPatient(pa);
                    if (!result.IsErrorOccured)
                    {
                        patientUID = result.SingleResult;
                        pCreate.Outputs.AddParameter("create", "Create patient UID", patientUID);
                        pCreate.Result = TestResult.Pass;
                    }
                }

                CheckPoint pImport = new CheckPoint("Import Image", "Test import");
                r.CheckPoints.Add(pImport);

                string filePath = string.Empty;
                string archivePath = string.Empty;
                bool move = false;
                for (int c = 0; c < ia.Length; c++)
                {
                    if (ia.GetParameterName(c) == "path")
                        filePath = ia.GetParameterValue(c);
                    if (ia.GetParameterName(c) == "archivePath")
                        archivePath = ia.GetParameterValue(c);
                    if (ia.GetParameterName(c) == "move")
                    {
                        if (ia.GetParameterValue(c) == "true")
                            move = true;
                    }
                }

                XMLResult rslImport = ims.importObject(patientUID, "", filePath, archivePath, move, "false");
                if (rslImport.IsErrorOccured)
                {
                    pImport.Result = TestResult.Fail;
                    pImport.Outputs.AddParameter("import", "Import image fail", rslImport.Message);
                    pImport.Outputs.AddParameter("import", "Import image error code", rslImport.Code.ToString());
                }
                else
                {
                    pImport.Result = TestResult.Pass;
                    pImport.Outputs.AddParameter("import", "Import image OK", rslImport.Message);

                    ObjFilter.AddParameter("patient_internal_id", patientUID);
                    ObjFilter.AddParameter("type", "presentationstate");
                    ObjFilter.AddParameter("current", "true");
                    XMLResult listObjcetRsl = ps.listObjects(ObjFilter);

                    CheckPoint pListObject = new CheckPoint("List Image", "Test list object");
                    r.CheckPoints.Add(pListObject);

                    if (listObjcetRsl.IsErrorOccured)
                    {
                        pListObject.Result = TestResult.Fail;
                        pListObject.Outputs.AddParameter("Erron in List Object", "List Object", "List Patient Presentation State Error");
                    }
                    else
                    {
                        pListObject.Outputs.AddParameter("List Object return content", "List Object", listObjcetRsl.ResultContent);
                        if (listObjcetRsl.ArrayResult.Length == 3)
                        {
                            bool isMatchXML = true;
                            for (int index = 0; index < listObjcetRsl.ArrayResult.Parameters.Count; index++)
                            {
                                XMLResult getPSRsl = pss.getPresentationState(listObjcetRsl.ArrayResult.Parameters[index].ParameterValue);
                                if (getPSRsl.ArrayResult.Parameters.Count != 4)
                                {
                                    isMatchXML = false;
                                    pListObject.Outputs.AddParameter("Get PS return content", "Get PS Description", getPSRsl.ResultContent);
                                    break;
                                }
                            }
                            if (isMatchXML)
                            {
                                pListObject.Result = TestResult.Pass;
                            }
                            else
                            {
                                pListObject.Result = TestResult.Fail;
                                pListObject.Outputs.AddParameter("Get PS description error", "Get PS Description", "Not return all xml and image id");
                            }
                        }
                        else
                        {
                            pListObject.Result = TestResult.Fail;
                            pListObject.Outputs.AddParameter("The PS count not match", "Get All PS Description", "Not three PS be retrieve.");
                        }
                    }
                }
                if (isDeletePatient)
                {
                    XMLResult rslDelete = ps.deletePatient(patientUID);
                    if (!rslDelete.IsErrorOccured)
                    {
                        pImport.Outputs.AddParameter("Delete created patient", "Delete Patient", rslDelete.ResultContent);
                    }
                }
                SaveRound(r);
            }
            Output();
        }