/// <summary> /// Deserialize JSON into a FHIR DocumentReference#Content /// </summary> public static void DeserializeJson(this DocumentReference.ContentComponent 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($"DocumentReference.ContentComponent >>> DocumentReference#Content.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } reader.Read(); current.DeserializeJsonProperty(ref reader, options, propertyName); } } throw new JsonException($"DocumentReference.ContentComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); }
/// <summary> /// Converts a PharmanetMessage to an HL7 FHIR DocumentReference model. /// </summary> /// <param name="messageModel">The PharmanetMessage to convert from.</param> /// <param name="related">The optional ResourceReference representing a reference to the request message.</param> /// <returns>Returns a new DocumentReference from the PharmanetMessage. /// If the requestDocumentReference is provided, it used that to fill out cross-referenced data. /// </returns> public static DocumentReference ToDocumentReference(PharmanetMessageModel messageModel, ResourceReference?related = null) { DocumentReference documentReference = new DocumentReference(); documentReference.Status = DocumentReferenceStatus.Current; documentReference.Date = DateTime.UtcNow; documentReference.Id = messageModel.TransactionId; // set the GUID as the base artefact ID. documentReference.MasterIdentifier = new Identifier(MasterIdentifierNamespace, MasterIdentifierUrnPrefix + messageModel.TransactionId); DocumentReference.ContentComponent item = new DocumentReference.ContentComponent(); item.Attachment = new Attachment(); string hl7Message = Encoding.UTF8.GetString(Convert.FromBase64String(messageModel.Hl7Message)); item.Attachment.Data = Encoding.UTF8.GetBytes(hl7Message); item.Attachment.ContentType = HL7v2ContentType; documentReference.Content.Add(item); if (related != null) { documentReference.Context = new DocumentReference.ContextComponent(); documentReference.Context.Related = new List <ResourceReference>(); documentReference.Context.Related.Add(related); } return(documentReference); }
private List<DocumentReference.ContentComponent> SetContent(GenerateDocumentReferenceOptions arguments) { var contentComponent = new DocumentReference.ContentComponent(); var attachment = new Attachment(); attachment.ContentType = arguments.ContentType; attachment.Url = $"Binary/{arguments.Id}"; contentComponent.Attachment = attachment; return new List<DocumentReference.ContentComponent> { contentComponent }; }
internal static DocumentReference ToFhirInternal(File file, DocumentReference documentReference) { var content = new DocumentReference.ContentComponent(); content.Attachment = new Attachment(); content.Attachment.ContentType = (file.ContentType == null) ? "application/octet-stream" : file.ContentType.ToString(); content.Attachment.Data = new byte[file.Content.Length]; file.Content.CopyTo(content.Attachment.Data, 0); documentReference.Content.Add(content); return(documentReference); }
private static ContentViewModel ToContentViewModel(this DocumentReference.ContentComponent contentComponent) { var attachment = contentComponent.Attachment; var viewModel = new ContentViewModel { Attachment = new AttachmentViewModel { ContentType = attachment.ContentType, Creation = attachment.CreationElement?.ToDateTimeOffset(), Title = attachment.Title, Url = attachment.Url } }; return(viewModel); }
private static ContentViewModel ToContentViewModel(this DocumentReference.ContentComponent contentComponent) { var attachment = contentComponent.Attachment; var viewModel = new ContentViewModel { Attachment = new AttachmentViewModel { ContentType = attachment.ContentType, Creation = attachment.CreationElement?.ToDateTimeOffset(), Title = attachment.Title, Url = (attachment.Url.StartsWith(_defaultUrlBase)) ? $"{_pointerUrlBase}{attachment.Url.Substring(_defaultUrlBase.Length)}" : attachment.Url } }; return(viewModel); }
internal static DocumentReference XmlToDocumentReference(DocumentReference documentReference, string xml) { var content = new DocumentReference.ContentComponent(); content.Attachment = new Attachment(); content.Attachment.ContentType = "application/xml"; byte[] bytesXml = Encoding.UTF8.GetBytes(xml); content.Attachment.Data = new byte[bytesXml.Length]; bytesXml.CopyTo(content.Attachment.Data, 0); documentReference.Content.Add(content); return(documentReference); }
/// <summary> /// Deserialize JSON into a FHIR DocumentReference#Content /// </summary> public static void DeserializeJsonProperty(this DocumentReference.ContentComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName) { switch (propertyName) { case "attachment": current.Attachment = new Hl7.Fhir.Model.Attachment(); ((Hl7.Fhir.Model.Attachment)current.Attachment).DeserializeJson(ref reader, options); break; case "format": current.Format = new Hl7.Fhir.Model.Coding(); ((Hl7.Fhir.Model.Coding)current.Format).DeserializeJson(ref reader, options); break; // Complex: content, Export: ContentComponent, Base: BackboneElement default: ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName); break; } }
/// <summary> /// Serialize a FHIR DocumentReference#Content into JSON /// </summary> public static void SerializeJson(this DocumentReference.ContentComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } // Component: DocumentReference#Content, Export: ContentComponent, Base: BackboneElement (BackboneElement) ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false); writer.WritePropertyName("attachment"); current.Attachment.SerializeJson(writer, options); if (current.Format != null) { writer.WritePropertyName("format"); current.Format.SerializeJson(writer, options); } if (includeStartObject) { writer.WriteEndObject(); } }