Example #1
0
        private string GetContentAs(string content, FhirMimeType mimeType)
        {
            var serializer = new SerializationWrapper(_arguments.FhirVersion);
            var resource   = serializer.Parse(content);

            return(serializer.Serialize(resource, mimeType));
        }
Example #2
0
        //[InlineData(@"TestData\account.profile-r4.json")]
        //[InlineData(@"TestData\activitydefinition.profile-r4.json")]
        //[InlineData(@"TestData\adverseevent.profile-r4.json")]
        //[InlineData(@"TestData\allergyintolerance.profile-r4.json")]
        //[InlineData(@"TestData\appointment.profile-r4.json")]
        //[InlineData(@"TestData\appointmentresponse.profile-r4.json")]
        //[InlineData(@"TestData\consent.profile-r4.json")]
        public async Task CanConvert_Questionnaire_FromR4ToR3_RoundTrip(string path)
        {
            var converterFromR4ToR3 = new FhirConverter(to: FhirVersion.R3, from: FhirVersion.R4);
            var converterFromR3ToR4 = new FhirConverter(to: FhirVersion.R4, from: FhirVersion.R3);

            var r4Serializer = new SerializationWrapper(FhirVersion.R4);
            var r4Resource   = r4Serializer.Parse(await File.ReadAllTextAsync(path));

            var r3Resource          = converterFromR4ToR3.Convert <Resource, Resource>(r4Resource.Resource);
            var r4ResourceRoundTrip = converterFromR3ToR4.Convert <Resource, Resource>(r3Resource);

            var r4ResourceContent          = r4Serializer.Serialize(r4Resource);
            var r4ResourceRoundTripContent = r4Serializer.Serialize(r4ResourceRoundTrip);

            Assert.Equal(r4ResourceContent, r4ResourceRoundTripContent);
        }
        public override async Task <OperationResultEnum> Execute()
        {
            Validate(_arguments);

            Binary binary = _generator.GenerateBinary(_arguments);

            var resource = new ResourceWrapper(binary, FhirVersion.R4);

            var serializer = new SerializationWrapper(FhirVersion.R4);

            var serialized = serializer.Serialize(resource, _arguments.MimeType);

            if (serialized == null)
            {
                _issues.Add(new Issue
                {
                    Details  = $"Failed to serialize binary from file\nLocation: '{_arguments.Path}'.",
                    Severity = IssueSeverityEnum.Error
                });

                return(OperationResultEnum.Failed);
            }

            await File.WriteAllTextAsync(@$ "{_arguments.OutPath}\binary-{_arguments.Id}.json", serialized);

            _logger.LogInformation($"Successfully generated 'binary-{_arguments.Id}.json' to location: '{_arguments.OutPath}'.");

            return(_issues.Any(issue => issue.Severity == IssueSeverityEnum.Error)
                ? OperationResultEnum.Failed
                : OperationResultEnum.Succeeded);
        }
Example #4
0
        public string Convert(string fromString)
        {
            var parser     = new SerializationWrapper(FromVersion);
            var serializer = new SerializationWrapper(ToVersion);

            var fromObject = parser.Parse(fromString);
            var converted  = Convert <Base, Base>(fromObject.Resource);

            return(serializer.Serialize(converted));
        }
        private async Task SerializeAndStore(BundleWrapper result, DirectoryInfo baseDir)
        {
            if (result == null)
            {
                return;
            }

            var serializer = new SerializationWrapper(result.FhirVersion);
            var resources  = result.GetResources();

            _logger.LogInformation($"  Fetched {resources.Count()} resources from server");
            foreach (var resource in resources)
            {
                string serialized = serializer.Serialize(resource, _arguments.MimeType);
                await Store(resource.Id, serialized, baseDir);
            }
        }
        public override async Task <OperationResultEnum> Execute()
        {
            _logger.LogInformation($"Starting conversion of source file: '{_arguments.Source}' from format: '{_arguments.FromMimeType}' to format '{_arguments.ToMimeType}'.");

            var serializer = new SerializationWrapper(_arguments.FhirVersion);
            var resource   = serializer.Parse(_arguments.SourceContent, _arguments.FromMimeType, true);
            var outContent = serializer.Serialize(resource, _arguments.ToMimeType.GetValueOrDefault());
            var fileName   = Path.GetFileName(_arguments.Source);
            var outPath    = GetOutPath(_arguments.OutPath, fileName, _arguments.ToMimeType.GetValueOrDefault());

            if (!string.IsNullOrWhiteSpace(outContent))
            {
                using var stream = File.Open(outPath, FileMode.OpenOrCreate, FileAccess.Write);
                await stream.WriteAsync(Encoding.UTF8.GetBytes(outContent));

                _logger.LogInformation($"Converted file stored at: '{outPath}'.");
            }

            return(await Task.FromResult(OperationResultEnum.Succeeded));
        }
Example #7
0
        public override async Task <OperationResultEnum> Execute()
        {
            DocumentReference documentReference = _documentReferenceGenerator.GenerateDocumentReference(_arguments);

            var resource   = new ResourceWrapper(documentReference, FhirVersion.R4);
            var serializer = new SerializationWrapper(FhirVersion.R4);

            var serialized = serializer.Serialize(resource, _arguments.MimeType);

            if (serialized == null)
            {
                _issues.Add(new Issue
                {
                    Details  = $"Failed to serialize documentreference for Id: '{_arguments.Id}'.",
                    Severity = IssueSeverityEnum.Error
                });

                return(OperationResultEnum.Failed);
            }

            await File.WriteAllTextAsync(@$ "{_arguments.OutPath}\documentreference-{_arguments.Id}.json", serialized);