Getting a "No snapshot defined for StructureDefini...
# support
j
Copy code
{
  "resourceType": "Encounter",
  "status": "active",
  "class": {
    "system": "http://terminology.hl7.org/CodeSystem/v3-ActCode",
    "code": "medical-visit",
    "display": "Medical Visit"
  },
  "meta": {
    "profile": [
      "https://example.com/fhir/StructureDefinition/custom-encounter"
    ]
  }
}
The above is a sample JSON but illustrates that this encounter should at least return a validation error generated by the custom profile. My custom profile is stored in Medplum. It has a snapshot as well. Why is this error occurring?
r
Hi @jasonwa.ng , I tried saving this resource using the StructureDefinition you DM'd me on the Medplum APp, and I did see validation error
Is it ok if I share the anonymized StructureDefinition I used during my test? I've replaced all urls with
example.com
j
Sounds good! Thank you. I also tried it again and it's still running into issues, so not super sure what's going on there.
I also tried saving it with a complete random profile structure definition URL (it worked but obviously didn't run any validations), but it still says the no snapshot defined error if I use the actual URL for the
StructureDefinition
I added
r
@jasonwa.ng these are the steps I took to repro: - Log into app.medplum.com - Navigate to
StructureDefinition
- Create a new
StructureDefinition
from JSON, using the contents of the file attached - Save - navigate to
Encounter
- Create a new
Encounter
using the JSON below - Try to save I end up seeing the error in the attached screenshot
Copy code
json
{
  "resourceType": "Encounter",
  "status": "active",
  "class": {
    "system": "http://terminology.hl7.org/CodeSystem/v3-ActCode",
    "code": "HH",
    "display": "Home Health"
  },
  "meta": {
    "profile": [
      "https://foomedical.org/fhir/StructureDefinition/abc-visit-encounter"
    ],
    "versionId": "77361ee9-e125-4cff-a440-426509805c09",
    "lastUpdated": "2024-01-11T08:57:26.559Z",
    "author": {
      "reference": "Practitioner/996a2c29-5aaa-4810-bd6f-5f2935e90239",
      "display": "Rahul Agarwal"
    },
    "project": "70721083-1dde-413a-bd2a-419771a8718e",
    "compartment": [
      {
        "reference": "Project/70721083-1dde-413a-bd2a-419771a8718e"
      }
    ]
  },
  "id": "04a1c6f9-3459-4b6f-9359-d5f011c5fedb"
}
j
Hi Rahul — I'm still getting some situations where identifiers fail to work correct or validations get dropped. For instance, with this resource: https://app.medplum.com/Encounter/97839d72-d4dc-4b0e-909f-b9e67bc9a7e4/json, the profile listed should apply an identifier validation but it doesn't seem to be running when I edit / save the resource.
r
@jasonwa.ng I can take a look at this. Are you still getting the
no snapshot defined
error ?
j
No — I moved past that, thank you!
r
if you don't mind sharing, what was the resolution?
j
I think I pasted what you had in and it started working ... I'm not quite sure why, given that the values didn't look different.
r
Hi Jason, I got the following error when trying to save a copy of the encounter you shared.
My Steps: 1. Navigate to
app.medplum.com/StructureDefinition
2. Click "new" 3. Paste json of the StructureDefinition (See attached) 4. Click Ok 5. Navigate to app.medplum.com/Encounter 6. Click "new" 7. Paste the attached JSON for the encoutner 8. Click "Ok"
j
Hi — yes, I am seeing this same error happening even when I have the right values included
So the above two files + the screenshot illustrate how I'm still getting the error even though I should be satisfying all the requirements:
Tried saving the right values and then adding the profile afterwards, still doesn't work
the funny thing I've noticed on my other
StructureDefinition
is that even after removing the constraint from the StructureDefinition, the error continues to pop up saying that the constraint that was removed is not satisfied
r
Hi @jasonwa.ng , that is curious. I've been able to repro this, so we'll dig in on our side
a couple thoughts to get you unblocked:
1. It seems like the field your trying to constrain is not unique across
Encounters
, but rather more of a "type". In this case, I would recommend that you actually constrain
Encounter.category
2. Rather than a FHIRpath
constraint
, the "more appropriate" way to encode this would be via "slicing'. Some resources here: https://build.fhir.org/profiling.html#slicing https://kodjin.com/blog/how-to-slice-an-fhir-resource/ Example: https://hl7.org/fhir/us/core/STU5.0.1/StructureDefinition-us-core-body-temperature.html
j
Hi Rahul — any updates here in terms of the flaky validations?
Thank you for the suggestion on slicing as well, it's something we can consider! I think we do have a notion of different "types" of Encounters, but they all have different fields and not just variations on the same validations, so I'm thinking it's more correct to use separate
Profile
instead of just slicing. Would love any opinions if this is the wrong approach!
r
Hi @jasonwa.ng , This bugfix went in over the weekend, which fixed some issues with root-level constraints
However, I do think the slicing approach makes the most sense for your use case. Typically, having a different "slice" for each encounter type would be the way to go
This is the approach the US Core implementation guide takes. If you take a look at the Observation Profiles (https://build.fhir.org/ig/HL7/US-Core/profiles-and-extensions.html#observation), they have a different profile for each of the core types of vitals
Each profile constrains
category
and
code
fields to fixed values, using slicing
j
Agreed, but I also want to have completely different fields stored in different ways with each different type of encounter, so it's not just a situation of having fixed/different values for the same fields across multiple encounter types. Because of that I figured that profiles were the way to go
Does that change your opinion on how best to structure things? This information is super helpful so I really appreciate your advice here, thank you Rahul!
r
Based on this, I still think having 1 profile per encounter type is the right way to go. However, if you could expand on the following, I can give better pointers to resources for profiling these fields specifically > completely different fields stored in different ways with each different type of encounter
Profiles can be a pretty deep topic, so wanted to point you to the right places
j
Thank you, that's really helpful!
I also just tried to validate my Encounter with the StructureDefinition again and it failed with the exact same identifier issue, so I don't know if this is resolved yet
even after dropping the offending constraint, the constraint still shows up as a validation error
r
Hi @jasonwa.ng , I think your issue is related to this: https://github.com/medplum/medplum/issues/3812
j
Amazing, thank you!
r
j
Thanks! I think I see that the caching is fixed but I'm still getting an error on my validations, specifically with identifiers (if I get rid of that constraint, it works). Any suggestions on what I'm doing wrong? Encounter: https://app.medplum.com/Encounter/13722e3b-17fa-43f1-9c29-cf1415f964a1/json Profile definition: https://app.medplum.com/StructureDefinition/b15af608-b92e-4fac-aa0a-474af44fd2dc
Hi @rahul1 — any updates here? Would love to know exactly why I'm failing validations even though I appear to have the right expression + the right data
For reference, here's the
StructureDefinition
constraint on `Encounter.identifier`:
Copy code
{
        "id": "Encounter.identifier",
        "path": "Encounter.identifier",
        "min": 1,
        "max": "*",
        "type": [
          {
            "code": "Identifier"
          }
        ],
        "constraint": [
          {
            "key": "encounter-has-number-identifier",
            "severity": "error",
            "human": "Encounter must have an identifier that denotes which visit number it is.",
            "expression": "identifier.where(system = 'https://terminology.blah.org/CodeSystem/encounter-number' and value.matches('[0-9]+')).exists()",
            "xpath": "f:identifier[f:system/@value='https://terminology.blah.org/CodeSystem/encounter-number' and f:value/@value cast as xs:integer]"
          }
        ]
      },
And this is the actual value:
Copy code
{
  "resourceType": "Encounter",
  "identifier": [
    {
      "system": "https://terminology.blah.org/CodeSystem/encounter-number",
      "value": "5"
    }
  ],
  ...
]
r
@jasonwa.ng - the issue here is that the constraint on
Encounter.identifier
is referring to
identifier
. When you attach a constraint at a path, the context for the constraint expression is already that variable. So in this case, your constraint is looking for
identifier.identifier.where(...)
The solution that I was able to make work was to move this constraint to the
Encounter
element definition