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

Add source generation #147

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
851 changes: 851 additions & 0 deletions SampleSourceGen/Education.StructureDefinition.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions SampleSourceGen/Education.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Microsoft.Health.Fhir.CodeGeneration;

namespace SampleSourceGen;

[GeneratedFhir("Education.StructureDefinition.json")]
public partial class Education
{
}
4,095 changes: 4,095 additions & 0 deletions SampleSourceGen/Models/Patient.StructureDefinition.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions SampleSourceGen/Models/Patient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Microsoft.Health.Fhir.CodeGeneration;

namespace SampleSourceGen.Models;

[GeneratedFhir("Models/Patient.StructureDefinition.json")]
public partial class Patient
{
}
755 changes: 755 additions & 0 deletions SampleSourceGen/Models/Pokemon.StructureDefinition.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions SampleSourceGen/Models/Pokemon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.Health.Fhir.CodeGeneration;

namespace SampleSourceGen.Models;

[GeneratedFhir(
"Models/Pokemon.StructureDefinition.json",
TerminologyResources = new[] { "Models/PokemonType.CodeSystem.json", "Models/PokemonType.ValueSet.json" })]
public partial class Pokemon
{
}
86 changes: 86 additions & 0 deletions SampleSourceGen/Models/PokemonType.CodeSystem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"resourceType": "CodeSystem",
"id": "pokemontypes",
"url": "http://pokemon.com/type",
"version": "1.0.0",
"name": "Pokemon Types",
"title": "Pokemon Types",
"status": "active",
"date": "2023-08-01",
"publisher": "The Pokemon Company",
"content": "complete",
"concept": [
{
"code": "normal",
"display": "Normal"
},
{
"code": "fighting",
"display": "Fighting"
},
{
"code": "flying",
"display": "Flying"
},
{
"code": "poison",
"display": "Poison"
},
{
"code": "ground",
"display": "Ground"
},
{
"code": "rock",
"display": "Rock"
},
{
"code": "bug",
"display": "Bug"
},
{
"code": "ghost",
"display": "Ghost"
},
{
"code": "steel",
"display": "Steel"
},
{
"code": "fire",
"display": "Fire"
},
{
"code": "water",
"display": "Water"
},
{
"code": "grass",
"display": "Grass"
},
{
"code": "electric",
"display": "Electric"
},
{
"code": "psychic",
"display": "Psychic"
},
{
"code": "ice",
"display": "Ice"
},
{
"code": "dragon",
"display": "Dragon"
},
{
"code": "dark",
"display": "Dark"
},
{
"code": "fairy",
"display": "Fairy"
}
]
}
18 changes: 18 additions & 0 deletions SampleSourceGen/Models/PokemonType.ValueSet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"resourceType": "ValueSet",
"id": "pokemontype",
"url": "http://pokemon.com/fhir/ValueSet/pokemontype",
"version": "1.0.0",
"name": "Pokemon Types",
"title": "Pokemon Types",
"status": "active",
"date": "2023-08-01",
"publisher": "The Pokemon Company",
"compose": {
"include": [
{
"system": "http://pokemon.com/type"
}
]
}
}
21 changes: 21 additions & 0 deletions SampleSourceGen/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using Hl7.Fhir.Model;

var edu = new SampleSourceGen.Education
{
Study = "abcd",
Graduated = new FhirBoolean(false),
Subject = new ResourceReference("/Study/abcd")
};

var patient = new SampleSourceGen.Models.Patient
{
Contact = new List<SampleSourceGen.Models.Patient.ContactComponent> { },
};

var pkmn = new SampleSourceGen.Models.Pokemon
{
Name = "Charmander",
NationalDexNo = 4,
PrimaryType = SampleSourceGen.Models.Pokemon.PokemonTypes.Fire,
};
28 changes: 28 additions & 0 deletions SampleSourceGen/SampleSourceGen.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="**/*.StructureDefinition.json" />
<AdditionalFiles Include="**/*.ValueSet.json" />
<AdditionalFiles Include="**/*.CodeSystem.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Hl7.Fhir.R5" Version="5.3.0" />
<PackageReference Include="System.Text.Json" Version="[6.0.8,)" OutputItemType="Analyzer" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\Microsoft.Health.Fhir.CodeGeneration\Microsoft.Health.Fhir.CodeGeneration.csproj" />
<ProjectReference Include="..\src\Microsoft.Health.Fhir.CodeGenCommon\Microsoft.Health.Fhir.CodeGenCommon.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Visible="false" />
<ProjectReference Include="..\src\Microsoft.Health.Fhir.SourceGenerator\Microsoft.Health.Fhir.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\src\Microsoft.Health.Fhir.SpecManager\Microsoft.Health.Fhir.SpecManager.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Visible="false" />
</ItemGroup>

