@@ -507,14 +507,14 @@ def _validate_content_extension(self, model: DocumentReference):
507507 Validate the content.extension field contains an appropriate coding.
508508 """
509509 logger .log (LogReference .VALIDATOR001 , step = "content_extension" )
510-
511510 logger .debug ("Validating extension" )
511+
512512 for i , content in enumerate (model .content ):
513- if len ( content .extension ) == 0 :
513+ if not content .extension :
514514 self .result .add_error (
515515 issue_code = "business-rule" ,
516516 error_code = "UNPROCESSABLE_ENTITY" ,
517- diagnostics = f "Invalid content extension: Extension must have at least one value" ,
517+ diagnostics = "Invalid content extension: Extension must have at least one value" ,
518518 field = f"content[{ i } ].extension" ,
519519 )
520520 return
@@ -525,44 +525,55 @@ def _validate_content_extension(self, model: DocumentReference):
525525 extension .url
526526 == "https://fhir.nhs.uk/England/StructureDefinition/Extension-England-ContentStability"
527527 ):
528- coding = extension .valueCodeableConcept .coding [0 ]
529- if coding .code != coding .display .lower () or coding .display not in [
530- "Static" ,
531- "Dynamic" ,
532- ]:
533- self .result .add_error (
534- issue_code = "business-rule" ,
535- error_code = "UNPROCESSABLE_ENTITY" ,
536- diagnostics = f"Invalid content extension display: { coding .display } Extension display must be the same as code either 'Static' or 'Dynamic'" ,
537- field = f"content[{ i } ].extension[{ j } ].valueCodeableConcept.coding[0].display" ,
538- )
528+ if not self ._validate_content_stability_extension (extension , i , j ):
539529 return
540530 has_content_stability = True
541-
542531 elif (
543532 extension .url
544533 == "https://fhir.nhs.uk/England/StructureDefinition/Extension-England-RetrievalMechanism"
545534 ):
546- coding = extension .valueCodeableConcept .coding [0 ]
547- retrievalDisplay = CONTENT_RETRIEVAL_CODE_MAP .get (coding .code )
548- if coding .display != retrievalDisplay :
549- self .result .add_error (
550- issue_code = "business-rule" ,
551- error_code = "UNPROCESSABLE_ENTITY" ,
552- diagnostics = f"Invalid content extension display: { coding .display } Expected display is '{ retrievalDisplay } '" ,
553- field = f"content[{ i } ].extension[{ j } ].valueCodeableConcept.coding[0].display" ,
554- )
535+ if not self ._validate_retrieval_mechanism_extension (
536+ extension , i , j
537+ ):
555538 return
556539
557540 if not has_content_stability :
558541 self .result .add_error (
559542 issue_code = "business-rule" ,
560543 error_code = "UNPROCESSABLE_ENTITY" ,
561- diagnostics = f "Invalid content extension: Extension must have one content stability extension see value set ('https://fhir.nhs.uk/England/CodeSystem/England-NRLContentStability')" ,
544+ diagnostics = "Invalid content extension: Extension must have one content stability extension see value set ('https://fhir.nhs.uk/England/CodeSystem/England-NRLContentStability')" ,
562545 field = f"content[{ i } ].extension" ,
563546 )
564547 return
565548
549+ def _validate_content_stability_extension (self , extension , i , j ):
550+ coding = extension .valueCodeableConcept .coding [0 ]
551+ if coding .code != coding .display .lower () or coding .display not in [
552+ "Static" ,
553+ "Dynamic" ,
554+ ]:
555+ self .result .add_error (
556+ issue_code = "business-rule" ,
557+ error_code = "UNPROCESSABLE_ENTITY" ,
558+ diagnostics = f"Invalid content extension display: { coding .display } Extension display must be the same as code either 'Static' or 'Dynamic'" ,
559+ field = f"content[{ i } ].extension[{ j } ].valueCodeableConcept.coding[0].display" ,
560+ )
561+ return False
562+ return True
563+
564+ def _validate_retrieval_mechanism_extension (self , extension , i , j ):
565+ coding = extension .valueCodeableConcept .coding [0 ]
566+ expected_retrieval_display = CONTENT_RETRIEVAL_CODE_MAP .get (coding .code )
567+ if coding .display != expected_retrieval_display :
568+ self .result .add_error (
569+ issue_code = "business-rule" ,
570+ error_code = "UNPROCESSABLE_ENTITY" ,
571+ diagnostics = f"Invalid content extension display: { coding .display } Expected display is '{ expected_retrieval_display } '" ,
572+ field = f"content[{ i } ].extension[{ j } ].valueCodeableConcept.coding[0].display" ,
573+ )
574+ return False
575+ return True
576+
566577 def _validate_author (self , model : DocumentReference ):
567578 """
568579 Validate the author field contains an appropriate coding system and code.
0 commit comments