//Case 1566: EK_HI00159159_Create Presentation State
        public void Run_PS_CreatePS_Case1566()
        {
            int runCount = 0;

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

                try
                {
                    #region Parameter initialize
                    string imageInternalID = string.Empty;
                    string currentPSID = string.Empty;
                    string patientInternalId = string.Empty;
                    string objectFileFullPath = string.Empty;

                    XMLParameter p_CreatePresentationState = new XMLParameter("presentationstate");

                    for (int i = 0; i < ids.InputParameters.Count; i++)
                    {
                        if (ids.InputParameters.GetParameter(i).Step == "importImage")
                        {
                            if (ids.InputParameters.GetParameter(i).Key == "patient_internal_id")
                            {
                                patientInternalId = ids.InputParameters.GetParameter(i).Value;
                            }
                            else if (ids.InputParameters.GetParameter(i).Key == "objectFileFullPath")
                            {
                                objectFileFullPath = ids.InputParameters.GetParameter(i).Value;
                            }
                        }
                        else if (ids.InputParameters.GetParameter(i).Step == "createPresentationState")
                        {
                            p_CreatePresentationState.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        }
                    }

                    bool ep_isCurrent = false;
                    for (int i = 0; i < ids.ExpectedValues.Count; i++)
                    {
                        if (ids.ExpectedValues.GetParameter(i).Key == "isCurrent")
                        {
                            ep_isCurrent = ids.ExpectedValues.GetParameter(i).Value.Equals("true");
                        }
                    }
                    #endregion

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

                    #region Step 1: Call ImportService.importObject to import a image
                    CheckPoint cp_ImportImage = new CheckPoint("Import Image", "Call ImportService.importObject to import a image");
                    r.CheckPoints.Add(cp_ImportImage);

                    XMLResult rt_ImportImage = importService.importObject(patientInternalId, null, objectFileFullPath, null, true, "false");
                    if (rt_ImportImage.IsErrorOccured)
                    {
                        cp_ImportImage.Result = TestResult.Fail;
                        cp_ImportImage.Outputs.AddParameter("Import", "Import image returns error", rt_ImportImage.Message);

                        SaveRound(r);
                        continue; // There is error when create image, end current run
                    }
                    else
                    {
                        cp_ImportImage.Result = TestResult.Pass;
                        cp_ImportImage.Outputs.AddParameter("Import", "Import image returns success", rt_ImportImage.Message);
                        imageInternalID = rt_ImportImage.MultiResults[0].Parameters[0].ParameterValue;
                        currentPSID = rt_ImportImage.MultiResults[1].Parameters[0].ParameterValue;
                    }
                    #endregion

                    #region Step 2: Call PresentationStateService.CreatePresentationState to create a PS for the image
                    string returnPSID = string.Empty;
                    CheckPoint cp_CreatePresentationState = new CheckPoint("Create PS", "Call PresentationStateService.CreatePresentationState to create a new ps");
                    r.CheckPoints.Add(cp_CreatePresentationState);

                    XMLResult rt_CreatePresentationState = psService.createPresentationState(imageInternalID, p_CreatePresentationState);
                    returnPSID = rt_CreatePresentationState.SingleResult;

                    if (rt_CreatePresentationState.IsErrorOccured)
                    {
                        cp_CreatePresentationState.Result = TestResult.Fail;
                        cp_CreatePresentationState.Outputs.AddParameter("create", "Create PS returns error", rt_CreatePresentationState.Message);
                    }
                    else
                    {
                        cp_CreatePresentationState.Result = TestResult.Pass;
                        cp_CreatePresentationState.Outputs.AddParameter("create", "Create PS returns success", rt_CreatePresentationState.Message);

                        CheckPoint cp_PresentationStateID = new CheckPoint("Check PS ID", "Check the retrun PS ID in create PS return");
                        r.CheckPoints.Add(cp_PresentationStateID);

                        if (currentPSID == returnPSID) // Return the old current PS ID, defect EK_HI00159159
                        {
                            cp_PresentationStateID.Result = TestResult.Fail;
                            cp_PresentationStateID.Outputs.AddParameter("Check PS ID", "Create PS returns error", "The return ID is not new as expected after call createPS");
                        }
                        else  //Actually return a new PS ID
                        {
                            //Get new current PS ID
                            XMLParameter pListPS = new XMLParameter("filter");
                            pListPS.AddParameter("current", "true");
                            currentPSID = imageService.listPresentationState(pListPS, imageInternalID).SingleResult;

                            if (ep_isCurrent == (currentPSID == returnPSID))
                            {
                                cp_PresentationStateID.Result = TestResult.Pass;
                                cp_PresentationStateID.Outputs.AddParameter("Check PS ID", "Create PS returns error", "The PS ID is correct after call createPS");
                            }
                            else
                            {
                                cp_PresentationStateID.Result = TestResult.Fail;
                                cp_PresentationStateID.Outputs.AddParameter("Check PS ID", "Create PS returns error", "The PS ID is not correct after call createPS");
                            }
                        }
                    }
                    #endregion

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

                    XMLResult rt_DeleteImage = imageService.deleteImage(imageInternalID, 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);
                    }
                    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);
                    SaveRound(r);
                }
            }

            Output();
        }
        // Case 1562: 1.1.04.05 SetImage_WorkFlow_02_Call setImage when archive path is NOT accessible and then call again when its  accessible
        public void Run_Image_SetInfo_WorkFlow_Case1562()
        {
            int runCount = 0;

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

                try
                {
                    #region Parameter initialize
                    string patientInternalId = string.Empty;
                    string objectFileFullPath = string.Empty;
                    string archivedPath = string.Empty;

                    XMLParameter pSetImageInfo = new XMLParameter("image");
                    XMLParameter pSetImageInfoWithError = new XMLParameter("image");
                    for (int i = 0; i < ids.InputParameters.Count; i++)
                    {
                        if (ids.InputParameters.GetParameter(i).Step == "importImage")
                        {
                            if (ids.InputParameters.GetParameter(i).Key == "patient_internal_id")
                            {
                                patientInternalId = ids.InputParameters.GetParameter(i).Value;
                            }
                            else if (ids.InputParameters.GetParameter(i).Key == "objectFileFullPath")
                            {
                                objectFileFullPath = ids.InputParameters.GetParameter(i).Value;
                            }
                            else if (ids.InputParameters.GetParameter(i).Key == "archivePath")
                            {
                                archivedPath = ids.InputParameters.GetParameter(i).Value;
                            }
                        }
                        else if (ids.InputParameters.GetParameter(i).Step == "setImageInfo_error")
                        {
                            pSetImageInfoWithError.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        }
                        else if (ids.InputParameters.GetParameter(i).Step == "setImageInfo_correct")
                        {
                            pSetImageInfo.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        }
                    }
                    #endregion

                    #region Step 1: Call ImportService.importObject to import a image
                    string imageInternalID = string.Empty;
                    string currentPSID = string.Empty;
                    ImportService importService = new ImportService();

                    CheckPoint cpImportImage = new CheckPoint("Import Image", "Call ImportService.importObject to import an archived  image");
                    r.CheckPoints.Add(cpImportImage);

                    XMLResult rtImportImage = importService.importObject(patientInternalId, null, objectFileFullPath, archivedPath, true, "false");
                    if (rtImportImage.IsErrorOccured)
                    {
                        cpImportImage.Result = TestResult.Fail;
                        cpImportImage.Outputs.AddParameter("Import image returns error", "Import image", rtImportImage.Message);

                        SaveRound(r);
                        continue; // There is error when create image, end current run
                    }
                    else
                    {
                        cpImportImage.Result = TestResult.Pass;
                        cpImportImage.Outputs.AddParameter("Import image returns success", "Import image", rtImportImage.Message);

                        imageInternalID = rtImportImage.MultiResults[0].Parameters[0].ParameterValue;
                        currentPSID = rtImportImage.MultiResults[1].Parameters[0].ParameterValue;
                    }
                    #endregion

                    ImageService imageService = new ImageService();

                    #region Step 2-1: Check the getImageDescription return is correct after import image
                    CheckPoint cpGetImageDescriptionAfterImport = new CheckPoint("Check getImageDescription return", "Check getImageDescription return is corerct or not after import image");
                    r.CheckPoints.Add(cpGetImageDescriptionAfterImport);

                    XMLResult rtGetImageDescriptionAfterImport = imageService.getImageDescription(imageInternalID);
                    string imagePathAfterImport = rtGetImageDescriptionAfterImport.MultiResults[0].GetParameterValueByName("path");
                    string archivedPathAfterImport = rtGetImageDescriptionAfterImport.MultiResults[0].GetParameterValueByName("archive_path");
                    string archiveTagAfterImport = rtGetImageDescriptionAfterImport.MultiResults[0].GetParameterValueByName("tags");

                    if (imagePathAfterImport == string.Empty && archivedPathAfterImport == archivedPath && string.IsNullOrEmpty(archiveTagAfterImport))
                    {
                        cpGetImageDescriptionAfterImport.Result = TestResult.Pass;
                        cpGetImageDescriptionAfterImport.Outputs.AddParameter("getImageDescription", "Check getImageDescription return", "The getImageDescription return is correct after import image");
                    }
                    else
                    {
                        cpGetImageDescriptionAfterImport.Result = TestResult.Fail;
                        cpGetImageDescriptionAfterImport.Outputs.AddParameter("getImageDescription", "Check getImageDescription return", "The getImageDescription return is not correct after import image. Actually get: " + rtGetImageDescriptionAfterImport.ResultContent);
                    }
                    #endregion

                    #region Step 2-2: Check the info is correct in getImageInfo return after import image
                    CheckPoint cpGetImageInfoAfterImport = new CheckPoint("Check getImageInfo return", "Check getImageInfo return is corerct or not import the image");
                    r.CheckPoints.Add(cpGetImageInfoAfterImport);

                    XMLParameter pGetImageInfoAfterImport = new XMLParameter("image");
                    pGetImageInfoAfterImport.AddParameter("internal_id", imageInternalID);
                    XMLResult rtGetImageInfo = imageService.getImageInfo(pGetImageInfoAfterImport);

                    imagePathAfterImport = rtGetImageInfo.DicomArrayResult.GetParameterValueByName("path");
                    archivedPathAfterImport = rtGetImageInfo.DicomArrayResult.GetParameterValueByName("archive_path");
                    archiveTagAfterImport = rtGetImageInfo.DicomArrayResult.GetParameterValueByName("tags");

                    if (string.IsNullOrEmpty(imagePathAfterImport) && string.IsNullOrEmpty(archivedPathAfterImport) && string.IsNullOrEmpty(archiveTagAfterImport))  // archivedPathAfterImport == archivedPath, will be supported in new service
                    {
                        cpGetImageInfoAfterImport.Result = TestResult.Pass;
                        cpGetImageInfoAfterImport.Outputs.AddParameter("getImageInfo", "Check getImageInfo return", "The getImageInfo return is correct after import image");
                    }
                    else
                    {
                        cpGetImageInfoAfterImport.Result = TestResult.Fail;
                        cpGetImageInfoAfterImport.Outputs.AddParameter("getImageInfo", "Check getImageInfo return", "The getImageInfo return is not correct after import image. Actually get: " + rtGetImageInfo.ResultContent);
                    }
                    #endregion

                    #region Step 3-1: Call imageService.SetImageInfo to save the archived image but the archive path is wrong
                    CheckPoint cpSetImageInfowithError = new CheckPoint("Set Image Info", "Call ImageService.SetImageInfo to save the archived image as normal image, with wrong path");
                    r.CheckPoints.Add(cpSetImageInfowithError);

                    XMLResult rtSetImageInfowithError = imageService.setImageInfo(pSetImageInfoWithError, imageInternalID);

                    if (rtSetImageInfowithError.IsErrorOccured)
                    {
                        cpSetImageInfowithError.Result = TestResult.Pass;
                        cpSetImageInfowithError.Outputs.AddParameter("SetImageInfo returns error as expected", "SetImageInfo", rtSetImageInfowithError.Message);
                    }
                    else
                    {
                        cpSetImageInfowithError.Result = TestResult.Fail;
                        cpSetImageInfowithError.Outputs.AddParameter("SetImageInfo returns success unexpectly", "SetImageInfo", rtSetImageInfowithError.Message);
                    }
                    #endregion

                    System.Threading.Thread.Sleep(1000);

                    #region Step 3-2: Call ImageService.SetImageInfo to save the archived image as normal image again
                    CheckPoint cpSetImageInfo = new CheckPoint("Set Image Info", "Call ImageService.SetImageInfo to save the archived image as normal image again, with correct path");
                    r.CheckPoints.Add(cpSetImageInfo);

                    XMLResult rtSetImageInfo = imageService.setImageInfo(pSetImageInfo, imageInternalID);

                    if (rtSetImageInfo.IsErrorOccured)
                    {
                        cpSetImageInfo.Result = TestResult.Fail;
                        cpSetImageInfo.Outputs.AddParameter("SetImageInfo returns error", "SetImageInfo", rtSetImageInfo.Message);
                    }
                    else
                    {
                        cpSetImageInfo.Result = TestResult.Pass;
                        cpSetImageInfo.Outputs.AddParameter("SetImageInfo returns success", "SetImageInfo", rtSetImageInfo.Message);

                        // Wait the file is transferred to server DB
                        System.Threading.Thread.Sleep(3000);

                        // Below to check the info is correct after setImageInfo. Check points includes:
                        //1. The Image ID and PS ID are not changed
                        //2. GetImageDescription return correct image path and archive path, correct archive flag
                        //3. GetImageInfo return correct image path, correct archive flag
                        //4. Use the image path to check the image file is in server DB
                        //5. The original archived image is not deleted

                        #region Step 4: Check the ps is set, not newly created after set image
                        CheckPoint cpPSID = new CheckPoint("Check PS ID", "Check the PS ID is not changed after call setImageInfo");
                        r.CheckPoints.Add(cpPSID);

                        XMLParameter pListPS = new XMLParameter("filter");
                        pListPS.AddParameter("current", "true");
                        string currentPSIDAfterSet = imageService.listPresentationState(pListPS, imageInternalID).SingleResult; // may need change

                        if (currentPSIDAfterSet == currentPSID)
                        {
                            cpPSID.Result = TestResult.Pass;
                            cpPSID.Outputs.AddParameter("listPresentationState", "Check PS ID", "The PS ID is not changed");
                        }
                        else
                        {
                            cpPSID.Result = TestResult.Fail;
                            cpPSID.Outputs.AddParameter("listPresentationState", "Check PS ID", "The PS ID is changed. Expect: " + currentPSID + "; Actually new PS ID: " + currentPSIDAfterSet);
                        }
                        #endregion

                        string imagePathAfterSet = string.Empty;
                        string archivePathAfterSet = string.Empty;
                        string archiveTagAfterSet = string.Empty;

                        #region Step 5: Check the getImageDescription return is correct after set image
                        CheckPoint cpGetImageDescriptionAfterSet = new CheckPoint("Check getImageDescription return", "Check getImageDescription return is corerct or not after call setImageInfo");
                        r.CheckPoints.Add(cpGetImageDescriptionAfterSet);

                        XMLResult rtGetImageDescriptionAfterSet = imageService.getImageDescription(imageInternalID);
                        imagePathAfterSet = rtGetImageDescriptionAfterSet.MultiResults[0].GetParameterValueByName("path");
                        archivePathAfterSet = rtGetImageDescriptionAfterSet.MultiResults[0].GetParameterValueByName("archive_path");
                        archiveTagAfterSet = rtGetImageDescriptionAfterSet.MultiResults[0].GetParameterValueByName("tags");

                        if (imagePathAfterSet.Contains(imageInternalID) && string.IsNullOrEmpty(archivePathAfterSet) && string.IsNullOrEmpty(archiveTagAfterSet)) // imagePathAfterSet sample: C:/Documents and Settings/All Users/Application Data/TW/PAS/pas_data/patient/03/8af0a7e63310cc65013310d46d0e0003/1956bc28-ca5e-4720-a857-d4de18fc1479/02962f27-e4be-4d59-b112-9663a2f2572b.dcm"
                        {
                            cpGetImageDescriptionAfterSet.Result = TestResult.Pass;
                            cpGetImageDescriptionAfterSet.Outputs.AddParameter("getImageDescription", "Check getImageDescription return", "The getImageDescription return is correct after set image");
                        }
                        else
                        {
                            cpGetImageDescriptionAfterSet.Result = TestResult.Fail;
                            cpGetImageDescriptionAfterSet.Outputs.AddParameter("getImageDescription", "Check getImageDescription return", "The getImageDescription return is not correct after set image. Actually get: " + rtGetImageDescriptionAfterSet.ResultContent);
                        }
                        #endregion

                        #region Step 6: Check the getImageinfo return is correct after set image
                        CheckPoint cpGetImageInfoAfterSet = new CheckPoint("Check getImageInfo return", "Check getImageInfo return is corerct or not after call setImageInfo");
                        r.CheckPoints.Add(cpGetImageInfoAfterSet);

                        XMLParameter pGetImageInfoAfterSet = new XMLParameter("image");
                        pGetImageInfoAfterSet.AddParameter("internal_id", imageInternalID);
                        XMLResult rtGetImageInfoAfterSet = imageService.getImageInfo(pGetImageInfoAfterSet);

                        imagePathAfterSet = rtGetImageInfoAfterSet.DicomArrayResult.GetParameterValueByName("path");
                        archivePathAfterSet = rtGetImageInfoAfterSet.DicomArrayResult.GetParameterValueByName("archive_path");
                        archiveTagAfterSet = rtGetImageInfoAfterSet.DicomArrayResult.GetParameterValueByName("tags");

                        if (imagePathAfterSet.Contains(imageInternalID) && string.IsNullOrEmpty(archivePathAfterSet) && string.IsNullOrEmpty(archiveTagAfterSet))
                        {
                            cpGetImageInfoAfterSet.Result = TestResult.Pass;
                            cpGetImageInfoAfterSet.Outputs.AddParameter("getImageInfo", "Check getImageInfo return", "The getImageInfo return is correct after set image");
                        }
                        else
                        {
                            cpGetImageInfoAfterSet.Result = TestResult.Fail;
                            cpGetImageInfoAfterSet.Outputs.AddParameter("getImageInfo", "Check getImageInfo return", "The getImageInfo return is not correct after set image. Actually get: " + rtGetImageInfoAfterSet.ResultContent);
                        }
                        #endregion

                        #region Step 7: Check the file exist in server DB
                        CheckPoint cpImageInDB = new CheckPoint("Check file in DB", "Check the file exist in server DB after call setImageInfo");
                        r.CheckPoints.Add(cpImageInDB);

                        if (Utility.IsImageExistInServerDB(imagePathAfterSet))
                        {
                            cpImageInDB.Result = TestResult.Pass;
                            cpImageInDB.Outputs.AddParameter("Check the file exist in server DB after call setImageInfo", "Check file in DB", "File exist");
                        }
                        else
                        {
                            cpImageInDB.Result = TestResult.Fail;
                            cpImageInDB.Outputs.AddParameter("Check the file exist in server DB after call setImageInfo", "Check file in DB", "File NOT exist");
                        }
                        #endregion

                        #region Step 8: Check the original archived image is not deleted
                        CheckPoint cpOriginalArchivedImage = new CheckPoint("Check original archived file", "Check the original archived image is not deleted after call setImageInfo");
                        r.CheckPoints.Add(cpOriginalArchivedImage);

                        if (System.IO.File.Exists(archivedPath))
                        {
                            cpOriginalArchivedImage.Result = TestResult.Pass;
                            cpOriginalArchivedImage.Outputs.AddParameter("Check the original archived image is not deleted after call setImageInfo", "Check original archived file", "File exist");
                        }
                        else
                        {
                            cpOriginalArchivedImage.Result = TestResult.Fail;
                            cpOriginalArchivedImage.Outputs.AddParameter("Check the original archived image is not deleted after call setImageInfo", "Check original archived file", "File NOT exist");
                        }
                        #endregion
                    }
                    #endregion

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

                    XMLResult rt_DeleteImage = imageService.deleteImage(imageInternalID, 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);
                    }
                    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.Result = TestResult.Fail;
                    cp.Outputs.AddParameter("Exception thrown", "Exception Message", ex.Message);
                    SaveRound(r);
                }
            }

            Output();
        }
        //Case 46: 1.3.6_ListPresentationStates_Normal
        public void Run_Image_ListPresentationStates_Normal_Case46()
        {
            int runCount = 0;

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

                try
                {
                    string imageInternalID = null;
                    ImageService imageService = new ImageService();

                    #region Initialize parameter
                    // Input parameter
                    XMLParameter p_listPSFilter = new XMLParameter("filter");
                    for (int i = 0; i < ids.InputParameters.Count; i++)
                    {
                        if (ids.InputParameters.GetParameter(i).Step == "listPresentationState")
                        {
                            if (ids.InputParameters.GetParameter(i).Key == "imageInternalID")
                            {
                                imageInternalID = ids.InputParameters.GetParameter(i).Value;
                            }
                            else if (ids.InputParameters.GetParameter(i).Key == "filter")
                            {
                                p_listPSFilter.AddParameter("current", ids.InputParameters.GetParameter(i).Value);
                            }
                        }
                    }

                    //Output value
                    bool ep_isReturnOK = true;
                    string ep_returnMessage = string.Empty;
                    XMLParameter ep_listPresentationState = new XMLParameter("presentationstate");
                    for (int i = 0; i < ids.ExpectedValues.Count; i++)
                    {
                        if (ids.ExpectedValues.GetParameter(i).Step == "listPresentationState")
                        {
                            if (ids.ExpectedValues.GetParameter(i).Key == "returnState")
                            {
                                if (ids.ExpectedValues.GetParameter(i).Value.ToLower() == "pass")
                                {
                                    ep_isReturnOK = true;
                                }
                                else if (ids.ExpectedValues.GetParameter(i).Value.ToLower() == "fail")
                                {
                                    ep_isReturnOK = false;
                                }
                            }
                            else if (ids.ExpectedValues.GetParameter(i).Key == "returnMessage")
                            {
                                ep_returnMessage = ids.ExpectedValues.GetParameter(i).Value;
                            }
                            else if (ids.ExpectedValues.GetParameter(i).Key == "internal_id")
                            {
                                ep_listPresentationState.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                            }
                        }
                    }
                    #endregion

                    #region Step 1: Call ImageService.listPresentationState to list presentationState
                    CheckPoint cp_listPresentationState = new CheckPoint("listPresentationState", "Call ImageService.listPresentationState to list presentationState");
                    r.CheckPoints.Add(cp_listPresentationState);

                    XMLResult rt_listPresentationState = imageService.listPresentationState(p_listPSFilter, imageInternalID);

                    if (ep_isReturnOK) // Expect the call returns ok
                    {
                        if (rt_listPresentationState.IsErrorOccured)
                        {
                            cp_listPresentationState.Result = TestResult.Fail;

                            System.Diagnostics.Debug.Print("Call ImageService.listPresentationState to list presentationState returns error.");
                            cp_listPresentationState.Outputs.AddParameter("listPresentationState", "Call ImageService.listPresentationState to list presentationState", rt_listPresentationState.Message);

                            SaveRound(r);
                            continue; // There is error, end current round and test case
                        }
                        else
                        {
                            // Check the return value
                            bool isPSCorrect = false;
                            int i = 0;
                            for (i = 0; i < ep_listPresentationState.Parameters.Count; i++)
                            {
                                isPSCorrect = rt_listPresentationState.ResultContent.Contains(ep_listPresentationState.Parameters[i].ParameterValue);
                                if (!isPSCorrect)
                                {
                                    break; // stop compare and keep the index to report which one is not shown
                                }
                            }

                            if (isPSCorrect)
                            {
                                cp_listPresentationState.Result = TestResult.Pass;

                                System.Diagnostics.Debug.Print("Call ImageService.listPresentationState to list presentationState succeeds and the PS info is correct.");
                                cp_listPresentationState.Outputs.AddParameter("listPresentationState", "Call ImageService.listPresentationState to list presentationState", rt_listPresentationState.Message);
                            }
                            else
                            {
                                cp_listPresentationState.Result = TestResult.Fail;

                                System.Diagnostics.Debug.Print("Call ImageService.listPresentationState to list presentationState return value is not correct.");
                                cp_listPresentationState.Outputs.AddParameter("listPresentationState", "Call ImageService.listPresentationState to list presentationState return value is not correct", "Expect PS: " + ep_listPresentationState.Parameters[i].ParameterValue + " to show in the return. Actually Get: " + rt_listPresentationState.ResultContent);
                            }
                        }
                    }
                    else // Expect the call returns error
                    {
                        if (rt_listPresentationState.IsErrorOccured)
                        {
                            // Check the return value
                            if (rt_listPresentationState.Message.Contains(ep_returnMessage))
                            {
                                cp_listPresentationState.Result = TestResult.Pass;

                                System.Diagnostics.Debug.Print("Call ImageService.listPresentationState to list presentationState returns error as expected.");
                                cp_listPresentationState.Outputs.AddParameter("listPresentationState", "Call ImageService.listPresentationState to list presentationState returns error as expected", rt_listPresentationState.Message);
                            }
                            else
                            {
                                cp_listPresentationState.Result = TestResult.Fail;

                                System.Diagnostics.Debug.Print("Call ImageService.listPresentationState to list presentationState not returns error as expected.");
                                cp_listPresentationState.Outputs.AddParameter("listPresentationState", "Call ImageService.listPresentationState to list presentationState not returns error as expected", "Expect: " + ep_returnMessage + "; Actually Get: " + rt_listPresentationState.Message);
                            }
                        }
                        else
                        {
                            cp_listPresentationState.Result = TestResult.Fail;

                            System.Diagnostics.Debug.Print("Call ImageService.listPresentationState to list presentationState not returns error as expected.");
                            cp_listPresentationState.Outputs.AddParameter("listPresentationState", "Call ImageService.listPresentationState to list presentationState not returns error as expected", rt_listPresentationState.Message);

                            SaveRound(r);
                            continue; // There is error, end test case
                        }
                    }
                    #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 1558:  1.1.04.01 SetImage_N01_Call setImage when the original archived image file is accessible
        public void Run_Image_SetInfo_Normal_Case1558()
        {
            int runCount = 0;

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

                try
                {
                    #region Parameter initialize
                    string patientInternalId = string.Empty;
                    string objectFileFullPath = string.Empty;
                    string archivePath = string.Empty;

                    XMLParameter pSetImageInfo = new XMLParameter("image");
                    for (int i = 0; i < ids.InputParameters.Count; i++)
                    {
                        if (ids.InputParameters.GetParameter(i).Step == "importImage")
                        {
                            if (ids.InputParameters.GetParameter(i).Key == "objectFileFullPath")
                            {
                                objectFileFullPath = ids.InputParameters.GetParameter(i).Value;
                            }
                            else if (ids.InputParameters.GetParameter(i).Key == "archivePath")
                            {
                                archivePath = ids.InputParameters.GetParameter(i).Value;
                            }
                        }
                        else if (ids.InputParameters.GetParameter(i).Step == "setImageInfo")
                        {
                            pSetImageInfo.AddParameter(ids.InputParameters.GetParameter(i).Key, ids.InputParameters.GetParameter(i).Value);
                        }
                    }
                    #endregion

                    #region Step 0: Create a patient for import
                    patientInternalId = PatientService.Utility_CreatePatientForSpecificCase("case1558");

                    if (string.IsNullOrEmpty(patientInternalId))
                    {
                        goto CLEANUP;
                    }
                    #endregion

                    string imageInternalID = string.Empty;
                    string currentPSID = string.Empty;
                    ImportService importService = new ImportService();

                    #region Step 1: Call ImportService.importObject to import a image
                    CheckPoint cpImportImage = new CheckPoint("Import Image", "Call ImportService.importObject to import an archived  image");
                    r.CheckPoints.Add(cpImportImage);

                    XMLResult rtImportImage = importService.importObject(patientInternalId, null, objectFileFullPath, archivePath, true, "false");
                    if (rtImportImage.IsErrorOccured)
                    {
                        cpImportImage.Result = TestResult.Fail;
                        cpImportImage.Outputs.AddParameter("Import image returns error", "Import image", rtImportImage.Message);

                        SaveRound(r);
                        continue; // There is error when create image, end current run
                    }
                    else
                    {
                        cpImportImage.Result = TestResult.Pass;
                        cpImportImage.Outputs.AddParameter("Import image returns success", "Import image", rtImportImage.Message);

                        imageInternalID = rtImportImage.MultiResults[0].Parameters[0].ParameterValue;
                        currentPSID = rtImportImage.MultiResults[1].Parameters[0].ParameterValue;
                    }
                    #endregion

                    string imagePathAfterImport = string.Empty;
                    string archivedPathAfterImport = string.Empty;
                    string archiveTagAfterImport = string.Empty;
                    ImageService imageSvc = new ImageService();

                    #region Step 2-1: Check the getImageDescription return is correct after import image
                    CheckPoint cpGetImageDescriptionAfterImport = new CheckPoint("Check getImageDescription return", "Check getImageDescription return is corerct or not after import image");
                    r.CheckPoints.Add(cpGetImageDescriptionAfterImport);

                    XMLResult rtGetImageDescriptionAfterImport = imageSvc.getImageDescription(imageInternalID);
                    imagePathAfterImport = rtGetImageDescriptionAfterImport.MultiResults[0].GetParameterValueByName("path");
                    archivedPathAfterImport = rtGetImageDescriptionAfterImport.MultiResults[0].GetParameterValueByName("archive_path");
                    archiveTagAfterImport = rtGetImageDescriptionAfterImport.MultiResults[0].GetParameterValueByName("tags");

                    if (string.IsNullOrEmpty(imagePathAfterImport) && archivedPathAfterImport.Equals(archivePath) && string.IsNullOrEmpty(archiveTagAfterImport)) //getImageDescription should return not tags info
                    {
                        cpGetImageDescriptionAfterImport.Result = TestResult.Pass;
                        cpGetImageDescriptionAfterImport.Outputs.AddParameter("getImageDescription", "Check getImageDescription return", "The getImageDescription return is correct after import image" + rtGetImageDescriptionAfterImport.ResultContent);
                    }
                    else
                    {
                        cpGetImageDescriptionAfterImport.Result = TestResult.Fail;
                        cpGetImageDescriptionAfterImport.Outputs.AddParameter("getImageDescription", "Check getImageDescription return", "The getImageDescription return is not correct after import image. Actually get: " + rtGetImageDescriptionAfterImport.ResultContent);
                    }
                    #endregion

                    #region Step 2-2: Check the info is correct in getImageInfo return after import image
                    CheckPoint cpGetImageInfoAfterImport = new CheckPoint("Check getImageInfo return", "Check getImageInfo return is corerct or not import the image");
                    r.CheckPoints.Add(cpGetImageInfoAfterImport);

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

                    imagePathAfterImport = rtGetImageInfo.DicomArrayResult.GetParameterValueByName("path");
                    archivedPathAfterImport = rtGetImageInfo.DicomArrayResult.GetParameterValueByName("archive_path");
                    archiveTagAfterImport = rtGetImageInfo.DicomArrayResult.GetParameterValueByName("tags");

                    if (string.IsNullOrEmpty(imagePathAfterImport) && string.IsNullOrEmpty(archivedPathAfterImport) && string.IsNullOrEmpty(archiveTagAfterImport)) //&& archivePath.Equals(archivedPathAfterImport) && archiveTagAfterImport == "archived", will be supported in new service
                    {
                        cpGetImageInfoAfterImport.Result = TestResult.Pass;
                        cpGetImageInfoAfterImport.Outputs.AddParameter("getImageInfo", "Check getImageInfo return", "The getImageInfo return is correct after import image." + rtGetImageInfo.ResultContent);
                    }
                    else
                    {
                        cpGetImageInfoAfterImport.Result = TestResult.Fail;
                        cpGetImageInfoAfterImport.Outputs.AddParameter("getImageInfo", "Check getImageInfo return", "The getImageInfo return is not correct after import image. Actually get: " + rtGetImageInfo.ResultContent);
                    }
                    #endregion

                    #region Step 2-3: Check the image info in listObject retrun after import, such as path, archivePath and tags
                    CheckPoint cpListObject = new CheckPoint("listObjects", "Call PatientService.listObjects to check the archive tag");
                    r.CheckPoints.Add(cpListObject);

                    NewPatientService patientSvcV2 = new NewPatientService();
                    PatientListObjectsRequestType pListObjects = new PatientListObjectsRequestType();
                    pListObjects.current = true;
                    pListObjects.currentSpecified = true;
                    pListObjects.patientInternalId = patientInternalId;
                    pListObjects.type = PatientListObjectsType.presentationState;
                    PatientListObjectsResponseType rtListObjectAfterImport = patientSvcV2.listObjects(pListObjects);

                    if (!patientSvcV2.LastReturnXMLValidateResult.isValid)
                    {
                        cpListObject.Result = TestResult.Fail;
                        cpListObject.Outputs.AddParameter("listObjects", "Check listObjects after import", "The listObjects return XML is not valid per XSD. Returned:" + patientSvcV2.LastReturnXML);
                    }
                    else
                    {
                        bool isArchivePathCorrect = string.Equals(rtListObjectAfterImport.presentationStates[0].image.archivePath, archivePath);
                        bool isPathCorrect = string.IsNullOrEmpty(rtListObjectAfterImport.presentationStates[0].image.path);
                        bool isTagCorrect = string.Equals(rtListObjectAfterImport.presentationStates[0].image.tags, "archived");

                        if (!isArchivePathCorrect || !isTagCorrect || !isPathCorrect)
                        {
                            cpListObject.Result = TestResult.Fail;
                            cpListObject.Outputs.AddParameter("listObjects", "Check the image info in the listObject return value", "The tag or archivedPath info is wrong in the return. Actually get: " + patientSvcV2.LastReturnXML);
                        }
                        else
                        {
                            cpListObject.Result = TestResult.Pass;
                            cpListObject.Outputs.AddParameter("listObjects", "Check the image info in the listObject return value", "The tag and archivedPath info is correct in the return.");
                        }
                    }
                    #endregion

                    #region Step 3: Call ImageService.SetImageInfo to save the archived image as normal image
                    CheckPoint cpSetImageInfo = new CheckPoint("Set Image Info", "Call ImageService.SetImageInfo to save the archived image as normal image");
                    r.CheckPoints.Add(cpSetImageInfo);

                    XMLResult rtSetImageInfo = imageSvc.setImageInfo(pSetImageInfo, imageInternalID);

                    if (rtSetImageInfo.IsErrorOccured)
                    {
                        cpSetImageInfo.Result = TestResult.Fail;
                        cpSetImageInfo.Outputs.AddParameter("SetImageInfo returns error", "SetImageInfo", rtSetImageInfo.Message);
                    }
                    else
                    {
                        cpSetImageInfo.Result = TestResult.Pass;
                        cpSetImageInfo.Outputs.AddParameter("SetImageInfo returns success", "SetImageInfo", rtSetImageInfo.Message);
                    #endregion

                        // Wait the file is transferred to server DB
                        System.Threading.Thread.Sleep(3000);

                        // Below to check the info is correct after setImageInfo. Check points includes:
                        //1. The Image ID and PS ID are not changed
                        //2. GetImageDescription return correct image path and archive path, correct archive flag
                        //3. GetImageInfo return correct image path, correct archive flag
                        //4. Use the image path to check the image file is in server DB
                        //5. The original archived image is not deleted
                        //6. The listObject return contains correct archive tag

                        #region Step 4: Check the ps is set, not newly created after set image
                        CheckPoint cpPSID = new CheckPoint("Check PS ID", "Check the PS ID is not changed after call setImageInfo");
                        r.CheckPoints.Add(cpPSID);

                        XMLParameter pListPS = new XMLParameter("filter");
                        pListPS.AddParameter("current", "true");
                        string currentPSIDAfterSet = imageSvc.listPresentationState(pListPS, imageInternalID).SingleResult;

                        if (currentPSIDAfterSet == currentPSID)
                        {
                            cpPSID.Result = TestResult.Pass;
                            cpPSID.Outputs.AddParameter("listPresentationState", "Check PS ID", "The PS ID is not changed");
                        }
                        else
                        {
                            cpPSID.Result = TestResult.Fail;
                            cpPSID.Outputs.AddParameter("listPresentationState", "Check PS ID", "The PS ID is changed. Expect: " + currentPSID + "; Actually new PS ID: " + currentPSIDAfterSet);
                        }
                        #endregion

                        string imagePathAfterSet = string.Empty;
                        string archivePathAfterSet = string.Empty;
                        string archivedTagAfterSet = string.Empty;

                        #region Step 5: Check the getImageDescription return is correct after set image
                        CheckPoint cpGetImageDescriptionAfterSet = new CheckPoint("Check getImageDescription return", "Check getImageDescription return is corerct or not after call setImageInfo");
                        r.CheckPoints.Add(cpGetImageDescriptionAfterSet);

                        XMLResult rtGetImageDescriptionAfterSet = imageSvc.getImageDescription(imageInternalID);
                        imagePathAfterSet = rtGetImageDescriptionAfterSet.MultiResults[0].GetParameterValueByName("path");
                        archivePathAfterSet = rtGetImageDescriptionAfterSet.MultiResults[0].GetParameterValueByName("archive_path");
                        archivedTagAfterSet = rtGetImageDescriptionAfterSet.MultiResults[0].GetParameterValueByName("tags");

                        if (imagePathAfterSet.Contains(imageInternalID) && string.IsNullOrEmpty(archivePathAfterSet) && string.IsNullOrEmpty(archivedTagAfterSet)) // imagePathAfterSet sampe: C:/Documents and Settings/All Users/Application Data/TW/PAS/pas_data/patient/03/8af0a7e63310cc65013310d46d0e0003/1956bc28-ca5e-4720-a857-d4de18fc1479/02962f27-e4be-4d59-b112-9663a2f2572b.dcm"
                        {
                            cpGetImageDescriptionAfterSet.Result = TestResult.Pass;
                            cpGetImageDescriptionAfterSet.Outputs.AddParameter("getImageDescription", "Check getImageDescription return", "The getImageDescription return is correct after set image");
                        }
                        else
                        {
                            cpGetImageDescriptionAfterSet.Result = TestResult.Fail;
                            cpGetImageDescriptionAfterSet.Outputs.AddParameter("getImageDescription", "Check getImageDescription return", "The getImageDescription return is not correct after set image. Actually get: " + rtGetImageDescriptionAfterSet.ResultContent);
                        }
                        #endregion

                        #region Step 6: Check the getImageinfo return is correct after set image
                        CheckPoint cpGetImageInfoAfterSet = new CheckPoint("Check getImageInfo return", "Check getImageInfo return is corerct or not after call setImageInfo");
                        r.CheckPoints.Add(cpGetImageInfoAfterSet);

                        XMLParameter pGetImageInfoAfterSet = new XMLParameter("image");
                        pGetImageInfoAfterSet.AddParameter("internal_id", imageInternalID);
                        XMLResult rtGetImageInfoAfterSet = imageSvc.getImageInfo(pGetImageInfoAfterSet);

                        imagePathAfterSet = rtGetImageInfoAfterSet.DicomArrayResult.GetParameterValueByName("path");
                        archivePathAfterSet = rtGetImageInfoAfterSet.DicomArrayResult.GetParameterValueByName("archive_path");
                        archivedTagAfterSet = rtGetImageInfoAfterSet.DicomArrayResult.GetParameterValueByName("tags");

                        if (imagePathAfterSet.Contains(Utility.GetCSDMConfig(CSDMConfigSection.local, "patientDirectory")) && imagePathAfterSet.Contains(imageInternalID) && string.IsNullOrEmpty(archivePathAfterSet) && string.IsNullOrEmpty(archivedTagAfterSet))
                        {
                            cpGetImageInfoAfterSet.Result = TestResult.Pass;
                            cpGetImageInfoAfterSet.Outputs.AddParameter("getImageInfo", "Check getImageInfo return", "The getImageInfo return is correct after set image");
                        }
                        else
                        {
                            cpGetImageInfoAfterSet.Result = TestResult.Fail;
                            cpGetImageInfoAfterSet.Outputs.AddParameter("getImageInfo", "Check getImageInfo return", "The getImageInfo return is not correct after set image. Actually get: " + rtGetImageInfoAfterSet.ResultContent);
                        }
                        #endregion

                        #region Step 7: Check the file exist in server DB
                        CheckPoint cpImageInDB = new CheckPoint("Check file in DB", "Check the file exist in server DB after call setImageInfo");
                        r.CheckPoints.Add(cpImageInDB);

                        if (Utility.IsImageExistInServerDB(imagePathAfterSet))
                        {
                            cpImageInDB.Result = TestResult.Pass;
                            cpImageInDB.Outputs.AddParameter("Check the file exist in server DB after call setImageInfo", "Check file in DB", "File exist");
                        }
                        else
                        {
                            cpImageInDB.Result = TestResult.Fail;
                            cpImageInDB.Outputs.AddParameter("Check the file exist in server DB after call setImageInfo", "Check file in DB", "File NOT exist");
                        }
                        #endregion

                        #region Step 8: Check the original archived image is not deleted
                        CheckPoint cpOriginalArchivedImage = new CheckPoint("Check original archived file", "Check the original archived image is not deleted after call setImageInfo");
                        r.CheckPoints.Add(cpOriginalArchivedImage);

                        if (System.IO.File.Exists(archivePath))
                        {
                            cpOriginalArchivedImage.Result = TestResult.Pass;
                            cpOriginalArchivedImage.Outputs.AddParameter("Check the original archived image is not deleted after call setImageInfo", "Check original archived file", "File exist");
                        }
                        else
                        {
                            cpOriginalArchivedImage.Result = TestResult.Fail;
                            cpOriginalArchivedImage.Outputs.AddParameter("Check the original archived image is not deleted after call setImageInfo", "Check original archived file", "File NOT exist");
                        }
                        #endregion

                        #region Step 9: Check the image info in listObject retrun after set, such as path, archivePath and tags
                        CheckPoint cpListObjectAfterSet = new CheckPoint("listObjects", "Call PatientService.listObjects to check the archive tag after set");
                        r.CheckPoints.Add(cpListObjectAfterSet);

                        PatientListObjectsResponseType rtListObjectAfterSet = patientSvcV2.listObjects(pListObjects);
                        if (!patientSvcV2.LastReturnXMLValidateResult.isValid)
                        {
                            cpListObjectAfterSet.Result = TestResult.Fail;
                            cpListObjectAfterSet.Outputs.AddParameter("listObjects", "Check listObjects after set", "The listObjects return XML is not valid per XSD. Returned:" + patientSvcV2.LastReturnXML);
                        }
                        else
                        {
                            //bool isPathCorrect = rtListObjectAfterSet.presentationStates[0].image.path.Contains(Utility.GetCSDMConfig(CSDMConfigSection.remote, "patientDirectory")) && rtListObjectAfterSet.presentationStates[0].image.path.Contains(imageInternalID);
                            bool isArchivePathCorrect = string.IsNullOrEmpty(rtListObjectAfterSet.presentationStates[0].image.archivePath);
                            bool isTagCorrect = string.IsNullOrEmpty(rtListObjectAfterSet.presentationStates[0].image.tags);

                            if (!isArchivePathCorrect)
                            {
                                cpListObjectAfterSet.Result = TestResult.Fail;
                                cpListObjectAfterSet.Outputs.AddParameter("listObjects", "Check the image info in the listObject return value", "The archivedPath info is wrong in the return. Actually get: " + patientSvcV2.LastReturnXML);
                            }
                            else if (!isTagCorrect)
                            {
                                cpListObjectAfterSet.Result = TestResult.Fail;
                                cpListObjectAfterSet.Outputs.AddParameter("listObjects", "Check the image info in the listObject return value", "The tag info is wrong in the return. Actually get: " + patientSvcV2.LastReturnXML);
                            }
                            //else if (!isPathCorrect)
                            //{
                            //    cpListObjectAfterSet.Result = TestResult.Fail;
                            //    cpListObjectAfterSet.Outputs.AddParameter("listObjects", "Check the image info in the listObject return value", "The path info is wrong in the return. Actually get: " + patientSvc.LastReturnXML);
                            //}
                            else
                            {
                                cpListObjectAfterSet.Result = TestResult.Pass;
                                cpListObjectAfterSet.Outputs.AddParameter("listObjects", "Check the image info in the listObject return value", "The tag and archivedPath info is correct in the return.");
                            }
                        }
                        #endregion
                    }

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

                        XMLResult rt_DeleteImage = imageSvc.deleteImage(imageInternalID, 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);
                        }
                        else
                        {
                            cp_DeleteImage.Result = TestResult.Pass;
                            cp_DeleteImage.Outputs.AddParameter("delete image", "Delete image returns success", rt_DeleteImage.Message);
                        }
                    }
                    #endregion

                CLEANUP:
                    #region Step 11: Delete the patient used in this case
                    if (!string.IsNullOrEmpty(patientInternalId))
                    {
                        CheckPoint cp_DeletePatient = new CheckPoint("Step 11: Delete Patient", "Call patientService.deletePatient to delete the patient");
                        r.CheckPoints.Add(cp_DeletePatient);

                        XMLResult rt_DeletePatient = PatientService.Utility_DeletePatientForSpecificCase(patientInternalId);
                        if (rt_DeletePatient.IsErrorOccured)
                        {
                            cp_DeletePatient.Result = TestResult.Fail;
                            cp_DeletePatient.Outputs.AddParameter("delete patient", "Delete patient returns error", rt_DeletePatient.Message);
                        }
                        else
                        {
                            cp_DeletePatient.Result = TestResult.Pass;
                            cp_DeletePatient.Outputs.AddParameter("delete patient", "Delete patient returns success", rt_DeletePatient.Message);
                        }
                    }
                    #endregion

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

            Output();
        }
        public void Run_Acquisition_RotateAdjustRetaken_Case1640()
        {
            int runCount = 0;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                runCount++;

                ReceiveNotification rn = new ReceiveNotification();
                List<string> topics = new List<string>();
                topics.Add("topic.imageCreated");
                string stopTopic = "teststop";
                string stopContent = "teststop";
                rn.startListon(topics, stopTopic, stopContent);

                string acqType = string.Empty;
                Round r = this.NewRound(runCount.ToString(), "7600CR Acquisition");
                CheckPoint pAcq = new CheckPoint("Acquire Image", "Acquisition CR7600");
                r.CheckPoints.Add(pAcq);
                AcquisitionService acqs = new AcquisitionService();
                XMLParameter acq = new XMLParameter("acq_info");
                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);
                    }
                    if (ids.InputParameters.GetParameter(i).Step == "acquireType")
                    {
                        acqType = ids.InputParameters.GetParameter(i).Value;
                    }
                }

                XMLResult rslAcq = acqs.startAcquisition(acq);
                if (rslAcq.IsErrorOccured)
                {
                    System.Diagnostics.Debug.Print("Acquire fail:");
                    pAcq.Result = TestResult.Fail;
                    pAcq.Outputs.AddParameter("Acquire image error", "startAcquisition", rslAcq.Message);
                    SaveRound(r);
                    continue;
                }
                System.Threading.Thread.Sleep(15000);

                System.Diagnostics.Process p = new System.Diagnostics.Process();
                switch (acqType)
                {
                    case "rotate":
                        p.StartInfo.FileName = "7600helperRotate.exe";
                        break;
                    case "adjust":
                        p.StartInfo.FileName = "7600helperAdjust.exe";
                        break;
                    case "retaken":
                        p.StartInfo.FileName = "7600helperRetaken.exe";
                        break;
                }
                p.Start();
                p.WaitForExit();

                int retrynum = 24;
                int n = 0;
                while (rn.getRecievedNumber() == 0)
                {
                    n++;
                    if (n < retrynum)
                    {
                        System.Threading.Thread.Sleep(5000);
                    }
                    else
                        break;
                }

                if (n == retrynum)
                {
                    pAcq.Result = TestResult.Fail;
                    pAcq.Outputs.AddParameter("Acquire 7600", "Notification Fail", @"Recieve Notification Timeout(120 seconds)");
                    SaveRound(r);
                    continue;
                }

                System.Threading.Thread.Sleep(15000);
                ApplicationService apps = new ApplicationService();
                apps.sendGenericNotification(stopTopic, stopContent);
                System.Threading.Thread.Sleep(1000);
                List<string> mmm = rn.getNotificationContent();
                ImageService imgs = new ImageService();
                if (acqType == "retaken")
                {
                    int notificationNum = mmm.Count;
                    if (notificationNum != 3)
                    {
                        pAcq.Result = TestResult.Fail;
                        pAcq.Outputs.AddParameter("Acquire 7600", "Notification number not correct", " Actual:" + notificationNum.ToString() + "Expect:3");
                        SaveRound(r);
                        continue;
                    }
                    foreach (string msg in mmm)
                    {
                        string[] token = msg.Split('=');
                        string imageid = token[token.Length - 1];
                        XMLParameter cImg = new XMLParameter("image");
                        cImg.AddParameter("internal_id", imageid);
                        XMLResult rslGetRetaken = imgs.getImageInfo(cImg);
                        if (rslGetRetaken.IsErrorOccured)
                        {
                            pAcq.Result = TestResult.Fail;
                            pAcq.Outputs.AddParameter("Acquire 7600", "Get Retaken Image Fail", rslGetRetaken.Message);
                            SaveRound(r);
                            goto error;
                        }
                    }

                    goto retaken;
                error:
                    continue;
                }

                string[] token1 = mmm[0].Split('=');
                string imageid1 = token1[token1.Length - 1];

                XMLParameter img = new XMLParameter("image");
                img.AddParameter("internal_id", imageid1);
                XMLResult rslGet = imgs.getImageInfo(img);
                if (rslGet.IsErrorOccured)
                {
                    pAcq.Result = TestResult.Fail;
                    pAcq.Outputs.AddParameter("Acquire 7600", "GetImage Fail", rslGet.Message);
                    SaveRound(r);
                    continue;
                }
                XMLParameter filter = new XMLParameter("filter");
                filter.AddParameter("current", "true");
                XMLResult rslListPS = imgs.listPresentationState(filter, imageid1);
                string psid = rslListPS.SingleResult;

                PresentationStateService pss = new PresentationStateService();
                XMLResult rslget = pss.getPresentationState(psid);
                string processingXml = rslget.MultiResults[0].Parameters[0].ParameterValue.Trim();
                ProcessingXMLParser parser = new ProcessingXMLParser(processingXml);
                ProcessingXMLInfo pinfo = parser.parse();

                if (acqType == "rotate" && pinfo.Rotate180Enabled != "true")
                {
                    pAcq.Result = TestResult.Fail;
                    pAcq.Outputs.AddParameter("Acquire 7600", "ProcessingXML not correct", "Rotate180 is " + pinfo.Rotate180Enabled);
                    SaveRound(r);
                    continue;
                }

                if (acqType == "adjust" && pinfo.BrightnessEnabled != "true" && pinfo.BrightnessValue == "0")
                {
                    pAcq.Result = TestResult.Fail;
                    pAcq.Outputs.AddParameter("Acquire 7600", "ProcessingXML not correct", "BrightnessValue is 0");
                    SaveRound(r);
                    continue;
                }
            retaken:
                pAcq.Result = TestResult.Pass;
                pAcq.Outputs.AddParameter("Acquire 7600", "Success", "OK");
                SaveRound(r);
            }
            Output();
        }