ahryman40k / typescript-fhir-types Goto Github PK
View Code? Open in Web Editor NEWTypescript / Javascript object model for FHIR standard
License: MIT License
Typescript / Javascript object model for FHIR standard
License: MIT License
When I generated enums for library, I took some ease.
So, In order to generate my code I've done things like this:
export enum ExpressionLanguageKind {
textCql = 'textCql',
textFhirpath = 'textFhirpath',
applicationXFhirQuery = 'applicationXFhirQuery'
}
and create the adapted keyof type with io-ts.
but data in json are more like that:
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/cqf-expression",
"valueExpression": {
"language": "text/cql",
"expression": "Now()"
}
}
]
See text/cql vs textCql ...
I need a better way to fix this !
PASS src/tests/account_coverage.spec.ts
PASS src/tests/tryout.spec.ts
PASS src/tests/account_guarantor.spec.ts (17.176s)
FAIL src/tests/account.spec.ts
● Test suite failed to run
TypeError: Cannot read property 'name' of undefined
146 | import * as t from 'io-ts';
147 |
> 148 | export const RTTI_ResourceList = t.union([
| ^
149 | RTTI_Account,
150 | RTTI_ActivityDefinition,
151 | RTTI_AdverseEvent,
at node_modules/io-ts/lib/index.js:764:59
at Array.map (<anonymous>)
at getUnionName (node_modules/io-ts/lib/index.js:764:25)
at Object.<anonymous>.exports.union (node_modules/io-ts/lib/index.js:770:35)
at Object.<anonymous> (src/Union/RTTI_ResourceList.ts:148:36)
at Object.<anonymous> (src/Resource/RTTI_Account.ts:6:1)
at Object.<anonymous> (src/__tests__/account.spec.ts:1:1)
Test Suites: 1 failed, 3 passed, 4 total
Tests: 5 passed, 5 total
Snapshots: 0 total
Time: 22.055s
The type Questionnaire_EnableWhenOperatorKind
uses words ("Equal", "Greater", ...) instead of symbols ("=", ">").
See the spec here:
https://www.hl7.org/fhir/questionnaire-definitions.html#Questionnaire.item.enableWhen.operator
Hi! Is it envisioned to release the library updated to recently released FHIR R4B (4.3.0)?
The library is best-in-class for FHIR support. Is there, by any chance, a way to (semi-)automatically ingest the newer standards?
I just checked out the library, so this is probably a misunderstanding:
When I decode this example AuditEvent the result doesn't validate because the example has numbers for outcome and agent.network.type. I see from the code that you have defined enums, and the library is expecting values like 'Success' for outcome, and 'MachineName' for agent.network.type.
The possible values for outcome are defined here. Network type is defined here. My understanding is that the code (ie the number) should be included in the resource.
Could you clarify what the expected behaviour for decode is, wrt these code fields?
const validationResult = R4.RTTI_AuditEvent.decode(auditEventJSON)
console.log(PathReporter.report(validationResult))
[ 'Invalid value "2" supplied to : IAuditEvent/0: { resourceType: "AuditEvent", type: ICoding, agent: Array<IAuditEvent_Agent>, source: IAuditEvent_Source }/agent: Array<IAuditEvent_Agent>/0: IAuditEvent_Agent/network: IAuditEvent_Network/type: AuditEvent_NetworkTypeKind',
'Invalid value "1" supplied to : IAuditEvent/0: { resourceType: "AuditEvent", type: ICoding, agent: Array<IAuditEvent_Agent>, source: IAuditEvent_Source }/agent: Array<IAuditEvent_Agent>/1: IAuditEvent_Agent/network: IAuditEvent_Network/type: AuditEvent_NetworkTypeKind',
'Invalid value "0" supplied to : IAuditEvent/1: Partial<{ id: RTTI_idType, meta: IMeta, implicitRules: RTTI_uriType, _implicitRules: IElement, language: RTTI_codeType, _language: IElement, text: INarrative, contained: Array, extension: Array, modifierExtension: Array, subtype: Array, action: AuditEventActionKind, _action: IElement, period: IPeriod, recorded: RTTI_instantType, _recorded: IElement, outcome: AuditEventOutcomeKind, _outcome: IElement, outcomeDesc: string, _outcomeDesc: IElement, purposeOfEvent: Array, entity: Array<IAuditEvent_Entity> }>/outcome: AuditEventOutcomeKind' ]
io-ts is a runtime type system for IO decoding/encoding.
@see: https://github.com/gcanti/io-ts
Great work! Thanks
Just curious...
Create test with Travis CI
And display badge on readme.md
If you do
import { IHumanName } from '@ahryman40k/ts-fhir-types/lib/R4'
import { HumanNameUseKind } from '@ahryman40k/ts-fhir-types/lib/R4/Resource/RTTI_HumanName'
let name: IHumanName = {
use: HumanNameUseKind._maiden,
}
// […] use the `name` var in some way
and webpack it, it’ll bring ~75K of stuff from typescript-fhir-types and io. And if you include HumanNameUseKind
from @ahryman40k/ts-fhir-types/lib/R4
, it’ll bring the entire library into the bundle.
If only we could use string literal types instead of enums… This would allow type-only imports, with zero code actually require()
d.
Hi I describe this issue with screens in below discussion. I removed your library and problem solved.
From FHIR schema.json, I generate resources, scalars and unions.
I may generate tests with FHIR samples too !
I'm trying to decode birthDate with the RTTI_Patient class, and it is not working.
Given this input:
{ "resourceType": "DiagnosticReport", "id": "d9d19378-8f55-4641-8462-b8f35cbc9dd3", "text": { "status": "generated", "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b>Pulmonary nodule narrative</b></p><p>small masses of tissue seen in lung</p></div>" }, "contained": [{ "resourceType": "Patient", "id": "patient1", "birthDate" : "2020-01-01", "identifier": [{ "use": "usual", "type": { "coding": [{ "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "MR" }] }, "value": "anonymous" }] }, { "resourceType": "ImagingStudy", "id": "study1", "status": "available", "identifier": [{ "use": "usual", "type": { "coding": [{ "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "ACSN" }] }, "value": "758843" }], "subject": { "reference": "#patient1" }, "procedureCode": [{ "coding": [{ "system": "http://loinc.org", "code": "79068-3", "display": "CT Chest w IV Contrast Screening" }], "text": "CT Chest" }] }], "imagingStudy": [{ "reference": "#study1" }], "status": "final", "category": [{ "coding": [{ "system": "http://terminology.hl7.org/CodeSystem/v2-0074", "code": "RAD", "display": "Radiology" }] }], "code": { "coding": [{ "system": "http://loinc.org", "code": "68604-8", "display": "Radiology Diagnostic study note" }] }, "subject": { "reference": "#ai-algorithm-details" }, "effectiveDateTime": "2018-04-13T12:00:00-05:00", "conclusion": "lung nodule seen." }
I am getting this error:
Invalid value undefined supplied to : IPatient/0: { resourceType: "Patient" }/resourceType: "Patient".
If I remove birthDate from the Patient object, it decodes fine.
According to spec: https://hl7.org/fhir/location.html (older versions as well), longitude and latitude should be required.
I may suggest a PR if time allows.
Cheers! :)
Current AuditEvent interface IAuditEvent
has
recorded?: string;
This field has a 1:1 cardinality in the FHIR spec (STU3/ DSTU4) so is mandatory.
Hi,
Thanks for your work on this library. It saves me quite some time.
I wonder why in the enums every entry is prefixed with an underscore, as I'm tempted to remove them.
export declare enum CarePlan_DetailStatusKind {
_notStarted = "not-started",
_scheduled = "scheduled",
_inProgress = "in-progress",
_onHold = "on-hold",
_completed = "completed",
_cancelled = "cancelled",
_stopped = "stopped",
_unknown = "unknown",
_enteredInError = "entered-in-error"
}
Can't figure out why but it seems R4 isn't freeze and modification are still occurs on R4, so definition can evolve ! Oo'
Hi,
Is it possible for the library to reject additional properties not defined in the FHIR Schema?
For example, the following object is accepted by the decode api
{
"resourceType": "Location",
"AdditionalField": "IsNotAllowed"
}
const validationResult = R4.RTTI_Location.decode(obj);
if (validationResult.isLeft()) {
return {
status: 400,
body: validationResult
}
}
return {
status: 200,
body: 'valid'
}
Hi
Is it somehow possible to generate a "prefilled" object with mandatory fields and fixed literals?
We use Profiles (TS interfaces) based on io-ts with e.g. already fixed meta information from external. We now don't want to recreate all the information in the interfaces again.
As far as I understand this is taking json objects and validates them.
Thanks for feedback
Hi, I just started using this package, and I am running into some issues that I was hoping you could help me with. I am pulling a FHIR patient resource from an end point, and getting the patient structure back that I want to leverage
import { R4 } from '@ahryman40k/ts-fhir-types'
import * as either from "fp-ts/lib/Either";
const fhir_patient = R4.RTTI_Patient.decode(patient_data) // patient_data is coming from an end_point
// I now have a either.Validation<R4.IPatient> for fhir_patient
The question I have is how do I now extract the R4.RTTI_Patient
from it. The documentation on the site says that
we should do
const obs: R4.IPatient = either.isRight(fhir_patient);
but as I understand it isRight
returns a bool, so cannot be cast to R4.IPatient
Am I missing something ? Or is there a different way of doing this with the current version of the package.
Thanks for any help that you can provide.
When downloading json from https://www.hl7.org/fhir/observation.profile.json It does not validate with
const structureDefinition: R4.IStructureDefinition = R4.RTTI_StructureDefinition.decode(jsons).value as R4.IStructureDefinition;
since the current version is 4.0.1 and there are slight chagnes
Say I wanted to make a function that does a runtime check of the provided type, like so
// what is the type of desiredType?
function isValidFHIRType(desiredType: any, resource: any) {
const checkResult = desiredType.decode(resource);
return checkResult.isRight();
}
I'm not sure what the type of the desiredType
argument would be. I saw that there is a RTTI_ResourceList
exported by this library, but this is not a Typescript Type or Interface
Is it possible to do RTTI when the desired RTTI is unknown when calling the decode
function?
Change to MIT licence.
Basic object models I've generated were verifying regexp provided by FHIR standard.
When migrating to io-ts, at first glance, to simplify thing, I forgot about those data checking.
It's time to make it works again.
These 2 types are presents in library but disconnected
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.