Skip to content

Commit

Permalink
[#42] Readded Ch Core constraints for identifiers to keep error severity
Browse files Browse the repository at this point in the history
  • Loading branch information
dvribeira committed Nov 29, 2023
1 parent 9b8b6b5 commit 469a904
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
63 changes: 63 additions & 0 deletions input/fsh/invariant/various.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,66 @@ Description: "The dateTime shall be an instant ('YYYY-MM-DDThh:mm:ss+zz:zz' or '
Expression: "$this.toString().matches('^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\\\\.[0-9]+)?(Z|(\\\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))$')"
Severity: #error
// Regex is from http://hl7.org/fhir/R4/datatypes.html#instant


/*
* BEGIN "Overridden" invariants from CH Core: since we cannot extend/inherit from invariants to change their severity, we must define the same invariants again.
* These are not in fact overridden, but just repeated with a different severity and explicitly added to CH EMED EPR profiles.
*/
Invariant: gln-length-error
Description: "GLN must be exactly 13 characters long"
Severity: #error
Expression: "matches('^[0-9]{13}$')"

Invariant: gln-modulus-10-error
Description: "GLN must pass the modulus 10 check - https://www.gs1.org/services/how-calculate-check-digit-manually"
Severity: #error
Expression: "(((10-((substring(0,1).toInteger()*1)+(substring(1,1).toInteger()*3)+(substring(2,1).toInteger()*1)+(substring(3,1).toInteger()*3)+(substring(4,1).toInteger()*1)+(substring(5,1).toInteger()*3)+(substring(6,1).toInteger()*1)+(substring(7,1).toInteger()*3)+(substring(8,1).toInteger()*1)+(substring(9,1).toInteger()*3)+(substring(10,1).toInteger()*1)+(substring(11,1).toInteger()*3))mod(10))mod(10))=substring(12,1).toInteger())"

Invariant: gln-startswith76-error
Description: "GLN must start with 76 for Swiss HCP"
Severity: #error
Expression: "startsWith('76')"

Invariant: ahvn13-digit-check-error
Description: "AHVN13 / NAVS13 must pass digit check - https://www.gs1.org/services/how-calculate-check-digit-manually"
Severity: #error
Expression: "(((10-(28+(substring(3,1).toInteger()*3)+(substring(4,1).toInteger()*1)+(substring(5,1).toInteger()*3)+(substring(6,1).toInteger()*1)+(substring(7,1).toInteger()*3)+(substring(8,1).toInteger()*1)+(substring(9,1).toInteger()*3)+(substring(10,1).toInteger()*1)+(substring(11,1).toInteger()*3))mod(10))mod(10))=substring(12,1).toInteger())"

Invariant: ahvn13-length-error
Description: "AHVN13 / NAVS13 must be exactly 13 characters long"
Severity: #error
Expression: "matches('^[0-9]{13}$')"

Invariant: ahvn13-startswith756-error
Description: "AHVN13 / NAVS13 must start with 756"
Severity: #error
Expression: "startsWith('756')"

Invariant: epr-spid-length-error
Description: "EPR-SPID must be exactly 18 characters long"
Severity: #error
Expression: "matches('^[0-9]{18}$')"

Invariant: epr-spid-modulus-10-error
Description: "EPR-SPID must pass the modulus 10 check - https://www.gs1.org/services/how-calculate-check-digit-manually"
Severity: #error
Expression: "(((10-((68+(substring(8,1).toInteger()*3)+(substring(9,1).toInteger()*1)+(substring(10,1).toInteger()*3)+(substring(11,1).toInteger()*1)+(substring(12,1).toInteger()*3)+(substring(13,1).toInteger()*1)+(substring(14,1).toInteger()*3)+(substring(15,1).toInteger()*1)+(substring(16,1).toInteger()*3))mod(10)))mod(10))=substring(17,1).toInteger())"

Invariant: epr-spid-startswith76133761-error
Description: "EPR-SPID must start with 76133761"
Severity: #error
Expression: "startsWith('76133761')"

Invariant: veka-length-error
Description: "Insurance card number must be exactly 20 characters long"
Severity: #error
Expression: "matches('^[0-9]{20}$')"

Invariant: veka-startswith807560-error
Description: "Insurance card number must start with 807560"
Severity: #error
Expression: "startsWith('807560')"
/*
* END "overridden" invariants.
*/
14 changes: 13 additions & 1 deletion input/fsh/ruleset/various.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@ RuleSet: no-support(path)
* {path} ^definition = """Implementers should not set or read this element.
This element is only kept as optional to allow submission of documents that would contain a value,
since those documents are still readable by others.
The meaning of this element is undefined in this profile."""
The meaning of this element is undefined in this profile."""

RuleSet: enforce-valid-gln
* value obeys gln-length-error and gln-modulus-10-error and gln-startswith76-error

RuleSet: enforce-valid-ahvn13
* value obeys ahvn13-digit-check-error and ahvn13-length-error and ahvn13-startswith756-error

RuleSet: enforce-valid-epr-spid
* value obeys epr-spid-length-error and epr-spid-modulus-10-error and epr-spid-startswith76133761-error

RuleSet: enforce-valid-veka
* value obeys veka-length-error and veka-startswith807560-error
2 changes: 1 addition & 1 deletion input/fsh/structuredefinition/organization.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Title: "CH EMED EPR Organization"
Description: "Definition of the organization for the eMedication context"

* insert domain-resource-ruleset

* identifier[GLN] insert enforce-valid-gln
* insert problematic-reference(identifier.assigner)
* insert problematic-reference(partOf)
* insert problematic-reference(endpoint)
3 changes: 3 additions & 0 deletions input/fsh/structuredefinition/patient.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Description: "Definition of the patient for the eMedication context"
* insert domain-resource-ruleset

* identifier insert identifier-ruleset
* identifier[AHVN13] insert enforce-valid-ahvn13
* identifier[EPR-SPID] insert enforce-valid-epr-spid
* identifier[insuranceCardNumber] insert enforce-valid-veka
* insert problematic-reference(identifier.assigner)
* insert problematic-reference(contact.organization)
* insert problematic-reference(generalPractitioner)
Expand Down
1 change: 1 addition & 0 deletions input/fsh/structuredefinition/practitioner.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Description: "Definition of the practitioner for the eMedication context"
* insert no-support(contained)
* insert no-support(extension)
* identifier insert identifier-ruleset
* identifier[GLN] insert enforce-valid-gln
* insert problematic-reference(identifier.assigner)
* insert problematic-reference(qualification.issuer)
// TODO ZSR is mandatory on paper prescription

0 comments on commit 469a904

Please sign in to comment.