示例#1
0
        public virtual Model.Observation GenerateObservation(ILookupTemplate <IFhirTemplate> config, IObservationGroup grp, Model.Identifier observationId, IDictionary <ResourceType, string> ids)
        {
            EnsureArg.IsNotNull(grp, nameof(grp));
            EnsureArg.IsNotNull(observationId, nameof(observationId));

            var patientId = Ensure.String.IsNotNullOrWhiteSpace(ids[ResourceType.Patient], nameof(ResourceType.Patient));
            var deviceId  = Ensure.String.IsNotNullOrWhiteSpace(ids[ResourceType.Device], nameof(ResourceType.Device));

            var observation = _fhirTemplateProcessor.CreateObservation(config, grp);

            observation.Subject    = patientId.ToReference <Model.Patient>();
            observation.Device     = deviceId.ToReference <Model.Device>();
            observation.Identifier = new List <Model.Identifier> {
                observationId
            };

            if (ids.TryGetValue(ResourceType.Encounter, out string encounterId))
            {
                observation.Encounter = encounterId.ToReference <Model.Encounter>();
            }

            return(observation);
        }
示例#2
0
        protected virtual void ProcessNormalizedEvent(Measurement normalizedEvent, ILookupTemplate <IFhirTemplate> fhirTemplate, DeviceResult validationResult)
        {
            var measurementGroup = new MeasurementGroup
            {
                MeasureType   = normalizedEvent.Type,
                CorrelationId = normalizedEvent.CorrelationId,
                DeviceId      = normalizedEvent.DeviceId,
                EncounterId   = normalizedEvent.EncounterId,
                PatientId     = normalizedEvent.PatientId,
                Data          = new List <Measurement>()
                {
                    normalizedEvent
                },
            };

            try
            {
                // Convert Measurement to Observation Group
                var observationGroup = _fhirTemplateProcessor.CreateObservationGroups(fhirTemplate, measurementGroup).First();

                // Build HL7 Observation
                validationResult.Observations.Add(_fhirTemplateProcessor.CreateObservation(fhirTemplate, observationGroup));
            }
            catch (TemplateNotFoundException e)
            {
                validationResult.CaptureError(
                    $"No Fhir Template exists with the type name [{e.Message}]. Ensure that all Fhir Template type names match Device Mapping type names (including casing)",
                    ErrorLevel.ERROR,
                    ValidationCategory.FHIRTRANSFORMATION,
                    LineInfo.Default);
            }
            catch (Exception e)
            {
                validationResult.CaptureException(e, ValidationCategory.FHIRTRANSFORMATION);
            }
        }