Exemple #1
0
        /// <summary>
        /// Create an appropriate entity based on the class code
        /// </summary>
        public override Core.Model.Acts.Act ToModelInstance(object dataInstance, DataContext context)
        {
            // Alright first, which type am I mapping to?

            if (dataInstance == null)
            {
                return(null);
            }

            DbActVersion dbActVersion = (dataInstance as CompositeResult)?.Values.OfType <DbActVersion>().FirstOrDefault() ?? dataInstance as DbActVersion ?? context.FirstOrDefault <DbActVersion>(o => o.VersionKey == (dataInstance as DbActSubTable).ParentKey);
            DbAct        dbAct        = (dataInstance as CompositeResult)?.Values.OfType <DbAct>().FirstOrDefault() ?? context.FirstOrDefault <DbAct>(o => o.Key == dbActVersion.Key);
            Act          retVal       = null;

            //
            switch (dbAct.ClassConceptKey.ToString().ToUpper())
            {
            case ActClassKeyStrings.ControlAct:
                retVal = new ControlActPersistenceService().ToModelInstance(
                    (dataInstance as CompositeResult)?.Values.OfType <DbControlAct>().FirstOrDefault() ?? context.FirstOrDefault <DbControlAct>(o => o.ParentKey == dbActVersion.VersionKey),
                    dbActVersion,
                    dbAct,
                    context);
                break;

            case ActClassKeyStrings.SubstanceAdministration:
                retVal = new SubstanceAdministrationPersistenceService().ToModelInstance(
                    (dataInstance as CompositeResult)?.Values.OfType <DbSubstanceAdministration>().FirstOrDefault() ?? context.FirstOrDefault <DbSubstanceAdministration>(o => o.ParentKey == dbActVersion.VersionKey),
                    dbActVersion,
                    dbAct,
                    context);
                break;

            case ActClassKeyStrings.Observation:
                var dbObs = (dataInstance as CompositeResult)?.Values.OfType <DbObservation>().FirstOrDefault() ?? context.FirstOrDefault <DbObservation>(o => o.ParentKey == dbActVersion.VersionKey);
                if (dbObs == null)
                {
                    this.m_tracer.TraceEvent(EventLevel.Warning, "Observation {0} is missing observation data! Even though class code is {1}", dbAct.Key, dbAct.ClassConceptKey);
                    retVal = this.ToModelInstance <Core.Model.Acts.Act>(dbActVersion, dbAct, context);
                }
                else
                {
                    switch (dbObs.ValueType)
                    {
                    case "ST":
                        retVal = new TextObservationPersistenceService().ToModelInstance(
                            (dataInstance as CompositeResult)?.Values.OfType <DbTextObservation>().FirstOrDefault() ?? context.FirstOrDefault <DbTextObservation>(o => o.ParentKey == dbObs.ParentKey),
                            dbObs,
                            dbActVersion,
                            dbAct,
                            context);
                        break;

                    case "CD":
                        retVal = new CodedObservationPersistenceService().ToModelInstance(
                            (dataInstance as CompositeResult)?.Values.OfType <DbCodedObservation>().FirstOrDefault() ?? context.FirstOrDefault <DbCodedObservation>(o => o.ParentKey == dbObs.ParentKey),
                            dbObs,
                            dbActVersion,
                            dbAct,
                            context);
                        break;

                    case "PQ":
                        retVal = new QuantityObservationPersistenceService().ToModelInstance(
                            (dataInstance as CompositeResult)?.Values.OfType <DbQuantityObservation>().FirstOrDefault() ?? context.FirstOrDefault <DbQuantityObservation>(o => o.ParentKey == dbObs.ParentKey),
                            dbObs,
                            dbActVersion,
                            dbAct,
                            context);
                        break;

                    default:
                        retVal = new ObservationPersistenceService().ToModelInstance(
                            dbObs,
                            dbActVersion,
                            dbAct,
                            context);
                        break;
                    }
                }
                break;

            case ActClassKeyStrings.Encounter:
                retVal = new EncounterPersistenceService().ToModelInstance(
                    (dataInstance as CompositeResult)?.Values.OfType <DbPatientEncounter>().FirstOrDefault() ?? context.FirstOrDefault <DbPatientEncounter>(o => o.ParentKey == dbActVersion.VersionKey),
                    dbActVersion,
                    dbAct,
                    context);
                break;

            case ActClassKeyStrings.Condition:
            default:
                retVal = this.ToModelInstance <Core.Model.Acts.Act>(dbActVersion, dbAct, context);
                break;
            }

            retVal.LoadAssociations(context);
            return(retVal);
        }
Exemple #2
0
 public TextObservationPersistenceService(IAdoPersistenceSettingsProvider settingsProvider) : base(settingsProvider)
 {
     this.m_observationPersistence = new ObservationPersistenceService(settingsProvider);
 }