Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nazrulworld/3d4a7ebecfac2ddaef88262218218273 to your computer and use it in GitHub Desktop.
Save nazrulworld/3d4a7ebecfac2ddaef88262218218273 to your computer and use it in GitHub Desktop.
qr_string = """{
"resourceType": "QuestionnaireResponse",
"id": "3141",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n <pre>\n Comorbidity? YES\n Cardial Comorbidity? YES\n Angina? YES\n MI? NO\n Vascular Comorbidity?\n (no answers)\n ...\n Histopathology\n Abdominal\n pT category: 1a\n ...\n </pre>\n </div>"
},
"contained": [
{
"resourceType": "Patient",
"id": "patsub",
"identifier": [
{
"system": "http://cancer.questionnaire.org/systems/id/patientnr",
"value": "A34442332"
},
{
"type": {
"text": "Dutch BSN"
},
"system": "urn:oid:2.16.840.1.113883.2.4.6.3",
"value": "188912345"
}
],
"gender": "male",
"birthDate": "1972-11-30"
},
{
"resourceType": "ServiceRequest",
"id": "order",
"status": "unknown",
"intent": "order",
"subject": {
"reference": "#patsub"
},
"requester": {
"reference": "Practitioner/example"
}
},
{
"resourceType": "Practitioner",
"id": "questauth",
"identifier": [
{
"type": {
"text": "AUMC, Den Helder"
},
"system": "http://cancer.questionnaire.org/systems/id/org",
"value": "AUMC"
}
]
}
],
"identifier": {
"system": "http://example.org/fhir/NamingSystem/questionnaire-ids",
"value": "Q12349876"
},
"basedOn": [
{
"reference": "#order"
}
],
"partOf": [
{
"reference": "Procedure/f201"
}
],
"status": "completed",
"subject": {
"reference": "#patsub"
},
"encounter": {
"reference": "Encounter/example"
},
"authored": "2013-02-19T14:15:00-05:00",
"author": {
"reference": "#questauth"
},
"item": [
{
"linkId": "1",
"item": [
{
"linkId": "1.1",
"answer": [
{
"valueCoding": {
"system": "http://cancer.questionnaire.org/system/code/yesno",
"code": "1",
"display": "Yes"
},
"item": [
{
"linkId": "1.1.1",
"item": [
{
"linkId": "1.1.1.1",
"answer": [
{
"valueCoding": {
"system": "http://cancer.questionnaire.org/system/code/yesno",
"code": "1"
}
}
]
},
{
"linkId": "1.1.1.2",
"answer": [
{
"valueCoding": {
"system": "http://cancer.questionnaire.org/system/code/yesno",
"code": "1"
}
}
]
},
{
"linkId": "1.1.1.3",
"answer": [
{
"valueCoding": {
"system": "http://cancer.questionnaire.org/system/code/yesno",
"code": "0"
}
}
]
}
]
}
]
}
]
}
]
}
]
}
"""
# if FHIR version R4
from fhir.resources import construct_fhir_element
# if FHIR version STU3
# from fhir.resources.STU3 import construct_fhir_element
import datetime
questionnaire_obj = construct_fhir_element("QuestionnaireResponse", qr_string)
for item in questionnaire_obj.item:
linkid = item.linkId
if item.item:
for itm in item.item:
# check certain question ref
if itm.linkId == "Foo LinkID":
if itm.answer is None:
# do your action
pass
elif itm.answer[0].valueCoding and itm.answer[0].valueCoding.code == "0":
# do action
pass
elif itm.answer[0].valueDateTime and itm.answer[0].valueDateTime > datetime.datetime.now():
# do action
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment