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

Filters Within Optional Field Declarations #35

Open
jp3477 opened this issue Apr 28, 2024 · 2 comments
Open

Filters Within Optional Field Declarations #35

jp3477 opened this issue Apr 28, 2024 · 2 comments

Comments

@jp3477
Copy link

jp3477 commented Apr 28, 2024

I have been able to create a JSON template for a SPARQL endpoint that works pretty well. However, I'm trying to now generate a structure that "conditionally" outputs one of three fields that all share the same root predicate but have different classes for the object. In the below example, the valueQuantity, valueCodeableConcept and valueString fields all originate from the predicate fhir:value.

I attempt to restrict them to different object classes in the $where clause with named variables. However, this does not produce the intended results if the fields are OPTIONAL. While the fields themselves are OPTIONAL, the class declarations in the $where clause seem to be absolute and will run independently of the fields in the translated SPARQL. Is there any way to fix these class declarations within the definition of the fields themselves using this package?

{
    "proto": {
        "id": "?observation$anchor",
        "identifier": {
            "id": "$fhir:identifier$asList$var:identifier",
            "value": "$fhir:value/fhir:v"
        },
        "status": "$fhir:status/fhir:v",
        "code": {
            "id": "$fhir:codeP$var:code$required",
            "coding": {
                "id": "$fhir:coding$asList",
                "system": "$fhir:system/fhir:v",
                "code": "$fhir:codeP/fhir:v",
                "display": "$fhir:display/fhir:v"
            }
        },
        "issued": "$fhir:issued/fhir:v",
        "valueQuantity": {
            "id": "$fhir:value$var:valueQuantity",
            "value": "$fhir:value/fhir:v",
            "code": "$fhir:codeP/fhir:v"
        },
        "valueCodeableConcept": {
            "id": "$fhir:value$var:valueCodeableConcept",
            "coding": {
                "id": "$fhir:coding$asList",
                "system": "$fhir:system/fhir:v",
                "code": "$fhir:codeP/fhir:v",
                "display": "$fhir:display/fhir:v"
            }
        },
        "valueString": "$fhir:value$var:valueString"
    },
    "$prefixes": {
        "fhir": "fhir/mcode.fhir.rdf.ttl/fhir.ttl#"
    },
    "$limit": 20,
    "$limitMode": "query",
    "$where": [
        "?observation a fhir:Observation",
        "?valueQuantity a fhir:Quantity",
        "?valueCodeableConcept a fhir:CodeableConcept",
        "?valueString a fhir:string"
    ]
}
@pasqLisena
Copy link
Member

pasqLisena commented May 2, 2024

Hi, this is basically a UNION, which we are not supporting.

The only way is is to take note of the class and filter afterwards programmatically (in your JS or other code)

E.g. for valueQuantity, you may have

        "valueQuantity": {
            "id": "$fhir:value$var:valueQuantity",
             "cls": "$rdf:type$var:valueQuantityClass",

And than use the cls value for removing or not the value

@jp3477
Copy link
Author

jp3477 commented May 2, 2024

Thanks for the response! That makes sense. I am already using a workaround of that sort, and I think it should be enough.

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