001/*- 002 * #%L 003 * Smile CDR - CDR 004 * %% 005 * Copyright (C) 2016 - 2026 Smile CDR, Inc. 006 * %% 007 * All rights reserved. 008 * #L% 009 */ 010package ca.cdr.api.model.json; 011 012import io.swagger.v3.oas.annotations.Operation; 013import io.swagger.v3.oas.annotations.Parameter; 014import org.hl7.fhir.instance.model.api.IBaseCoding; 015 016import java.util.List; 017 018public interface ISessionConsentDetails { 019 020 String CONSENT_ACTOR_ROLE_URI = "https://smilecdr.com/ns/ConsentSystem/ConsentActorRole"; 021 022 List<SmartFhirContextEntryJson> getFhirContext(); 023 024 /** 025 * Gets the consent purpose coding associated with this session. 026 * 027 * @return the consent purpose coding, or null if not set 028 */ 029 @Operation( 030 summary = "getConsentPurpose", 031 description = "Provides the coding of the purpose associated with the consent.") 032 IBaseCoding getConsentPurpose(); 033 034 @Operation( 035 summary = "setConsentPurpose", 036 description = "Sets the coding of the purpose associated with the consent.") 037 void setConsentPurpose( 038 @Parameter(name = "theSystem", description = "The coding system of the purpose code") String theSystem, 039 @Parameter(name = "theCode", description = "The purpose code") String theCode); 040 041 /** 042 * The "actor" reference for the purpose of consent. 043 * E.g. Organization/my-hospital or Patient/the-patient 044 * 045 * @param theActorResourceId the resource id of the actor 046 * 047 */ 048 @Operation( 049 summary = "setConsentActor", 050 description = "Sets the actor reference associated with the consent purpose.") 051 default void setConsentActor( 052 @Parameter(name = "theActorResourceId", description = "The resource id of the actor") 053 String theActorResourceId) { 054 SmartFhirContextEntryJson fhirContextEntryJson = getFhirContextReferencesForRole(CONSENT_ACTOR_ROLE_URI); 055 if (fhirContextEntryJson != null) { 056 fhirContextEntryJson.setReference(theActorResourceId); 057 } else { 058 addFhirContextReference(theActorResourceId, CONSENT_ACTOR_ROLE_URI); 059 } 060 } 061 062 @Operation( 063 summary = "getConsentActor", 064 description = "Provides the actor reference associated with the consent purpose.") 065 default String getConsentActor() { 066 SmartFhirContextEntryJson fhirContextEntryJson = getFhirContextReferencesForRole(CONSENT_ACTOR_ROLE_URI); 067 return fhirContextEntryJson == null ? null : fhirContextEntryJson.getReference(); 068 } 069 070 @Operation( 071 summary = "getFhirContextReferencesForRole", 072 description = "Provides the fhirContext entry for a given role or null if there are none.") 073 default SmartFhirContextEntryJson getFhirContextReferencesForRole( 074 @Parameter(name = "theRoleUri") String theRoleUri) { 075 return getFhirContext().stream() 076 .filter(c -> c.getRole() != null && c.getRole().equalsIgnoreCase(theRoleUri)) 077 .findFirst() 078 .orElse(null); 079 } 080 081 @Operation( 082 summary = "addFhirContextReference", 083 description = "Adds a Smart fhirContext entry containing only the reference") 084 default void addFhirContextReference( 085 @Parameter(name = "theReference", description = "A reference to a FHIR resource in the fhirContext.") 086 String theReference) { 087 getFhirContext().add(SmartFhirContextEntryJson.withReferenceOnly(theReference)); 088 } 089 090 @Operation( 091 summary = "addFhirContextReference", 092 description = "Adds a Smart fhirContext entry containing the reference and role") 093 default void addFhirContextReference( 094 @Parameter(name = "theReference", description = "A reference to a FHIR resource in the fhirContext.") 095 String theReference, 096 @Parameter(name = "theRole", description = "A reference to a role URI in the fhirContext") String theRole) { 097 getFhirContext().add(SmartFhirContextEntryJson.withReferenceAndRole(theReference, theRole)); 098 } 099}