{"id":28089518,"url":"https://github.com/zombitrafik/fhirx","last_synced_at":"2025-10-05T02:23:18.505Z","repository":{"id":185018151,"uuid":"672855964","full_name":"zombitrafik/fhirx","owner":"zombitrafik","description":"Fhirx is a library to generate typescript classes from HL7 FHIR structure definition JSON file","archived":false,"fork":false,"pushed_at":"2023-08-04T07:20:21.000Z","size":14,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-03T13:48:27.853Z","etag":null,"topics":["fhir","fhir-parser","fhir-resources","library","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zombitrafik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-07-31T10:17:37.000Z","updated_at":"2025-03-25T14:49:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"729d3d79-123f-4697-82e2-ddfb4a29ae20","html_url":"https://github.com/zombitrafik/fhirx","commit_stats":null,"previous_names":["zombitrafik/fhirx"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zombitrafik/fhirx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zombitrafik%2Ffhirx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zombitrafik%2Ffhirx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zombitrafik%2Ffhirx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zombitrafik%2Ffhirx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zombitrafik","download_url":"https://codeload.github.com/zombitrafik/fhirx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zombitrafik%2Ffhirx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278399691,"owners_count":25980334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fhir","fhir-parser","fhir-resources","library","typescript"],"created_at":"2025-05-13T12:59:27.469Z","updated_at":"2025-10-05T02:23:18.477Z","avatar_url":"https://github.com/zombitrafik.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"left\"\u003eFhirx\u003c/h1\u003e\n\n\u003cp align=\"left\"\u003eFhirx is a library to generate typescript classes from HL7 FHIR structure definition JSON file.\u003c/p\u003e\n\n\u003chr\u003e\n\n\u003cp align=\"left\"\u003e\n  \u003ca href=\"https://www.npmjs.com/fhirx\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/fhirx.svg?logo=npm\u0026logoColor=fff\u0026label=NPM+package\u0026color=limegreen\" alt=\"Fhirx on npm\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Development setup\n\n### Prerequisites\n\n- Install [Node.js] which includes [Node Package Manager][npm]\n\n### Setting up the project\n\nInstall Fhirx:\n\n```\nnpm install --save-dev fhirx\n```\n\nCreate `fhirx.config.js` file in the root of the project:\n\n```js\nmodule.exports = {}\n```\n\nSupported config properties:\n\n| Property                       | Required | Type    | Default                   | Description                                                                                                                                                                      |\n|:-------------------------------|:--------:|---------|:--------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `structureDefinition.path`     |   true   | string  |                           | You must provide a path to the folder where structure definition JSON file is stored.                                                                                            |\n| `structureDefinition.filename` |  false   | string  | structure-definition.json | Allows you to change the default name of the structure definition JSON file.                                                                                                     |\n| `outputPath`                   |   true   | string  |                           | You must provide a path to the folder where FHIR classes will be generated.                                                                                                      |\n| `namespace`                    |  false   | string  | Fhir                      | Allows you to change the default name of the exported namespace.                                                                                                                 |\n| `load`                         |  false   | Promise |                           | This field is optional, but required if you want to use CLI to fetch structure definition file. \u003cbr\u003e The `load` function should return a valid Structure Definition JSON object. |\n\n`fhirx.config.js` example:\n\n```js\nmodule.exports = {\n  structureDefinition: {\n    path: 'src/fhirx'\n  },\n  outputPath: 'src/fhirx/generated';\n}\n```\n\n### CLI\nTo generate Fhir classes use the following command:\n\n`fhirx --compile`\n\nTo patch Fhir classes use the following command:\n\n`fhirx --patch-resources`\n\nTo load structure definition JSON file use the following command:\n\n`fhirx --load-structure-definition`\n\n## Usage\n\nConsidering that `outputPath: 'src/fhirx/generated'` and `namespace: 'Fhir'`:\n\n```typescript\nimport {Fhir} from 'src/fhirx/generated/fhir';\n\nexport class Main {\n  constructor() {\n    const appointment = new Fhir.Appointment()\n      .setStatus('pending')\n      .setComment('comment')\n      .setAppointmentType(\n        new Fhir.CodeableConcept()\n          .addCoding(\n            new Fhir.Coding()\n              .setCode('code')\n              .setDisplay('display')\n          )\n          .addCoding(\n            new Fhir.Coding()\n              .setCode('code2')\n              .setDisplay('display2')\n          )\n      )\n\n    console.log(appointment.toPlainObject());\n  }\n}\n\n```\n\n### Serialization\n\nEvery model supports `.toPlainObject()` method that converts class instance to JavaScript Object. \u003cbr\u003e\nIn addition, every model supports `.toJSON()` method, thus you can pass a class instance to request and it will be converted to the JSON automatically\n\n### Deserialization\n\nEvery model accepts an object as the first argument in the constructor and recursively deserialize all the properties to class instances. \u003cbr\u003e\nExample:\n\n```typescript\nconst appointment = new Fhir.Appointment({\n  appointmentType: {\n    coding: [\n      {\n        code: 'code',\n        display: 'display'\n      },\n      {\n        code: 'code2',\n        display: 'display2'\n      },\n    ]\n  }\n});\n\nconsole.log(appointment.getAppointmentType().getCodings()[1].getCode()); // code2\n```\n\n\n## Patching resources\n\nYou can extend generated classes to put more logic there. \u003cbr\u003e\nIn order to do that you need to create `extensions` folder inside `outputPath` folder provided in the config. \u003cbr\u003e\nPut your extensions in `extensions` folder.\n\n### Creating class extension\n\nFile name should match the class you want to extend and have a suffix `.extension.ts`. \u003cbr\u003e\nFor example: `bundle.extension.ts`, `appointment.extension.ts`, `codeable-concept.extension.ts` etc. \u003cbr\u003e\n\nExtension class name should match the class name you want to extend and have a suffix `Extension`. \u003cbr\u003e\nFor example: `BundleExtension`, `AppointmentExtension`, `CodeableConceptExtension` etc.\n\nClass extension example:\n```typescript\n/* File path: [\u003coutputPath\u003e/extensions/bundle.extension.ts] */\n\nimport { Bundle } from '../resources/bundle';\nimport { Resource } from '../resources/resource';\n\nexport class BundleExtension extends Bundle {\n  public findResources\u003cT extends Resource\u003e(resourceType: string): T[] {\n    return this.getEntries()\n      .filter(entry =\u003e entry.getResource()?.resourceType === resourceType)\n      .map(entry =\u003e entry.getResource()) as T[];\n  }\n\n  public findResource\u003cT extends Resource\u003e(resourceType: string): T | null {\n    const resources = this.findResources\u003cT\u003e(resourceType);\n    return resources[0] || null;\n  }\n}\n```\n\n### Applying extensions\n\nIf a new extension(s) was added you need to run `fhirx --patch-resources` command, otherwise your changes won't be applied. \u003cbr\u003e\nNote: you \u003cb\u003eDO NOT\u003c/b\u003e need to run `fhirx --patch-resources` if you're making changes to already existing extension. Although it won't break anything, but just useless.\n\n## Loading structure definition from remote\n\nAlthough, this is not a commonly used feature, but might be required in some cases :)\n\n\n### Modify `fhirx.config.js`\n\n```js\nmodule.exports = {\n    load: async () =\u003e {\n        const response = await fetch('YOUR_URL');\n        return response.json();\n    },\n    structureDefinition: {\n        path: 'src/fhirx'\n    },\n    ...\n}\n```\n\n### Run command\n\n`fhirx --load-structure-definition`\n\n## References\n\n- [\u003cb\u003eHL7\u003c/b\u003eFHIR][fhir]\n- [StructureDefinition][fhir-structure-definition]\n\nLike \u003cb\u003eFhirx\u003c/b\u003e? Give the repo a star ⭐\n\n[fhir]: http://hl7.org/fhir/\n\n[fhir-structure-definition]: https://build.fhir.org/structuredefinition.html\n\n[node.js]: https://nodejs.org/\n\n[npm]: https://www.npmjs.com/get-npm\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzombitrafik%2Ffhirx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzombitrafik%2Ffhirx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzombitrafik%2Ffhirx/lists"}