/// <summary> /// Deserialize JSON into a FHIR ResearchSubject /// </summary> public static void DeserializeJson(this ResearchSubject 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($"ResearchSubject >>> ResearchSubject.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } reader.Read(); current.DeserializeJsonProperty(ref reader, options, propertyName); } } throw new JsonException($"ResearchSubject: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); }
public static ResearchSubject CreateObject() { var subject = new ResearchSubject(); subject.Id = "ST01"; var consent = new Consent(); subject.Period = new Period { Start = "2018/01/02" }; return(subject); }
public void ObsReferCast_Test() { double c = 1; Observation obs = new Observation(); obs.Subject = new ResourceReference(); obs.Value = new Quantity(); ResearchSubject s = new ResearchSubject(); // (obs.Value as SimpleQuantity).Value = c; }
/// <summary> /// Serialize a FHIR ResearchSubject into JSON /// </summary> public static void SerializeJson(this ResearchSubject current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } writer.WriteString("resourceType", "ResearchSubject"); // Complex: ResearchSubject, Export: ResearchSubject, 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.WriteString("status", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.StatusElement.Value)); if (current.Period != null) { writer.WritePropertyName("period"); current.Period.SerializeJson(writer, options); } writer.WritePropertyName("study"); current.Study.SerializeJson(writer, options); writer.WritePropertyName("individual"); current.Individual.SerializeJson(writer, options); if (current.AssignedArmElement != null) { if (!string.IsNullOrEmpty(current.AssignedArmElement.Value)) { writer.WriteString("assignedArm", current.AssignedArmElement.Value); } if (current.AssignedArmElement.HasExtensions() || (!string.IsNullOrEmpty(current.AssignedArmElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_assignedArm", false, current.AssignedArmElement.Extension, current.AssignedArmElement.ElementId); } } if (current.ActualArmElement != null) { if (!string.IsNullOrEmpty(current.ActualArmElement.Value)) { writer.WriteString("actualArm", current.ActualArmElement.Value); } if (current.ActualArmElement.HasExtensions() || (!string.IsNullOrEmpty(current.ActualArmElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_actualArm", false, current.ActualArmElement.Extension, current.ActualArmElement.ElementId); } } if (current.Consent != null) { writer.WritePropertyName("consent"); current.Consent.SerializeJson(writer, options); } if (includeStartObject) { writer.WriteEndObject(); } }
/// <summary> /// Deserialize JSON into a FHIR ResearchSubject /// </summary> public static void DeserializeJsonProperty(this ResearchSubject current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName) { switch (propertyName) { case "identifier": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ResearchSubject 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($"ResearchSubject 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 "status": if (reader.TokenType == JsonTokenType.Null) { current.StatusElement = new Code <Hl7.Fhir.Model.ResearchSubject.ResearchSubjectStatus>(); reader.Skip(); } else { current.StatusElement = new Code <Hl7.Fhir.Model.ResearchSubject.ResearchSubjectStatus>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.ResearchSubject.ResearchSubjectStatus>(reader.GetString())); } break; case "_status": if (current.StatusElement == null) { current.StatusElement = new Code <Hl7.Fhir.Model.ResearchSubject.ResearchSubjectStatus>(); } ((Hl7.Fhir.Model.Element)current.StatusElement).DeserializeJson(ref reader, options); break; case "period": current.Period = new Hl7.Fhir.Model.Period(); ((Hl7.Fhir.Model.Period)current.Period).DeserializeJson(ref reader, options); break; case "study": current.Study = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Study).DeserializeJson(ref reader, options); break; case "individual": current.Individual = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Individual).DeserializeJson(ref reader, options); break; case "assignedArm": if (reader.TokenType == JsonTokenType.Null) { current.AssignedArmElement = new FhirString(); reader.Skip(); } else { current.AssignedArmElement = new FhirString(reader.GetString()); } break; case "_assignedArm": if (current.AssignedArmElement == null) { current.AssignedArmElement = new FhirString(); } ((Hl7.Fhir.Model.Element)current.AssignedArmElement).DeserializeJson(ref reader, options); break; case "actualArm": if (reader.TokenType == JsonTokenType.Null) { current.ActualArmElement = new FhirString(); reader.Skip(); } else { current.ActualArmElement = new FhirString(reader.GetString()); } break; case "_actualArm": if (current.ActualArmElement == null) { current.ActualArmElement = new FhirString(); } ((Hl7.Fhir.Model.Element)current.ActualArmElement).DeserializeJson(ref reader, options); break; case "consent": current.Consent = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Consent).DeserializeJson(ref reader, options); break; // Complex: ResearchSubject, Export: ResearchSubject, Base: DomainResource default: ((Hl7.Fhir.Model.DomainResource)current).DeserializeJsonProperty(ref reader, options, propertyName); break; } }