lantanagroup / FHIR.js

Node.JS library for serializing/deserializing FHIR resources between JS/JSON and XML using various node.js XML libraries
Apache License 2.0
104 stars 29 forks source link

targetProfile can be a single string #58

Closed VPelt closed 2 years ago

VPelt commented 2 years ago

Here is a patch that was needed to allow STU3 profiles to work. It seems targetProfiles can be a string and not just an array of strings

--- a/node_modules/fhir/validator.js
+++ b/node_modules/fhir/validator.js
@@ -272,19 +272,19 @@ class Validator {
             const nextValidationResponse = nextValidationInstance.response;
             this.response.valid = !this.response.valid ? this.response.valid : nextValidationResponse.valid;
             this.response.messages = this.response.messages.concat(nextValidationResponse.messages);
-            const targetProfiles = (property._targetProfiles || [])
+            const targetProfiles = (property._targetProfiles ? (Array.isArray(property._targetProfiles) ? property._targetProfiles : [property._targetProfiles]) : [])
                 .filter(p => !!p && p.indexOf('/') >= 0)
                 .map((p) => {
-                const split = p.split('/');
-                return split[split.length - 1];
-            });
-            if (property._type === 'Reference' && targetProfiles.length != 0 && targetProfiles.indexOf('Resource') < 0) {
-                const targetProfiles = (property._targetProfiles || [])
-                    .filter(p => !!p && p.indexOf('/') >= 0)
-                    .map((p) => {
                     const split = p.split('/');
                     return split[split.length - 1];
                 });
+            if (property._type === 'Reference' && targetProfiles.length != 0 && targetProfiles.indexOf('Resource') < 0) {
+                const targetProfiles = (property._targetProfiles ? (Array.isArray(property._targetProfiles) ? property._targetProfiles : [property._targetProfiles]) : [])
+                    .filter(p => !!p && p.indexOf('/') >= 0)
+                    .map((p) => {
+                        const split = p.split('/');
+                        return split[split.length - 1];
+                    });
                 const referenceSplit = obj.reference ?
                     obj.reference.split('|')[0].split('/') :
                     [];
seanmcilvenna commented 2 years ago

Can you provide a comment on what the issue is here? Are you proposing a change? The formatting of your original message came through poorly so I'm not sure what's going on here. :)

VPelt commented 2 years ago

My appologies, i posted a patch that i wrote in order to process fhir STU 3 profiles. these files themself had been validated but targetprofiles is not always a string array. This way we can handle both cases