From e8009d3ce31dc48a2279a336c4470522a3c098a8 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 18 Aug 2022 09:39:15 +1000 Subject: [PATCH] fix SHEX generation issue --- .../fhir/r5/conformance/ShExGenerator.java | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ShExGenerator.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ShExGenerator.java index 580742349..07009a442 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ShExGenerator.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ShExGenerator.java @@ -593,11 +593,11 @@ public class ShExGenerator { } } else if (typ.getCode().startsWith(Constants.NS_SYSTEM_TYPE)) { - String xt = typ.getWorkingCode(); + String xt = getShexCode(typ.getWorkingCode()); + // TODO: Remove the next line when the type of token gets switched to string // TODO: Add a rdf-type entry for valueInteger to xsd:integer (instead of int) - ST td_entry = tmplt(PRIMITIVE_ELEMENT_DEFN_TEMPLATE).add("typ", - xt.replace("xsd:token", "xsd:string").replace("xsd:int", "xsd:integer")); + ST td_entry = tmplt(PRIMITIVE_ELEMENT_DEFN_TEMPLATE).add("typ", xt); StringBuilder facets = new StringBuilder(); if(ed.hasMinValue()) { DataType mv = ed.getMinValue(); @@ -631,6 +631,53 @@ public class ShExGenerator { } } + private String getShexCode(String c) { + switch (c) { + case "boolean" : + return "xsd:boolean"; + case "integer" : + return "xsd:int"; + case "integer64" : + return "xsd:long"; + case "decimal" : + return "xsd:decimal, xsd:double"; + case "base64Binary" : + return "xsd:base64Binary"; + case "instant" : + return "xsd:dateTime"; + case "string" : + return "xsd:string"; + case "uri" : + return "xsd:anyURI"; + case "date" : + return "xsd:gYear, xsd:gYearMonth, xsd:date"; + case "dateTime" : + return "xsd:gYear, xsd:gYearMonth, xsd:date, xsd:dateTime"; + case "time" : + return "xsd:time"; + case "code" : + return "xsd:token"; + case "oid" : + return "xsd:anyURI"; + case "uuid" : + return "xsd:anyURI"; + case "url" : + return "xsd:anyURI"; + case "canonical" : + return "xsd:anyURI"; + case "id" : + return "xsd:string"; + case "unsignedInt" : + return "xsd:nonNegativeInteger"; + case "positiveInt" : + return "xsd:positiveInteger"; + case "markdown" : + return "xsd:string"; + } + throw new Error("Not implemented yet"); + + } + /** * Generate a set of alternative shapes * @param ed Containing element definition