/// <summary> /// Deserialize JSON into a FHIR Patient#Link /// </summary> public static void DeserializeJson(this Patient.LinkComponent 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($"Patient.LinkComponent >>> Patient#Link.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } reader.Read(); current.DeserializeJsonProperty(ref reader, options, propertyName); } } throw new JsonException($"Patient.LinkComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); }
/// <summary> /// Deserialize JSON into a FHIR Patient#Link /// </summary> public static void DeserializeJsonProperty(this Patient.LinkComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName) { switch (propertyName) { case "other": current.Other = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Other).DeserializeJson(ref reader, options); break; case "type": if (reader.TokenType == JsonTokenType.Null) { current.TypeElement = new Code <Hl7.Fhir.Model.Patient.LinkType>(); reader.Skip(); } else { current.TypeElement = new Code <Hl7.Fhir.Model.Patient.LinkType>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.Patient.LinkType>(reader.GetString())); } break; case "_type": if (current.TypeElement == null) { current.TypeElement = new Code <Hl7.Fhir.Model.Patient.LinkType>(); } ((Hl7.Fhir.Model.Element)current.TypeElement).DeserializeJson(ref reader, options); break; // Complex: link, Export: LinkComponent, Base: BackboneElement default: ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName); break; } }
public void AddALinkElementToStoredPatient() { var reference = new ResourceReference { Display = "Test Care Provider" }; var link = new Patient.LinkComponent { Other = reference, Type = Patient.LinkType.Refer }; _fhirResourceRepository.Patient.Link.Add(link); }
private async Task <Patient> CreatePatientWithLinks(Patient.LinkType linkType, List <Patient> patientsReferencedByLink) { Patient patientWithLink = Samples.GetJsonSample <Patient>("PatientWithMinimalData"); patientWithLink.Link = new List <Patient.LinkComponent>(); foreach (Patient patientReferencedByLink in patientsReferencedByLink) { var link = new Patient.LinkComponent { Type = linkType, Other = new ResourceReference($"Patient/{patientReferencedByLink.Id}"), }; patientWithLink.Link.Add(link); } return(await TestFhirClient.CreateAsync(patientWithLink)); }
/// <summary> /// Serialize a FHIR Patient#Link into JSON /// </summary> public static void SerializeJson(this Patient.LinkComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } // Component: Patient#Link, Export: LinkComponent, Base: BackboneElement (BackboneElement) ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false); writer.WritePropertyName("other"); current.Other.SerializeJson(writer, options); writer.WriteString("type", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.TypeElement.Value)); if (includeStartObject) { writer.WriteEndObject(); } }