</Project>
89 changes: 89 additions & 0 deletions TestSourceGen/Education.StructureDefinition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"resourceType": "StructureDefinition",
"id": "Education",
"url": "http://hl7.org/fhir/StructureDefinition/Education",
"version": "0.1",
"name": "Education",
"status": "draft",
"publisher": "Firely",
"description": "Study or other form of education that a person has done.",
"copyright": "Copyright (C) 2019 Firely",
"fhirVersion": "4.0.1",
"kind": "resource",
"abstract": false,
"type": "Education",
"baseDefinition": "http://hl7.org/fhir/StructureDefinition/DomainResource",
"derivation": "specialization",
"differential": {
"element": [
{
"id": "Education.subject",
"path": "Education.subject",
"short": "Who was educated?",
"definition": "Person who has done this education.",
"min": 1,
"max": "1",
"type": [
{
"code": "Reference",
"targetProfile": "http://hl7.org/fhir/StructureDefinition/Person"
},
{
"code": "Reference",
"targetProfile": "http://hl7.org/fhir/StructureDefinition/Patient"
},
{
"code": "Reference",
"targetProfile": "http://hl7.org/fhir/StructureDefinition/Practitioner"
}
]
},
{
"id": "Education.institute",
"path": "Education.institute",
"short": "Where did you do this study?",
"definition": "Educational institute, like a university or training company",
"min": 0,
"max": "1",
"type": [
{
"code": "Reference",
"targetProfile": "http://hl7.org/fhir/StructureDefinition/Organization"
}
]
},
{
"id": "Education.study",
"path": "Education.study",
"short": "What study?",
"definition": "Name of the study that the subject followed.",
"min": 1,
"max": "1",
"type": [
{
"code": "string",
"profile": "http://hl7.org/fhir/StructureDefinition/string"
}
]
},
{
"id": "Education.graduated[x]",
"path": "Education.graduated[x]",
"short": "Did subject graduate for the study?",
"definition": "Did the subject graduate for the study? If possible enter the date of graduation.",
"min": 1,
"max": "1",
"type": [
{
"code": "boolean",
"profile": "http://hl7.org/fhir/StructureDefinition/boolean"
},
{
"code": "date",
"profile": "http://hl7.org/fhir/StructureDefinition/date"
}
]
}
]
}
}
3,286 changes: 3,286 additions & 0 deletions TestSourceGen/Patient.StructureDefinition.json

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions TestSourceGen/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://aka.ms/new-console-template for more information

using Microsoft.CodeAnalysis;
using Microsoft.Health.Fhir.SourceGenerator;
using Microsoft.Health.Fhir.SourceGenerator.Parsing;

var resourceClass = new ResourcePartialClass(Location.None, typeof(Program).Namespace!, "Patient", "Patient.StructureDefinition.json", Array.Empty<string>());

var emitter = new Emitter(resourceClass, diag => Console.Error.WriteLine(diag.GetMessage()));

var code = emitter.Emit();

Console.WriteLine(code);
27 changes: 27 additions & 0 deletions TestSourceGen/TestSourceGen.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Content Include="*.StructureDefinition.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" PrivateAssets="all" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.2.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\Microsoft.Health.Fhir.SourceGenerator\Microsoft.Health.Fhir.SourceGenerator.csproj" />
<ProjectReference Include="..\src\Microsoft.Health.Fhir.SpecManager\Microsoft.Health.Fhir.SpecManager.csproj" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions fhir-codegen.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
.gitignore = .gitignore
CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md
src\Directory.Build.props = src\Directory.Build.props
.github\workflows\docs.yaml = .github\workflows\docs.yaml
GeoPol.xml = GeoPol.xml
LICENSE = LICENSE
Expand All @@ -32,6 +33,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Health.Fhir.CodeG
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FhirCodeGenBlazor", "src\FhirCodeGenBlazor\FhirCodeGenBlazor.csproj", "{F91764FD-EE86-4FBC-951F-819361ABCA4F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleSourceGen", "SampleSourceGen\SampleSourceGen.csproj", "{08CA896F-B304-4B08-A35A-F6D64C166AF7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Health.Fhir.SourceGenerator", "src\Microsoft.Health.Fhir.SourceGenerator\Microsoft.Health.Fhir.SourceGenerator.csproj", "{213EE0DD-ECE8-47AF-8301-42BEAE4EFE54}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestSourceGen", "TestSourceGen\TestSourceGen.csproj", "{956E4954-BBC8-4471-B53C-9424F1FE681A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Health.Fhir.CodeGeneration", "src\Microsoft.Health.Fhir.CodeGeneration\Microsoft.Health.Fhir.CodeGeneration.csproj", "{37BFB554-48B3-4BBA-83ED-415956898C48}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -62,6 +71,22 @@ Global
{F91764FD-EE86-4FBC-951F-819361ABCA4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F91764FD-EE86-4FBC-951F-819361ABCA4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F91764FD-EE86-4FBC-951F-819361ABCA4F}.Release|Any CPU.Build.0 = Release|Any CPU
{08CA896F-B304-4B08-A35A-F6D64C166AF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08CA896F-B304-4B08-A35A-F6D64C166AF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08CA896F-B304-4B08-A35A-F6D64C166AF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08CA896F-B304-4B08-A35A-F6D64C166AF7}.Release|Any CPU.Build.0 = Release|Any CPU
{213EE0DD-ECE8-47AF-8301-42BEAE4EFE54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{213EE0DD-ECE8-47AF-8301-42BEAE4EFE54}.Debug|Any CPU.Build.0 = Debug|Any CPU
{213EE0DD-ECE8-47AF-8301-42BEAE4EFE54}.Release|Any CPU.ActiveCfg = Release|Any CPU
{213EE0DD-ECE8-47AF-8301-42BEAE4EFE54}.Release|Any CPU.Build.0 = Release|Any CPU
{956E4954-BBC8-4471-B53C-9424F1FE681A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{956E4954-BBC8-4471-B53C-9424F1FE681A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{956E4954-BBC8-4471-B53C-9424F1FE681A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{956E4954-BBC8-4471-B53C-9424F1FE681A}.Release|Any CPU.Build.0 = Release|Any CPU
{37BFB554-48B3-4BBA-83ED-415956898C48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37BFB554-48B3-4BBA-83ED-415956898C48}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37BFB554-48B3-4BBA-83ED-415956898C48}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37BFB554-48B3-4BBA-83ED-415956898C48}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading