//Case 1073: 1.3.7_GetPresentationStateInfo_N06_Import image and check the DICOM info value is correct in GetPSInfo return
        public void Run_PS_Import_GetPSInfo_Case1073()
        {
            int runCount = 0;

            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;

                Round r = this.NewRound(runCount.ToString(), ids.Description);

                try
                {
                    string patientID = null;
                    string objectFileFullPath = null;
                    XMLParameter getPSInfoReturnParam = new XMLParameter("DICOM INFO in getPSInfo return");

                    for (int i = 0; i < ids.InputParameters.Count; i++)
                    {
                        if (ids.InputParameters.GetParameter(i).Step == "import")
                        {
                            if (ids.InputParameters.GetParameter(i).Key == "patientInternalID")
                            {
                                patientID = ids.InputParameters.GetParameter(i).Value;
                            }
                            if (ids.InputParameters.GetParameter(i).Key == "objectFileFullPath")
                            {
                                objectFileFullPath = ids.InputParameters.GetParameter(i).Value;
                            }
                        }
                    }

                    for (int i = 0; i < ids.ExpectedValues.Count; i++)
                    {
                        if (ids.ExpectedValues.GetParameter(i).Step == "getPSInfo")
                        {
                            // Add the key to check and the expected value
                            getPSInfoReturnParam.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                        }
                    }

                    #region Step 1: import the image
                    CheckPoint pImport = new CheckPoint("Import", "Import the prepared DICOM image file");
                    r.CheckPoints.Add(pImport);

                    ImportService import = new ImportService();
                    XMLResult importResult = import.importObject(patientID, null, objectFileFullPath, null, true, null);

                    if (importResult.IsErrorOccured)
                    {
                        pImport.Result = TestResult.Fail;

                        System.Diagnostics.Debug.Print("Call import service to import DICOM image file returns error.");
                        pImport.Outputs.AddParameter("import", "Import DICOM image file", importResult.Message);

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

                        System.Diagnostics.Debug.Print("Call import service to import DICOM image file succeeds.");
                        pImport.Outputs.AddParameter("import", "Import DICOM image file", importResult.Message);
                    }
                    #endregion

                    #region Step 2: call getPSInfo
                    CheckPoint pGetPSInfo = new CheckPoint("GetPSInfo", "Get the presentionstate info");
                    r.CheckPoints.Add(pGetPSInfo);

                    PresentationStateService psService = new PresentationStateService();

                    XMLParameterCollection getPSInfoParam = new XMLParameterCollection();

                    for (int i = 0; i < importResult.MultiResults.Count; i++)
                    {
                        if (importResult.MultiResults[i].Name.ToLower() == "presentationstate")
                        {
                            getPSInfoParam.Add(importResult.MultiResults[i]);
                            break; // get the PS ID, end for loop
                        }
                    }

                    XMLResult getPSResult = psService.getPresentationStateInfo(getPSInfoParam);

                    if (getPSResult.IsErrorOccured)
                    {
                        pGetPSInfo.Result = TestResult.Fail;

                        System.Diagnostics.Debug.Print("Call getPSInfo returns error.");
                        pGetPSInfo.Outputs.AddParameter("getPSInfo", "Get the presentionstate info", importResult.Message);

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

                        System.Diagnostics.Debug.Print("Call getPSInfo succeeds.");
                        pGetPSInfo.Outputs.AddParameter("import", "Get the presentionstate info", importResult.Message);
                    }
                    #endregion

                    #region Step 3: check the dicom info in getPSInfo return
                    CheckPoint pDICOMInfo = new CheckPoint("DICOMInfo", "Check the DICOM info in the returned presentionstate info");
                    r.CheckPoints.Add(pDICOMInfo);

                    bool isValueEqual = false;
                    bool isKeyShow = false;

                    foreach (XMLParameterNode psNode in getPSInfoReturnParam.Parameters)
                    {
                        isValueEqual = false;
                        isKeyShow = false;

                        int i = 0;
                        for (i = 0; i < getPSResult.DicomArrayResult.Parameters.Count; i++)
                        {
                            if (getPSResult.DicomArrayResult.Parameters[i].ParameterName.ToLower() == "dicom_info")
                            {
                                if (getPSResult.DicomArrayResult.Parameters[i].ParameterValue.Contains("<parameter key=\"" + psNode.ParameterName + "\" value=\"" + psNode.ParameterValue + "\" />"))   // <parameter key="dcm_modality" value="PX" />
                                {
                                    isKeyShow = true;
                                    isValueEqual = true;
                                    break;
                                }
                            }
                            //if (psNode.ParameterName == getPSResult.DicomArrayResult.Parameters[i].ParameterName)  // need change here to check the dicom info
                            //{
                            //    isKeyShow = true;
                            //    isValueEqual = string.Equals(psNode.ParameterValue, getPSResult.DicomArrayResult.Parameters[i].ParameterValue);
                            //    break; // End current for loop to search node
                            //}
                        }

                        if (!isValueEqual) // There value is not matched or not found, log fail and then end the compare progress
                        {
                            pDICOMInfo.Result = TestResult.Fail;

                            if (isKeyShow)
                            {
                                System.Diagnostics.Debug.Print("The return value in getPSInfo does not match the expected.");
                                pDICOMInfo.Outputs.AddParameter("DICOMInfo", "Check the DICOM info in the returned presentionstate info", "The value does not match the expected for node: " + psNode.ParameterName + ". Expect: " + psNode.ParameterValue + ". Actually: " + getPSResult.MultiResults[0].Parameters[i].ParameterValue);
                            }
                            else
                            {
                                System.Diagnostics.Debug.Print("The return value in getPSInfo does not contain the node: " + psNode.ParameterName);
                                pDICOMInfo.Outputs.AddParameter("DICOMInfo", "Check the DICOM info in the returned presentionstate info", "The return value in getPSInfo does not contain the node: " + psNode.ParameterName);
                            }

                            break; // End current foreach loop, not compare the follwing nodes
                        }
                    }

                    if (isValueEqual)
                    {
                        pDICOMInfo.Result = TestResult.Pass;

                        System.Diagnostics.Debug.Print("The return values in getPSInfo all match the expected.");
                        pDICOMInfo.Outputs.AddParameter("DICOMInfo", "Check the DICOM info in the returned presentionstate info", "The return values in getPSInfo all match the expected");
                    }
                    #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 10: 1.3.7_SetPresentationStateInfo_Normal
        public void Run_PS_SetPresentationStateInfo_Normal_Case10()
        {
            int runCount = 0;

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

                try
                {
                    #region Parameter initialize
                    bool isImportImage = false;
                    string psID = null;
                    string imageID = null;

                    //Input parameters
                    string p_Import_patientId = null;
                    string p_Import_objectFileFullPath = null;
                    XMLParameter p_setPresentationStateInfo = new XMLParameter("presentationstate");
                    for (int i = 0; i < ids.InputParameters.Count; i++)
                    {
                        if (ids.InputParameters.GetParameter(i).Step == "import")
                        {
                            isImportImage = true;
                            if (ids.InputParameters.GetParameter(i).Key == "patientInternalId")
                            {
                                p_Import_patientId = ids.InputParameters.GetParameter(i).Value;
                            }
                            else if (ids.InputParameters.GetParameter(i).Key == "objectFileFullPath")
                            {
                                p_Import_objectFileFullPath = ids.InputParameters.GetParameter(i).Value;
                            }
                        }
                        else if (ids.InputParameters.GetParameter(i).Step == "setPresentationStateInfo")
                        {
                            if (ids.InputParameters.GetParameter(i).Key == "presentationStateInternalID")
                            {
                                psID = ids.InputParameters.GetParameter(i).Value;
                            }
                            else
                            {
                                p_setPresentationStateInfo.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                            }
                        }
                    }

                    // Output value
                    bool ep_isSetPSInfoReturnOK = true;
                    string ep_SetPSInfoReturnMessage = string.Empty;
                    XMLParameter ep_getPresentationStateInfo = new XMLParameter();
                    for (int i = 0; i < ids.ExpectedValues.Count; i++)
                    {
                        if (ids.ExpectedValues.GetParameter(i).Step == "setPresentationStateInfo")
                        {
                            switch (ids.ExpectedValues.GetParameter(i).Key)
                            {
                                case "returnState":
                                    {
                                        if (ids.ExpectedValues.GetParameter(i).Value.ToLower().Equals("pass"))
                                        {
                                            ep_isSetPSInfoReturnOK = true;
                                        }
                                        else if (ids.ExpectedValues.GetParameter(i).Value.ToLower().Equals("fail"))
                                        {
                                            ep_isSetPSInfoReturnOK = false;
                                        }
                                        break;
                                    }
                                case "returnMessage":
                                    {
                                        ep_SetPSInfoReturnMessage = ids.ExpectedValues.GetParameter(i).Value;
                                        break;
                                    }
                                default:
                                    break;
                            }
                        }
                        else if (ids.ExpectedValues.GetParameter(i).Step == "getPresentationStateInfo")
                        {
                            ep_getPresentationStateInfo.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                        }
                    }
                    #endregion

                    ImportService importService = new ImportService();
                    PresentationStateService psService = new PresentationStateService();

                    if (isImportImage)
                    {
                        #region Step 1: Call ImportService.ImportObject to import an image and create a PS
                        CheckPoint cp_Import = new CheckPoint("Import Image", "Call ImportService.ImportObject to import an image");
                        r.CheckPoints.Add(cp_Import);

                        XMLResult rt_Import = importService.importObject(p_Import_patientId, null, p_Import_objectFileFullPath, null, true, "FALSE");
                        if (rt_Import.IsErrorOccured)
                        {
                            cp_Import.Result = TestResult.Fail;
                            cp_Import.Outputs.AddParameter("import", "Import image returns error", rt_Import.Message);

                            SaveRound(r);
                            continue; // Error happens, end current Test Set
                        }
                        else
                        {
                            cp_Import.Result = TestResult.Pass;
                            cp_Import.Outputs.AddParameter("import", "Import image returns success as expected", rt_Import.Message);

                            imageID = rt_Import.MultiResults[0].Parameters[0].ParameterValue; // This one is the ImageID
                            psID = rt_Import.MultiResults[1].Parameters[0].ParameterValue; // This one is the PS ID
                        }
                        #endregion
                    }

                    #region Step 2: Call PresentationStateService.SetPresentationStateInfo to set the PSInfo for the image
                    CheckPoint cp_SetPresentationStateInfo = new CheckPoint("Set PSInfo", "Call PresentationStateService.SetPresentationStateInfo to set ps info");
                    r.CheckPoints.Add(cp_SetPresentationStateInfo);

                    XMLResult rt_SetPresentationStateInfo = psService.setPresentationStateInfo(p_setPresentationStateInfo, psID);
                    if (ep_isSetPSInfoReturnOK) // Expect the call return OK
                    {
                        if (rt_SetPresentationStateInfo.IsErrorOccured)
                        {
                            cp_SetPresentationStateInfo.Result = TestResult.Fail;
                            cp_SetPresentationStateInfo.Outputs.AddParameter("state", "Set PresentationStateInfo returns error", rt_SetPresentationStateInfo.Message);

                            SaveRound(r);
                            continue; // Error happens, end current Test Set
                        }
                        else
                        {
                            cp_SetPresentationStateInfo.Result = TestResult.Pass;
                            cp_SetPresentationStateInfo.Outputs.AddParameter("state", "Set PresentationStateInfo returns success as expected", rt_SetPresentationStateInfo.Message);

                            #region Step 3: Call PresentationStateService.GetPresentationStateInfo to get the PSInfo for the image
                            CheckPoint cp_GetPresentationStateInfo = new CheckPoint("Get PSInfo", "Call PresentationStateService.GetPresentationStateInfo and check the return state");
                            r.CheckPoints.Add(cp_GetPresentationStateInfo);

                            XMLParameterCollection p_GetPresentationStateInfo = new XMLParameterCollection();
                            XMLParameter p_GetPSInfo_ID = new XMLParameter("presentationstate");
                            p_GetPSInfo_ID.AddParameter("internal_id", psID); // Add current psID as the input param
                            XMLParameter p_GetPSInfo_Preferences = new XMLParameter("preferences");
                            p_GetPresentationStateInfo.Add(p_GetPSInfo_ID);
                            p_GetPresentationStateInfo.Add(p_GetPSInfo_Preferences);

                            XMLResult rt_GetPresentationStateInfo = psService.getPresentationStateInfo(p_GetPresentationStateInfo);

                            if (rt_GetPresentationStateInfo.IsErrorOccured)
                            {
                                cp_GetPresentationStateInfo.Result = TestResult.Fail;
                                cp_GetPresentationStateInfo.Outputs.AddParameter("state", "Get PSInfo returns error", rt_GetPresentationStateInfo.Message);

                                SaveRound(r);
                                continue; // Error happens, end current Test Get
                            }
                            else
                            {
                                cp_GetPresentationStateInfo.Result = TestResult.Pass;
                                cp_GetPresentationStateInfo.Outputs.AddParameter("state", "Get PSInfo returns succeed", rt_GetPresentationStateInfo.Message);

                                // Check the return value is correct
                                #region Step 4: Check the values in PresentationStateService.getPresentationStateInfo return are correct
                                CheckPoint cp_getPSInfoReturnValues = new CheckPoint("Get PSInfo", "Check the values in PresentationStateService.GetPresentationStateInfo return");
                                r.CheckPoints.Add(cp_getPSInfoReturnValues);

                                // Add two check values dynamically
                                ep_getPresentationStateInfo.AddParameter("internal_id", psID);
                                ep_getPresentationStateInfo.AddParameter("image_internal_id", imageID);

                                bool isValueEqual = false;
                                bool isKeyShow = false;
                                foreach (XMLParameterNode psNode in ep_getPresentationStateInfo.Parameters)
                                {
                                    isValueEqual = false;
                                    isKeyShow = false;

                                    int i = 0;
                                    for (i = 0; i < rt_GetPresentationStateInfo.DicomArrayResult.Parameters.Count; i++)
                                    {
                                        if (psNode.ParameterName == rt_GetPresentationStateInfo.DicomArrayResult.Parameters[i].ParameterName)
                                        {
                                            isKeyShow = true;
                                            isValueEqual = string.Equals(psNode.ParameterValue, rt_GetPresentationStateInfo.DicomArrayResult.Parameters[i].ParameterValue.Replace("\r", "").Replace("\n", ""));
                                            break; // Find the node, end current for loop to search node
                                        }
                                    }

                                    if (!isValueEqual) // There value is not matched or not found, log fail and then end the compare progress
                                    {
                                        cp_getPSInfoReturnValues.Result = TestResult.Fail;

                                        if (isKeyShow)
                                        {
                                            System.Diagnostics.Debug.Print("The return value in getPresentationStateInfo does not match the expected.");
                                            cp_getPSInfoReturnValues.Outputs.AddParameter("PSInfo Info", "Check the values in PresentationStateService.getPresentationStateInfo return", "The value does not match the expected for node: " + psNode.ParameterName + ". Expect: " + psNode.ParameterValue + ". Actually: " + rt_GetPresentationStateInfo.MultiResults[0].Parameters[i].ParameterValue);
                                        }
                                        else
                                        {
                                            System.Diagnostics.Debug.Print("The return value in getPresentationStateInfo does not contain the node: " + psNode.ParameterName);
                                            cp_getPSInfoReturnValues.Outputs.AddParameter("PSInfo Info", "Check the values in PresentationStateService.getPresentationStateInfo return", "The return value does not contain the node: " + psNode.ParameterName);
                                        }

                                        break; // End current foreach loop, not compare the follwing nodes
                                    }
                                }

                                if (isValueEqual)
                                {
                                    cp_getPSInfoReturnValues.Result = TestResult.Pass;

                                    System.Diagnostics.Debug.Print("The return values in getPresentationStateInfoInfo all match the expected.");
                                    cp_getPSInfoReturnValues.Outputs.AddParameter("PSInfo Info", "Check the values in PresentationStateService.getPresentationStateInfoInfo return", "The return values all match the expected");
                                }
                                #endregion
                            }
                            #endregion
                        }
                    }
                    else // Expect the call return error
                    {
                        if (rt_SetPresentationStateInfo.IsErrorOccured) // There is error
                        {
                            if (rt_SetPresentationStateInfo.Message.ToLower().Contains(ep_SetPSInfoReturnMessage.ToLower()))
                            {
                                cp_SetPresentationStateInfo.Result = TestResult.Pass;
                                cp_SetPresentationStateInfo.Outputs.AddParameter("state", "Set PresentationStateInfo returns error as expected", rt_SetPresentationStateInfo.Message);
                            }
                            else
                            {
                                cp_SetPresentationStateInfo.Result = TestResult.Fail;
                                cp_SetPresentationStateInfo.Outputs.AddParameter("state", "Set PresentationStateInfo returns error message not match the expected. ", "Expect: " + ep_SetPSInfoReturnMessage + "; Actually returns: " + rt_SetPresentationStateInfo.Message);

                                SaveRound(r);
                                continue; // Error happens, end current Test Get
                            }
                        }
                        else // There is no error
                        {
                            cp_SetPresentationStateInfo.Result = TestResult.Fail;
                            cp_SetPresentationStateInfo.Outputs.AddParameter("state", "Set PS not returns error as expected. ", "Actually returns: " + rt_SetPresentationStateInfo.Message);

                            SaveRound(r);
                            continue; // Error happens, end current Test Get
                        }
                    }
                    #endregion

                    if (isImportImage)
                    {
                        #region Step 5: Call ImageService.deleteImage to delete the created image
                        ImageService imageService = new ImageService();
                        CheckPoint cp_DeleteImage = new CheckPoint("Delete Image", "Call imageService.deleteImage to delete the image");
                        r.CheckPoints.Add(cp_DeleteImage);

                        XMLResult rt_DeleteImage = imageService.deleteImage(imageID, new XMLParameter("preferences"));
                        if (rt_DeleteImage.IsErrorOccured)
                        {
                            cp_DeleteImage.Result = TestResult.Fail;
                            cp_DeleteImage.Outputs.AddParameter("delete image", "Delete image returns error", rt_DeleteImage.Message);

                            SaveRound(r);
                            continue; // End current test set
                        }
                        else
                        {
                            cp_DeleteImage.Result = TestResult.Pass;
                            cp_DeleteImage.Outputs.AddParameter("delete image", "Delete image returns success", rt_DeleteImage.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 1089: 1.3.7_GetPresentationStateInfo_N07_Acq image and then check the DICOM info value is correct in getPSInfo return
        public void Run_PS_Acq_GetPSInfo_Case1089()
        {
            int runCount = 0;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Acquisition");
                AcquisitionService acqs = new AcquisitionService();
                PresentationStateService pss = new PresentationStateService();

                XMLParameter acq = new XMLParameter("acq_info");
                XMLParameter psa = new XMLParameter("presentationstate");

                XMLParameterCollection psaCollection = new XMLParameterCollection();

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

                CheckPoint pAcquire = new CheckPoint("Acquire Image", "Acquisition RVG");
                r.CheckPoints.Add(pAcquire);
                System.Diagnostics.Debug.Print("Acquire start");

                XMLResult rslAcqRVG = acqs.startAcquisition(acq);
                System.Threading.Thread.Sleep(3000);
                if (rslAcqRVG.IsErrorOccured)
                {
                    System.Diagnostics.Debug.Print("Acquire fail:");
                    pAcquire.Result = TestResult.Fail;
                    pAcquire.Outputs.AddParameter("Acquire image error", "startAcquisition", rslAcqRVG.Message);
                }
                else
                {
                    pAcquire.Outputs.AddParameter("Acquire session ID", "startAcquisition", rslAcqRVG.SingleResult);
                    int DORVGcount = 0;
                    XMLResult getAcqRVG = new XMLResult();
                    do
                    {
                        System.Threading.Thread.Sleep(3000);
                        System.Diagnostics.Debug.Print("get acquire in do");
                        DORVGcount++;
                        getAcqRVG = acqs.getAcquisitionResult(rslAcqRVG.SingleResult);
                        if (!getAcqRVG.IsErrorOccured)
                        {
                            string psUid = string.Empty;

                            ParseXMLContent parser = new ParseXMLContent(getAcqRVG.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)
                            {
                                pAcquire.Result = TestResult.Pass;
                                pAcquire.Outputs.AddParameter("getAcquisitionResult", "Acquisition", getAcqRVG.ResultContent);

                                psUid = psIDs[0];

                                psa.AddParameter("internal_id", psUid);
                                XMLParameter psPreferences = new XMLParameter("preferences");
                                psaCollection.Add(psa);
                                psaCollection.Add(psPreferences);

                                XMLResult psinforeturn = pss.getPresentationStateInfo(psaCollection);

                                CheckPoint pGetPSinfo = new CheckPoint("Get Presentation State", "PS Desc");
                                r.CheckPoints.Add(pGetPSinfo);
                                for (int findvalue = 0; findvalue < psinforeturn.DicomArrayResult.Length; findvalue++)
                                {
                                    XMLParameterNode psnode = psinforeturn.DicomArrayResult.Parameters[findvalue];
                                    if (psnode.ParameterName == "acquired" && psnode.ParameterValue == "true")
                                    {
                                        pGetPSinfo.Result = TestResult.Pass;
                                        pGetPSinfo.Outputs.AddParameter("get presentation state", "get presentation state info as expect", "The acquired node value is true for newly acq image");
                                        break;
                                    }
                                }
                                if (pGetPSinfo.Result != TestResult.Pass)
                                {
                                    pGetPSinfo.Result = TestResult.Fail;
                                    pGetPSinfo.Outputs.AddParameter("get presentation state", "get presentation state info not as expect", "The acquired node value is NOT true for newly acq image. Actually get: " + psinforeturn.ResultContent);
                                }
                            }
                            else
                            {
                                pAcquire.Result = TestResult.Fail;
                                pAcquire.Outputs.AddParameter("getAcquisitionResult", "Acquisition", "Wrong return XML: " + getAcqRVG.ResultContent);
                            }

                            break; // The test case is finished, end the "do" loop
                        }
                        if (getAcqRVG.IsErrorOccured && getAcqRVG.Code != 499)
                            continue;
                        if (getAcqRVG.Code != 0 && getAcqRVG.Code != 499)
                        {
                            pAcquire.Result = TestResult.Fail;
                            pAcquire.Outputs.AddParameter("Get acquire image error", "getAcquisitionResult", getAcqRVG.Message);
                        }
                        System.Diagnostics.Debug.Print("get acquireResult:" + DORVGcount);
                        if (DORVGcount > 60)
                        {
                            pAcquire.Result = TestResult.Fail;
                            pAcquire.Outputs.AddParameter("Get acquire image error", "getAcquisitionResult", "Acquire great with 3 minutes, timeout!");
                            break;
                        }
                    } while (true);
                }
                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 78: 1.3.7_GetPresentationStateInfo_Exception
        public void Run_PS_GetPresentationStateInfo_Exception_Case78()
        {
            int runCount = 0;

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

                try
                {
                    #region Parameter initialize
                    //Input parameters
                    XMLParameterCollection p_getPresentationStateInfo = new XMLParameterCollection();
                    XMLParameter p_PSID = new XMLParameter("presentationstate");
                    XMLParameter p_Preferences = new XMLParameter("preferences");
                    for (int i = 0; i < ids.InputParameters.Count; i++)
                    {
                        if (ids.InputParameters.GetParameter(i).Step == "getPresentationStateInfo")
                        {
                            if (ids.InputParameters.GetParameter(i).Key == "internal_id")
                            {
                                p_PSID.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                            }
                            else if (ids.InputParameters.GetParameter(i).Key == "teeth_number_notation")
                            {
                                p_Preferences.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                            }
                        }
                    }
                    p_getPresentationStateInfo.Add(p_PSID);
                    p_getPresentationStateInfo.Add(p_Preferences);

                    // Output value
                    bool ep_isReturnOK = true;
                    string ep_ReturnValue = string.Empty;
                    string ep_imageID = string.Empty;
                    XMLParameter ep_getPresentationStateInfo = new XMLParameter("presentationstate");
                    for (int i = 0; i < ids.ExpectedValues.Count; i++)
                    {
                        if (ids.ExpectedValues.GetParameter(i).Step == "getPresentationStateInfo")
                        {
                            switch (ids.ExpectedValues.GetParameter(i).Key)
                            {
                                case "returnState":
                                    {
                                        if (ids.ExpectedValues.GetParameter(i).Value.ToLower().Equals("pass"))
                                        {
                                            ep_isReturnOK = true;
                                        }
                                        else if (ids.ExpectedValues.GetParameter(i).Value.ToLower().Equals("fail"))
                                        {
                                            ep_isReturnOK = false;
                                        }
                                        break;
                                    }
                                case "returnMessage":
                                    {
                                        ep_ReturnValue = ids.ExpectedValues.GetParameter(i).Value;
                                        break;
                                    }
                                default:
                                    {
                                        ep_getPresentationStateInfo.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                                        break;
                                    }
                            }
                        }
                    }
                    #endregion

                    PresentationStateService psService = new PresentationStateService();

                    #region Step 1: Call PresentationStateService.GetPresentationStateInfo to get a PS for the image
                    CheckPoint cp_GetPresentationStateInfo = new CheckPoint("Get PS Info", "Call PresentationStateService.GetPresentationStateInfo to get ps info");
                    r.CheckPoints.Add(cp_GetPresentationStateInfo);

                    XMLResult rt_GetPresentationStateInfo = psService.getPresentationStateInfo(p_getPresentationStateInfo);
                    if (true == ep_isReturnOK) // Expect the call returns OK
                    {
                        if (rt_GetPresentationStateInfo.IsErrorOccured)
                        {
                            cp_GetPresentationStateInfo.Result = TestResult.Fail;
                            cp_GetPresentationStateInfo.Outputs.AddParameter("get", "Get PS returns error", rt_GetPresentationStateInfo.Message);
                        }
                        else
                        {
                            cp_GetPresentationStateInfo.Result = TestResult.Pass;
                            cp_GetPresentationStateInfo.Outputs.AddParameter("get", "Get PS returns succeed", rt_GetPresentationStateInfo.Message);

                            // Check the return value is correct
                            #region Step 2: Check the values in PresentationStateService.getPresentationStateInfo return are correct
                            CheckPoint cp_getPSInfoReturn = new CheckPoint("Get PS Info", "Check the values in PresentationStateService.GetPresentationStateInfo return");
                            r.CheckPoints.Add(cp_getPSInfoReturn);

                            bool isValueEqual = false;
                            bool isKeyShow = false;

                            foreach (XMLParameterNode psNode in ep_getPresentationStateInfo.Parameters)
                            {
                                isValueEqual = false;
                                isKeyShow = false;

                                int i = 0;
                                for (i = 0; i < rt_GetPresentationStateInfo.MultiResults[0].Parameters.Count; i++)
                                {
                                    if (psNode.ParameterName == rt_GetPresentationStateInfo.MultiResults[0].Parameters[i].ParameterName)
                                    {
                                        isKeyShow = true;
                                        isValueEqual = string.Equals(psNode.ParameterValue, rt_GetPresentationStateInfo.MultiResults[0].Parameters[i].ParameterValue);
                                        break; // End current for loop to search node
                                    }
                                }

                                if (!isValueEqual) // There value is not matched or not found, log fail and then end the compare progress
                                {
                                    cp_getPSInfoReturn.Result = TestResult.Fail;

                                    if (isKeyShow)
                                    {
                                        System.Diagnostics.Debug.Print("The return value in getPresentationStateInfo does not match the expected.");
                                        cp_getPSInfoReturn.Outputs.AddParameter("PS Info", "Check the values in PresentationStateService.getPresentationStateInfo return", "The value does not match the expected for node: " + psNode.ParameterName + ". Expect: " + psNode.ParameterValue + ". Actually: " + rt_GetPresentationStateInfo.MultiResults[0].Parameters[i].ParameterValue);
                                    }
                                    else
                                    {
                                        System.Diagnostics.Debug.Print("The return value in getPresentationStateInfo does not contain the node: " + psNode.ParameterName);
                                        cp_getPSInfoReturn.Outputs.AddParameter("PS Info", "Check the values in PresentationStateService.getPresentationStateInfo return", "The return value does not contain the node: " + psNode.ParameterName);
                                    }

                                    break; // End current foreach loop, not compare the follwing nodes
                                }
                            }

                            if (isValueEqual)
                            {
                                cp_getPSInfoReturn.Result = TestResult.Pass;

                                System.Diagnostics.Debug.Print("The return values in getPresentationStateInfo all match the expected.");
                                cp_getPSInfoReturn.Outputs.AddParameter("PS Info", "Check the values in PresentationStateService.getPresentationStateInfo return", "The return values all match the expected");
                            }
                            #endregion
                        }
                    }
                    else // Expect the call return error
                    {
                        if (rt_GetPresentationStateInfo.IsErrorOccured) // There is error
                        {
                            if (rt_GetPresentationStateInfo.Message.ToLower().Contains(ep_ReturnValue.ToLower()))
                            {
                                cp_GetPresentationStateInfo.Result = TestResult.Pass;
                                cp_GetPresentationStateInfo.Outputs.AddParameter("get", "Get PS Info returns error as expected", rt_GetPresentationStateInfo.Message);
                            }
                            else
                            {
                                cp_GetPresentationStateInfo.Result = TestResult.Fail;
                                cp_GetPresentationStateInfo.Outputs.AddParameter("get", "Get PS Info returns error message not match the expected. ", "Expect: " + ep_ReturnValue + "; Actually returns: " + rt_GetPresentationStateInfo.Message);
                            }
                        }
                        else // There is no error
                        {
                            cp_GetPresentationStateInfo.Result = TestResult.Fail;
                            cp_GetPresentationStateInfo.Outputs.AddParameter("get", "Get PS Info not returns error as expected. ", "Actually returns: " + rt_GetPresentationStateInfo.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 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();
        }
        public override void Run()
        {
            string newPSId = string.Empty;
            string setPSInfoString = string.Empty;
            string getPSInfoString = string.Empty;
            PresentationStateService psService = new PresentationStateService();

            try
            {
                //create a new patient and import a new image to get a new ps id.
                string newPatientId = CommonLib.CreatePatient();
                ImportService import = new ImportService();
                XMLResult r = import.importObject(newPatientId, string.Empty, @"c:\PASPerformance\001.png", null, true, string.Empty);
                newPSId = r.MultiResults[1].GetParameterValueByIndex(0);
                XMLParameter psId = new XMLParameter("presentationstate");
                psId.AddParameter("internal_id", newPSId);
                getPSInfoString = psId.GenerateXML();
                XMLParameterCollection c = new XMLParameterCollection();
                c.Add(psId);
                setPSInfoString = psService.getPresentationStateInfo(c).ArrayResult.GenerateXML();
            }
            catch (Exception ex)
            {
                LogRecordType lr = new LogRecordType();
                lr.FunctionName = this.mFunctionName;
                lr.Lable = this.mLabel;
                string innerText = ex.InnerException == null ? string.Empty : ex.InnerException.Message;
                lr.Message = ex.Message + innerText == string.Empty ? string.Empty : "(" + innerText + ")";
                lr.Passed = false;

                Log.AddRecord(lr);

                this.RiseSingleCallCompleteEvent(lr.ResponseTime, lr.Passed, true);
                this.RiseTestCaseCompleteEvent();

                this.mExecuted = this.mRepeat;
                this.mFailed = this.mRepeat;
                return;
            }

            double userCaseResponse=0;

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

                try
                {
                    //get ps info
                    XMLResult getResult=new XMLResult (psService.InvokeMethod ("getPresentationStateInfo", new object []{getPSInfoString }));

                    //if get presentation infor failed.
                    if (getResult.IsErrorOccured)
                    {
                        lr.Message = "Get PS info faild. Message: " + getResult.Message;
                        lr.ResponseTime = psService.ResponseTime;
                        lr.Passed = false;
                        Log.AddRecord(lr);
                        this.mFailed++;
                        continue;
                    }
                    else  //if get ps info successed
                    {
                        userCaseResponse = psService.ResponseTime;
                    }

                    //set ps info
                    XMLResult setResult = new XMLResult(psService.InvokeMethod("setPresentationStateInfo", new object[] { setPSInfoString, newPSId}));

                    //if set ps info failed
                    if (setResult.IsErrorOccured)
                    {
                        lr.Message = "Set PS info failed. Message: " + setResult.Message;
                        lr.ResponseTime = psService.ResponseTime;
                        lr.Passed = false;
                        Log.AddRecord(lr);
                        this.mFailed++;
                        continue;
                    }
                    else  //if set ps info successed.
                    {
                        userCaseResponse += psService.ResponseTime;
                    }

                    lr.ResponseTime = userCaseResponse;
                    this.ExecutedTime += userCaseResponse;
                }
                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.mExecuted = i;
                Log.AddRecord(lr);

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

            this.RiseTestCaseCompleteEvent();
        }
        //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 1203: 1.3.10_ImportImage_N07_Import single 8100 dicom thin layer slice
        public void Run_Import_8100Slice_Case1203()
        {
            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);
                    }
                }

                string epGetImageInfoImageType = null;
                string epGetImageInfoAnatomicRegion = null;
                string epGetImageInfoAnatomicRegionModifiers = null;
                string epGetPSInfoImageType = null;
                string epGetPSInfoAnatomicRegion = null;
                string epGetPSInfoAnatomicRegionModifiers = null;

                for (int i = 0; i < ids.ExpectedValues.Count; i++)
                {
                    if (ids.ExpectedValues.GetParameter(i).Step == "getImageInfo")
                    {
                        switch (ids.ExpectedValues.GetParameter(i).Key)
                        {
                            case "image_type":
                                epGetImageInfoImageType = ids.ExpectedValues.GetParameter(i).Value;
                                break;
                            case "dcm_anatomic_region":
                                epGetImageInfoAnatomicRegion = ids.ExpectedValues.GetParameter(i).Value;
                                break;
                            case "dcm_anatomic_region_modifiers":
                                epGetImageInfoAnatomicRegionModifiers = ids.ExpectedValues.GetParameter(i).Value;
                                break;
                            default:
                                break;
                        }
                    }
                    else if (ids.ExpectedValues.GetParameter(i).Step == "getPresentationStateInfo")
                    {
                        switch (ids.ExpectedValues.GetParameter(i).Key)
                        {
                            case "image_type":
                                epGetPSInfoImageType = ids.ExpectedValues.GetParameter(i).Value;
                                break;
                            case "dcm_anatomic_region":
                                epGetPSInfoAnatomicRegion = ids.ExpectedValues.GetParameter(i).Value;
                                break;
                            case "dcm_anatomic_region_modifiers":
                                epGetPSInfoAnatomicRegionModifiers = ids.ExpectedValues.GetParameter(i).Value;
                                break;
                            default:
                                break;
                        }
                    }
                }

                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 image_type and anatomic_region
                        ImageService imageSvc = new ImageService();
                        PresentationStateService psSvc = new PresentationStateService();

                        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 image_type, anatomic_region values in return are correct
                            if (!rtGetImageInfo.ResultContent.Contains("parameter key=\"image_type\" value=\"" + epGetImageInfoImageType + "\""))  //parameter key="image_type" value="PANOV6"
                            {
                                cpGetImageInfo.Result = TestResult.Fail;
                                cpGetImageInfo.Outputs.AddParameter("Get Image Info return wrong image_type info", "getImageInfo", rtGetImageInfo.ResultContent);
                            }
                            else if (!rtGetImageInfo.ResultContent.Contains("parameter key=\"dcm_anatomic_region\" value=\"" + epGetImageInfoAnatomicRegion + "\""))  // parameter key="dcm_anatomic_region" value="Jaw region"
                            {
                                cpGetImageInfo.Result = TestResult.Fail;
                                cpGetImageInfo.Outputs.AddParameter("Get Image Info return wrong dcm_anatomic_region info", "getImageInfo", rtGetImageInfo.ResultContent);
                            }
                            else if (!rtGetImageInfo.ResultContent.Contains("parameter key=\"dcm_anatomic_region_modifiers\" value=\"" + epGetImageInfoAnatomicRegionModifiers + "\""))  // parameter key="dcm_anatomic_region_modifiers" value="Molar 1"
                            {
                                cpGetImageInfo.Result = TestResult.Fail;
                                cpGetImageInfo.Outputs.AddParameter("Get Image Info return wrong dcm_anatomic_region_modifiers info", "getImageInfo", rtGetImageInfo.ResultContent);
                            }
                            else
                            {
                                cpGetImageInfo.Result = TestResult.Pass;
                                cpGetImageInfo.Outputs.AddParameter("Get Image Info return correct info", "getImageInfo", rtGetImageInfo.ResultContent);
                            }
                        }

                        XMLParameterCollection pGetPSInfo = new XMLParameterCollection();
                        XMLParameter psList = new XMLParameter("presentationstate");
                        psList.AddParameter("internal_id", psID);
                        pGetPSInfo.Add(psList);

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

                        XMLResult rtGetPSInfo = psSvc.getPresentationStateInfo(pGetPSInfo);
                        if (rtGetPSInfo.IsErrorOccured)
                        {
                            cpGetPSInfo.Result = TestResult.Fail;
                            cpGetPSInfo.Outputs.AddParameter("Get PS Info return error", "GetPSInfo", rtGetPSInfo.ResultContent);
                        }
                        else
                        {
                            cpGetPSInfo.Outputs.AddParameter("Get PS Info return success", "GetPSInfo", rtGetPSInfo.Message);

                            // Check the image_type, anatomic_region values in return are correct
                            if (!rtGetPSInfo.ResultContent.Contains("parameter key=\"image_type\" value=\"" + epGetPSInfoImageType + "\"")) //parameter key="image_type" value="PANOV6"
                            {
                                cpGetPSInfo.Result = TestResult.Fail;
                                cpGetPSInfo.Outputs.AddParameter("Get PS Info return wrong image_type info", "GetPSInfo", rtGetPSInfo.ResultContent);
                            }
                            else if (!rtGetPSInfo.ResultContent.Contains("parameter key=\"dcm_anatomic_region\" value=\"" + epGetPSInfoAnatomicRegion + "\""))  // parameter key="dcm_anatomic_region" value="Jaw region"
                            {
                                cpGetPSInfo.Result = TestResult.Fail;
                                cpGetPSInfo.Outputs.AddParameter("Get PS Info return wrong dcm_anatomic_region info", "GetPSInfo", rtGetPSInfo.ResultContent);
                            }
                            else if (!rtGetPSInfo.ResultContent.Contains("parameter key=\"dcm_anatomic_region_modifiers\" value=\"" + epGetPSInfoAnatomicRegionModifiers + "\""))  // parameter key="dcm_anatomic_region_modifiers" value="Molar 1"
                            {
                                cpGetPSInfo.Result = TestResult.Fail;
                                cpGetPSInfo.Outputs.AddParameter("Get PS Info return wrong dcm_anatomic_region_modifiers info", "GetPSInfo", rtGetPSInfo.ResultContent);
                            }
                            else
                            {
                                cpGetPSInfo.Result = TestResult.Pass;
                                cpGetPSInfo.Outputs.AddParameter("Get PS Info return correct info", "GetPSInfo", rtGetPSInfo.ResultContent);
                            }
                        }

                        CheckPoint cpGetPS = new CheckPoint("GetPS", "Call GetPS to check the ps xml info");
                        r.CheckPoints.Add(cpGetPS);

                        XMLResult rtGetPS = psSvc.getPresentationState(psID);
                        if (rtGetPS.IsErrorOccured)
                        {
                            cpGetPS.Result = TestResult.Fail;
                            cpGetPS.Outputs.AddParameter("Get PS return error", "GetPS", rtGetPS.ResultContent);
                        }
                        else
                        {
                            cpGetPS.Outputs.AddParameter("Get PS return success", "GetPS", rtGetPS.Message);

                            if (rtGetPS.ResultContent.Contains("parameter key=\"general.xml\"") && rtGetPS.ResultContent.Contains("parameter key=\"processing.xml\"") && rtGetPS.ResultContent.Contains("parameter key=\"annotation.xml\"")) // Should return empty ps info for this case as there is not
                            {
                                cpGetPS.Result = TestResult.Pass;
                                cpGetPS.Outputs.AddParameter("Get PS return correct info", "GetPS", rtGetPS.ResultContent);
                            }
                            else
                            {
                                cpGetPS.Result = TestResult.Fail;
                                cpGetPS.Outputs.AddParameter("Get PS return wrong content", "GetPS", rtGetPS.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();
        }