~ inspect instant for specific RDF datatype (#2473)

This commit is contained in:
Eric Prud'hommeaux 2021-04-09 11:59:26 +02:00 committed by GitHub
parent 38436e5c1b
commit fa921a3cc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 4 deletions

View File

@ -300,7 +300,7 @@ public class RDFParser extends BaseParser {
String propertyName = constructPredicateName(resource, childDefinition, childName, parentElement); String propertyName = constructPredicateName(resource, childDefinition, childName, parentElement);
if (element != null) { if (element != null) {
XSDDatatype dataType = getXSDDataTypeForFhirType(element.fhirType()); XSDDatatype dataType = getXSDDataTypeForFhirType(element.fhirType(), encodedValue);
rdfResource.addProperty(rdfModel.createProperty(propertyName), this.createFhirValueBlankNode(rdfModel, encodedValue, dataType, cardinalityIndex)); rdfResource.addProperty(rdfModel.createProperty(propertyName), this.createFhirValueBlankNode(rdfModel, encodedValue, dataType, cardinalityIndex));
} }
} }
@ -314,7 +314,7 @@ public class RDFParser extends BaseParser {
if (value != null || !hasNoExtensions(pd)) { if (value != null || !hasNoExtensions(pd)) {
if (value != null) { if (value != null) {
String propertyName = constructPredicateName(resource, childDefinition, childName, parentElement); String propertyName = constructPredicateName(resource, childDefinition, childName, parentElement);
XSDDatatype dataType = getXSDDataTypeForFhirType(pd.fhirType()); XSDDatatype dataType = getXSDDataTypeForFhirType(pd.fhirType(), value);
Resource valueResource = this.createFhirValueBlankNode(rdfModel, value, dataType, cardinalityIndex); Resource valueResource = this.createFhirValueBlankNode(rdfModel, value, dataType, cardinalityIndex);
if (!hasNoExtensions(pd)) { if (!hasNoExtensions(pd)) {
IBaseHasExtensions hasExtension = (IBaseHasExtensions)pd; IBaseHasExtensions hasExtension = (IBaseHasExtensions)pd;
@ -411,7 +411,7 @@ public class RDFParser extends BaseParser {
* @param fhirType hapi field type * @param fhirType hapi field type
* @return XSDDatatype value * @return XSDDatatype value
*/ */
private XSDDatatype getXSDDataTypeForFhirType(String fhirType) { private XSDDatatype getXSDDataTypeForFhirType(String fhirType, String value) {
switch (fhirType) { switch (fhirType) {
case "boolean": case "boolean":
return XSDDatatype.XSDboolean; return XSDDatatype.XSDboolean;
@ -423,7 +423,16 @@ public class RDFParser extends BaseParser {
return XSDDatatype.XSDdate; return XSDDatatype.XSDdate;
case "dateTime": case "dateTime":
case "instant": case "instant":
return XSDDatatype.XSDdateTime; switch (value.length()) { // assumes valid lexical value
case 4:
return XSDDatatype.XSDgYear;
case 7:
return XSDDatatype.XSDgYearMonth;
case 10:
return XSDDatatype.XSDdate;
default:
return XSDDatatype.XSDdateTime;
}
case "code": case "code":
case "string": case "string":
default: default: