From 3d69504ebaef667493074f286bc3a80be728ddb1 Mon Sep 17 00:00:00 2001 From: dogukan10 Date: Wed, 11 Sep 2024 14:50:08 +0300 Subject: [PATCH] :bug: Accept strings for 'uri' data type and find extension url correctly while handling the slice restrictions --- .../io/onfhir/validation/FhirContentValidator.scala | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/onfhir-validation/src/main/scala/io/onfhir/validation/FhirContentValidator.scala b/onfhir-validation/src/main/scala/io/onfhir/validation/FhirContentValidator.scala index 82d2c897..fd8c0c68 100644 --- a/onfhir-validation/src/main/scala/io/onfhir/validation/FhirContentValidator.scala +++ b/onfhir-validation/src/main/scala/io/onfhir/validation/FhirContentValidator.scala @@ -707,10 +707,10 @@ class FhirContentValidator( if(disc._2 == "url" && sliceRestriction.path.contains("extension")) { (sliceRestriction.restrictions.get(ConstraintKeys.DATATYPE) : @unchecked) match { //If this is a restriction on resource profile that mentions an Extension profile, find the url of that extension profile - case Some(TypeRestriction(typs)) => + case Some(TypeRestriction(typs)) if typs.head._2.nonEmpty => val extensionUrl = typs.head._2.head Seq(Seq(disc._2 -> FixedOrPatternRestriction(JString(extensionUrl), isFixed = true))) - case None => + case _ => //If there is no such type restriction, we are inside a restriction definition and there should be a element definition for url that has fixed value sliceSubElements .map(_.find(_._1 == "url") @@ -1112,7 +1112,11 @@ class FhirContentValidator( private def evaluateDataTypeConstraint(dataType: String, value: JValue, elementRestrictions: Seq[ElementRestrictions]): Seq[ConstraintFailure] ={ findFirstFhirRestriction(ConstraintKeys.DATATYPE, elementRestrictions) match { case Some(TypeRestriction(edataTypes)) => - if(edataTypes.map(_._1).contains(dataType)) + val dataTypes = edataTypes.map(_._1) + // Check if the expected data types contain the provided data type. + // Additionally, allow "string" as a valid data type if "uri" is present among the expected types, + // as "uri" can sometimes be represented as a string in certain cases such as deep extensions + if(dataTypes.contains(dataType) || (dataTypes.contains(FHIR_DATA_TYPES.URI) && dataType.contentEquals(FHIR_DATA_TYPES.STRING))) Nil else Seq(ConstraintFailure(s"Data type of element $dataType does not match with any expected data type ${edataTypes.map(_._1).mkString(", ")}!"))