/// <summary> /// Deserialize JSON into a FHIR DeviceUseStatement /// </summary> public static void DeserializeJson(this DeviceUseStatement 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($"DeviceUseStatement >>> DeviceUseStatement.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } reader.Read(); current.DeserializeJsonProperty(ref reader, options, propertyName); } } throw new JsonException($"DeviceUseStatement: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); }
/// <summary> /// Serialize a FHIR DeviceUseStatement into JSON /// </summary> public static void SerializeJson(this DeviceUseStatement current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } writer.WriteString("resourceType", "DeviceUseStatement"); // Complex: DeviceUseStatement, Export: DeviceUseStatement, 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(); } if ((current.BasedOn != null) && (current.BasedOn.Count != 0)) { writer.WritePropertyName("basedOn"); writer.WriteStartArray(); foreach (ResourceReference val in current.BasedOn) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } writer.WriteString("status", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.StatusElement.Value)); writer.WritePropertyName("subject"); current.Subject.SerializeJson(writer, options); if ((current.DerivedFrom != null) && (current.DerivedFrom.Count != 0)) { writer.WritePropertyName("derivedFrom"); writer.WriteStartArray(); foreach (ResourceReference val in current.DerivedFrom) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (current.Timing != null) { switch (current.Timing) { case Timing v_Timing: writer.WritePropertyName("timingTiming"); v_Timing.SerializeJson(writer, options); break; case Period v_Period: writer.WritePropertyName("timingPeriod"); v_Period.SerializeJson(writer, options); break; case FhirDateTime v_FhirDateTime: if (v_FhirDateTime != null) { if (!string.IsNullOrEmpty(v_FhirDateTime.Value)) { writer.WriteString("timingDateTime", v_FhirDateTime.Value); } if (v_FhirDateTime.HasExtensions() || (!string.IsNullOrEmpty(v_FhirDateTime.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_timingDateTime", false, v_FhirDateTime.Extension, v_FhirDateTime.ElementId); } } break; } } if (current.RecordedOnElement != null) { if (!string.IsNullOrEmpty(current.RecordedOnElement.Value)) { writer.WriteString("recordedOn", current.RecordedOnElement.Value); } if (current.RecordedOnElement.HasExtensions() || (!string.IsNullOrEmpty(current.RecordedOnElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_recordedOn", false, current.RecordedOnElement.Extension, current.RecordedOnElement.ElementId); } } if (current.Source != null) { writer.WritePropertyName("source"); current.Source.SerializeJson(writer, options); } writer.WritePropertyName("device"); current.Device.SerializeJson(writer, options); if ((current.ReasonCode != null) && (current.ReasonCode.Count != 0)) { writer.WritePropertyName("reasonCode"); writer.WriteStartArray(); foreach (CodeableConcept val in current.ReasonCode) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.ReasonReference != null) && (current.ReasonReference.Count != 0)) { writer.WritePropertyName("reasonReference"); writer.WriteStartArray(); foreach (ResourceReference val in current.ReasonReference) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (current.BodySite != null) { writer.WritePropertyName("bodySite"); current.BodySite.SerializeJson(writer, options); } if ((current.Note != null) && (current.Note.Count != 0)) { writer.WritePropertyName("note"); writer.WriteStartArray(); foreach (Annotation val in current.Note) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (includeStartObject) { writer.WriteEndObject(); } }
/// <summary> /// Deserialize JSON into a FHIR DeviceUseStatement /// </summary> public static void DeserializeJsonProperty(this DeviceUseStatement current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName) { switch (propertyName) { case "identifier": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"DeviceUseStatement 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($"DeviceUseStatement 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 "basedOn": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"DeviceUseStatement error reading 'basedOn' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.BasedOn = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_BasedOn = new Hl7.Fhir.Model.ResourceReference(); v_BasedOn.DeserializeJson(ref reader, options); current.BasedOn.Add(v_BasedOn); if (!reader.Read()) { throw new JsonException($"DeviceUseStatement error reading 'basedOn' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.BasedOn.Count == 0) { current.BasedOn = null; } break; case "status": if (reader.TokenType == JsonTokenType.Null) { current.StatusElement = new Code <Hl7.Fhir.Model.DeviceUseStatement.DeviceUseStatementStatus>(); reader.Skip(); } else { current.StatusElement = new Code <Hl7.Fhir.Model.DeviceUseStatement.DeviceUseStatementStatus>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.DeviceUseStatement.DeviceUseStatementStatus>(reader.GetString())); } break; case "_status": if (current.StatusElement == null) { current.StatusElement = new Code <Hl7.Fhir.Model.DeviceUseStatement.DeviceUseStatementStatus>(); } ((Hl7.Fhir.Model.Element)current.StatusElement).DeserializeJson(ref reader, options); break; case "subject": current.Subject = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Subject).DeserializeJson(ref reader, options); break; case "derivedFrom": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"DeviceUseStatement error reading 'derivedFrom' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.DerivedFrom = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_DerivedFrom = new Hl7.Fhir.Model.ResourceReference(); v_DerivedFrom.DeserializeJson(ref reader, options); current.DerivedFrom.Add(v_DerivedFrom); if (!reader.Read()) { throw new JsonException($"DeviceUseStatement error reading 'derivedFrom' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.DerivedFrom.Count == 0) { current.DerivedFrom = null; } break; case "timingTiming": current.Timing = new Hl7.Fhir.Model.Timing(); ((Hl7.Fhir.Model.Timing)current.Timing).DeserializeJson(ref reader, options); break; case "timingPeriod": current.Timing = new Hl7.Fhir.Model.Period(); ((Hl7.Fhir.Model.Period)current.Timing).DeserializeJson(ref reader, options); break; case "timingDateTime": if (reader.TokenType == JsonTokenType.Null) { current.Timing = new FhirDateTime(); reader.Skip(); } else { current.Timing = new FhirDateTime(reader.GetString()); } break; case "_timingDateTime": if (current.Timing == null) { current.Timing = new FhirDateTime(); } ((Hl7.Fhir.Model.Element)current.Timing).DeserializeJson(ref reader, options); break; case "recordedOn": if (reader.TokenType == JsonTokenType.Null) { current.RecordedOnElement = new FhirDateTime(); reader.Skip(); } else { current.RecordedOnElement = new FhirDateTime(reader.GetString()); } break; case "_recordedOn": if (current.RecordedOnElement == null) { current.RecordedOnElement = new FhirDateTime(); } ((Hl7.Fhir.Model.Element)current.RecordedOnElement).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 "device": current.Device = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Device).DeserializeJson(ref reader, options); break; case "reasonCode": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"DeviceUseStatement error reading 'reasonCode' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.ReasonCode = new List <CodeableConcept>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.CodeableConcept v_ReasonCode = new Hl7.Fhir.Model.CodeableConcept(); v_ReasonCode.DeserializeJson(ref reader, options); current.ReasonCode.Add(v_ReasonCode); if (!reader.Read()) { throw new JsonException($"DeviceUseStatement error reading 'reasonCode' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.ReasonCode.Count == 0) { current.ReasonCode = null; } break; case "reasonReference": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"DeviceUseStatement error reading 'reasonReference' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.ReasonReference = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_ReasonReference = new Hl7.Fhir.Model.ResourceReference(); v_ReasonReference.DeserializeJson(ref reader, options); current.ReasonReference.Add(v_ReasonReference); if (!reader.Read()) { throw new JsonException($"DeviceUseStatement error reading 'reasonReference' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.ReasonReference.Count == 0) { current.ReasonReference = null; } break; case "bodySite": current.BodySite = new Hl7.Fhir.Model.CodeableConcept(); ((Hl7.Fhir.Model.CodeableConcept)current.BodySite).DeserializeJson(ref reader, options); break; case "note": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"DeviceUseStatement error reading 'note' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Note = new List <Annotation>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.Annotation v_Note = new Hl7.Fhir.Model.Annotation(); v_Note.DeserializeJson(ref reader, options); current.Note.Add(v_Note); if (!reader.Read()) { throw new JsonException($"DeviceUseStatement error reading 'note' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Note.Count == 0) { current.Note = null; } break; // Complex: DeviceUseStatement, Export: DeviceUseStatement, Base: DomainResource default: ((Hl7.Fhir.Model.DomainResource)current).DeserializeJsonProperty(ref reader, options, propertyName); break; } }