Closed adeel-ansari closed 3 years ago
Hi @adeel-ansari, Thank you for reporting this. Can you give more details about the error you are facing ? Which forge commands cause issues ?
Hi @MFSY ,
I last tried this back in Oct 2020 so I will try to re-create the issue. Unfortunately, when running the notebook (upgraded from forge 0.3.3 to 0.5.2) now I'm receiving another error (
If I recall, there were issues with commands described in the tutorials (tutorial 01):
If I tried with our SHACL shapes something like patient.name.HumanName.family it wouldn't work.
From the link above, the PatientName portion looks like this:
fhir:Patient.name [ fhir:index 0; fhir:HumanName.use [ fhir:value "official" ]; fhir:HumanName.family [ fhir:value "Chalmers" ]; fhir:HumanName.given [ fhir:value "Peter"; fhir:index 0 ], [ fhir:value "James"; fhir:index 1 ] ]
If needed, I can share the context, shapes, sample data.
@MFSY , I downgraded to 0.3.3 and it got rid of the recursion error. Here's an example of where I'm having trouble accessing some of the patient attributes.
forge.template("patient", output="json", only_required=True)
data = {
"type": "patient",
"fhir:Patient.active": [
{
"@type": "fhir:boolean",
"fhir:value":"False"
}
]
}
resource_patient = forge.from_json(data)
print(type(resource_patient))
forge.validate(resource_patient)
The output is:
{
"type": "Patient"
}
<class 'kgforge.core.resource.Resource'>
<action> _validate_one
<succeeded> True
print(resource_patient)
{
type: patient
"fhir:Patient.active":
[
{
@type: fhir:boolean
"fhir:value": False
}
]
}
From here I'm not sure how to access the attribute fhir:Patient.active. if I try:
resource_patient['fhir:Patient.active']
TypeError: 'Resource' object is not subscriptable
Maybe I need to access the attribute differently or modify the context?
Hi @adeel-ansari ,
Thanks for the detailed description. resource_patient
is a Resource so it is not possible to access its member as with a python dict.
I recommend to use one of the two following options to access such type of property:
resource_patient .__getitem__('fhir:Patient.active')
: this is using an internal accessor.
or
resource_patient_json = forge.as_json(resource_patient)
resource_patient_json['fhir:Patient.active']
# Once your are done, then get back a resource from the json
resource_patient = forge.from_json(resource_patient_json)
About the forge version, we recommend to use the latest as many fixes are being made. As for the recursion error, please open another ticket for us to have look.
Thanks @MFSY, I tried the second approach successfully. I'll let you know if this approach causes any problems for any further forge functionality.
I think the first approach (getitem) may need me to upgrade. I'll try it once the recursion error is resolved. Opening a ticket for that soon.
Thanks for the help.
Some ontologies use '.' in the property and class names. Example here: http://hl7.org/fhir/patient-example.ttl.html
If we use a tool such as TopBraidComposer to generate the SHACL shapes, the shapes also have '.' in the names.
I think this causes problems with some of the forge commands because I think in forge the '.' means we're trying to access another property. I don't think it expects that it's part of the name.
Is there a way to handle '.' is shapes and property names?