public void TestUriReassignments() { Patient p = new Patient(); p.Link = new List<ResourceReference>() { new ResourceReference { Type = "patient", Reference = "patient/@10" } }; p.Provider = new ResourceReference() { Type = "organization", Reference = "http://outside.com/fhir/organization/@100" }; p.Contact = new List<Patient.ContactComponent>() { new Patient.ContactComponent() { Organization = new ResourceReference() { Type = "organization", Reference = "http://hl7.org/fhir/organization/@200" } } }; p.Photo = new List<Attachment>() { new Attachment() { Url = new Uri("media/@300", UriKind.Relative) }, new Attachment() { Url = new Uri("#containedPhoto", UriKind.Relative) }, new Attachment() { Url = new Uri("http://www.nu.nl/fotos/1.jpg", UriKind.Absolute) } }; var pic300 = new Media(); pic300.Content = new Attachment() { Url = new Uri("http://hl7.org/fhir/binary/@300") }; var importer = new ResourceImporter(new Uri("http://hl7.org/fhir")); importer.QueueNewResourceEntry("patient", "1", p); importer.QueueNewResourceEntry("patient", "10", new Patient()); importer.QueueNewResourceEntry(new Uri("http://outside.com/fhir/organization/@100"), new Organization()); importer.QueueNewResourceEntry("media", "300", pic300); var result = importer.ImportQueued(); var p1 = (ResourceEntry<Patient>)result.First(); Assert.AreEqual("patient/@10", p1.Resource.Link[0].Reference); Assert.AreEqual("organization/@11", p1.Resource.Provider.Reference); Assert.AreEqual("organization/@200", p1.Resource.Contact.First().Organization.Reference); Assert.AreEqual("media/@300", p1.Resource.Photo.First().Url.ToString()); Assert.AreEqual("#containedPhoto", p1.Resource.Photo.Skip(1).First().Url.ToString()); Assert.AreEqual("http://www.nu.nl/fotos/1.jpg", p1.Resource.Photo.Skip(2).First().Url.ToString()); Assert.AreEqual("binary/@300", pic300.Content.Url.ToString()); }
public static void SerializeMedia(Hl7.Fhir.Model.Media value, IFhirWriter writer, bool summary) { writer.WriteStartRootObject("Media"); writer.WriteStartComplexContent(); // Serialize element _id if (value.LocalIdElement != null) { writer.WritePrimitiveContents("_id", value.LocalIdElement, XmlSerializationHint.Attribute); } // Serialize element extension if (value.Extension != null && !summary && value.Extension.Count > 0) { writer.WriteStartArrayElement("extension"); foreach (var item in value.Extension) { writer.WriteStartArrayMember("extension"); ExtensionSerializer.SerializeExtension(item, writer, summary); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element language if (value.LanguageElement != null && !summary) { writer.WriteStartElement("language"); CodeSerializer.SerializeCode(value.LanguageElement, writer, summary); writer.WriteEndElement(); } // Serialize element text if (value.Text != null && !summary) { writer.WriteStartElement("text"); NarrativeSerializer.SerializeNarrative(value.Text, writer, summary); writer.WriteEndElement(); } // Serialize element contained if (value.Contained != null && !summary && value.Contained.Count > 0) { writer.WriteStartArrayElement("contained"); foreach (var item in value.Contained) { writer.WriteStartArrayMember("contained"); FhirSerializer.SerializeResource(item, writer, summary); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element type if (value.TypeElement != null) { writer.WriteStartElement("type"); CodeSerializer.SerializeCode <Hl7.Fhir.Model.Media.MediaType>(value.TypeElement, writer, summary); writer.WriteEndElement(); } // Serialize element subtype if (value.Subtype != null) { writer.WriteStartElement("subtype"); CodeableConceptSerializer.SerializeCodeableConcept(value.Subtype, writer, summary); writer.WriteEndElement(); } // Serialize element identifier if (value.Identifier != null && value.Identifier.Count > 0) { writer.WriteStartArrayElement("identifier"); foreach (var item in value.Identifier) { writer.WriteStartArrayMember("identifier"); IdentifierSerializer.SerializeIdentifier(item, writer, summary); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element dateTime if (value.DateTimeElement != null) { writer.WriteStartElement("dateTime"); FhirDateTimeSerializer.SerializeFhirDateTime(value.DateTimeElement, writer, summary); writer.WriteEndElement(); } // Serialize element subject if (value.Subject != null) { writer.WriteStartElement("subject"); ResourceReferenceSerializer.SerializeResourceReference(value.Subject, writer, summary); writer.WriteEndElement(); } // Serialize element requester if (value.Requester != null) { writer.WriteStartElement("requester"); ResourceReferenceSerializer.SerializeResourceReference(value.Requester, writer, summary); writer.WriteEndElement(); } // Serialize element operator if (value.Operator != null) { writer.WriteStartElement("operator"); ResourceReferenceSerializer.SerializeResourceReference(value.Operator, writer, summary); writer.WriteEndElement(); } // Serialize element view if (value.View != null) { writer.WriteStartElement("view"); CodeableConceptSerializer.SerializeCodeableConcept(value.View, writer, summary); writer.WriteEndElement(); } // Serialize element deviceName if (value.DeviceNameElement != null) { writer.WriteStartElement("deviceName"); FhirStringSerializer.SerializeFhirString(value.DeviceNameElement, writer, summary); writer.WriteEndElement(); } // Serialize element height if (value.HeightElement != null) { writer.WriteStartElement("height"); IntegerSerializer.SerializeInteger(value.HeightElement, writer, summary); writer.WriteEndElement(); } // Serialize element width if (value.WidthElement != null) { writer.WriteStartElement("width"); IntegerSerializer.SerializeInteger(value.WidthElement, writer, summary); writer.WriteEndElement(); } // Serialize element frames if (value.FramesElement != null) { writer.WriteStartElement("frames"); IntegerSerializer.SerializeInteger(value.FramesElement, writer, summary); writer.WriteEndElement(); } // Serialize element length if (value.LengthElement != null) { writer.WriteStartElement("length"); IntegerSerializer.SerializeInteger(value.LengthElement, writer, summary); writer.WriteEndElement(); } // Serialize element content if (value.Content != null && !summary) { writer.WriteStartElement("content"); AttachmentSerializer.SerializeAttachment(value.Content, writer, summary); writer.WriteEndElement(); } writer.WriteEndComplexContent(); writer.WriteEndRootObject(); }
public override IDeepCopyable CopyTo(IDeepCopyable other) { var dest = other as DiagnosticReport; if (dest == null) { throw new ArgumentException("Can only copy to an object of the same type", "other"); } base.CopyTo(dest); if (Identifier != null) { dest.Identifier = new List <Hl7.Fhir.Model.Identifier>(Identifier.DeepCopy()); } if (BasedOn != null) { dest.BasedOn = new List <Hl7.Fhir.Model.ResourceReference>(BasedOn.DeepCopy()); } if (StatusElement != null) { dest.StatusElement = (Code <Hl7.Fhir.Model.DiagnosticReport.DiagnosticReportStatus>)StatusElement.DeepCopy(); } if (Category != null) { dest.Category = new List <Hl7.Fhir.Model.CodeableConcept>(Category.DeepCopy()); } if (Code != null) { dest.Code = (Hl7.Fhir.Model.CodeableConcept)Code.DeepCopy(); } if (Subject != null) { dest.Subject = (Hl7.Fhir.Model.ResourceReference)Subject.DeepCopy(); } if (Encounter != null) { dest.Encounter = (Hl7.Fhir.Model.ResourceReference)Encounter.DeepCopy(); } if (Effective != null) { dest.Effective = (Hl7.Fhir.Model.DataType)Effective.DeepCopy(); } if (IssuedElement != null) { dest.IssuedElement = (Hl7.Fhir.Model.Instant)IssuedElement.DeepCopy(); } if (Performer != null) { dest.Performer = new List <Hl7.Fhir.Model.ResourceReference>(Performer.DeepCopy()); } if (ResultsInterpreter != null) { dest.ResultsInterpreter = new List <Hl7.Fhir.Model.ResourceReference>(ResultsInterpreter.DeepCopy()); } if (Specimen != null) { dest.Specimen = new List <Hl7.Fhir.Model.ResourceReference>(Specimen.DeepCopy()); } if (Result != null) { dest.Result = new List <Hl7.Fhir.Model.ResourceReference>(Result.DeepCopy()); } if (ImagingStudy != null) { dest.ImagingStudy = new List <Hl7.Fhir.Model.ResourceReference>(ImagingStudy.DeepCopy()); } if (Media != null) { dest.Media = new List <Hl7.Fhir.Model.DiagnosticReport.MediaComponent>(Media.DeepCopy()); } if (ConclusionElement != null) { dest.ConclusionElement = (Hl7.Fhir.Model.FhirString)ConclusionElement.DeepCopy(); } if (ConclusionCode != null) { dest.ConclusionCode = new List <Hl7.Fhir.Model.CodeableConcept>(ConclusionCode.DeepCopy()); } if (PresentedForm != null) { dest.PresentedForm = new List <Hl7.Fhir.Model.Attachment>(PresentedForm.DeepCopy()); } return(dest); }
/// <summary> /// Parse Media /// </summary> public static Hl7.Fhir.Model.Media ParseMedia(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Media existingInstance = null) { Hl7.Fhir.Model.Media result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Media(); string currentElementName = reader.CurrentElementName; reader.EnterElement(); while (reader.HasMoreElements()) { var atName = reader.CurrentElementName; // Parse element extension if (atName == "extension") { result.Extension = new List <Hl7.Fhir.Model.Extension>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "extension")) { result.Extension.Add(ExtensionParser.ParseExtension(reader, errors)); } reader.LeaveArray(); } // Parse element language else if (atName == "language") { result.LanguageElement = CodeParser.ParseCode(reader, errors); } // Parse element text else if (atName == "text") { result.Text = NarrativeParser.ParseNarrative(reader, errors); } // Parse element contained else if (atName == "contained") { result.Contained = new List <Hl7.Fhir.Model.Resource>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "contained")) { result.Contained.Add(ParserUtils.ParseContainedResource(reader, errors)); } reader.LeaveArray(); } // Parse element _id else if (atName == "_id") { result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id))); } // Parse element type else if (atName == "type") { result.TypeElement = CodeParser.ParseCode <Hl7.Fhir.Model.Media.MediaType>(reader, errors); } // Parse element subtype else if (atName == "subtype") { result.Subtype = CodeableConceptParser.ParseCodeableConcept(reader, errors); } // Parse element identifier else if (atName == "identifier") { result.Identifier = new List <Hl7.Fhir.Model.Identifier>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "identifier")) { result.Identifier.Add(IdentifierParser.ParseIdentifier(reader, errors)); } reader.LeaveArray(); } // Parse element dateTime else if (atName == "dateTime") { result.DateTimeElement = FhirDateTimeParser.ParseFhirDateTime(reader, errors); } // Parse element subject else if (atName == "subject") { result.Subject = ResourceReferenceParser.ParseResourceReference(reader, errors); } // Parse element requester else if (atName == "requester") { result.Requester = ResourceReferenceParser.ParseResourceReference(reader, errors); } // Parse element operator else if (atName == "operator") { result.Operator = ResourceReferenceParser.ParseResourceReference(reader, errors); } // Parse element view else if (atName == "view") { result.View = CodeableConceptParser.ParseCodeableConcept(reader, errors); } // Parse element deviceName else if (atName == "deviceName") { result.DeviceNameElement = FhirStringParser.ParseFhirString(reader, errors); } // Parse element height else if (atName == "height") { result.HeightElement = IntegerParser.ParseInteger(reader, errors); } // Parse element width else if (atName == "width") { result.WidthElement = IntegerParser.ParseInteger(reader, errors); } // Parse element frames else if (atName == "frames") { result.FramesElement = IntegerParser.ParseInteger(reader, errors); } // Parse element length else if (atName == "length") { result.LengthElement = IntegerParser.ParseInteger(reader, errors); } // Parse element content else if (atName == "content") { result.Content = AttachmentParser.ParseAttachment(reader, errors); } else { errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader); reader.SkipSubElementsFor(currentElementName); result = null; } } reader.LeaveElement(); return(result); }