Example #1
0
        /// <summary>
        /// Deserialize JSON into a FHIR DeviceMetric#Calibration
        /// </summary>
        public static void DeserializeJson(this DeviceMetric.CalibrationComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options)
        {
            string propertyName;

            while (reader.Read())
            {
                if (reader.TokenType == JsonTokenType.EndObject)
                {
                    return;
                }

                if (reader.TokenType == JsonTokenType.PropertyName)
                {
                    propertyName = reader.GetString();
                    if (Hl7.Fhir.Serialization.FhirSerializerOptions.Debug)
                    {
                        Console.WriteLine($"DeviceMetric.CalibrationComponent >>> DeviceMetric#Calibration.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    reader.Read();
                    current.DeserializeJsonProperty(ref reader, options, propertyName);
                }
            }

            throw new JsonException($"DeviceMetric.CalibrationComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
Example #2
0
        /// <summary>
        /// Serialize a FHIR DeviceMetric#Calibration into JSON
        /// </summary>
        public static void SerializeJson(this DeviceMetric.CalibrationComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            // Component: DeviceMetric#Calibration, Export: CalibrationComponent, Base: BackboneElement (BackboneElement)
            ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false);

            if (current.TypeElement != null)
            {
                if (current.TypeElement.Value != null)
                {
                    writer.WriteString("type", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.TypeElement.Value));
                }
                if (current.TypeElement.HasExtensions() || (!string.IsNullOrEmpty(current.TypeElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_type", false, current.TypeElement.Extension, current.TypeElement.ElementId);
                }
            }

            if (current.StateElement != null)
            {
                if (current.StateElement.Value != null)
                {
                    writer.WriteString("state", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.StateElement.Value));
                }
                if (current.StateElement.HasExtensions() || (!string.IsNullOrEmpty(current.StateElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_state", false, current.StateElement.Extension, current.StateElement.ElementId);
                }
            }

            if (current.TimeElement != null)
            {
                if (current.TimeElement.Value != null)
                {
                    writer.WriteString("time", ((DateTimeOffset)current.TimeElement.Value).ToString("yyyy-MM-dd'T'HH:mm:ss.FFFFFFFK", System.Globalization.CultureInfo.InvariantCulture));
                }
                if (current.TimeElement.HasExtensions() || (!string.IsNullOrEmpty(current.TimeElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_time", false, current.TimeElement.Extension, current.TimeElement.ElementId);
                }
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Example #3
0
        public static async Task <string> UpdateSecure(
            [OrchestrationTrigger] DurableOrchestrationContext context)
        {
            _targetDeviceId = context.GetInput <string[]>();

            if (Client == null)
            {
                Client = await GetSecureDocumentClient();
            }

            var deviceId        = _targetDeviceId[0];
            var updateVersionId = _targetDeviceId[1];
            var specType        = _targetDeviceId[2];



            // Get the DeviceComponent Document
            var doc = await context.CallActivityAsync <dynamic>("GetDoc", deviceId);


            _documentId = doc.Id;


            var binder = new Binder();

            binder.BindingData.Add("documentId", _documentId);
            binder.BindingData.Add("attachmentId", updateVersionId);

            // Get the Attachment
            string attachment = await context.CallActivityAsync <dynamic>(nameof(GetAttachment), binder);


            var result = await context.CallActivityAsync <CloudToDeviceMethodResult>(nameof(StartFirmwareUpdate), attachment);

            if (result.Status != 0)
            {
                return(result.Status.ToString());
            }


            var status = await context.CallActivityAsync <string>(nameof(QueryTwinFwUpdateReportedSecure), DateTime.Now);

            var instant = new DateTimeOffset(DateTime.Parse(status));

            var spec = new DeviceComponent.ProductionSpecificationComponent
            {
                ComponentId    = { Value = Guid.NewGuid().ToString() },
                ProductionSpec = updateVersionId
            };
            var coding = new Coding(null, specType, specType.ToUpper());

            spec.SpecType.Coding.Add(coding);

            var ps = new DeviceComponent().ProductionSpecification;

            ps.Add(spec);

            // Update the LastSystemChange value
            var deviceComponentUpdate = new DeviceComponent
            {
                Id                          = _documentId,
                Type                        = doc.Type,
                Text                        = doc.Text,
                Source                      = doc.Source,
                Parent                      = doc.Parent,
                FhirComments                = doc.FhirComments,
                ImplicitRules               = doc.ImplicitRules,
                Identifier                  = doc.Identifier,
                OperationalStatus           = doc.OperationalStatus,
                Contained                   = doc.Contained,
                LastSystemChange            = instant,
                MeasurementPrinciple        = doc.MeasurementPrinciple,
                ParameterGroup              = doc.ParameterGroup,
                MeasurementPrincipleElement = doc.MeasurementPrincipleElement,
                LanguageCode                = doc.LanguageCode,
                ProductionSpecification     = ps,
                Language                    = doc.Language
            };

            var json = JsonConvert.SerializeObject(deviceComponentUpdate);


            // Update the Device Docuument
            var upDate = await context.CallActivityAsync <HttpResponseMessage>(nameof(UpdateDoc), json);

            if (!upDate.IsSuccessStatusCode)
            {
                return(upDate.StatusCode.ToString());
            }

            var cal = new DeviceMetric.CalibrationComponent
            {
                Type =
                    null,                     //values: unspecified, ofset, gin, two-point see https://www.hl7.org/fhir/valueset-metric-calibration-type.html
                State =
                    null,                     // values: not-calibrated,  calibration-required, calibrated, unspecified see https://www.hl7.org/fhir/valueset-metric-calibration-state.html
                Time = instant                // value: DateTimeOffset
            };
            var calibration = new DeviceMetric().Calibration;

            calibration.Add(cal);


            var deviceMetric = new DeviceMetric
            {
                OperationalStatus = doc.Result.OperationalStatus,
                Category          = doc.Result.Category,
                Color             = doc.Result.Color,
                Contained         = doc.Result.Contained,
                Type              = doc.Result.Type,
                Unit              = doc.Result.Unit,
                Source            = doc.Result.Source,
                Parent            = doc.Result.Parent,
                MeasurementPeriod = null,
                Calibration       = calibration
            };

            json = JsonConvert.SerializeObject(deviceMetric);

            upDate = await context.CallActivityAsync <HttpResponseMessage>(nameof(UpdateDoc), json);


            return(upDate.StatusCode.ToString());
        }
Example #4
0
        /// <summary>
        /// Deserialize JSON into a FHIR DeviceMetric#Calibration
        /// </summary>
        public static void DeserializeJsonProperty(this DeviceMetric.CalibrationComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "type":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.TypeElement = new Code <Hl7.Fhir.Model.DeviceMetric.DeviceMetricCalibrationType>();
                    reader.Skip();
                }
                else
                {
                    current.TypeElement = new Code <Hl7.Fhir.Model.DeviceMetric.DeviceMetricCalibrationType>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.DeviceMetric.DeviceMetricCalibrationType>(reader.GetString()));
                }
                break;

            case "_type":
                if (current.TypeElement == null)
                {
                    current.TypeElement = new Code <Hl7.Fhir.Model.DeviceMetric.DeviceMetricCalibrationType>();
                }
                ((Hl7.Fhir.Model.Element)current.TypeElement).DeserializeJson(ref reader, options);
                break;

            case "state":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.StateElement = new Code <Hl7.Fhir.Model.DeviceMetric.DeviceMetricCalibrationState>();
                    reader.Skip();
                }
                else
                {
                    current.StateElement = new Code <Hl7.Fhir.Model.DeviceMetric.DeviceMetricCalibrationState>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.DeviceMetric.DeviceMetricCalibrationState>(reader.GetString()));
                }
                break;

            case "_state":
                if (current.StateElement == null)
                {
                    current.StateElement = new Code <Hl7.Fhir.Model.DeviceMetric.DeviceMetricCalibrationState>();
                }
                ((Hl7.Fhir.Model.Element)current.StateElement).DeserializeJson(ref reader, options);
                break;

            case "time":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.TimeElement = new Instant();
                    reader.Skip();
                }
                else
                {
                    current.TimeElement = new Instant(DateTimeOffset.Parse(reader.GetString()));
                }
                break;

            case "_time":
                if (current.TimeElement == null)
                {
                    current.TimeElement = new Instant();
                }
                ((Hl7.Fhir.Model.Element)current.TimeElement).DeserializeJson(ref reader, options);
                break;

            // Complex: calibration, Export: CalibrationComponent, Base: BackboneElement
            default:
                ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }