protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5EX_SPOaMOfEID_1558 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            var madeObservationsForExaminationID = ORM_HEC_ACT_PerformedAction_MadeObservation.Query.Search(Connection, Transaction, new ORM_HEC_ACT_PerformedAction_MadeObservation.Query()
            {
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID,
                HEC_ACT_PerformedAction_RefID = Parameter.ExaminationID
            });
            foreach (var observation in Parameter.MadeObservationsToDelete)
            {
                var PerformedActionMadeObservations = madeObservationsForExaminationID.Where(obs => obs.PotentialObservation_RefID == observation.ObservationID);

                if (PerformedActionMadeObservations != null)
                {
                    foreach (var perActMadeObs in PerformedActionMadeObservations)
                    {
                        perActMadeObs.IsDeleted = true;
                        perActMadeObs.Modification_Timestamp = DateTime.Now;
                        perActMadeObs.Save(Connection, Transaction);
                    }
                }
            }
            foreach (var observation in Parameter.MadeObservationsToAdd)
            {
                //if potential observation does not exists, first create it
                Guid potentialObservationID = observation.ObservationID;
                if (observation.ObservationID == Guid.Empty)
                {
                    ORM_HEC_PotentialObservation potObs = new ORM_HEC_PotentialObservation();
                    potObs.Observation_Text           = observation.ObservationText;
                    potObs.Tenant_RefID               = securityTicket.TenantID;
                    potObs.HEC_PotentialObservationID = Guid.NewGuid();
                    potObs.Modification_Timestamp     = DateTime.Now;
                    potObs.Save(Connection, Transaction);
                    potentialObservationID = potObs.HEC_PotentialObservationID;
                }
                ORM_HEC_ACT_PerformedAction_MadeObservation madeObservation = new ORM_HEC_ACT_PerformedAction_MadeObservation();
                madeObservation.HEC_ACT_PerformedAction_RefID = Parameter.ExaminationID;
                madeObservation.PotentialObservation_RefID    = potentialObservationID;
                madeObservation.Comment                = observation.ObservationText.Contents[0].Content;
                madeObservation.Tenant_RefID           = securityTicket.TenantID;
                madeObservation.Modification_Timestamp = DateTime.Now;
                madeObservation.Save(Connection, Transaction);
            }
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guids Execute(DbConnection Connection, DbTransaction Transaction, P_L5DI_SPO_1452 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guids();
            //Put your code here

            List <Guid> resultID = new List <Guid>();
            foreach (var observationParam in Parameter.PotentialObservation)
            {
                ORM_HEC_DIA_TypicalPotentialObservation typicalPotentialObservation = ORM_HEC_DIA_TypicalPotentialObservation.Query.Search(Connection, Transaction, new ORM_HEC_DIA_TypicalPotentialObservation.Query {
                    HEC_DIA_TypicalPotentialObservationID = observationParam.TypicalPotentialObservationID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                }).SingleOrDefault();
                if (!observationParam.IsDeleted)
                {
                    if (observationParam.NewPotentialObservation)
                    {
                        ORM_HEC_PotentialObservation potentialObservation = new ORM_HEC_PotentialObservation();
                        potentialObservation.HEC_PotentialObservationID = observationParam.PotentialObservationID;
                        potentialObservation.Observation_Text           = observationParam.Observation_Text;
                        potentialObservation.IsDeleted    = false;
                        potentialObservation.Tenant_RefID = securityTicket.TenantID;
                        potentialObservation.Save(Connection, Transaction);
                    }
                    if (typicalPotentialObservation == null)
                    {
                        typicalPotentialObservation = new ORM_HEC_DIA_TypicalPotentialObservation();
                        typicalPotentialObservation.HEC_DIA_TypicalPotentialObservationID = observationParam.TypicalPotentialObservationID;
                    }
                    typicalPotentialObservation.PotentialDiagnosis_RefID   = observationParam.PotentialDiagnosis_RefID;
                    typicalPotentialObservation.PotentialObservation_RefID = observationParam.PotentialObservationID;
                    typicalPotentialObservation.IsDeleted    = false;
                    typicalPotentialObservation.Tenant_RefID = securityTicket.TenantID;
                    typicalPotentialObservation.Save(Connection, Transaction);
                    resultID.Add(typicalPotentialObservation.HEC_DIA_TypicalPotentialObservationID);
                }
                else if (typicalPotentialObservation != null && observationParam.IsDeleted)
                {
                    typicalPotentialObservation.IsDeleted = true;
                    typicalPotentialObservation.Save(Connection, Transaction);
                    resultID.Add(typicalPotentialObservation.HEC_DIA_TypicalPotentialObservationID);
                }
            }
            returnValue.Result = resultID.ToArray();

            return(returnValue);

            #endregion UserCode
        }