Skip to content

Commit

Permalink
Merge pull request #73 from srdc/fix-fhir-content-validator
Browse files Browse the repository at this point in the history
Accept strings for 'uri' data type and find extension url correctly while handling the slice restrictions
  • Loading branch information
tnamli authored Sep 11, 2024
2 parents e4e4a3c + 3d69504 commit 71c66f0
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(", ")}!"))
Expand Down

0 comments on commit 71c66f0

Please sign in to comment.