-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support authorized patient ids that include base url
- Loading branch information
1 parent
8210ae2
commit 223f673
Showing
8 changed files
with
344 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
src/test/java/edu/ohsu/cmp/ecp/sds/PatientAppClientForeignPartitionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package edu.ohsu.cmp.ecp.sds; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.hamcrest.Matchers.greaterThanOrEqualTo; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static edu.ohsu.cmp.ecp.sds.SupplementalDataStoreMatchers.identifiesResource; | ||
import static edu.ohsu.cmp.ecp.sds.SupplementalDataStoreMatchers.identifiesSameResourceAs; | ||
|
||
import java.util.List; | ||
|
||
import org.hl7.fhir.instance.model.api.IIdType; | ||
import org.hl7.fhir.r4.model.CodeableConcept; | ||
import org.hl7.fhir.r4.model.Coding; | ||
import org.hl7.fhir.r4.model.Condition; | ||
import org.hl7.fhir.r4.model.IdType; | ||
import org.hl7.fhir.r4.model.Linkage; | ||
import org.hl7.fhir.r4.model.QuestionnaireResponse; | ||
import org.hl7.fhir.r4.model.Patient; | ||
import org.hl7.fhir.r4.model.Reference; | ||
import org.hl7.fhir.r4.model.Type; | ||
import org.hl7.fhir.r4.model.UriType; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import ca.uhn.fhir.jpa.starter.AppTestMockPermissionRegistry; | ||
import ca.uhn.fhir.jpa.starter.AppTestMockPrincipalRegistry; | ||
import ca.uhn.fhir.rest.client.api.IGenericClient; | ||
import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException; | ||
import junit.framework.AssertionFailedError; | ||
|
||
@ActiveProfiles( "auth-aware-test") | ||
public class PatientAppClientForeignPartitionTest extends BaseSuppplementalDataStoreTest { | ||
|
||
/* | ||
* Use Case: store NON-LOCAL Patient and other resources in the patient compartment | ||
*/ | ||
|
||
@Autowired | ||
AppTestMockPrincipalRegistry mockPrincipalRegistry ; | ||
|
||
@Autowired | ||
AppTestMockPermissionRegistry mockPermissionRegistry ; | ||
|
||
private static final String FOREIGN_PARTITION_NAME = "http://my.ehr.org/fhir/R4/" ; | ||
|
||
private IIdType authorizedPatientId; | ||
private IGenericClient patientAppClient ; | ||
|
||
@BeforeEach | ||
public void setupAuthorizedPatient() { | ||
authorizedPatientId = new IdType( FOREIGN_PARTITION_NAME, "Patient", createTestSpecificId(), null ); | ||
String token = mockPrincipalRegistry.register().principal( "MyPatient", authorizedPatientId.toString() ).token() ; | ||
|
||
patientAppClient = authenticatingClientTargetingPartition( token, FOREIGN_PARTITION_NAME ) ; | ||
} | ||
|
||
@Test | ||
void canStoreAndReadPatientThatIsAuthorizedPatient() { | ||
Patient patient = new Patient() ; | ||
patient.setId( new IdType( "Patient", authorizedPatientId.getIdPart() ) ) ; | ||
IIdType patientId = patientAppClient.update().resource(patient).execute().getId(); | ||
|
||
assertThat( patientId, identifiesResource( patient ) ); | ||
|
||
Patient readPatient = patientAppClient.read().resource(Patient.class).withId( patientId ).execute(); | ||
|
||
assertThat( readPatient, notNullValue() ); | ||
assertThat( readPatient.getIdElement(), identifiesSameResourceAs( patient.getIdElement() ) ); | ||
} | ||
|
||
@Test | ||
void canStorePatientWithoutAdditionalSetup() { | ||
String subjectPatientId = createTestSpecificId() ; | ||
Patient subjectPatient = new Patient() ; | ||
subjectPatient.setId( new IdType( "Patient", subjectPatientId ) ) ; | ||
|
||
IIdType claimedPatientId = patientAppClient.update().resource(subjectPatient).execute().getId(); | ||
|
||
Patient readPatientResp = patientAppClient.read().resource(Patient.class).withId(claimedPatientId).execute(); | ||
|
||
Assertions.assertNotNull( readPatientResp ); | ||
} | ||
|
||
private Condition createHealthConcern( Reference subjectRef, String codeAsPlainText ) { | ||
Condition condition = new Condition() ; | ||
condition.setSubject( subjectRef ) ; | ||
|
||
CodeableConcept healthConcernCategory = new CodeableConcept(); | ||
healthConcernCategory.addCoding( new Coding( "http://hl7.org/fhir/ValueSet/condition-category", "health-concern", "health concern" ) ) ; | ||
condition.setCategory( asList( healthConcernCategory ) ) ; | ||
|
||
condition.setCode( healthConcernCategory.setText(codeAsPlainText) ) ; | ||
|
||
return condition ; | ||
} | ||
|
||
@Test | ||
void canStoreConditionWhereSubjectIsClaimedPatientWithoutAdditionalSetup() { | ||
String subjectPatientId = createTestSpecificId() ; | ||
Patient subjectPatient = new Patient() ; | ||
subjectPatient.setId( new IdType( "Patient", subjectPatientId ) ) ; | ||
|
||
IIdType claimedPatientId = patientAppClient.update().resource(subjectPatient).execute().getId(); | ||
|
||
Condition condition = createHealthConcern( new Reference(claimedPatientId), "my health concern" ) ; | ||
|
||
IIdType conditionId = patientAppClient.create().resource(condition).execute().getId(); | ||
|
||
Condition readQuestResp = patientAppClient.read().resource(Condition.class).withId(conditionId).execute(); | ||
|
||
Assertions.assertNotNull( readQuestResp ); | ||
} | ||
|
||
@Test | ||
void canExpunge() { | ||
String authorizedPatientId = createTestSpecificId() ; | ||
String token = mockPrincipalRegistry.register().principal( "MyPatient", "Patient/" + authorizedPatientId ).token() ; | ||
|
||
IGenericClient patientAppClient = authenticatingClient( token ) ; | ||
|
||
Reference authorizedPatient = new Reference( new IdType( "Patient", authorizedPatientId ) ); | ||
|
||
List<Linkage> linkages = new TestClientSearch(patientAppClient).searchLinkagesWhereItemRefersTo( authorizedPatient.getReferenceElement() ) ; | ||
assertThat( linkages, hasSize(1) ) ; | ||
Linkage linkage = linkages.get(0) ; | ||
Reference localPatientRef = | ||
linkage.getItem().stream() | ||
.filter( i -> i.getType() == Linkage.LinkageType.SOURCE ) | ||
.map( Linkage.LinkageItemComponent::getResource ) | ||
.findFirst() | ||
.orElseThrow( AssertionFailedError::new ) | ||
; | ||
|
||
String questId = createTestSpecificId(); | ||
|
||
QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse() ; | ||
questionnaireResponse.setSubject( authorizedPatient ) ; | ||
questionnaireResponse.setQuestionnaire( questId ) ; | ||
IIdType questRespId = patientAppClient.create().resource(questionnaireResponse).execute().getId(); | ||
|
||
QuestionnaireResponse readQuestResp = patientAppClient.read().resource(QuestionnaireResponse.class).withId(questRespId).execute(); | ||
Assertions.assertNotNull( readQuestResp ); | ||
|
||
// patientAppClient | ||
// .operation() | ||
// .onInstance( localPatientRef.getReferenceElement() ) | ||
// .named( "$expunge" ) | ||
// .withParameter( BooleanType.class, "expungeEverything", new BooleanType(true) ) | ||
// ; | ||
} | ||
|
||
} |
Oops, something went wrong.