LinuxForHealth / hl7v2-fhir-converter

Converts HL7 v2 Messages to FHIR Resources
Apache License 2.0
89 stars 35 forks source link

org full url space problem #65

Closed sueschm closed 3 years ago

sueschm commented 3 years ago

Error: "text": "FHIRProvider: Id value: 'NIST MPI' contain invalid character ' ' [Bundle.entry[1]]"

{ "resourceType": "Bundle", "id": "49bad1cf-ef5a-4728-943c-e3b99f523fe8", "meta": { "lastUpdated": "2021-03-17T20:00:53.944+00:00" }, "type": "collection", "entry": [ { "fullUrl": "urn:uuid:Patient/6218f954-cbff-4b9d-881d-c10565a9cefe", "resource": { "resourceType": "Patient", "id": "6218f954-cbff-4b9d-881d-c10565a9cefe", "identifier": [ { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "MR", "display": "Medical record number" } ], "text": "MR" }, "value": "18547545", "assigner": { "reference": "Organization/NIST MPI" } }, { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "SS", "display": "Social Security number" } ], "text": "SS" }, "value": "111111111", "assigner": { "reference": "Organization/SSN" } } ], "name": [ { "family": "Lerr", "given": [ "Todd" ], "prefix": [ "Jr" ] }, { "family": "Gwinn", "given": [ "Theodore" ], "prefix": [ "Jr" ] } ], "gender": "male", "birthDate": "2009-06-07" } }, { "fullUrl": "urn:uuid:Organization/NISTMPI", "resource": { "resourceType": "Organization", "id": "NIST MPI", "name": "Assigning Authority" } }, { "fullUrl": "urn:uuid:Organization/SSN", "resource": { "resourceType": "Organization", "id": "SSN", "name": "Assigning Authority" } }, { "fullUrl": "urn:uuid:Observation/b449c70c-3972-4fbc-9b73-4d225f79a799", "resource": { "resourceType": "Observation", "id": "b449c70c-3972-4fbc-9b73-4d225f79a799", "identifier": [ { "value": "5671-3_system generated" } ], "status": "final", "code": { "coding": [ { "system": "http://loinc.org", "version": "2.40", "code": "5671-3", "display": "Lead [Mass/volume] in Blood" } ], "text": "Lead [Mass/volume] in Blood" }, "subject": { "reference": "Patient/6218f954-cbff-4b9d-881d-c10565a9cefe" }, "effectiveDateTime": "2012-06-15", "issued": "2012-06-17T00:00:00-05:00", "interpretation": [ { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0078", "code": "H", "display": "High" } ], "text": "H" } ], "method": { "coding": [ { "version": "20090501", "code": "0263", "display": "Atomic Absorption Spectrophotometry" } ], "text": "Atomic Absorption Spectrophotometry" }, "referenceRange": [ { "low": { "unit": "ug/dL" }, "high": { "unit": "ug/dL" }, "text": "0.0 - 5.0" } ] } }, { "fullUrl": "urn:uuid:DiagnosticReport/94d57a12-84cc-4d6a-b157-8e2c2e56a087", "resource": { "resourceType": "DiagnosticReport", "id": "94d57a12-84cc-4d6a-b157-8e2c2e56a087", "identifier": [ { "value": "system generated" } ], "status": "final", "code": { "coding": [ { "system": "http://loinc.org", "version": "2.40", "code": "5671-3", "display": "Lead [Mass/volume] in Blood" } ], "text": "Lead [Mass/volume] in Blood" }, "subject": { "reference": "Patient/6218f954-cbff-4b9d-881d-c10565a9cefe" }, "effectiveDateTime": "2012-06-15", "issued": "2012-06-17T00:00:00-05:00", "result": [ { "reference": "Observation/b449c70c-3972-4fbc-9b73-4d225f79a799" } ] } } ] }

ssnowski commented 3 years ago

This can be reproduced in 1.0.5 with

ConverterOptions converterOptions = new ConverterOptions.Builder().withValidateResource().build();
new HL7ToFHIRConverter().convert(
        "MSH|^~\\&|Thing with Spaces 1|1|||20050110045504||ADT^A01|599102|P|2.3||| \n" +
        "EVN|A01|20050110045502||||| \n" +
        "PID|1||10006579^^^1^MRN^1||DUCK^DONALD^D||19241010|M||1|111 DUCK ST^^FOWL^CA^999990000^^M|1|8885551212|8885551212|1|2||40007716^^^Thing with Spaces 2^VN^1|123121234|||||||||||NO \n" +
        "PV1|1|I|PREOP^101^1^1^^^S|3|||37^DISNEY^WALT^^^^^^Thing with Spaces 3^^^^CI|||01||||1|||37^DISNEY^WALT^^^^^^Thing with Spaces 4^^^^CI|2|40007716^^^Thing with Spaces 5^VN|4|||||||||||||||||||1||G|||20050110045253|||||"
        , converterOptions);

Which yields error java.lang.IllegalArgumentException: Validation issues encountered. Bundle.entry[3].fullUrl URI values cannot have whitespace('urn:uuid:Organization/Thing with Spaces 5') ERROR

EDIT: fixed error and inconsistency introduced by Brian's previous edit

cragun47 commented 3 years ago

Working on this.

cragun47 commented 3 years ago

The HL7DataExtractor and HL7MessageData are parsing and splitting up the messages correctly. The problem and error comes when the resulting bundle is validated.

Using the following modified data:

        "EVN|A01|20050110045502||||| \n" +
        "PID|1||10006579^^^1^MRN^1||DUCK^DONALD^D||19241010|M||1|111 DUCK ST^^FOWL^CA^999990000^^M|1|8885551212|8885551212|1|2||40007716^^^Space OK2^VN^1|123121234|||||||||||NO \n" +
        "PV1|1|I|PREOP^101^1^1^^^S|3|||37^DISNEY^WALT^^^^^^Space OK3a^^^^CI|||01||||1|||37^DISNEY^WALT^^^^^^Space OK3b^^^^CI|2|40007716^^^CXThingwithSpaces4 OrgID^VN|4|||||||||||||||||||1||G|||20050110045253|||||"
    ;

The parser creates this URI: UriType@155 "UriType[urn:uuid:Organization/CXThingwithSpaces4 OrgID]" The parser creates a resource with this id: IdType@163 "Organization/CXThingwithSpaces4 OrgID"

But the validator fails to validate, and rightly so.
FHIRContext.encodeResourceToString lines 67-73 finds the problem

2021-06-04 12:07:46.551 [main] [ ] ERROR [76 ] FHIRContext - Validation issues: Bundle.entry[3].fullUrl URI values cannot have whitespace('urn:uuid:Organization/CXThingwithSpaces4 OrgID') ERROR

HL7Org https://www.hl7.org/fhir/datatypes.html#id defines id as

Any combination of upper- or lower-case ASCII letters ('A'..'Z', and 'a'..'z', numerals ('0'..'9'), '-' and '.', with a length limit of 64 characters. (This might be an integer, an un-prefixed OID, UUID or any other identifier pattern that meets these constraints.) | xs:string | JSON string -- | -- | -- | Regex:[A-Za-z0-9-.]{1,64}

Uri defined according the RFC3986, which doesn't allow unencoded spaces. Any spaces must be encoded. URL defined according to RFC1738, which doesn't allow unencoded spaces. Any spaces must be encoded.

Thus, the data is in error, and correctly flagged as an error. The validator is doing it's job correctly.

The converter could be changed to encode any discovered spaces, but this seems a design issue and a new feature request, not a bug.

LisaWellman commented 3 years ago

Agree this is working correctly, we are not requesting an enhancement so I am closing.

sueschm commented 3 years ago

We will need to keep an eye on this one and see if our users need it. We have a whole bunch of example messages that have spaces that Kyle got from somewhere in the lab results folder. I will add a card to our board to make changes to them so they work.

cragun47 commented 3 years ago

One of my concerns of adding a feature to encode IDs, is then they are no longer the same ID. "spaced identifier" is not really the same as "spaced%20identifier" Unless you know it's encoded. URLs are a little different, because encoding is often used.

On Mon, Jun 7, 2021 at 8:28 AM sueschm @.***> wrote:

We will need to keep an eye on this one and see if our users need it. We have a whole bunch of example messages that have spaces that Kyle got from somewhere in the lab results folder. I will add a card to our board to make changes to them so they work.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/LinuxForHealth/hl7v2-fhir-converter/issues/65#issuecomment-855977937, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFP5IIFSHCIVPQM66EOVO3TRTJSRANCNFSM4ZM27JGA .

-- Brian Cragun LinkedIn http://www.linkedin.com/in/briancragun