/// <summary> /// Deserialize JSON into a FHIR MessageHeader#MessageDestination /// </summary> public static void DeserializeJsonProperty(this MessageHeader.MessageDestinationComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName) { switch (propertyName) { case "name": if (reader.TokenType == JsonTokenType.Null) { current.NameElement = new FhirString(); reader.Skip(); } else { current.NameElement = new FhirString(reader.GetString()); } break; case "_name": if (current.NameElement == null) { current.NameElement = new FhirString(); } ((Hl7.Fhir.Model.Element)current.NameElement).DeserializeJson(ref reader, options); break; case "target": current.Target = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Target).DeserializeJson(ref reader, options); break; case "endpoint": if (reader.TokenType == JsonTokenType.Null) { current.EndpointElement = new FhirUrl(); reader.Skip(); } else { current.EndpointElement = new FhirUrl(reader.GetString()); } break; case "_endpoint": if (current.EndpointElement == null) { current.EndpointElement = new FhirUrl(); } ((Hl7.Fhir.Model.Element)current.EndpointElement).DeserializeJson(ref reader, options); break; case "receiver": current.Receiver = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Receiver).DeserializeJson(ref reader, options); break; // Complex: destination, Export: MessageDestinationComponent, Base: BackboneElement default: ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName); break; } }
/// <summary> /// Deserialize JSON into a FHIR MessageHeader#MessageDestination /// </summary> public static void DeserializeJson(this MessageHeader.MessageDestinationComponent 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($"MessageHeader.MessageDestinationComponent >>> MessageHeader#MessageDestination.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } reader.Read(); current.DeserializeJsonProperty(ref reader, options, propertyName); } } throw new JsonException($"MessageHeader.MessageDestinationComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); }
/// <summary>Constructor that creates a new, empty message for the specified message type.</summary> protected BaseMessage(String messageType) { // Start with a Bundle. MessageBundle = new Bundle(); MessageBundle.Id = Guid.NewGuid().ToString(); MessageBundle.Type = Bundle.BundleType.Message; MessageBundle.Timestamp = DateTime.Now; // Start with a MessageHeader. Header = new MessageHeader(); Header.Id = Guid.NewGuid().ToString(); Header.Event = new FhirUri(messageType); MessageHeader.MessageDestinationComponent dest = new MessageHeader.MessageDestinationComponent(); dest.Endpoint = "http://nchs.cdc.gov/vrdr_submission"; Header.Destination.Add(dest); MessageHeader.MessageSourceComponent src = new MessageHeader.MessageSourceComponent(); Header.Source = src; MessageBundle.AddResourceEntry(Header, "urn:uuid:" + Header.Id); Record = new Parameters(); Record.Id = Guid.NewGuid().ToString(); MessageBundle.AddResourceEntry(this.Record, "urn:uuid:" + this.Record.Id); Header.Focus.Add(new ResourceReference("urn:uuid:" + this.Record.Id)); }
/// <summary> /// Serialize a FHIR MessageHeader#MessageDestination into JSON /// </summary> public static void SerializeJson(this MessageHeader.MessageDestinationComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } // Component: MessageHeader#MessageDestination, Export: MessageDestinationComponent, Base: BackboneElement (BackboneElement) ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false); if (current.NameElement != null) { if (!string.IsNullOrEmpty(current.NameElement.Value)) { writer.WriteString("name", current.NameElement.Value); } if (current.NameElement.HasExtensions() || (!string.IsNullOrEmpty(current.NameElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_name", false, current.NameElement.Extension, current.NameElement.ElementId); } } if (current.Target != null) { writer.WritePropertyName("target"); current.Target.SerializeJson(writer, options); } writer.WriteString("endpoint", current.EndpointElement.Value); if (current.Receiver != null) { writer.WritePropertyName("receiver"); current.Receiver.SerializeJson(writer, options); } if (includeStartObject) { writer.WriteEndObject(); } }