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

Incorrect parsing of StructureDefinition element ids for polymorphic elements #124

Closed
ArdonToonstra opened this issue Mar 20, 2023 · 2 comments

Comments

@ArdonToonstra
Copy link

  • fhir.resources version: 6.5.0
  • Python version: 3.11.2
  • Operating System: Windows

Description

I am trying to parse our created logical models in StructueDefinitions. For a few elements, we have defined polymorphic elements, like the JSON snippet below. I believe this is valid FHIR.

 {
   "id": "LaboratoryTestResult.LaboratoryTest.TestResult[x]",
   "path": "LaboratoryTestResult.LaboratoryTest.TestResult[x]",
    "short": "TestResult",

However, If I try to parse this resource, I get errors, like this:

2023-03-17 18:27:01.457242	error	Parsing error, skipped: package/LogicalModel-HdBe-LaboratoryTestResult.json. Error message: 3 validation errors for StructureDefinition
differential -> element -> 3 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
differential -> element -> 7 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)
differential -> element -> 8 -> id
  string does not match regex "^[A-Za-z0-9\-.]+$" (type=value_error.str.regex; pattern=^[A-Za-z0-9\-.]+$)

This is the related definition of the FHIR element: https://www.hl7.org/fhir/element-definitions.html#Element.id which is of type string
The constraint is based on: https://www.hl7.org/fhir/datatypes.html#id for type id.

Should this constraint apply to ElementDefinition.id ? Also, FHIR itself uses [x] in the Element.id : https://www.hl7.org/fhir/observation.profile.json.html

What I Did

if resource.get("resourceType") == "StructureDefinition" and resource.get("kind") == "logical":
                try:
                    struct_def = StructureDefinition.parse_obj(resource)
                    struct_defs.append(struct_def)
                except Exception as e:
                    write_log('error', f'Parsing error, skipped: {member.name}. Error message: {str(e)}' )
                    print(str(member.name) + ': Parsing error, skipped')
                    pass  
@delcroip
Copy link

see #55

my regex

from fhir.resources.fhirtypes import Id
Id.configure_constraints(regex=re.compile(r"^[A-Za-z0-9\-\.]+(\[x\](\.[a-zA-Z]+)?)?(:[A-Za-z0-9\-.]+(\[x\](\.[a-zA-Z]+)?)?)?$"))      
Id.configure_constraints(max_length=128)      
``

@ArdonToonstra
Copy link
Author

Thanks! That works. Will close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants