/// <summary> /// Deserialize JSON into a FHIR ResearchStudy /// </summary> public static void DeserializeJson(this ResearchStudy 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($"ResearchStudy >>> ResearchStudy.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } reader.Read(); current.DeserializeJsonProperty(ref reader, options, propertyName); } } throw new JsonException($"ResearchStudy: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); }
/// <summary> /// Serialize a FHIR ResearchStudy into JSON /// </summary> public static void SerializeJson(this ResearchStudy current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } writer.WriteString("resourceType", "ResearchStudy"); // Complex: ResearchStudy, Export: ResearchStudy, 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.TitleElement != null) { if (!string.IsNullOrEmpty(current.TitleElement.Value)) { writer.WriteString("title", current.TitleElement.Value); } if (current.TitleElement.HasExtensions() || (!string.IsNullOrEmpty(current.TitleElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_title", false, current.TitleElement.Extension, current.TitleElement.ElementId); } } if ((current.Protocol != null) && (current.Protocol.Count != 0)) { writer.WritePropertyName("protocol"); writer.WriteStartArray(); foreach (ResourceReference val in current.Protocol) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.PartOf != null) && (current.PartOf.Count != 0)) { writer.WritePropertyName("partOf"); writer.WriteStartArray(); foreach (ResourceReference val in current.PartOf) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } writer.WriteString("status", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.StatusElement.Value)); if (current.PrimaryPurposeType != null) { writer.WritePropertyName("primaryPurposeType"); current.PrimaryPurposeType.SerializeJson(writer, options); } if (current.Phase != null) { writer.WritePropertyName("phase"); current.Phase.SerializeJson(writer, options); } if ((current.Category != null) && (current.Category.Count != 0)) { writer.WritePropertyName("category"); writer.WriteStartArray(); foreach (CodeableConcept val in current.Category) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.Focus != null) && (current.Focus.Count != 0)) { writer.WritePropertyName("focus"); writer.WriteStartArray(); foreach (CodeableConcept val in current.Focus) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.Condition != null) && (current.Condition.Count != 0)) { writer.WritePropertyName("condition"); writer.WriteStartArray(); foreach (CodeableConcept val in current.Condition) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.Contact != null) && (current.Contact.Count != 0)) { writer.WritePropertyName("contact"); writer.WriteStartArray(); foreach (ContactDetail val in current.Contact) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.RelatedArtifact != null) && (current.RelatedArtifact.Count != 0)) { writer.WritePropertyName("relatedArtifact"); writer.WriteStartArray(); foreach (RelatedArtifact val in current.RelatedArtifact) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.Keyword != null) && (current.Keyword.Count != 0)) { writer.WritePropertyName("keyword"); writer.WriteStartArray(); foreach (CodeableConcept val in current.Keyword) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.Location != null) && (current.Location.Count != 0)) { writer.WritePropertyName("location"); writer.WriteStartArray(); foreach (CodeableConcept val in current.Location) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (current.Description != null) { if (!string.IsNullOrEmpty(current.Description.Value)) { writer.WriteString("description", current.Description.Value); } if (current.Description.HasExtensions() || (!string.IsNullOrEmpty(current.Description.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_description", false, current.Description.Extension, current.Description.ElementId); } } if ((current.Enrollment != null) && (current.Enrollment.Count != 0)) { writer.WritePropertyName("enrollment"); writer.WriteStartArray(); foreach (ResourceReference val in current.Enrollment) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (current.Period != null) { writer.WritePropertyName("period"); current.Period.SerializeJson(writer, options); } if (current.Sponsor != null) { writer.WritePropertyName("sponsor"); current.Sponsor.SerializeJson(writer, options); } if (current.PrincipalInvestigator != null) { writer.WritePropertyName("principalInvestigator"); current.PrincipalInvestigator.SerializeJson(writer, options); } if ((current.Site != null) && (current.Site.Count != 0)) { writer.WritePropertyName("site"); writer.WriteStartArray(); foreach (ResourceReference val in current.Site) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (current.ReasonStopped != null) { writer.WritePropertyName("reasonStopped"); current.ReasonStopped.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 ((current.Arm != null) && (current.Arm.Count != 0)) { writer.WritePropertyName("arm"); writer.WriteStartArray(); foreach (ResearchStudy.ArmComponent val in current.Arm) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.Objective != null) && (current.Objective.Count != 0)) { writer.WritePropertyName("objective"); writer.WriteStartArray(); foreach (ResearchStudy.ObjectiveComponent val in current.Objective) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (includeStartObject) { writer.WriteEndObject(); } }
/// <summary> /// Deserialize JSON into a FHIR ResearchStudy /// </summary> public static void DeserializeJsonProperty(this ResearchStudy current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName) { switch (propertyName) { case "identifier": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy 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($"ResearchStudy 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 "title": if (reader.TokenType == JsonTokenType.Null) { current.TitleElement = new FhirString(); reader.Skip(); } else { current.TitleElement = new FhirString(reader.GetString()); } break; case "_title": if (current.TitleElement == null) { current.TitleElement = new FhirString(); } ((Hl7.Fhir.Model.Element)current.TitleElement).DeserializeJson(ref reader, options); break; case "protocol": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy error reading 'protocol' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Protocol = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_Protocol = new Hl7.Fhir.Model.ResourceReference(); v_Protocol.DeserializeJson(ref reader, options); current.Protocol.Add(v_Protocol); if (!reader.Read()) { throw new JsonException($"ResearchStudy error reading 'protocol' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Protocol.Count == 0) { current.Protocol = null; } break; case "partOf": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy error reading 'partOf' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.PartOf = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_PartOf = new Hl7.Fhir.Model.ResourceReference(); v_PartOf.DeserializeJson(ref reader, options); current.PartOf.Add(v_PartOf); if (!reader.Read()) { throw new JsonException($"ResearchStudy error reading 'partOf' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.PartOf.Count == 0) { current.PartOf = null; } break; case "status": if (reader.TokenType == JsonTokenType.Null) { current.StatusElement = new Code <Hl7.Fhir.Model.ResearchStudy.ResearchStudyStatus>(); reader.Skip(); } else { current.StatusElement = new Code <Hl7.Fhir.Model.ResearchStudy.ResearchStudyStatus>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.ResearchStudy.ResearchStudyStatus>(reader.GetString())); } break; case "_status": if (current.StatusElement == null) { current.StatusElement = new Code <Hl7.Fhir.Model.ResearchStudy.ResearchStudyStatus>(); } ((Hl7.Fhir.Model.Element)current.StatusElement).DeserializeJson(ref reader, options); break; case "primaryPurposeType": current.PrimaryPurposeType = new Hl7.Fhir.Model.CodeableConcept(); ((Hl7.Fhir.Model.CodeableConcept)current.PrimaryPurposeType).DeserializeJson(ref reader, options); break; case "phase": current.Phase = new Hl7.Fhir.Model.CodeableConcept(); ((Hl7.Fhir.Model.CodeableConcept)current.Phase).DeserializeJson(ref reader, options); break; case "category": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy error reading 'category' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Category = new List <CodeableConcept>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.CodeableConcept v_Category = new Hl7.Fhir.Model.CodeableConcept(); v_Category.DeserializeJson(ref reader, options); current.Category.Add(v_Category); if (!reader.Read()) { throw new JsonException($"ResearchStudy error reading 'category' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Category.Count == 0) { current.Category = null; } break; case "focus": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy error reading 'focus' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Focus = new List <CodeableConcept>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.CodeableConcept v_Focus = new Hl7.Fhir.Model.CodeableConcept(); v_Focus.DeserializeJson(ref reader, options); current.Focus.Add(v_Focus); if (!reader.Read()) { throw new JsonException($"ResearchStudy error reading 'focus' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Focus.Count == 0) { current.Focus = null; } break; case "condition": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy error reading 'condition' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Condition = new List <CodeableConcept>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.CodeableConcept v_Condition = new Hl7.Fhir.Model.CodeableConcept(); v_Condition.DeserializeJson(ref reader, options); current.Condition.Add(v_Condition); if (!reader.Read()) { throw new JsonException($"ResearchStudy error reading 'condition' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Condition.Count == 0) { current.Condition = null; } break; case "contact": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy error reading 'contact' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Contact = new List <ContactDetail>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ContactDetail v_Contact = new Hl7.Fhir.Model.ContactDetail(); v_Contact.DeserializeJson(ref reader, options); current.Contact.Add(v_Contact); if (!reader.Read()) { throw new JsonException($"ResearchStudy error reading 'contact' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Contact.Count == 0) { current.Contact = null; } break; case "relatedArtifact": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy error reading 'relatedArtifact' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.RelatedArtifact = new List <RelatedArtifact>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.RelatedArtifact v_RelatedArtifact = new Hl7.Fhir.Model.RelatedArtifact(); v_RelatedArtifact.DeserializeJson(ref reader, options); current.RelatedArtifact.Add(v_RelatedArtifact); if (!reader.Read()) { throw new JsonException($"ResearchStudy error reading 'relatedArtifact' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.RelatedArtifact.Count == 0) { current.RelatedArtifact = null; } break; case "keyword": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy error reading 'keyword' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Keyword = new List <CodeableConcept>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.CodeableConcept v_Keyword = new Hl7.Fhir.Model.CodeableConcept(); v_Keyword.DeserializeJson(ref reader, options); current.Keyword.Add(v_Keyword); if (!reader.Read()) { throw new JsonException($"ResearchStudy error reading 'keyword' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Keyword.Count == 0) { current.Keyword = null; } break; case "location": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy error reading 'location' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Location = new List <CodeableConcept>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.CodeableConcept v_Location = new Hl7.Fhir.Model.CodeableConcept(); v_Location.DeserializeJson(ref reader, options); current.Location.Add(v_Location); if (!reader.Read()) { throw new JsonException($"ResearchStudy error reading 'location' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Location.Count == 0) { current.Location = null; } break; case "description": if (reader.TokenType == JsonTokenType.Null) { current.Description = new Markdown(); reader.Skip(); } else { current.Description = new Markdown(reader.GetString()); } break; case "_description": if (current.Description == null) { current.Description = new Markdown(); } ((Hl7.Fhir.Model.Element)current.Description).DeserializeJson(ref reader, options); break; case "enrollment": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy error reading 'enrollment' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Enrollment = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_Enrollment = new Hl7.Fhir.Model.ResourceReference(); v_Enrollment.DeserializeJson(ref reader, options); current.Enrollment.Add(v_Enrollment); if (!reader.Read()) { throw new JsonException($"ResearchStudy error reading 'enrollment' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Enrollment.Count == 0) { current.Enrollment = null; } break; case "period": current.Period = new Hl7.Fhir.Model.Period(); ((Hl7.Fhir.Model.Period)current.Period).DeserializeJson(ref reader, options); break; case "sponsor": current.Sponsor = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Sponsor).DeserializeJson(ref reader, options); break; case "principalInvestigator": current.PrincipalInvestigator = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.PrincipalInvestigator).DeserializeJson(ref reader, options); break; case "site": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy error reading 'site' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Site = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_Site = new Hl7.Fhir.Model.ResourceReference(); v_Site.DeserializeJson(ref reader, options); current.Site.Add(v_Site); if (!reader.Read()) { throw new JsonException($"ResearchStudy error reading 'site' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Site.Count == 0) { current.Site = null; } break; case "reasonStopped": current.ReasonStopped = new Hl7.Fhir.Model.CodeableConcept(); ((Hl7.Fhir.Model.CodeableConcept)current.ReasonStopped).DeserializeJson(ref reader, options); break; case "note": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy 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($"ResearchStudy 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; case "arm": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy error reading 'arm' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Arm = new List <ResearchStudy.ArmComponent>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResearchStudy.ArmComponent v_Arm = new Hl7.Fhir.Model.ResearchStudy.ArmComponent(); v_Arm.DeserializeJson(ref reader, options); current.Arm.Add(v_Arm); if (!reader.Read()) { throw new JsonException($"ResearchStudy error reading 'arm' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Arm.Count == 0) { current.Arm = null; } break; case "objective": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchStudy error reading 'objective' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Objective = new List <ResearchStudy.ObjectiveComponent>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResearchStudy.ObjectiveComponent v_Objective = new Hl7.Fhir.Model.ResearchStudy.ObjectiveComponent(); v_Objective.DeserializeJson(ref reader, options); current.Objective.Add(v_Objective); if (!reader.Read()) { throw new JsonException($"ResearchStudy error reading 'objective' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Objective.Count == 0) { current.Objective = null; } break; // Complex: ResearchStudy, Export: ResearchStudy, Base: DomainResource default: ((Hl7.Fhir.Model.DomainResource)current).DeserializeJsonProperty(ref reader, options, propertyName); break; } }