fhircraft


Namefhircraft JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryPydantic FHIR modeling
upload_time2024-08-20 13:31:57
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseThe MIT License (MIT) Copyright (c) 2024 to present Luis Fábregas-Ibáñez and individual contributors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords fhir pydantic healthcare modelling validation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <a name="readme-top"></a>

<!-- PROJECT LOGO -->

<br />
<div align="center">
  <a href="https://github.com/luisfabib/fhircraft">
    <img src="docs/assets/images/logo-banner.png" width="50%">
  </a>

  [![CI](https://github.com/luisfabib/fhircraft/actions/workflows/CI.yaml/badge.svg?branch=main&event=push)](https://github.com/luisfabib/fhircraft/actions/workflows/CI.yaml)
  [![releases](https://img.shields.io/github/v/release/luisfabib/fhircraft)](https://github.com/luisfabib/fhircraft)
  [![versions](https://img.shields.io/pypi/pyversions/fhircraft.svg)](https://github.com/luisfabib/fhircraft)
  [![license](https://img.shields.io/github/license/luisfabib/fhircraft.svg)](https://github.com/luisfabib/fhircraft/blob/main/LICENSE)
  [![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://docs.pydantic.dev/latest/contributing/#badges)
  ![FHIR Releases](https://img.shields.io/badge/FHIR-R4_R4B_R5-blue?style=flat&logo=fireship&logoColor=red&labelColor=%231e293b)

  <p align="center">
    Fhircraft is a Python package that dynamically generates Pydantic FHIR (Fast Healthcare Interoperability Resources) resource models from FHIR specifications, enabling comprehensive data structuring, validation, and typing within Python. It also offers a fully functional FHIRPath engine and code generation features to facilitate integration with other systems.
    <br />
    <br />
    :construction:<i> This package is under active development. Major and/or breaking changes are to be expected in future updates.</i>:construction:
    <br />
    <br />
    <a href="https://luisfabib.github.io/fhircraft "><strong>Explore the docs »</strong></a>
    <br />
    <br />
    <a href="https://github.com/luisfabib/fhircraft/issues/new?labels=bug&template=bug-report---.md">Report Bug</a>
    ·
    <a href="https://github.com/luisfabib/fhircraft/issues/new?labels=enhancement&template=feature-request---.md">Request Feature</a>
  </p>
</div>

## Why use Fhircraft?

- **Dynamic FHIR models** – Generate Pydantic FHIR resource models dynamically from FHIR specification; get all FHIR's data structuring, validation and typing in a pythonic way.

- **Simple FHIR validation** – Perform complete parsing and validation of FHIR resources without leaving Python; avoid dealing with FHIR's often complex rules and constraints. 

- **Pydantic core** – Profit from Pydantic's validation and (de)-serialization capabilities which have made it the most widely used data validation library for Python.     

- **Code generator** – Leverage the code generation features of Fhircraft to write static Pydantic/Python code that can be integrated into other systems. 

- **Pythonic FHIRPath** – Fhircraft provides a fully functional, pythonic and compliant FHIRPath engine to easily work with FHIR resources without leaving Python.  


## Usage 

### Prerequisites

A valid installation of Python >3.8 is required.  


### Installation

To install `fhircraft`, you can download and install the package via `pip` (requires `pip` > 24.1):

```bash
pip install fhircraft
``` 

or install it from the source 

```bash
pip install git+https://github.com/luisfabib/fhircraft.git
```

### Getting Started

This is a quick reference on how to quickly accomplish the most common tasks with Fhircraft:

- #### Constructing FHIR Pydantic models 

  To generate a Pydantic model representation for a FHIR resource, use the `construct_resource_model` function. This function automatically creates a model based on the structure definition of the specified resource or profile.
  For optimal control and security, it is recommended to manage FHIR structure definitions as local files. These files should be loaded into Python and parsed into dictionary objects.
  
  ``` python 
    from fhircraft.fhir.resources.factory import construct_resource_model
    from fhicraft.utils import load_file
    patient_model = construct_resource_model(
        structure_definition=load_file('FHIR_StructureDefinition_Patient.json')
    )
  ``` 

- #### Generating Pydantic FHIR models' source code

  Fhircraft allows you to generate reusable source code for Pydantic FHIR models. By using the `generate_resource_model_code` function, you can obtain the source code (as a string) that defines the FHIR Pydantic model. This can be particularly useful for integrating the model into other projects or sharing it across different applications.


  ``` python
  from fhircraft.fhir.resources.generator import generate_resource_model_code
  source_code = generate_resource_model_code(patient_model)
  ```

  You can save the generated source code and reuse it as needed. Keep in mind that the code requires Fhircraft and its dependencies to be installed in order to function properly.

- #### Validating FHIR payloads

  The generated Pydantic models can be used to validate FHIR payloads, ensuring that they conform to the structure and constraints of the specified resource or profile.

  ``` python
  from fhicraft.utils import load_file
  data = load_file('my_fhir_patient.json')
  my_patient = patient_model.model_validate(data)
  ```

  If the input data does not conform to the expected FHIR resource or profile, the Pydantic model will raise a `ValidationError`. If no error is raised, the FHIR payload is valid and successfully loaded into the model.


- #### Model manipulation using FHIRPath

  You can specify the FHIRPath expression as a string in the standard notation to interact with the resource efficiently. This feature allows for complex queries and updates, enhancing your ability to work with FHIR data programmatically.

  ``` python
  from fhicraft.fhir.path import fhirpath
  patient_surname = my_patient.get_fhirpath('Patient.name.surname')
  ```

<p align="right">(<a href="#readme-top">back to top</a>)</p>

<!-- CONTRIBUTING -->
## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/amazing_feature`)
3. Commit your Changes (`git commit -m 'Add some amazing feature'`)
4. Push to the Branch (`git push origin feature/amazing_feature`)
5. Open a Pull Request (PR)

<p align="right">(<a href="#readme-top">back to top</a>)</p>

<!-- ACKNOWLEDGMENTS -->
## Support

This project has been supported by the following institutions:

- **University Hospital of Zurich**
  
  <a href="https://www.usz.ch/"><img src="docs/assets/images/usz-logo.png" width="20%"></a>



<!-- LICENSE -->
## License

Distributed under the MIT License. See ![LICENSE](https://github.com/luisfabib/fhircraft?tab=MIT-1-ov-file) for more information.

<p align="right">(<a href="#readme-top">back to top</a>)</p>


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fhircraft",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "FHIR, Pydantic, healthcare, modelling, validation",
    "author": null,
    "author_email": "Luis F\u00e1bregas-Ib\u00e1\u00f1ez <luisfabib@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/14/d0/01be9a4ffb5aba61e8b7a23a5dc4ec67dbee3cd2a5ba3214ef9c6632e1fd/fhircraft-0.1.0.tar.gz",
    "platform": null,
    "description": "<a name=\"readme-top\"></a>\n\n<!-- PROJECT LOGO -->\n\n<br />\n<div align=\"center\">\n  <a href=\"https://github.com/luisfabib/fhircraft\">\n    <img src=\"docs/assets/images/logo-banner.png\" width=\"50%\">\n  </a>\n\n  [![CI](https://github.com/luisfabib/fhircraft/actions/workflows/CI.yaml/badge.svg?branch=main&event=push)](https://github.com/luisfabib/fhircraft/actions/workflows/CI.yaml)\n  [![releases](https://img.shields.io/github/v/release/luisfabib/fhircraft)](https://github.com/luisfabib/fhircraft)\n  [![versions](https://img.shields.io/pypi/pyversions/fhircraft.svg)](https://github.com/luisfabib/fhircraft)\n  [![license](https://img.shields.io/github/license/luisfabib/fhircraft.svg)](https://github.com/luisfabib/fhircraft/blob/main/LICENSE)\n  [![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://docs.pydantic.dev/latest/contributing/#badges)\n  ![FHIR Releases](https://img.shields.io/badge/FHIR-R4_R4B_R5-blue?style=flat&logo=fireship&logoColor=red&labelColor=%231e293b)\n\n  <p align=\"center\">\n    Fhircraft is a Python package that dynamically generates Pydantic FHIR (Fast Healthcare Interoperability Resources) resource models from FHIR specifications, enabling comprehensive data structuring, validation, and typing within Python. It also offers a fully functional FHIRPath engine and code generation features to facilitate integration with other systems.\n    <br />\n    <br />\n    :construction:<i> This package is under active development. Major and/or breaking changes are to be expected in future updates.</i>:construction:\n    <br />\n    <br />\n    <a href=\"https://luisfabib.github.io/fhircraft \"><strong>Explore the docs \u00bb</strong></a>\n    <br />\n    <br />\n    <a href=\"https://github.com/luisfabib/fhircraft/issues/new?labels=bug&template=bug-report---.md\">Report Bug</a>\n    \u00b7\n    <a href=\"https://github.com/luisfabib/fhircraft/issues/new?labels=enhancement&template=feature-request---.md\">Request Feature</a>\n  </p>\n</div>\n\n## Why use Fhircraft?\n\n- **Dynamic FHIR models** \u2013 Generate Pydantic FHIR resource models dynamically from FHIR specification; get all FHIR's data structuring, validation and typing in a pythonic way.\n\n- **Simple FHIR validation** \u2013 Perform complete parsing and validation of FHIR resources without leaving Python; avoid dealing with FHIR's often complex rules and constraints. \n\n- **Pydantic core** \u2013 Profit from Pydantic's validation and (de)-serialization capabilities which have made it the most widely used data validation library for Python.     \n\n- **Code generator** \u2013 Leverage the code generation features of Fhircraft to write static Pydantic/Python code that can be integrated into other systems. \n\n- **Pythonic FHIRPath** \u2013 Fhircraft provides a fully functional, pythonic and compliant FHIRPath engine to easily work with FHIR resources without leaving Python.  \n\n\n## Usage \n\n### Prerequisites\n\nA valid installation of Python >3.8 is required.  \n\n\n### Installation\n\nTo install `fhircraft`, you can download and install the package via `pip` (requires `pip` > 24.1):\n\n```bash\npip install fhircraft\n``` \n\nor install it from the source \n\n```bash\npip install git+https://github.com/luisfabib/fhircraft.git\n```\n\n### Getting Started\n\nThis is a quick reference on how to quickly accomplish the most common tasks with Fhircraft:\n\n- #### Constructing FHIR Pydantic models \n\n  To generate a Pydantic model representation for a FHIR resource, use the `construct_resource_model` function. This function automatically creates a model based on the structure definition of the specified resource or profile.\n  For optimal control and security, it is recommended to manage FHIR structure definitions as local files. These files should be loaded into Python and parsed into dictionary objects.\n  \n  ``` python \n    from fhircraft.fhir.resources.factory import construct_resource_model\n    from fhicraft.utils import load_file\n    patient_model = construct_resource_model(\n        structure_definition=load_file('FHIR_StructureDefinition_Patient.json')\n    )\n  ``` \n\n- #### Generating Pydantic FHIR models' source code\n\n  Fhircraft allows you to generate reusable source code for Pydantic FHIR models. By using the `generate_resource_model_code` function, you can obtain the source code (as a string) that defines the FHIR Pydantic model. This can be particularly useful for integrating the model into other projects or sharing it across different applications.\n\n\n  ``` python\n  from fhircraft.fhir.resources.generator import generate_resource_model_code\n  source_code = generate_resource_model_code(patient_model)\n  ```\n\n  You can save the generated source code and reuse it as needed. Keep in mind that the code requires Fhircraft and its dependencies to be installed in order to function properly.\n\n- #### Validating FHIR payloads\n\n  The generated Pydantic models can be used to validate FHIR payloads, ensuring that they conform to the structure and constraints of the specified resource or profile.\n\n  ``` python\n  from fhicraft.utils import load_file\n  data = load_file('my_fhir_patient.json')\n  my_patient = patient_model.model_validate(data)\n  ```\n\n  If the input data does not conform to the expected FHIR resource or profile, the Pydantic model will raise a `ValidationError`. If no error is raised, the FHIR payload is valid and successfully loaded into the model.\n\n\n- #### Model manipulation using FHIRPath\n\n  You can specify the FHIRPath expression as a string in the standard notation to interact with the resource efficiently. This feature allows for complex queries and updates, enhancing your ability to work with FHIR data programmatically.\n\n  ``` python\n  from fhicraft.fhir.path import fhirpath\n  patient_surname = my_patient.get_fhirpath('Patient.name.surname')\n  ```\n\n<p align=\"right\">(<a href=\"#readme-top\">back to top</a>)</p>\n\n<!-- CONTRIBUTING -->\n## Contributing\n\nContributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\nIf you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag \"enhancement\".\n\n1. Fork the Project\n2. Create your Feature Branch (`git checkout -b feature/amazing_feature`)\n3. Commit your Changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the Branch (`git push origin feature/amazing_feature`)\n5. Open a Pull Request (PR)\n\n<p align=\"right\">(<a href=\"#readme-top\">back to top</a>)</p>\n\n<!-- ACKNOWLEDGMENTS -->\n## Support\n\nThis project has been supported by the following institutions:\n\n- **University Hospital of Zurich**\n  \n  <a href=\"https://www.usz.ch/\"><img src=\"docs/assets/images/usz-logo.png\" width=\"20%\"></a>\n\n\n\n<!-- LICENSE -->\n## License\n\nDistributed under the MIT License. See ![LICENSE](https://github.com/luisfabib/fhircraft?tab=MIT-1-ov-file) for more information.\n\n<p align=\"right\">(<a href=\"#readme-top\">back to top</a>)</p>\n\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2024 to present Luis F\u00e1bregas-Ib\u00e1\u00f1ez and individual contributors.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Pydantic FHIR modeling",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://luisfabib.github.io/fhircraft/",
        "Homepage": "https://github.com/luisfabib/fhircraft",
        "Issues": "https://github.com/luisfabib/fhircraft/issues"
    },
    "split_keywords": [
        "fhir",
        " pydantic",
        " healthcare",
        " modelling",
        " validation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "255f7432326c6546ddaf7e199016962ff0a64f13c9b323d86d59831e437306bf",
                "md5": "e539b6fd1281db48a1efb60ad630d1fc",
                "sha256": "23a33136fcd09119cfa2383cd39a87033bebdaa759ee87152606c12e12d8d00c"
            },
            "downloads": -1,
            "filename": "fhircraft-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e539b6fd1281db48a1efb60ad630d1fc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 12546136,
            "upload_time": "2024-08-20T13:31:55",
            "upload_time_iso_8601": "2024-08-20T13:31:55.229053Z",
            "url": "https://files.pythonhosted.org/packages/25/5f/7432326c6546ddaf7e199016962ff0a64f13c9b323d86d59831e437306bf/fhircraft-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "14d001be9a4ffb5aba61e8b7a23a5dc4ec67dbee3cd2a5ba3214ef9c6632e1fd",
                "md5": "2464316dc054be1bfbddf43e0e32d513",
                "sha256": "238eb1f5661d18b9b8f55ab744e81794d8f7a99951da9c7fe0b0dc1e3aa94815"
            },
            "downloads": -1,
            "filename": "fhircraft-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2464316dc054be1bfbddf43e0e32d513",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 12457180,
            "upload_time": "2024-08-20T13:31:57",
            "upload_time_iso_8601": "2024-08-20T13:31:57.817749Z",
            "url": "https://files.pythonhosted.org/packages/14/d0/01be9a4ffb5aba61e8b7a23a5dc4ec67dbee3cd2a5ba3214ef9c6632e1fd/fhircraft-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-20 13:31:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "luisfabib",
    "github_project": "fhircraft",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fhircraft"
}
        
Elapsed time: 0.30280s