Skip to content

Commit

Permalink
fix: dotnet property names
Browse files Browse the repository at this point in the history
  • Loading branch information
krvital committed Sep 26, 2024
1 parent 7f2f88d commit 54dbeaf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
42 changes: 21 additions & 21 deletions src/aidbox_sdk/generator/dotnet.clj
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@
(defn generate-property
"Generates class property from schema element."
[{:keys [name array required value type choices] :as element}]
(let [name (uppercase-first-letter name)
lang-type (str/replace (or value type "") #"_" "")
(let [name' (->pascal-case name)
lang-type (str/replace (or value type "") #"[_-]" "")
type (str
(when required "required ")
lang-type
Expand All @@ -133,11 +133,11 @@

(= (:type element) "Meta")
(if (:profile element)
(format "public new Meta Meta { get; } = new() { Profile = [\"%s\"] };" (:profile element))
(format "public %s Meta { get; set; }" name))
(format "public new Meta Meta { get; } = new() { Profile = [\"%s\"] };" (:profile element))
(format "public %s Meta { get; set; }" name'))

:else
(str "public " type " " name " { get; set; }"
(str "public " type " " name' " { get; set; }"
(when (and (:required element)
(:codeable-concept-pattern element)) " = new()")
(:meta element)))))
Expand Down Expand Up @@ -267,25 +267,25 @@

(generate-search-params [_ ir-schemas]
(map (fn [ir-schema]
{:path (io/file "search" (str (:name ir-schema) "SearchParameters.cs"))
:content
(generate-module
:name "Aidbox.FHIR.Search"
:classes (generate-class
{:name (str (:name ir-schema) "SearchParameters")
:resource-name (str (:name ir-schema) "SearchParameters")
:base (when (:base ir-schema)
(str (:base ir-schema) "SearchParameters"))
:elements (map (fn [el] (update el :name ->pascal-case))
(:elements ir-schema))}))})
ir-schemas))
{:path (io/file "search" (str (:name ir-schema) "SearchParameters.cs"))
:content
(generate-module
:name "Aidbox.FHIR.Search"
:classes (generate-class
{:name (str (:name ir-schema) "SearchParameters")
:resource-name (str (:name ir-schema) "SearchParameters")
:base (when (:base ir-schema)
(str (:base ir-schema) "SearchParameters"))
:elements (map (fn [el] (update el :name ->pascal-case))
(:elements ir-schema))}))})
ir-schemas))

(generate-constraints [_ constraint-ir-schemas]
(mapv (fn [[name' schema]]
{:path (constraint-file-path schema name')
:content (generate-constraint-module
(assoc schema :url name'))})
constraint-ir-schemas))
{:path (constraint-file-path schema name')
:content (generate-constraint-module
(assoc schema :url name'))})
constraint-ir-schemas))

(generate-sdk-files [_] (generator/prepare-sdk-files :dotnet)))

Expand Down
2 changes: 0 additions & 2 deletions test/aidbox_sdk/generator/dotnet_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@
:content
"using Aidbox.FHIR.Base;\nusing Aidbox.FHIR.Utils;\n\nnamespace Aidbox.FHIR.R4.Core;\n\npublic class Patient : DomainResource\n{\n public bool? MultipleBirthBoolean { get; set; }\n public Base.Address[]? Address { get; set; }\n public string? DeceasedDateTime { get; set; }\n public Base.ResourceReference? ManagingOrganization { get; set; }\n public bool? DeceasedBoolean { get; set; }\n public Base.HumanName[]? Name { get; set; }\n public string? BirthDate { get; set; }\n public int? MultipleBirthInteger { get; set; }\n public object? MultipleBirth \n {\n get\n {\n if (MultipleBirthBoolean is not null)\n {\n return MultipleBirthBoolean;\n }\n \n if (MultipleBirthInteger is not null)\n {\n return MultipleBirthInteger;\n }\n \n return null;\n }\n \n set\n {\n if (value?.GetType() == typeof(bool))\n {\n MultipleBirthBoolean = (bool)value;\n return;\n }\n \n if (value?.GetType() == typeof(int))\n {\n MultipleBirthInteger = (int)value;\n return;\n }\n \n throw new ArgumentException(\"Invalid type provided\");\n }\n }\n public object? Deceased \n {\n get\n {\n if (DeceasedDateTime is not null)\n {\n return DeceasedDateTime;\n }\n \n if (DeceasedBoolean is not null)\n {\n return DeceasedBoolean;\n }\n \n return null;\n }\n \n set\n {\n if (value?.GetType() == typeof(string))\n {\n DeceasedDateTime = (string)value;\n return;\n }\n \n if (value?.GetType() == typeof(bool))\n {\n DeceasedBoolean = (bool)value;\n return;\n }\n \n throw new ArgumentException(\"Invalid type provided\");\n }\n }\n public Base.Attachment[]? Photo { get; set; }\n public PatientLink[]? Link { get; set; }\n public bool? Active { get; set; }\n public PatientCommunication[]? Communication { get; set; }\n public Base.Identifier[]? Identifier { get; set; }\n public Base.ContactPoint[]? Telecom { get; set; }\n public Base.ResourceReference[]? GeneralPractitioner { get; set; }\n public string? Gender { get; set; }\n public Base.CodeableConcept? MaritalStatus { get; set; }\n public PatientContact[]? Contact { get; set; }\n\n public class PatientLink : BackboneElement\n {\n public required string Type { get; set; }\n public required Base.ResourceReference Other { get; set; }\n }\n\n public class PatientCommunication : BackboneElement\n {\n public required Base.CodeableConcept Language { get; set; }\n public bool? Preferred { get; set; }\n }\n\n public class PatientContact : BackboneElement\n {\n public Base.HumanName? Name { get; set; }\n public string? Gender { get; set; }\n public Base.Period? Period { get; set; }\n public Base.Address? Address { get; set; }\n public Base.ContactPoint[]? Telecom { get; set; }\n public Base.ResourceReference? Organization { get; set; }\n public Base.CodeableConcept[]? Relationship { get; set; }\n }\n}"})))



(deftest test-generate-search-params
(is
(= (sut/generate-search-params generator fixtures/patient-search-params-ir-schemas)
Expand Down

0 comments on commit 54dbeaf

Please sign in to comment.