wso2 / mi-vscode

Micro Integrator extension for Visual Studio Code
Apache License 2.0
2 stars 3 forks source link

MI datamapper unable to load the FHIR model schemas #118

Open sameeragunarathne opened 3 months ago

sameeragunarathne commented 3 months ago

Description:

For healthcare use cases, we have to do mappings related to FHIR resource models. When loading the schemas to the datamapper it shows an error and model is not loaded to the datamapper UI. Please refer to the attached json schema for the FHIR Patient resource model in order to reproduce the behaviour.

fhir_schema_patient.json

Data mapper state:(FYI this schema is valid but the datamapper complains it as invalid)

Screenshot 2024-07-22 at 13 50 37 Screenshot 2024-07-22 at 13 53 01

Suggested Labels:

Bug

Suggested Assignees:

Affected Product Version: MI 4.3.0

OS, DB, other environment details and versions:

Steps to reproduce:

Related Issues:

arunans23 commented 3 months ago

There are two improvements that needs to be done here on the data mapper.

For example, the following schema is not supported at the moment.

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Person",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string"
    },
    "lastName": {
      "type": "string"
    },
    "age": {
      "type": "integer",
      "minimum": 0
    },
    "address": {
      "$ref": "#/definitions/address"
    }
  },
  "required": ["firstName", "lastName", "address"],
  "definitions": {
    "address": {
      "type": "object",
      "properties": {
        "streetAddress": {
          "type": "string"
        },
        "city": {
          "type": "string"
        },
        "state": {
          "type": "string"
        },
        "postalCode": {
          "type": "string"
        }
      },
      "required": ["streetAddress", "city", "state", "postalCode"]
    }
  }
}

The same schema can be represented as below without $ref which is supported in Datamapper atm.

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Person",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string"
    },
    "lastName": {
      "type": "string"
    },
    "age": {
      "type": "integer",
      "minimum": 0
    },
    "address": {
      "type": "object",
      "properties": {
        "streetAddress": {
          "type": "string"
        },
        "city": {
          "type": "string"
        },
        "state": {
          "type": "string"
        },
        "postalCode": {
          "type": "string"
        }
      },
      "required": ["streetAddress", "city", "state", "postalCode"]
    }
  },
  "required": ["firstName", "lastName", "address"]
}

This is an improvement that needs to be supported in the DataMapper.

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Vehicle",
  "type": "object",
  "properties": {
    "type": {
      "type": "string"
    },
    "details": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "make": {
              "type": "string"
            },
            "model": {
              "type": "string"
            },
            "year": {
              "type": "integer",
              "minimum": 1886
            },
            "seats": {
              "type": "integer",
              "minimum": 1
            }
          },
          "required": ["make", "model", "year", "seats"],
          "title": "Car"
        },
        {
          "type": "object",
          "properties": {
            "brand": {
              "type": "string"
            },
            "type": {
              "type": "string"
            },
            "gearCount": {
              "type": "integer",
              "minimum": 1
            }
          },
          "required": ["brand", "type", "gearCount"],
          "title": "Bike"
        }
      ]
    }
  },
  "required": ["type", "details"]
}

The UI should be improved to support union types in typescript to facilitate this.