/// <summary> /// Deserialize JSON into a FHIR ClinicalImpression /// </summary> public static void DeserializeJson(this ClinicalImpression 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($"ClinicalImpression >>> ClinicalImpression.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } reader.Read(); current.DeserializeJsonProperty(ref reader, options, propertyName); } } throw new JsonException($"ClinicalImpression: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); }
public void TestVisitDataChoiceProperty() { _expectedActionCounter = 1; ClinicalImpression ci = new ClinicalImpression(); ci.Code = new CodeableConcept("test.system", "test.code"); _sut.VisitByPath(ci, ob => { _actualActionCounter++; if (ob.ToString() != "test.system") { Assert.Fail(); } }, "code.coding.system"); }
/// <summary> /// Serialize a FHIR ClinicalImpression into JSON /// </summary> public static void SerializeJson(this ClinicalImpression current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } writer.WriteString("resourceType", "ClinicalImpression"); // Complex: ClinicalImpression, Export: ClinicalImpression, 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.StatusReason != null) { writer.WritePropertyName("statusReason"); current.StatusReason.SerializeJson(writer, options); } if (current.Code != null) { writer.WritePropertyName("code"); current.Code.SerializeJson(writer, options); } if (current.DescriptionElement != null) { if (!string.IsNullOrEmpty(current.DescriptionElement.Value)) { writer.WriteString("description", current.DescriptionElement.Value); } if (current.DescriptionElement.HasExtensions() || (!string.IsNullOrEmpty(current.DescriptionElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_description", false, current.DescriptionElement.Extension, current.DescriptionElement.ElementId); } } writer.WritePropertyName("subject"); current.Subject.SerializeJson(writer, options); if (current.Encounter != null) { writer.WritePropertyName("encounter"); current.Encounter.SerializeJson(writer, options); } if (current.Effective != null) { switch (current.Effective) { case FhirDateTime v_FhirDateTime: if (v_FhirDateTime != null) { if (!string.IsNullOrEmpty(v_FhirDateTime.Value)) { writer.WriteString("effectiveDateTime", v_FhirDateTime.Value); } if (v_FhirDateTime.HasExtensions() || (!string.IsNullOrEmpty(v_FhirDateTime.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_effectiveDateTime", false, v_FhirDateTime.Extension, v_FhirDateTime.ElementId); } } break; case Period v_Period: writer.WritePropertyName("effectivePeriod"); v_Period.SerializeJson(writer, options); break; } } if (current.DateElement != null) { if (!string.IsNullOrEmpty(current.DateElement.Value)) { writer.WriteString("date", current.DateElement.Value); } if (current.DateElement.HasExtensions() || (!string.IsNullOrEmpty(current.DateElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_date", false, current.DateElement.Extension, current.DateElement.ElementId); } } if (current.Assessor != null) { writer.WritePropertyName("assessor"); current.Assessor.SerializeJson(writer, options); } if (current.Previous != null) { writer.WritePropertyName("previous"); current.Previous.SerializeJson(writer, options); } if ((current.Problem != null) && (current.Problem.Count != 0)) { writer.WritePropertyName("problem"); writer.WriteStartArray(); foreach (ResourceReference val in current.Problem) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.Investigation != null) && (current.Investigation.Count != 0)) { writer.WritePropertyName("investigation"); writer.WriteStartArray(); foreach (ClinicalImpression.InvestigationComponent val in current.Investigation) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.ProtocolElement != null) && (current.ProtocolElement.Count != 0)) { int valueCount = 0; int extensionCount = 0; foreach (FhirUri val in current.ProtocolElement) { if (!string.IsNullOrEmpty(val.Value)) { valueCount++; } if (val.HasExtensions()) { extensionCount++; } } if (valueCount > 0) { writer.WritePropertyName("protocol"); writer.WriteStartArray(); foreach (FhirUri val in current.ProtocolElement) { if (string.IsNullOrEmpty(val.Value)) { writer.WriteNullValue(); } else { writer.WriteStringValue(val.Value); } } writer.WriteEndArray(); } if (extensionCount > 0) { writer.WritePropertyName("_protocol"); writer.WriteStartArray(); foreach (FhirUri val in current.ProtocolElement) { if (val.HasExtensions() || (!string.IsNullOrEmpty(val.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, string.Empty, true, val.Extension, val.ElementId); } else { writer.WriteNullValue(); } } writer.WriteEndArray(); } } if (current.SummaryElement != null) { if (!string.IsNullOrEmpty(current.SummaryElement.Value)) { writer.WriteString("summary", current.SummaryElement.Value); } if (current.SummaryElement.HasExtensions() || (!string.IsNullOrEmpty(current.SummaryElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_summary", false, current.SummaryElement.Extension, current.SummaryElement.ElementId); } } if ((current.Finding != null) && (current.Finding.Count != 0)) { writer.WritePropertyName("finding"); writer.WriteStartArray(); foreach (ClinicalImpression.FindingComponent val in current.Finding) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.PrognosisCodeableConcept != null) && (current.PrognosisCodeableConcept.Count != 0)) { writer.WritePropertyName("prognosisCodeableConcept"); writer.WriteStartArray(); foreach (CodeableConcept val in current.PrognosisCodeableConcept) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.PrognosisReference != null) && (current.PrognosisReference.Count != 0)) { writer.WritePropertyName("prognosisReference"); writer.WriteStartArray(); foreach (ResourceReference val in current.PrognosisReference) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.SupportingInfo != null) && (current.SupportingInfo.Count != 0)) { writer.WritePropertyName("supportingInfo"); writer.WriteStartArray(); foreach (ResourceReference val in current.SupportingInfo) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } 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 ClinicalImpression /// </summary> public static void DeserializeJsonProperty(this ClinicalImpression current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName) { switch (propertyName) { case "identifier": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ClinicalImpression 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($"ClinicalImpression 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.ClinicalImpression.ClinicalImpressionStatus>(); reader.Skip(); } else { current.StatusElement = new Code <Hl7.Fhir.Model.ClinicalImpression.ClinicalImpressionStatus>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.ClinicalImpression.ClinicalImpressionStatus>(reader.GetString())); } break; case "_status": if (current.StatusElement == null) { current.StatusElement = new Code <Hl7.Fhir.Model.ClinicalImpression.ClinicalImpressionStatus>(); } ((Hl7.Fhir.Model.Element)current.StatusElement).DeserializeJson(ref reader, options); break; case "statusReason": current.StatusReason = new Hl7.Fhir.Model.CodeableConcept(); ((Hl7.Fhir.Model.CodeableConcept)current.StatusReason).DeserializeJson(ref reader, options); break; case "code": current.Code = new Hl7.Fhir.Model.CodeableConcept(); ((Hl7.Fhir.Model.CodeableConcept)current.Code).DeserializeJson(ref reader, options); break; case "description": if (reader.TokenType == JsonTokenType.Null) { current.DescriptionElement = new FhirString(); reader.Skip(); } else { current.DescriptionElement = new FhirString(reader.GetString()); } break; case "_description": if (current.DescriptionElement == null) { current.DescriptionElement = new FhirString(); } ((Hl7.Fhir.Model.Element)current.DescriptionElement).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 "encounter": current.Encounter = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Encounter).DeserializeJson(ref reader, options); break; case "effectiveDateTime": if (reader.TokenType == JsonTokenType.Null) { current.Effective = new FhirDateTime(); reader.Skip(); } else { current.Effective = new FhirDateTime(reader.GetString()); } break; case "_effectiveDateTime": if (current.Effective == null) { current.Effective = new FhirDateTime(); } ((Hl7.Fhir.Model.Element)current.Effective).DeserializeJson(ref reader, options); break; case "effectivePeriod": current.Effective = new Hl7.Fhir.Model.Period(); ((Hl7.Fhir.Model.Period)current.Effective).DeserializeJson(ref reader, options); break; case "date": if (reader.TokenType == JsonTokenType.Null) { current.DateElement = new FhirDateTime(); reader.Skip(); } else { current.DateElement = new FhirDateTime(reader.GetString()); } break; case "_date": if (current.DateElement == null) { current.DateElement = new FhirDateTime(); } ((Hl7.Fhir.Model.Element)current.DateElement).DeserializeJson(ref reader, options); break; case "assessor": current.Assessor = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Assessor).DeserializeJson(ref reader, options); break; case "previous": current.Previous = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Previous).DeserializeJson(ref reader, options); break; case "problem": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ClinicalImpression error reading 'problem' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Problem = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_Problem = new Hl7.Fhir.Model.ResourceReference(); v_Problem.DeserializeJson(ref reader, options); current.Problem.Add(v_Problem); if (!reader.Read()) { throw new JsonException($"ClinicalImpression error reading 'problem' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Problem.Count == 0) { current.Problem = null; } break; case "investigation": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ClinicalImpression error reading 'investigation' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Investigation = new List <ClinicalImpression.InvestigationComponent>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ClinicalImpression.InvestigationComponent v_Investigation = new Hl7.Fhir.Model.ClinicalImpression.InvestigationComponent(); v_Investigation.DeserializeJson(ref reader, options); current.Investigation.Add(v_Investigation); if (!reader.Read()) { throw new JsonException($"ClinicalImpression error reading 'investigation' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Investigation.Count == 0) { current.Investigation = null; } break; case "protocol": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ClinicalImpression error reading 'protocol' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.ProtocolElement = new List <FhirUri>(); while (reader.TokenType != JsonTokenType.EndArray) { if (reader.TokenType == JsonTokenType.Null) { current.ProtocolElement.Add(new FhirUri()); reader.Skip(); } else { current.ProtocolElement.Add(new FhirUri(reader.GetString())); } if (!reader.Read()) { throw new JsonException($"ClinicalImpression error reading 'protocol' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.ProtocolElement.Count == 0) { current.ProtocolElement = null; } break; case "_protocol": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ClinicalImpression error reading 'protocol' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } int i_protocol = 0; while (reader.TokenType != JsonTokenType.EndArray) { if (i_protocol >= current.ProtocolElement.Count) { current.ProtocolElement.Add(new FhirUri()); } if (reader.TokenType == JsonTokenType.Null) { reader.Skip(); } else { ((Hl7.Fhir.Model.Element)current.ProtocolElement[i_protocol++]).DeserializeJson(ref reader, options); } if (!reader.Read()) { throw new JsonException($"ClinicalImpression error reading 'protocol' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } break; case "summary": if (reader.TokenType == JsonTokenType.Null) { current.SummaryElement = new FhirString(); reader.Skip(); } else { current.SummaryElement = new FhirString(reader.GetString()); } break; case "_summary": if (current.SummaryElement == null) { current.SummaryElement = new FhirString(); } ((Hl7.Fhir.Model.Element)current.SummaryElement).DeserializeJson(ref reader, options); break; case "finding": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ClinicalImpression error reading 'finding' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Finding = new List <ClinicalImpression.FindingComponent>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ClinicalImpression.FindingComponent v_Finding = new Hl7.Fhir.Model.ClinicalImpression.FindingComponent(); v_Finding.DeserializeJson(ref reader, options); current.Finding.Add(v_Finding); if (!reader.Read()) { throw new JsonException($"ClinicalImpression error reading 'finding' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Finding.Count == 0) { current.Finding = null; } break; case "prognosisCodeableConcept": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ClinicalImpression error reading 'prognosisCodeableConcept' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.PrognosisCodeableConcept = new List <CodeableConcept>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.CodeableConcept v_PrognosisCodeableConcept = new Hl7.Fhir.Model.CodeableConcept(); v_PrognosisCodeableConcept.DeserializeJson(ref reader, options); current.PrognosisCodeableConcept.Add(v_PrognosisCodeableConcept); if (!reader.Read()) { throw new JsonException($"ClinicalImpression error reading 'prognosisCodeableConcept' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.PrognosisCodeableConcept.Count == 0) { current.PrognosisCodeableConcept = null; } break; case "prognosisReference": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ClinicalImpression error reading 'prognosisReference' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.PrognosisReference = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_PrognosisReference = new Hl7.Fhir.Model.ResourceReference(); v_PrognosisReference.DeserializeJson(ref reader, options); current.PrognosisReference.Add(v_PrognosisReference); if (!reader.Read()) { throw new JsonException($"ClinicalImpression error reading 'prognosisReference' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.PrognosisReference.Count == 0) { current.PrognosisReference = null; } break; case "supportingInfo": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ClinicalImpression error reading 'supportingInfo' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.SupportingInfo = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_SupportingInfo = new Hl7.Fhir.Model.ResourceReference(); v_SupportingInfo.DeserializeJson(ref reader, options); current.SupportingInfo.Add(v_SupportingInfo); if (!reader.Read()) { throw new JsonException($"ClinicalImpression error reading 'supportingInfo' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.SupportingInfo.Count == 0) { current.SupportingInfo = null; } break; case "note": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"ClinicalImpression 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($"ClinicalImpression 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: ClinicalImpression, Export: ClinicalImpression, Base: DomainResource default: ((Hl7.Fhir.Model.DomainResource)current).DeserializeJsonProperty(ref reader, options, propertyName); break; } }
public ClinicalImpressionBase(BreastRadiologyDocument doc, ClinicalImpression resource) : base() { this.Init(doc, resource); }