I am currently generating classes from their StructureDefinition stored in a Json file in a npm package.
For this, I use the following code :
public void Load() throws Exception {
if (ctxt == null) {
ctxt = TestingUtilities.getSharedWorkerContext();
FilesystemPackageCacheManager pc = new FilesystemPackageCacheManager(true);
NpmPackage npm = pc.loadPackage("hl7.fhir.fr.core", "1.1.0");
ctxt.loadFromPackage(npm, new TestPackageLoader(Utilities.strings(SimpleWorkerContext.defaultTypesToLoad().stream().toArray(String[]::new))));
File folder = new File("C:\\Users\\a884402\\.fhir\\packages\\hl7.fhir.fr.core#1.1.0\\package\\");
for (File file : folder.listFiles()){
if (!file.isDirectory()){
try {
ctxt.cacheResource(new JsonParser().parse(Files.readString(Path.of(file.getAbsolutePath()))));
System.out.println(file.getAbsolutePath() + " chargé.");
}
catch(Exception e){
System.out.println(file.getAbsolutePath() + " PAS chargé.");
}
}
}
}
}
public void CreatePatientFromProfile(String profileURL) throws Exception {
this.Load();
try {
var peBuilder = new PEBuilder(ctxt, PEBuilder.PEElementPropertiesPolicy.NONE, false);
Patient res = (Patient) peBuilder.createResource(profileURL, true);
String json = new JsonParser().setOutputStyle(IParser.OutputStyle.PRETTY).composeString(res);
System.out.println(json);
}
catch (FHIRException fhirException){fhirException.printStackTrace();}
}
My problem is, when I call CreatePatientFromProfile(url), it throws the following exception :
After looking at the Extension class, I saw that the method addChild() throws this exception, but I don't understand why. In my patient profile, I have an extension with an URL with a fixed value and a cardinality of 1..1, so the generation of the class with the PEBuilder will try to add a child as an URL, but then it fails because of the exception.
Is there a workaround to avoid the exception, or is thsi normal and there's something I haven't understood properly?
The problem is that because of this error, I can't generate my class according a profile structure definition with all the required fields.
Hello,
I am currently generating classes from their StructureDefinition stored in a Json file in a npm package.
For this, I use the following code :
My problem is, when I call CreatePatientFromProfile(url), it throws the following exception :
After looking at the Extension class, I saw that the method addChild() throws this exception, but I don't understand why. In my patient profile, I have an extension with an URL with a fixed value and a cardinality of 1..1, so the generation of the class with the PEBuilder will try to add a child as an URL, but then it fails because of the exception.
Is there a workaround to avoid the exception, or is thsi normal and there's something I haven't understood properly?
The problem is that because of this error, I can't generate my class according a profile structure definition with all the required fields.
Thank you !