Skip to content

Commit

Permalink
feature/model update v3 (#207)
Browse files Browse the repository at this point in the history
# PR Context

# Added
- added new consent and bibliography reference models and vocabs
- added `doi` field to resource models

# Changes
- split up YearMonth and Year temporal types and improved patterns
- applied all changes to model fields according to model v3
- update LOINC pattern

# Fixed
- fix temporal entity schemas

---------

Signed-off-by: Nicolas Drebenstedt <[email protected]>
Signed-off-by: Janina Esins <[email protected]>
Co-authored-by: RKIMetadataExchange <[email protected]>
Co-authored-by: erichesse <[email protected]>
Co-authored-by: Kamran Ali <[email protected]>
Co-authored-by: esinsj <[email protected]>
  • Loading branch information
5 people authored Oct 28, 2024
1 parent 16a8f03 commit 6ad5e05
Show file tree
Hide file tree
Showing 27 changed files with 874 additions and 329 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- added new consent and bibliography reference models and vocabs
- added doi field to resource models
- helper function for primary source look up

### Changes

- upgrade mex-model dependency to version 3
- make ruff linter config opt-out, instead of opt-in
- make instances of extracted data hashable
- BREAKING: Wikidata convenience function refactored and renamed to 'helper'
- wikidata helper function split between mex-common and mex-extractors
- code de-duplication: fixture extracted_primary_sources now uses function-part of primary sources helper
- split up YearMonth and Year temporal types and improved patterns
- applied all changes to model fields according to model v3
- update LOINC pattern

### Deprecated

### Removed

### Fixed

- fix temporal entity schemas

### Security

## [0.38.0] - 2024-10-11
Expand Down
52 changes: 52 additions & 0 deletions mex/common/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- AccessPlatform
- Activity
- BibliographicResource
- Consent
- ContactPoint
- Distribution
- Organization
Expand Down Expand Up @@ -95,6 +97,26 @@
from mex.common.models.base.merged_item import MergedItem
from mex.common.models.base.model import BaseModel
from mex.common.models.base.rules import AdditiveRule, PreventiveRule, SubtractiveRule
from mex.common.models.bibliographic_resource import (
AdditiveBibliographicResource,
BaseBibliographicResource,
BibliographicResourceRuleSetRequest,
BibliographicResourceRuleSetResponse,
ExtractedBibliographicResource,
MergedBibliographicResource,
PreventiveBibliographicResource,
SubtractiveBibliographicResource,
)
from mex.common.models.consent import (
AdditiveConsent,
BaseConsent,
ConsentRuleSetRequest,
ConsentRuleSetResponse,
ExtractedConsent,
MergedConsent,
PreventiveConsent,
SubtractiveConsent,
)
from mex.common.models.contact_point import (
AdditiveContactPoint,
BaseContactPoint,
Expand Down Expand Up @@ -199,6 +221,8 @@
"ADDITIVE_MODEL_CLASSES",
"AdditiveAccessPlatform",
"AdditiveActivity",
"AdditiveBibliographicResource",
"AdditiveConsent",
"AdditiveContactPoint",
"AdditiveDistribution",
"AdditiveOrganization",
Expand All @@ -222,6 +246,8 @@
"BASE_MODEL_CLASSES",
"BaseAccessPlatform",
"BaseActivity",
"BaseBibliographicResource",
"BaseConsent",
"BaseContactPoint",
"BaseDistribution",
"BaseModel",
Expand All @@ -232,6 +258,8 @@
"BaseResource",
"BaseVariable",
"BaseVariableGroup",
"ConsentRuleSetRequest",
"ConsentRuleSetResponse",
"ContactPointRuleSetRequest",
"ContactPointRuleSetResponse",
"DistributionRuleSetRequest",
Expand All @@ -240,6 +268,8 @@
"EXTRACTED_MODEL_CLASSES",
"ExtractedAccessPlatform",
"ExtractedActivity",
"ExtractedBibliographicResource",
"ExtractedConsent",
"ExtractedContactPoint",
"ExtractedData",
"ExtractedDistribution",
Expand All @@ -260,6 +290,8 @@
"MERGED_MODEL_CLASSES",
"MergedAccessPlatform",
"MergedActivity",
"MergedBibliographicResource",
"MergedConsent",
"MergedContactPoint",
"MergedDistribution",
"MergedItem",
Expand All @@ -284,6 +316,8 @@
"PREVENTIVE_MODEL_CLASSES",
"PreventiveAccessPlatform",
"PreventiveActivity",
"PreventiveBibliographicResource",
"PreventiveConsent",
"PreventiveContactPoint",
"PreventiveDistribution",
"PreventiveOrganization",
Expand All @@ -308,6 +342,8 @@
"SUBTRACTIVE_MODEL_CLASSES",
"SubtractiveAccessPlatform",
"SubtractiveActivity",
"SubtractiveBibliographicResource",
"SubtractiveConsent",
"SubtractiveContactPoint",
"SubtractiveDistribution",
"SubtractiveOrganization",
Expand All @@ -331,6 +367,8 @@
AnyBaseModel = (
BaseAccessPlatform
| BaseActivity
| BaseBibliographicResource
| BaseConsent
| BaseContactPoint
| BaseDistribution
| BaseOrganization
Expand All @@ -349,6 +387,8 @@
AnyExtractedModel = (
ExtractedAccessPlatform
| ExtractedActivity
| ExtractedBibliographicResource
| ExtractedConsent
| ExtractedContactPoint
| ExtractedDistribution
| ExtractedOrganization
Expand All @@ -369,6 +409,8 @@
AnyMergedModel = (
MergedAccessPlatform
| MergedActivity
| MergedBibliographicResource
| MergedConsent
| MergedContactPoint
| MergedDistribution
| MergedOrganization
Expand All @@ -387,6 +429,8 @@
AnyAdditiveModel = (
AdditiveAccessPlatform
| AdditiveActivity
| AdditiveBibliographicResource
| AdditiveConsent
| AdditiveContactPoint
| AdditiveDistribution
| AdditiveOrganization
Expand All @@ -407,6 +451,8 @@
AnySubtractiveModel = (
SubtractiveAccessPlatform
| SubtractiveActivity
| SubtractiveBibliographicResource
| SubtractiveConsent
| SubtractiveContactPoint
| SubtractiveDistribution
| SubtractiveOrganization
Expand All @@ -427,6 +473,8 @@
AnyPreventiveModel = (
PreventiveAccessPlatform
| PreventiveActivity
| PreventiveBibliographicResource
| PreventiveConsent
| PreventiveContactPoint
| PreventiveDistribution
| PreventiveOrganization
Expand All @@ -453,6 +501,8 @@
AnyRuleSetRequest = (
AccessPlatformRuleSetRequest
| ActivityRuleSetRequest
| BibliographicResourceRuleSetRequest
| ConsentRuleSetRequest
| ContactPointRuleSetRequest
| DistributionRuleSetRequest
| OrganizationRuleSetRequest
Expand All @@ -473,6 +523,8 @@
AnyRuleSetResponse = (
AccessPlatformRuleSetResponse
| ActivityRuleSetResponse
| BibliographicResourceRuleSetResponse
| ConsentRuleSetResponse
| ContactPointRuleSetResponse
| DistributionRuleSetResponse
| OrganizationRuleSetResponse
Expand Down
2 changes: 1 addition & 1 deletion mex/common/models/access_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
MergedContactPointIdentifier,
MergedOrganizationalUnitIdentifier,
MergedPersonIdentifier,
MergedPrimarySourceIdentifier,
TechnicalAccessibility,
Text,
)
from mex.common.types.identifier import MergedPrimarySourceIdentifier


class _Stem(BaseModel):
Expand Down
8 changes: 5 additions & 3 deletions mex/common/models/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
Identifier,
Link,
MergedActivityIdentifier,
MergedBibliographicResourceIdentifier,
MergedContactPointIdentifier,
MergedOrganizationalUnitIdentifier,
MergedOrganizationIdentifier,
MergedPersonIdentifier,
MergedPrimarySourceIdentifier,
Text,
Theme,
Year,
YearMonth,
YearMonthDay,
)
Expand All @@ -43,7 +45,7 @@ class _OptionalLists(_Stem):
activityType: list[ActivityType] = []
alternativeTitle: list[Text] = []
documentation: list[Link] = []
end: list[YearMonthDay | YearMonth] = []
end: list[YearMonthDay | YearMonth | Year] = []
externalAssociate: list[
Annotated[
MergedOrganizationIdentifier | MergedPersonIdentifier,
Expand All @@ -55,9 +57,9 @@ class _OptionalLists(_Stem):
involvedPerson: list[MergedPersonIdentifier] = []
involvedUnit: list[MergedOrganizationalUnitIdentifier] = []
isPartOfActivity: list[MergedActivityIdentifier] = []
publication: list[Link] = []
publication: list[MergedBibliographicResourceIdentifier] = []
shortName: list[Text] = []
start: list[YearMonthDay | YearMonth] = []
start: list[YearMonthDay | YearMonth | Year] = []
succeeds: list[MergedActivityIdentifier] = []
theme: list[Theme] = []
website: list[Link] = []
Expand Down
6 changes: 6 additions & 0 deletions mex/common/models/base/extracted_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class ExtractedData(BaseEntity):
),
examples=["123456", "item-501", "D7/x4/zz.final3"],
min_length=1,
max_length=1000,
pattern=r"^[^\n\r]+$",
frozen=True,
),
]
Expand Down Expand Up @@ -94,3 +96,7 @@ def _get_stable_target_id(
.assign(self.hadPrimarySource, self.identifierInPrimarySource)
.stableTargetId
)

def __hash__(self) -> int:
"""Calculates a hash value to make the object cachable."""
return hash(f"{self.hadPrimarySource}\n{self.identifierInPrimarySource}")
Loading

0 comments on commit 6ad5e05

Please sign in to comment.