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

Regenerate models based off of R4 (4.0.1) #149

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[bumpversion]
current_version = 4.1.0
current_version = 4.2.0
files = fhirclient/client.py
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ session_data

# IDE files
*.sublime-*

/.idea/
.DS_Store
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ If you have any question or concerns, feel free to reach out to us at
[pep257]: http://www.python.org/dev/peps/pep-0257/
[good commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
[squash]: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
[AUTHORS.md]: https://github.com/smart-on-fhir/client-py/blob/master/AUTHORS.md
[AUTHORS.md]: https://github.com/smart-on-fhir/client-py/blob/main/AUTHORS.md
[procedures]: http://twistedmatrix.com/trac/wiki/CompatibilityPolicy
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ SMART FHIR Client
=================

This is _fhirclient_, a flexible Python client for [FHIR][] servers supporting the [SMART on FHIR][smart] protocol.
The client is compatible with Python 2.7.10 and Python 3.

Client versioning is not identical to FHIR versioning.
The `master` branch is usually on the latest version of the client as shown below, possibly on bugfix releases thereof.
The `main` branch is usually on the latest version of the client as shown below, possibly on bugfix releases thereof.
The `develop` branch should be on recent freezes, and the `feature/latest-ci` branch is periodically updated to the latest FHIR continuous integration builds.

Version | FHIR |  
-----------|---------------|---------
Version | FHIR |  
-----------|--------------|---------
**4.2.0** | `4.0.1` | (R4)
**4.0.0** | `4.0.0` | (R4)
**3.0.0** | `3.0.0` | (STU-3)
**x.x** | `1.8.0` | (STU-3 Ballot, Jan 2017)
Expand Down Expand Up @@ -224,6 +224,6 @@ Using setuptools (*Note*: Alternatively, you can use twine https://pypi.python.o
[smart]: http://docs.smarthealthit.org
[fhir-parser]: https://github.com/smart-on-fhir/fhir-parser
[docs]: https://smart-on-fhir.github.io/client-py
[flask_app]: https://github.com/smart-on-fhir/client-py/blob/master/flask_app.py
[flask_app]: https://github.com/smart-on-fhir/client-py/blob/main/flask_app.py
[doxygen]: http://www.stack.nl/~dimitri/doxygen
[doxypypy]: https://github.com/Feneric/doxypypy
4 changes: 2 additions & 2 deletions fhir-parser-resources/fhirsearch_tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from models.fhirsearch import FHIRSearch
from fhirclient.models.fhirsearch import FHIRSearch

if '__main__' == __name__:
from models.patient import Patient
from fhirclient.models.patient import Patient
print('1 '+FHIRSearch(Patient, {'name': 'Willis'}).construct())
print('1 '+Patient.where({'name': 'Willis'}).construct())
# print('1 '+Patient.where().name('Willis').construct())
Expand Down
1 change: 1 addition & 0 deletions fhir-parser-resources/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# unit tests
write_unittests = True
tpl_unittest_target = '../fhirclient/models' # target directory to write the generated unit test files to
tpl_unittest_target_ptrn = '{}_tests.py' # TODO: remove in future when we re-organize tests


# all these files should be copied to dirname(`tpl_resource_target_ptrn`): tuples of (path/to/file, module, array-of-class-names)
Expand Down
13 changes: 12 additions & 1 deletion fhir-parser-resources/template-elementfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@ def instantiate(cls, resource_type, jsondict):
:param dict jsondict: The JSON dictionary to use for data
:returns: A resource of the respective type or `Element`
"""
{%- for klass in classes %}{% if klass.resource_type %}
{%- for klass in classes %}
{%- if klass.resource_type %}
if "{{ klass.resource_type }}" == resource_type:
from . import {{ klass.module }}
return {{ klass.module }}.{{ klass.name }}(jsondict)
{%- elif klass.name %}
{#- backwards compatibility:
# fhir-parser stopped providing resource_type for non-resources.
# But we already shipped code that allowed creating non-resources.
# So to avoid an API break, we keep generating this for all classes.
# Can reconsider whether we want this once we jump to R5. (R4-QUIRK)
#}
if "{{ klass.name }}" == resource_type:
from . import {{ klass.module }}
return {{ klass.module }}.{{ klass.name }}(jsondict)
{%- endif %}{% endfor %}
from . import element
return element.Element(jsondict)
Expand Down
15 changes: 13 additions & 2 deletions fhir-parser-resources/template-resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ class {{ klass.name }}({% if klass.superclass in imports %}{{ klass.superclass.m
{%- if klass.resource_type %}

resource_type = "{{ klass.resource_type }}"
{%- elif klass.name %}
{#- backwards compatibility:
# fhir-parser stopped providing resource_type for non-resources.
# But we already shipped code that had this property for all classes.
# So to avoid an API break, we keep generating this for all classes.
# Can remove once we jump to R5. (R4-QUIRK)
#}

resource_type = "{{ klass.name }}"
{%- endif %}

def __init__(self, jsondict=None, strict=True):
Expand All @@ -33,7 +42,8 @@ def __init__(self, jsondict=None, strict=True):
:param dict jsondict: A JSON dictionary to use for initialization
:param bool strict: If True (the default), invalid variables will raise a TypeError
"""
{%- for prop in klass.properties %}
{#- sorted just to avoid churn during another update - can remove as its own PR at some point #}
{%- for prop in klass.properties|sort(attribute="name", case_sensitive=True) %}

self.{{ prop.name }} = None
""" {{ prop.short|wordwrap(67, wrapstring="\n ") }}.
Expand All @@ -55,7 +65,8 @@ def elementProperties(self):
{%- endif %}{% endfor %}
{%- endif %}
js.extend([
{%- for prop in klass.properties %}
{#- sorted just to avoid churn during another update - can remove as its own PR at some point #}
{%- for prop in klass.properties|sort(attribute="name", case_sensitive=True) %}
("{{ prop.name }}", "{{ prop.orig_name }}",
{%- if prop.module_name %} {{ prop.module_name }}.{% else %} {% endif %}{{ prop.class_name }}, {# #}
{{- prop.is_array }},
Expand Down
2 changes: 1 addition & 1 deletion fhirclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from server import FHIRServer, FHIRUnauthorizedException, FHIRNotFoundException

__version__ = '4.1.0'
__version__ = '4.2.0'
__author__ = 'SMART Platforms Team'
__license__ = 'APACHE2'
__copyright__ = "Copyright 2017 Boston Children's Hospital"
Expand Down
8 changes: 4 additions & 4 deletions fhirclient/fhirreference_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class TestResourceReference(unittest.TestCase):

def testContainedResourceDetection(self):
with io.open('test_contained_resource.json', 'r', encoding='utf-8') as h:
with io.open('fhirclient/test_contained_resource.json', 'r', encoding='utf-8') as h:
data = json.load(h)
q = questionnaire.Questionnaire(data)
self.assertIsNotNone(q, "Must instantiate Questionnaire")
Expand Down Expand Up @@ -52,7 +52,7 @@ def testContainedResourceDetection(self):
self.assertEqual('ValueSet', contained.resource_type)

def testRelativeReference(self):
with io.open('test_relative_reference.json', 'r', encoding='utf-8') as h:
with io.open('fhirclient/test_relative_reference.json', 'r', encoding='utf-8') as h:
data = json.load(h)
q = questionnaire.Questionnaire(data)
self.assertIsNotNone(q, "Must instantiate Questionnaire")
Expand Down Expand Up @@ -81,7 +81,7 @@ def testRelativeReference(self):
self.assertIsNotNone(relative, "Must resolve relative ValueSet even if requesting `Resource`")

def testBundleReferences(self):
with io.open('test_bundle.json', 'r', encoding='utf-8') as h:
with io.open('fhirclient/test_bundle.json', 'r', encoding='utf-8') as h:
data = json.load(h)
b = bundle.Bundle(data)
self.assertIsNotNone(b, "Must instantiate Bundle")
Expand Down Expand Up @@ -128,7 +128,7 @@ def __init__(self):
def request_json(self, path, nosign=False):
assert path
parts = os.path.split(path)
filename = '_'.join(parts) + '.json'
filename = 'fhirclient/' + '_'.join(parts) + '.json'
with io.open(filename, 'r', encoding='utf-8') as handle:
return json.load(handle)
return None
Expand Down
4 changes: 2 additions & 2 deletions fhirclient/models/account.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Generated from FHIR 4.0.0-a53ec6ee1b (http://hl7.org/fhir/StructureDefinition/Account) on 2019-05-07.
# 2019, SMART Health IT.
# Generated from FHIR 4.0.1-9346c8cc45 (http://hl7.org/fhir/StructureDefinition/Account) on 2024-07-15.
# 2024, SMART Health IT.
Comment on lines -4 to +5
Copy link
Contributor Author

@mikix mikix Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK so all the files in fhirclient/models/ are "owned" by fhir-parser. And I changed the templates (see above) to make sure that all the actual models themselves would only see real 4.0.0 -> 4.0.1 changes and not artifacts of changes in the generator.

I've gone through all the models myself and confirmed that you only see:

  • Comment changes like this
  • Comment changes on some properties (usually enums) that list more values than previously.

The test files however, I didn't find as easy a way to avoid churn in. But it was less important, so I didn't try very hard. Sorry. But hopefully those don't need close review.

We're still not running the tests during any CI - I hope to fix that later, but wanted to get on a known-good model-generation baseline first. The old generated tests were wonky.



from . import domainresource
Expand Down
28 changes: 14 additions & 14 deletions fhirclient/models/account_tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Generated from FHIR 4.0.0-a53ec6ee1b on 2019-05-07.
# 2019, SMART Health IT.
# Generated from FHIR 4.0.1-9346c8cc45 on 2024-07-15.
# 2024, SMART Health IT.


import os
Expand All @@ -22,7 +22,7 @@ def instantiate_from(self, filename):
return account.Account(js)

def testAccount1(self):
inst = self.instantiate_from("account-example.json")
inst = self.instantiate_from("account-example-with-guarantor.json")
self.assertIsNotNone(inst, "Must have instantiated a Account instance")
self.implAccount1(inst)

Expand All @@ -33,28 +33,32 @@ def testAccount1(self):

def implAccount1(self, inst):
self.assertEqual(inst.coverage[0].priority, 1)
self.assertEqual(inst.coverage[1].priority, 2)
self.assertEqual(inst.description, "Hospital charges")
self.assertEqual(inst.id, "example")
self.assertFalse(inst.guarantor[0].onHold)
self.assertEqual(inst.guarantor[0].period.start.date, FHIRDate("2016-01-01").date)
self.assertEqual(inst.guarantor[0].period.start.as_json(), "2016-01-01")
self.assertEqual(inst.id, "ewg")
self.assertEqual(inst.identifier[0].system, "urn:oid:0.1.2.3.4.5.6.7")
self.assertEqual(inst.identifier[0].value, "654321")
self.assertEqual(inst.meta.tag[0].code, "HTEST")
self.assertEqual(inst.meta.tag[0].display, "test health data")
self.assertEqual(inst.meta.tag[0].system, "http://terminology.hl7.org/CodeSystem/v3-ActReason")
self.assertEqual(inst.name, "HACC Funded Billing for Peter James Chalmers")
self.assertEqual(inst.name, "Inpatient: Peter James Chalmers")
self.assertEqual(inst.servicePeriod.end.date, FHIRDate("2016-06-30").date)
self.assertEqual(inst.servicePeriod.end.as_json(), "2016-06-30")
self.assertEqual(inst.servicePeriod.start.date, FHIRDate("2016-01-01").date)
self.assertEqual(inst.servicePeriod.start.as_json(), "2016-01-01")
self.assertEqual(inst.status, "active")
self.assertEqual(inst.text.div, "<div xmlns=\"http://www.w3.org/1999/xhtml\">HACC Funded Billing for Peter James Chalmers</div>")
self.assertEqual(inst.text.div, "<div xmlns=\"http://www.w3.org/1999/xhtml\">Inpatient Admission for Peter James Chalmers Account</div>")
self.assertEqual(inst.text.status, "generated")
self.assertEqual(inst.type.coding[0].code, "PBILLACCT")
self.assertEqual(inst.type.coding[0].display, "patient billing account")
self.assertEqual(inst.type.coding[0].system, "http://terminology.hl7.org/CodeSystem/v3-ActCode")
self.assertEqual(inst.type.text, "patient")

def testAccount2(self):
inst = self.instantiate_from("account-example-with-guarantor.json")
inst = self.instantiate_from("account-example.json")
self.assertIsNotNone(inst, "Must have instantiated a Account instance")
self.implAccount2(inst)

Expand All @@ -65,24 +69,20 @@ def testAccount2(self):

def implAccount2(self, inst):
self.assertEqual(inst.coverage[0].priority, 1)
self.assertEqual(inst.coverage[1].priority, 2)
self.assertEqual(inst.description, "Hospital charges")
self.assertFalse(inst.guarantor[0].onHold)
self.assertEqual(inst.guarantor[0].period.start.date, FHIRDate("2016-01-01").date)
self.assertEqual(inst.guarantor[0].period.start.as_json(), "2016-01-01")
self.assertEqual(inst.id, "ewg")
self.assertEqual(inst.id, "example")
self.assertEqual(inst.identifier[0].system, "urn:oid:0.1.2.3.4.5.6.7")
self.assertEqual(inst.identifier[0].value, "654321")
self.assertEqual(inst.meta.tag[0].code, "HTEST")
self.assertEqual(inst.meta.tag[0].display, "test health data")
self.assertEqual(inst.meta.tag[0].system, "http://terminology.hl7.org/CodeSystem/v3-ActReason")
self.assertEqual(inst.name, "Inpatient: Peter James Chalmers")
self.assertEqual(inst.name, "HACC Funded Billing for Peter James Chalmers")
self.assertEqual(inst.servicePeriod.end.date, FHIRDate("2016-06-30").date)
self.assertEqual(inst.servicePeriod.end.as_json(), "2016-06-30")
self.assertEqual(inst.servicePeriod.start.date, FHIRDate("2016-01-01").date)
self.assertEqual(inst.servicePeriod.start.as_json(), "2016-01-01")
self.assertEqual(inst.status, "active")
self.assertEqual(inst.text.div, "<div xmlns=\"http://www.w3.org/1999/xhtml\">Inpatient Admission for Peter James Chalmers Account</div>")
self.assertEqual(inst.text.div, "<div xmlns=\"http://www.w3.org/1999/xhtml\">HACC Funded Billing for Peter James Chalmers</div>")
self.assertEqual(inst.text.status, "generated")
self.assertEqual(inst.type.coding[0].code, "PBILLACCT")
self.assertEqual(inst.type.coding[0].display, "patient billing account")
Expand Down
7 changes: 4 additions & 3 deletions fhirclient/models/activitydefinition.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Generated from FHIR 4.0.0-a53ec6ee1b (http://hl7.org/fhir/StructureDefinition/ActivityDefinition) on 2019-05-07.
# 2019, SMART Health IT.
# Generated from FHIR 4.0.1-9346c8cc45 (http://hl7.org/fhir/StructureDefinition/ActivityDefinition) on 2024-07-15.
# 2024, SMART Health IT.


from . import domainresource
Expand Down Expand Up @@ -91,7 +91,8 @@ def __init__(self, jsondict=None, strict=True):
List of `Identifier` items (represented as `dict` in JSON). """

self.intent = None
""" proposal | plan | order.
""" proposal | plan | directive | order | original-order | reflex-order
| filler-order | instance-order | option.
Type `str`. """

self.jurisdiction = None
Expand Down
Loading