Skip to content

Commit

Permalink
📝 readme, changes log are updated, as preparation for next release.
Browse files Browse the repository at this point in the history
  • Loading branch information
nazrulworld committed Apr 5, 2021
1 parent 92caf7b commit 9cea524
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ History
New Feature

- Parsing YAML file or string/bytes contents, now accept extra parameter ``loader`` class.
- Parsing from XML file or string/bytes contents are now supported. With possible to provide xmlparser for schema validation purpose.

Bugfixes

Expand Down
57 changes: 54 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ Along side with JSON string export, it is possible to export as XML string!
Before using this feature, make sure associated dependent library is installed. Use ``fhir.resources[xml]`` or ``fhir.resources[all]`` as
your project requirements.

**XML schema validator!**
It is possible to provide custom xmlparser, during load from file or string, meaning that you can validate
data against FHIR xml schema(and/or your custom schema).

Example-1 Export::
>>> from fhir.resources.patient import Patient
>>> data = {"active": True, "gender": "male", "birthDate": "2000-09-18", "name": [{"text": "Primal Kons"}]}
Expand All @@ -526,11 +530,58 @@ Example-1 Export::
<birthDate value="2000-09-18"/>
</Patient>


Example-2 Import from string::
>>> from fhir.resources.patient import Patient
>>> data = {"active": True, "gender": "male", "birthDate": "2000-09-18", "name": [{"text": "Primal Kons"}]}
>>> patient_obj = Patient(**data)
>>> xml_str = patient_obj.xml(pretty_print=True)
>>> print(xml_str)
>>> data = b"""<?xml version='1.0' encoding='utf-8'?>
... <Patient xmlns="http://hl7.org/fhir">
... <active value="true"/>
... <name>
... <text value="Primal Kons"/>
... </name>
... <gender value="male"/>
... <birthDate value="2000-09-18"/>
... </Patient>"""
>>> patient = Patient.parse_raw(data, content_type="text/xml")
>>> print(patient.json(indent=2))
{
"resourceType": "Patient",
"active": true,
"name": [
{
"text": "Primal Kons",
"family": "Kons",
"given": [
"Primal"
]
}
],
"gender": "male",
"birthDate": "2000-09-18"
}

>>> with xml parser
>>> import lxml
>>> schema = lxml.etree.XMLSchema(file=str(FHIR_XSD_DIR / "patient.xsd"))
>>> xmlparser = lxml.etree.XMLParser(schema=schema)
>>> patient2 = Patient.parse_raw(data, content_type="text/xml", xmlparser=xmlparser)
>>> patient2 == patient
True

Example-3 Import from file::
>>> patient3 = Patient.parse_file("Patient.xml")
>>> patient3 == patient and patient3 == patient2
True


**XML FAQ**

- Import from XML string or file is not supported yet and is in todo list.
- Although generated XML is validated against ``FHIR/patient.xsd`` and ``FHIR/observation.xsd`` in tests, but we suggest you check output of your production data.
- Comment feature is included, but we recommend you check in your complex usages.
- Although generated XML is validated against ``FHIR/patient.xsd`` and ``FHIR/observation.xsd`` in tests, but we suggest you check output of your production data.
- Comment feature is included, but we recommend you check in your complex usages.


YAML Supports
Expand Down
2 changes: 1 addition & 1 deletion fhir/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .fhirtypesvalidators import get_fhir_model_class

__fhir_version__ = "4.0.1"
__version__ = "6.2.0b1"
__version__ = "6.2.0b2"


def construct_fhir_element(
Expand Down

0 comments on commit 9cea524

Please sign in to comment.