Beispiel #1
0
        public override IContentTemplate Create(TemplateContainer jsonTemplate)
        {
            EnsureArg.IsNotNull(jsonTemplate, nameof(jsonTemplate));

            if (!jsonTemplate.MatchTemplateName(TargetTypeName))
            {
                return(null);
            }

            if (jsonTemplate.Template?.Type != JTokenType.Object)
            {
                throw new InvalidTemplateException($"Expected an object for the template property value for template type {TargetTypeName}.");
            }

            var calculatedFunctionTemplate = jsonTemplate.Template.ToValidTemplate <CalculatedFunctionContentTemplate>();

            calculatedFunctionTemplate.EnsureExpressionLanguageIsSet();
            var measurementExtractor = new MeasurementExtractor(calculatedFunctionTemplate, CreateExpressionEvaluatorFactory(calculatedFunctionTemplate));

            return(measurementExtractor);
        }
        private void PerformEvaluation(CalculatedFunctionContentTemplate template)
        {
            var time  = DateTime.UtcNow;
            var token = JToken.FromObject(new
            {
                heartrate = "60",
                device    = "abc",
                date      = time,
                session   = "abcdefg",
                patient   = "patient123",
            });

            var measurementExtractor = new MeasurementExtractor(template, new TemplateExpressionEvaluatorFactory());
            var result = measurementExtractor.GetMeasurements(token).ToArray();

            Assert.NotNull(result);
            Assert.Collection(result, m =>
            {
                Assert.Equal("heartrate", m.Type);
                Assert.Equal(time, m.OccurrenceTimeUtc);
                Assert.Equal("abc", m.DeviceId);
                Assert.Equal("patient123", m.PatientId);
                Assert.Equal("abcdefg", m.CorrelationId);
                Assert.Null(m.EncounterId);
                Assert.Collection(
                    m.Properties,
                    p =>
                {
                    Assert.Equal("hr", p.Name);
                    Assert.Equal("60", p.Value);
                },
                    p =>
                {
                    Assert.Equal("pie", p.Name);
                    Assert.Equal("patient123", p.Value);
                });
            });
        }