//Case 34: 1.3.1_SetPatient_Normal
        public void Run_Patient_SetPatient_Normal_Case34()
        {
            int runCount = 0;
            int matchItem = 1;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "set patient");
                CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                r.CheckPoints.Add(pCreate);
                PatientService ps = new PatientService();

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

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

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

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

                XMLResult rslGet = ps.getPatient(patientUID);

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

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

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

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

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

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

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

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

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

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

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

                            CheckPoint pGetPS = new CheckPoint("Get Presentation State", "PS Desc");
                            r.CheckPoints.Add(pGetPS);
                            if (psreturn.MultiResults.Count == 1 && !string.IsNullOrEmpty(psreturn.MultiResults[0].GetParameterValueByName("image_internal_id")) && string.IsNullOrEmpty(psreturn.MultiResults[0].GetParameterValueByName("general.xml")) && string.IsNullOrEmpty(psreturn.MultiResults[0].GetParameterValueByName("processing.xml")) && string.IsNullOrEmpty(psreturn.MultiResults[0].GetParameterValueByName("annotation.xml")))
                            {
                                pGetPS.Result = TestResult.Pass;
                                pGetPS.Outputs.AddParameter("get presentation state", "get presentation state as expect", psreturn.ResultContent);
                            }
                            else
                            {
                                pGetPS.Result = TestResult.Fail;
                                pGetPS.Outputs.AddParameter("get presentation state", "get presentation state not as expect", psreturn.ResultContent);
                            }
                        }
                    }
                }
                if (isDeletePatient)
                {
                    XMLResult rltDelete = ps.deletePatient(patientUID);
                    if (!rltDelete.IsErrorOccured)
                    {
                        pCreate.Outputs.AddParameter("Delete created patient", "Delete Patient", rltDelete.Message);
                    }
                }
                SaveRound(r);
            }
            Output();
        }
        //Case 1043: 1.3.17_workflow_ImportCeph_GetImageInfo_RadilogIsNotSaved
        public void Run_WorkFlow_ImportCeph_RadioLog_Case1043()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            bool isDeletePatient = true;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Import image");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                XMLParameter epGetVolumeInfo = new XMLParameter();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    SaveRound(r);
                }
                catch (Exception ex)
                {
                    CheckPoint cp = new CheckPoint();
                    r.CheckPoints.Add(cp);
                    cp.Outputs.AddParameter("Exception thrown", "Exception Message", ex.ToString());
                    cp.Result = TestResult.Fail;
                    SaveRound(r);
                }
            }
            Output();
        }
        //Case 512: 1.2.3_ImportZip_Normal
        public void Run_Import_Zip_Case512()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            bool isDeletePatient = false;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                isDeletePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Import image");
                CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                r.CheckPoints.Add(pCreate);
                PatientService ps = new PatientService();
                ImportService ims = new ImportService();
                PresentationStateService pss = new PresentationStateService();

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

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

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

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

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

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

                    if (listObjcetRsl.IsErrorOccured)
                    {
                        pListObject.Result = TestResult.Fail;
                        pListObject.Outputs.AddParameter("Erron in List Object", "List Object", "List Patient Presentation State Error");
                    }
                    else
                    {
                        pListObject.Outputs.AddParameter("List Object return content", "List Object", listObjcetRsl.ResultContent);
                        if (listObjcetRsl.ArrayResult.Length == 3)
                        {
                            bool isMatchXML = true;
                            for (int index = 0; index < listObjcetRsl.ArrayResult.Parameters.Count; index++)
                            {
                                XMLResult getPSRsl = pss.getPresentationState(listObjcetRsl.ArrayResult.Parameters[index].ParameterValue);
                                if (getPSRsl.ArrayResult.Parameters.Count != 4)
                                {
                                    isMatchXML = false;
                                    pListObject.Outputs.AddParameter("Get PS return content", "Get PS Description", getPSRsl.ResultContent);
                                    break;
                                }
                            }
                            if (isMatchXML)
                            {
                                pListObject.Result = TestResult.Pass;
                            }
                            else
                            {
                                pListObject.Result = TestResult.Fail;
                                pListObject.Outputs.AddParameter("Get PS description error", "Get PS Description", "Not return all xml and image id");
                            }
                        }
                        else
                        {
                            pListObject.Result = TestResult.Fail;
                            pListObject.Outputs.AddParameter("The PS count not match", "Get All PS Description", "Not three PS be retrieve.");
                        }
                    }
                }
                if (isDeletePatient)
                {
                    XMLResult rslDelete = ps.deletePatient(patientUID);
                    if (!rslDelete.IsErrorOccured)
                    {
                        pImport.Outputs.AddParameter("Delete created patient", "Delete Patient", rslDelete.ResultContent);
                    }
                }
                SaveRound(r);
            }
            Output();
        }
        // Case 721: 1.3.10_ImportImage_N02_Archived image
        public void Run_Import_ArchivedImage_Case721()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            bool isDeletePatient = true;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Import image");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                XMLParameter epImport = new XMLParameter();

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

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

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

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

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

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

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

                        #region Call getImageInfo to check expected key and value

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

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

                        #endregion
                    }

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

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

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

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

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

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

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

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

                int getn = rn.getNotificationNumber();

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

                if (getn == 3)
                {
                    pNotification.Result = TestResult.Pass;
                    foreach (string mmm in rn.getNotificationContent())
                        pNotification.Outputs.AddParameter("Notification message", "Content:", mmm);
                }
                else
                {
                    pNotification.Result = TestResult.Fail;
                    pNotification.Outputs.AddParameter("Message", "Content:", "miss message on receive");
                }
                if (isDeletePatient)
                {
                    XMLResult rslDelete = ps.deletePatient(patientUID);
                    if (!rslDelete.IsErrorOccured)
                    {
                        pNotification.Outputs.AddParameter("Delete created patient", "Delete Patient", rslDelete.ResultContent);
                    }
                }
                SaveRound(r);
            }
            Output();
        }
        // Case 1658: 1.2.3_ImportImage_SimpleInstance_large file
        public void Run_Import_SimpleInstance_LargeFile_Case1658()
        {
            int runCount = 0;
            string patientUID = string.Empty;
            bool isCreatePatient = false;
            bool isDeletePatient = true;
            foreach (InputDataSet ids in this.Input.DataSets)
            {
                isCreatePatient = false;
                runCount++;
                Round r = this.NewRound(runCount.ToString(), "Import image");

                string instanceID = null;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    System.Threading.Thread.Sleep(10000);

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

                    SaveRound(r);
                }
                catch (Exception ex)
                {
                    CheckPoint cp = new CheckPoint();
                    r.CheckPoints.Add(cp);
                    cp.Outputs.AddParameter("Exception thrown", "Exception Message", ex.Message);
                    cp.Result = TestResult.Fail;
                    SaveRound(r);
                }
            }
            Output();
        }
        // Case 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();
        }
        // Case 1496: 1.2.3_ImportImage_FMS
        public void Run_Import_FMS_Case1496()
        {
            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");
                CheckPoint pCreate = new CheckPoint("Create Patient", "Test create");
                r.CheckPoints.Add(pCreate);

                PatientService ps = new PatientService();
                ImportService ims = new ImportService();
                XMLParameter pa = new XMLParameter("patient");
                XMLParameter ia = new XMLParameter("import");

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

                string ep_nodeNum = string.Empty;
                string ep_totalSubImageNum = string.Empty;
                string ep_successImageNum = string.Empty;
                for (int i = 0; i < ids.ExpectedValues.Count; i++)
                {
                    if (ids.ExpectedValues.GetParameter(i).Step == "import")
                    {
                        if (ids.ExpectedValues.GetParameter(i).Key == "node")
                        {
                            ep_nodeNum = ids.ExpectedValues.GetParameter(i).Value;
                        }
                        else if (ids.ExpectedValues.GetParameter(i).Key == "total")
                        {
                            ep_totalSubImageNum = ids.ExpectedValues.GetParameter(i).Value;
                        }
                        else if (ids.ExpectedValues.GetParameter(i).Key == "success")
                        {
                            ep_successImageNum = ids.ExpectedValues.GetParameter(i).Value;
                        }
                    }
                }

                XMLParameter epGetFMSInfo = new XMLParameter();
                //XMLParameter epGetFMSDescription = new XMLParameter();

                for (int i = 0; i < ids.ExpectedValues.Count; i++)
                {
                    if (ids.ExpectedValues.GetParameter(i).Step == "getFMSInfo")
                    {
                        epGetFMSInfo.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                    }
                    //else if (ids.ExpectedValues.GetParameter(i).Step == "getFMSDescription")
                    //{
                    //    epGetFMSDescription.AddParameter(ids.ExpectedValues.GetParameter(i).Key, ids.ExpectedValues.GetParameter(i).Value);
                    //}
                }

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

                    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 FMS return sample:
                       <trophy type="result" version="1.0">
                          <status code="0" message="ok" />
                        - <fms>
                          <parameter key="internal_id" value="637e9a0d-73dc-447e-bf7d-607b6a088468" />
                          </fms>
                        - <image>
                          <parameter key="internal_id" value="c8e90079-1f6f-4d6c-92d2-4cd91e63c3bc" />
                          </image>
                        - <presentationstate>
                          <parameter key="internal_id" value="2ff59bd5-d1c3-4a3b-a514-9871abded236" />
                          </presentationstate>
                        - <image>
                          <parameter key="internal_id" value="9057d7c5-8e1a-4aee-95ce-a4a9e98dc42e" />
                          </image>
                        - <presentationstate>
                          <parameter key="internal_id" value="99179d8d-9855-4bb4-b1c0-c47c7e364d95" />
                          </presentationstate>
                          </trophy>
                     * **********************/

                    if (rslImport.IsErrorOccured)
                    {
                        pImport.Result = TestResult.Fail;
                        pImport.Outputs.AddParameter("Import FMS fail", "Import", rslImport.Message);
                        pImport.Outputs.AddParameter("Import FMS returns error code", "Import", rslImport.Code.ToString());
                    }
                    else
                    {
                        if (rslImport.MultiResults.Count.ToString() != ep_nodeNum)
                        {
                            pImport.Result = TestResult.Fail;
                            pImport.Outputs.AddParameter("Import FMS returns wrong node", "Import", rslImport.ResultContent);
                        }
                        else
                        {
                            pImport.Result = TestResult.Pass;

                            for (int i = 0; i < rslImport.MultiResults.Count - 1; i++)
                            {
                                string internalID = rslImport.MultiResults[i].GetParameterValueByName("internal_id");
                                if (internalID == null || internalID == string.Empty)
                                {
                                    pImport.Result = TestResult.Fail;
                                    pImport.Outputs.AddParameter("Import image returns wrong FMS, image or PS info", "Import", rslImport.ResultContent);
                                    break;
                                }
                            }

                            if (pImport.Result == TestResult.Pass)
                            {
                                string totalSubImages = rslImport.MultiResults[rslImport.MultiResults.Count - 1].GetParameterValueByName("total");
                                string successSubImages = rslImport.MultiResults[rslImport.MultiResults.Count - 1].GetParameterValueByName("success");

                                if (totalSubImages != ep_totalSubImageNum || successSubImages != ep_successImageNum)
                                {
                                    pImport.Result = TestResult.Fail;
                                    pImport.Outputs.AddParameter("Import FMS returns wrong info for [other] when import sub images", "Import", rslImport.ResultContent);
                                }
                                else
                                {
                                    pImport.Result = TestResult.Pass;
                                    pImport.Outputs.AddParameter("import FMS returns OK", "Import", rslImport.ResultContent);
                                }
                            }
                        }
                    }

                    #region Call GetFMSInfo to check the return value
                    FMSService fmsSvc = new FMSService();

                    string fmsID = string.Empty; // Try to get from the import return
                    fmsID = rslImport.MultiResults[0].GetParameterValueByName("internal_id");

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

                    XMLResult rtGetFMSInfo = fmsSvc.getFMSInfo(fmsID);
                    if (rtGetFMSInfo.IsErrorOccured)
                    {
                        cpGetFMSInfo.Result = TestResult.Fail;
                        cpGetFMSInfo.Outputs.AddParameter("Get FMS Info returns error", "getFMSInfo", rtGetFMSInfo.ResultContent);
                    }
                    else
                    {
                        cpGetFMSInfo.Outputs.AddParameter("Get FMS Info returns success", "getFMSInfo", rtGetFMSInfo.Message);

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

                        if (cpGetFMSInfo.Result != TestResult.Fail)
                        {
                            cpGetFMSInfo.Result = TestResult.Pass;
                            cpGetFMSInfo.Outputs.AddParameter("Get FMS Info return all correct info", "GetFMSInfo", rtGetFMSInfo.ResultContent);
                        }
                    }
                    #endregion

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

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