Skip to content

Commit 75534a3

Browse files
NRL-518 ContentStability validation mostly on pydantic
1 parent 3d8f0bd commit 75534a3

File tree

13 files changed

+499
-363
lines changed

13 files changed

+499
-363
lines changed

api/consumer/swagger.yaml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,11 +1070,14 @@ components:
10701070
extension:
10711071
type: array
10721072
items:
1073-
$ref: "#/components/schemas/Extension"
1074-
description: Additional content defined by implementations.
1073+
$ref: "#/components/schemas/ContentStabilityExtension"
1074+
description: Additional extension for content stability.
1075+
minItems: 1
1076+
maxItems: 1
10751077
required:
10761078
- attachment
10771079
- format
1080+
- extension
10781081
DocumentReferenceRelatesTo:
10791082
type: object
10801083
properties:
@@ -1191,6 +1194,46 @@ components:
11911194
type: string
11921195
pattern: \S*
11931196
description: The reference details for the link.
1197+
ContentStabilityExtension:
1198+
type: object
1199+
properties:
1200+
url:
1201+
type: string
1202+
enum:
1203+
[
1204+
"https://fhir.nhs.uk/England/StructureDefinition/Extension-England-ContentStability",
1205+
]
1206+
valueCodeableConcept:
1207+
type: object
1208+
properties:
1209+
coding:
1210+
type: array
1211+
items:
1212+
type: object
1213+
properties:
1214+
system:
1215+
type: string
1216+
enum:
1217+
[
1218+
"https://fhir.nhs.uk/England/CodeSystem/England-NRLContentStability",
1219+
]
1220+
code:
1221+
type: string
1222+
enum: ["static", "dynamic"]
1223+
display:
1224+
type: string
1225+
enum: ["Static", "Dynamic"]
1226+
required:
1227+
- system
1228+
- code
1229+
- display
1230+
minItems: 1
1231+
maxItems: 1
1232+
required:
1233+
- coding
1234+
required:
1235+
- url
1236+
- valueCodeableConcept
11941237
Identifier:
11951238
type: object
11961239
properties:

api/producer/swagger.yaml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,11 +1635,14 @@ components:
16351635
extension:
16361636
type: array
16371637
items:
1638-
$ref: "#/components/schemas/Extension"
1639-
description: Additional content defined by implementations.
1638+
$ref: "#/components/schemas/ContentStabilityExtension"
1639+
description: Additional extension for content stability.
1640+
minItems: 1
1641+
maxItems: 1
16401642
required:
16411643
- attachment
16421644
- format
1645+
- extension
16431646
DocumentReferenceRelatesTo:
16441647
type: object
16451648
properties:
@@ -1757,6 +1760,46 @@ components:
17571760
type: string
17581761
pattern: \S*
17591762
description: The reference details for the link.
1763+
ContentStabilityExtension:
1764+
type: object
1765+
properties:
1766+
url:
1767+
type: string
1768+
enum:
1769+
[
1770+
"https://fhir.nhs.uk/England/StructureDefinition/Extension-England-ContentStability",
1771+
]
1772+
valueCodeableConcept:
1773+
type: object
1774+
properties:
1775+
coding:
1776+
type: array
1777+
items:
1778+
type: object
1779+
properties:
1780+
system:
1781+
type: string
1782+
enum:
1783+
[
1784+
"https://fhir.nhs.uk/England/CodeSystem/England-NRLContentStability",
1785+
]
1786+
code:
1787+
type: string
1788+
enum: ["static", "dynamic"]
1789+
display:
1790+
type: string
1791+
enum: ["Static", "Dynamic"]
1792+
required:
1793+
- system
1794+
- code
1795+
- display
1796+
minItems: 1
1797+
maxItems: 1
1798+
required:
1799+
- coding
1800+
required:
1801+
- url
1802+
- valueCodeableConcept
17601803
Identifier:
17611804
type: object
17621805
properties:

layer/nrlf/consumer/fhir/r4/model.py

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generated by datamodel-codegen:
22
# filename: swagger.yaml
3-
# timestamp: 2024-12-05T16:54:49+00:00
3+
# timestamp: 2024-12-06T02:57:59+00:00
44

