Stream: python
Topic: stoopid python question
Eric Haas (Apr 18 2018 at 20:08):
What can go inside the model parenthesis?
- dict works
- json too
- another model?
import fhirclient.models.questionnaire as Q import fhirclient.models.coding as C e.g valuecoding = C.Coding({'code':'code', 'system': 'system':'display': 'display'} ) option = Q.QuestionnaireItemOption({valuecoding})
Bob Milius (Apr 19 2018 at 16:52):
I'm no python expert, but I would do this:
option = Q.QuestionnaireItemOption() option.valueCoding = valuecoding
Bob Milius (Apr 19 2018 at 17:12):
help(option)
says
| __init__(self, jsondict=None, strict=True) | Initialize all valid properties. | | :raises: FHIRValidationError on validation errors, unless strict is False | :param dict jsondict: A JSON dictionary to use for initialization | :param bool strict: If True (the default), invalid variables will raise a TypeError
So it looks like you can put in a jsondict in the parens.
Tried this and it also seems to work:
option = Q.QuestionnaireItemOption({'valueCoding':valuecoding.as_json()}) print(json.dumps(option.as_json(), indent=4)) { "valueCoding": { "code": "code", "display": "display", "system": "system" } }
Pascal Pfiffner (Apr 19 2018 at 18:22):
It's designed to take an in-memory representation of FHIR-JSON (meaning technically it's a Python dict
).
Eric Haas (Apr 19 2018 at 19:16):
ty
Last updated: Apr 12 2022 at 19:14 UTC