medizininformatik-initiative / fhir-compatibility-test

Apache License 2.0
2 stars 0 forks source link

Skript doesn't work with patient ressources which have the Link attribute. #2

Open NamUKF opened 2 years ago

NamUKF commented 2 years ago

In the Method query_successfulthe JSON response validates, by checking the link in the Bundle ressource.

https://github.com/medizininformatik-initiative/fhir-compatibility-test/blob/ab018cacb332f934dea19c703e66339390760327/fhir-compatibility-test-client.py#L78

However bundle is not the only ressource which has 'link' in its ressource. For example the Patient resource can have link as an entry.

https://simplifier.net/packages/de.medizininformatikinitiative.kerndatensatz.person/2.0.0-ballot2/files/533897/~overview

it results in an error msg:

Traceback (most recent call last):
  File "fhir-compatibility-test-client.py", line 154, in <module>
    execute_compatibility_queries(report["compatibilityQueries"])
  File "fhir-compatibility-test-client.py", line 134, in execute_compatibility_queries
    if query['nResourcesFound'] > 0 and not references_correct(resp['json'], query['refsToCheck']):
  File "fhir-compatibility-test-client.py", line 108, in references_correct
    ref_resp = execute_query(f'/{match.value}')
  File "fhir-compatibility-test-client.py", line 80, in execute_query
    if 'link' in resp_object['json'].keys() and not query_successful(query_url, resp_object['json']['link']):
  File "fhir-compatibility-test-client.py", line 44, in query_successful
    if link['relation'] == 'self':
KeyError: 'relation'

The patient resource we used:

{"address":[{"type":"both","line":["Hugstetter Str. 55"],"city":"Küssaberg","postalCode":"79790","country":"DE"}],"meta":{"versionId":"13698850","lastUpdated":"2022-09-05T11:44:45.581Z","profile":["https://www.medizininformatik-initiative.de/fhir/core/modul-person/StructureDefinition/Patient"],"security":[{"system":"http://terminology.hl7.org/CodeSystem/v3-ObservationValue","code":"REDACTED","display":"redacted"},{"code":"SUBSTITUTED","display":"exact value is replaced with a predefined value"},{"system":"http://terminology.hl7.org/CodeSystem/v3-ObservationValue","code":"PSEUDED","display":"pseudonymized"}]},"birthDate":"1972","resourceType":"Patient","extension":[{"url":"https://uniklinik-freiburg.de/fhir/ResourceVersion","valueCoding":{"system":"https://uniklinik-freiburg.de/fhir/ResourceVersion","code":"mii-kds-pat-2-0-0-ballot2","display":"de.medizininformatikinitiative.kerndatensatz.person 2.0.0-ballot2"}}],"link":[{"other":{"reference":"Patient/p69984879115486X55"},"type":"replaces"}],"id":"p459315851425X6833","identifier":[{"use":"usual","type":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/v2-0203","code":"MR"}]},"system":"https://www.uniklinik-freiburg.de/fhir/sid/patient-id","value":"p459315851425X6833"}],"gender":"male"}

Fix: bei der Code Stelle: https://github.com/medizininformatik-initiative/fhir-compatibility-test/blob/ab018cacb332f934dea19c703e66339390760327/fhir-compatibility-test-client.py#L78

Validiert das das JSON Objekt was reinkommt, ein Bundle ist, ansonsten nicht den selflink überprüfen.

 80         resp_links = resp_object['json']['link'] if resp_object['json']["resourceType"] == "Bundle" else ''
 81
 82         if 'link' in resp_object['json'].keys() and not query_successful(query_url, resp_links):
 83             resp_object['status'] = "failed"
juliangruendner commented 2 years ago

@NamUKF please specify further and give an example as the issue cannot be understood otherwise