55
from __future__ import annotations
66

@@ -230,6 +230,25 @@ class Coding(BaseModel):
230230
] = None
231231

232232

233+
class CodingItem(BaseModel):
234+
system: Literal[
235+
"https://fhir.nhs.uk/England/CodeSystem/England-NRLContentStability"
236+
]
237+
code: Literal["static", "dynamic"]
238+
display: Literal["Static", "Dynamic"]
239+
240+
241+
class ValueCodeableConcept(BaseModel):
242+
coding: Annotated[List[CodingItem], Field(max_length=1, min_length=1)]
243+
244+
245+
class ContentStabilityExtension(BaseModel):
246+
url: Literal[
247+
"https://fhir.nhs.uk/England/StructureDefinition/Extension-England-ContentStability"
248+
]
249+
valueCodeableConcept: ValueCodeableConcept
250+
251+
233252
class Period(BaseModel):
234253
id: Annotated[
235254
Optional[str],
@@ -427,6 +446,31 @@ class RequestHeaderCorrelationId(RootModel[str]):
427446
root: Annotated[str, Field(examples=["11C46F5F-CDEF-4865-94B2-0EE0EDCC26DA"])]
428447

429448

449+
class DocumentReferenceContent(BaseModel):
450+
id: Annotated[
451+
Optional[str],
452+
Field(
453+
description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.",
454+
pattern="[A-Za-z0-9\\-\\.]{1,64}",
455+
),
456+
] = None
457+
attachment: Annotated[
458+
Attachment,
459+
Field(
460+
description="The document or URL of the document along with critical metadata to prove content has integrity."
461+
),
462+
]
463+
format: Annotated[
464+
Coding,
465+
Field(
466+
description="An identifier of the document encoding, structure, and template that the document conforms to beyond the base format indicated in the mimeType."
467+
),
468+
]
469+
extension: Annotated[
470+
List[ContentStabilityExtension], Field(max_length=1, min_length=1)
471+
]
472+
473+
430474
class RequestHeader(BaseModel):
431475
odsCode: RequestHeaderOdsCode
432476

@@ -818,29 +862,6 @@ class DocumentReferenceContext(BaseModel):
818862
related: Optional[List[Reference]] = None
819863

820864

821-
class DocumentReferenceContent(BaseModel):
822-
id: Annotated[
823-
Optional[str],
824-
Field(
825-
description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.",
826-
pattern="[A-Za-z0-9\\-\\.]{1,64}",
827-
),
828-
] = None
829-
attachment: Annotated[
830-
Attachment,
831-
Field(
832-
description="The document or URL of the document along with critical metadata to prove content has integrity."
833-
),
834-
]
835-
format: Annotated[
836-
Coding,
837-
Field(
838-
description="An identifier of the document encoding, structure, and template that the document conforms to beyond the base format indicated in the mimeType."
839-
),
840-
]
841-
extension: Optional[List[Extension]] = None
842-
843-
844865
class DocumentReferenceRelatesTo(BaseModel):
845866
id: Annotated[
846867
Optional[str],
@@ -1032,7 +1053,6 @@ class Signature(BaseModel):
10321053
Bundle.model_rebuild()
10331054
BundleEntry.model_rebuild()
10341055
DocumentReferenceContext.model_rebuild()
1035-
DocumentReferenceContent.model_rebuild()
10361056
DocumentReferenceRelatesTo.model_rebuild()
10371057
CodeableConcept.model_rebuild()
10381058
Identifier.model_rebuild()

layer/nrlf/core/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def format_error_location(loc: List) -> str:
2121

2222
def diag_for_error(error: ErrorDetails) -> str:
2323
loc_string = format_error_location(error["loc"])
24-
return f"{loc_string}: {error['msg']}" if loc_string else f"root: {error['msg']}"
24+
return f"{loc_string or 'root'}: {error['msg']}"
2525

2626

2727
def expression_for_error(error: ErrorDetails) -> Optional[str]:

0 commit comments

Comments
 (0)