Пример #1
0
        /// <summary>
        /// Deserialize JSON into a FHIR DeviceMetric
        /// </summary>
        public static void DeserializeJson(this DeviceMetric 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 >>> DeviceMetric.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    reader.Read();
                    current.DeserializeJsonProperty(ref reader, options, propertyName);
                }
            }

            throw new JsonException($"DeviceMetric: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
Пример #2
0
        public static LegacyLeadType ToLegacyLeadType(this DeviceMetric?metric)
        {
            DeviceMetric?nullable = metric;

            if (!nullable.HasValue)
            {
                return(LegacyLeadType.Web);
            }
            DeviceMetric valueOrDefault = nullable.GetValueOrDefault();

            if (valueOrDefault == DeviceMetric.Desktop)
            {
                return(LegacyLeadType.Web);
            }
            if (valueOrDefault != DeviceMetric.Mobile)
            {
                throw new ArgumentOutOfRangeException("metric");
            }
            return(LegacyLeadType.Web);
        }
Пример #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());
        }
Пример #4
0
        /// <summary>
        /// Serialize a FHIR DeviceMetric into JSON
        /// </summary>
        public static void SerializeJson(this DeviceMetric current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            writer.WriteString("resourceType", "DeviceMetric");
            // Complex: DeviceMetric, Export: DeviceMetric, Base: DomainResource (DomainResource)
            ((Hl7.Fhir.Model.DomainResource)current).SerializeJson(writer, options, false);

            if ((current.Identifier != null) && (current.Identifier.Count != 0))
            {
                writer.WritePropertyName("identifier");
                writer.WriteStartArray();
                foreach (Identifier val in current.Identifier)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            writer.WritePropertyName("type");
            current.Type.SerializeJson(writer, options);

            if (current.Unit != null)
            {
                writer.WritePropertyName("unit");
                current.Unit.SerializeJson(writer, options);
            }

            if (current.Source != null)
            {
                writer.WritePropertyName("source");
                current.Source.SerializeJson(writer, options);
            }

            if (current.Parent != null)
            {
                writer.WritePropertyName("parent");
                current.Parent.SerializeJson(writer, options);
            }

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

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

            writer.WriteString("category", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.CategoryElement.Value));

            if (current.MeasurementPeriod != null)
            {
                writer.WritePropertyName("measurementPeriod");
                current.MeasurementPeriod.SerializeJson(writer, options);
            }

            if ((current.Calibration != null) && (current.Calibration.Count != 0))
            {
                writer.WritePropertyName("calibration");
                writer.WriteStartArray();
                foreach (DeviceMetric.CalibrationComponent val in current.Calibration)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Пример #5
0
        /// <summary>
        /// Deserialize JSON into a FHIR DeviceMetric
        /// </summary>
        public static void DeserializeJsonProperty(this DeviceMetric current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "identifier":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"DeviceMetric error reading 'identifier' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Identifier = new List <Identifier>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.Identifier v_Identifier = new Hl7.Fhir.Model.Identifier();
                    v_Identifier.DeserializeJson(ref reader, options);
                    current.Identifier.Add(v_Identifier);

                    if (!reader.Read())
                    {
                        throw new JsonException($"DeviceMetric error reading 'identifier' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Identifier.Count == 0)
                {
                    current.Identifier = null;
                }
                break;

            case "type":
                current.Type = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Type).DeserializeJson(ref reader, options);
                break;

            case "unit":
                current.Unit = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Unit).DeserializeJson(ref reader, options);
                break;

            case "source":
                current.Source = new Hl7.Fhir.Model.ResourceReference();
                ((Hl7.Fhir.Model.ResourceReference)current.Source).DeserializeJson(ref reader, options);
                break;

            case "parent":
                current.Parent = new Hl7.Fhir.Model.ResourceReference();
                ((Hl7.Fhir.Model.ResourceReference)current.Parent).DeserializeJson(ref reader, options);
                break;

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

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

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

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

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

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

            case "measurementPeriod":
                current.MeasurementPeriod = new Hl7.Fhir.Model.Timing();
                ((Hl7.Fhir.Model.Timing)current.MeasurementPeriod).DeserializeJson(ref reader, options);
                break;

            case "calibration":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"DeviceMetric error reading 'calibration' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Calibration = new List <DeviceMetric.CalibrationComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.DeviceMetric.CalibrationComponent v_Calibration = new Hl7.Fhir.Model.DeviceMetric.CalibrationComponent();
                    v_Calibration.DeserializeJson(ref reader, options);
                    current.Calibration.Add(v_Calibration);

                    if (!reader.Read())
                    {
                        throw new JsonException($"DeviceMetric error reading 'calibration' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Calibration.Count == 0)
                {
                    current.Calibration = null;
                }
                break;

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