Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

516 ON-HOLD Prepend resource type (eg Library or Measure) to resource file extension #531

Draft
wants to merge 4 commits into
base: develop-2.0
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,21 @@

namespace Hl7.Cql.Packaging.PostProcessors;

internal class WriteToFileFhirResourcePostProcessor : FhirResourcePostProcessor
internal class WriteToFileFhirResourcePostProcessor(
IOptions<FhirResourceWriterOptions> fhirResourceWriterOptions,
ILogger<WriteToFileFhirResourcePostProcessor> logger
)
: FhirResourcePostProcessor
{
private static readonly JsonSerializerOptions JsonSerializerOptions = new JsonSerializerOptions().ForFhir(ModelInfo.ModelInspector).Pretty();

private readonly FhirResourceWriterOptions _fhirResourceWriterOptions;
private readonly ILogger<WriteToFileFhirResourcePostProcessor> _logger;

public WriteToFileFhirResourcePostProcessor(
IOptions<FhirResourceWriterOptions> fhirResourceWriterOptions,
ILogger<WriteToFileFhirResourcePostProcessor> logger)
{
_fhirResourceWriterOptions = fhirResourceWriterOptions.Value;
_logger = logger;
}
private readonly FhirResourceWriterOptions _fhirResourceWriterOptions = fhirResourceWriterOptions.Value;
private readonly ILogger<WriteToFileFhirResourcePostProcessor> _logger = logger;

public override void ProcessResource(Resource resource)
{
var file = new FileInfo($"{Path.Combine(_fhirResourceWriterOptions.OutDirectory!.FullName, resource.Id)}.json");
var fileName = $"{Path.Combine(_fhirResourceWriterOptions.OutDirectory!.FullName, $"{resource.Id}")}.{resource.GetType().Name.ToLowerInvariant()}.json";
var file = new FileInfo(fileName);
_logger.LogInformation("Writing FHIR Resource file: '{file}'", file.FullName);

if (resource is Library library
Expand Down