3

I am trying to generate java code from an xsd for FHIR.

I downloaded the code generation schema from here and then I ran:

xjc patient.xsd

But I've got the following exception:

parsing a schema...
[ERROR] src-resolve: Cannot resolve the name 'Account' to a(n) 'type definition' component.
  line 332 of file:/Users/gerard/Downloads/fhir-codegen-xsd/fhir-base.xsd

[ERROR] src-resolve: Cannot resolve the name 'DetectedIssue' to a(n) 'type definition' component.
  line 354 of file:/Users/gerard/Downloads/fhir-codegen-xsd/fhir-base.xsd

[ERROR] src-resolve: Cannot resolve the name 'ImplementationGuide' to a(n) 'type definition' component.
  line 380 of file:/Users/gerard/Downloads/fhir-codegen-xsd/fhir-base.xsd

[ERROR] src-resolve: Cannot resolve the name 'MedicationOrder' to a(n) 'type definition' component.
  line 387 of file:/Users/gerard/Downloads/fhir-codegen-xsd/fhir-base.xsd

[ERROR] src-resolve: Cannot resolve the name 'QuestionnaireResponse' to a(n) 'type definition' component.
  line 409 of file:/Users/gerard/Downloads/fhir-codegen-xsd/fhir-base.xsd

[ERROR] src-resolve: Cannot resolve the name 'Parameters' to a(n) 'type definition' component.
  line 425 of file:/Users/gerard/Downloads/fhir-codegen-xsd/fhir-base.xsd

[ERROR] src-resolve: Cannot resolve the name 'MeasuredQuantity' to a(n) 'type definition' component.
  line 225 of file:/Users/gerard/Downloads/fhir-codegen-xsd/questionnaireanswers.xsd

I've imported to eclipse all the xsd and I see the same errors in fhir-base.xsd. Not sure how to solve it because for example the account.xsd is in the same directory.

Gerard Ribas
  • 717
  • 1
  • 9
  • 17

2 Answers2

2

I was having the same problem. I've tried three resources from the archive provided on the fhir website:

fhir-base.xsd
fhir-all.xsd
fhir-single.xsd

Every error seems to take the same form (73 of these entries) against fhir-base.xsd...

[ERROR] Property "Lang" is already defined. Use <jaxb:property> to resolve this conflict.
  line 323 of file:/E:/fhir-spec/resources/fhir-all-xsd/fhir-xhtml.xsd

[ERROR] The following location is relevant to the above error
  line 324 of file:/E:/fhir-spec/resources/fhir-all-xsd/fhir-xhtml.xsd

Just trying some brute-force tactics.. I found and commented out a few lines in fhir-xhtml.xsd:

Lines 323, 324
<xs:attribute name="lang" type="LanguageCode"/>
<xs:attribute ref="xml:lang"/>

Line 1351
<xs:attribute name="lang" type="LanguageCode"/>

After this I was able to generate code successfully.

mkdir gen
xjc -d gen fhir-base.xsd

I couldn't find anywhere "official" eg github, etc to file an issue. I'm not exactly sure of the intent of the xhtml stuff to begin with, but I wonder if what may be happening here is a conflict between the fhir data type 'LanguageCode' and the html specification for language code?

Good luck!

1

There's a separate schema called fhir-all.xsd. Code generators tend to be happier when everything's all in one file, so we publish this schema for that purpose.

Lloyd McKenzie
  • 6,345
  • 1
  • 13
  • 10
  • The error Property "Lang" is already defined .../fhir-xhtml.xsd still exists. Even when using fhir-all.xsd as it just references fhir-xhtml.xsd. Is there are known workarround – sandrozbinden Aug 23 '20 at 10:58