Skip to content

Commit

Permalink
View remote patient
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Mar 27, 2024
1 parent 3c0a97c commit 4ab0882
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 212 deletions.
2 changes: 1 addition & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var _ ServerInterface = (*Wrapper)(nil)
type Wrapper struct {
APIAuth *Auth
ACL *acl.Repository
NutsClient nutsClient.HTTPClient
NutsClient *nutsClient.HTTPClient
CustomerRepository customers.Repository
PatientRepository patients.Repository
ReportRepository reports.Repository
Expand Down
65 changes: 41 additions & 24 deletions api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -593,32 +593,42 @@ paths:
$ref: "#/components/schemas/Patient"

/private/network/discovery:
get:
# Search has become a POST instead of GET, since it uses an object (query) as input,
# which OpenAPI Codegenerator does not handle properly for GET operations.
post:
description: Searches for other care organizations on Nuts Network.
operationId: searchOrganizations
parameters:
- name: query
in: query
description: Keyword for finding care organizations.
required: true
schema:
type: string
- name: didServiceType
in: query
description: >
Filters other care organizations on the Nuts Network on service, only returning care organizations have a service in their DID Document which' type matches the given didServiceType and not including your own.
If not supplied, care organizations aren't filtered on service.
required: false
schema:
type: string
- name: discoveryServiceType
in: query
description: >
Filters other care organizations on the Nuts Network on service, only returning care organizations that registered for the given service at a discovery server.
It false, it will search on all Discovery Services.
required: false
schema:
type: string
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- query
properties:
query:
type: object
additionalProperties:
type: string
description: >
The search query, key-value string properties. E.g.:
'credentialSubject.organization.name: Ziekenhuis'
discoveryServiceID:
description: >
Filters other care organizations on the Nuts Network, only returning care organizations that registered for the given Discovery Service.
It false, it will search on all Discovery Services.
type: string
didServiceType:
description: >
Filters other care organizations on the Nuts Network on service, only returning care organizations have a service in their DID Document which' type matches the given didServiceType and not including your own.
If not supplied, care organizations aren't filtered on service.
type: string
excludeOwn:
description: >
If true, the current care organization is excluded from the search results.
Defaults to false.
type: boolean
responses:
200:
description: Search successful.
Expand Down Expand Up @@ -1023,6 +1033,7 @@ components:
- name
- city
- did
- discoveryServices
properties:
name:
description: Name of the care organization.
Expand All @@ -1033,6 +1044,12 @@ components:
did:
description: Decentralized Identifier which uniquely identifies the care organization on the Nuts Network.
type: string
discoveryServices:
description: >
List of Discovery Services the care organization is registered with.
type: array
items:
type: string
CreateTransferNegotiationRequest:
description: An request object to create a new transfer negotiation.
type: object
Expand Down
30 changes: 0 additions & 30 deletions api/discovery.go

This file was deleted.

31 changes: 4 additions & 27 deletions api/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 14 additions & 9 deletions api/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,33 @@ import (
"github.com/nuts-foundation/nuts-demo-ehr/domain/types"
)

type SearchOrganizationsParams = types.SearchOrganizationsParams

func (w Wrapper) SearchOrganizations(ctx echo.Context, params SearchOrganizationsParams) error {
func (w Wrapper) SearchOrganizations(ctx echo.Context) error {
customer, err := w.getCustomer(ctx)
if err != nil {
return err
}

organizations, err := w.NutsClient.SearchService(ctx.Request().Context(), params.Query, params.DiscoveryServiceType, params.DidServiceType)
var request types.SearchOrganizationsJSONRequestBody
if err := ctx.Bind(&request); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
organizations, err := w.NutsClient.SearchDiscoveryService(ctx.Request().Context(), request.Query, request.DiscoveryServiceID, request.DidServiceType)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

var results = make([]types.Organization, 0)

var results = make(map[string]types.Organization, 0)
for _, organization := range organizations {
// Hide our own organization
if organization.ID == *customer.Did {
if request.ExcludeOwn != nil && *request.ExcludeOwn && organization.ID == *customer.Did {
continue
}

results = append(results, types.FromNutsOrganization(organization))
current, exists := results[organization.ID]
if !exists {
current = types.FromNutsOrganization(organization.NutsOrganization)
}
current.DiscoveryServices = append(current.DiscoveryServices, organization.ServiceID)
results[organization.ID] = current
}

return ctx.JSON(http.StatusOK, results)
Expand Down
1 change: 0 additions & 1 deletion domain/fhir/eoverdracht/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/monarko/fhirgo/STU3/resources"
"github.com/nuts-foundation/nuts-demo-ehr/domain/fhir"
"github.com/nuts-foundation/nuts-demo-ehr/domain/types"
types2 "github.com/oapi-codegen/runtime/types"
"github.com/tidwall/gjson"
)

Expand Down
1 change: 0 additions & 1 deletion domain/fhir/zorginzage/convertors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/nuts-foundation/nuts-demo-ehr/domain/fhir"
"github.com/nuts-foundation/nuts-demo-ehr/domain/types"
types2 "github.com/oapi-codegen/runtime/types"
)

func ToEpisode(episode *fhir.EpisodeOfCare) *types.Episode {
Expand Down
1 change: 0 additions & 1 deletion domain/transfer/sender/sql_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
sqlUtil "github.com/nuts-foundation/nuts-demo-ehr/sql"

"github.com/jmoiron/sqlx"
openapi_types "github.com/oapi-codegen/runtime/types"
)

type sqlTransfer struct {
Expand Down
25 changes: 17 additions & 8 deletions domain/types/generated_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 16 additions & 17 deletions nuts/client/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,27 @@ type DiscoverySearchResult struct {
}

type Discovery interface {
SearchService(ctx context.Context, organizationSearchParam string, discoveryServiceID *string, didServiceType *string) ([]DiscoverySearchResult, error)
SearchDiscoveryService(ctx context.Context, query map[string]string, discoveryServiceID *string, didServiceType *string) ([]DiscoverySearchResult, error)
}

func (c HTTPClient) SearchService(ctx context.Context, organizationSearchParam string, discoveryServiceID *string, didServiceType *string) ([]DiscoverySearchResult, error) {
func (c HTTPClient) SearchDiscoveryService(ctx context.Context, query map[string]string, discoveryServiceID *string, didServiceType *string) ([]DiscoverySearchResult, error) {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

searchParams := map[string]interface{}{
"credentialSubject.organization.name": organizationSearchParam + "*",
}

var serviceIDs []string
if discoveryServiceID != nil {
results, err := c.searchDiscoveryService(ctx, searchParams, *discoveryServiceID, didServiceType)
serviceIDs = append(serviceIDs, *discoveryServiceID)
} else {
// service ID not specified, search all discovery services
var err error
serviceIDs, err = c.getDiscoveryServices(ctx)
if err != nil {
return nil, err
}
return results, nil
}
// service ID not specified, search all discovery services
discoveryServices, err := c.getDiscoveryServices(ctx)
if err != nil {
return nil, err
}
searchResults := make([]DiscoverySearchResult, 0)
for _, serviceID := range discoveryServices {
currResults, err := c.searchDiscoveryService(ctx, searchParams, serviceID, didServiceType)
for _, serviceID := range serviceIDs {
currResults, err := c.searchDiscoveryService(ctx, query, serviceID, didServiceType)
if err != nil {
return nil, err
}
Expand All @@ -54,8 +49,12 @@ func (c HTTPClient) SearchService(ctx context.Context, organizationSearchParam s
return searchResults, nil
}

func (c HTTPClient) searchDiscoveryService(ctx context.Context, query map[string]interface{}, discoveryServiceID string, didServiceType *string) ([]DiscoverySearchResult, error) {
params := nutsDiscoveryClient.SearchPresentationsParams{Query: &query}
func (c HTTPClient) searchDiscoveryService(ctx context.Context, query map[string]string, discoveryServiceID string, didServiceType *string) ([]DiscoverySearchResult, error) {
queryAsMap := make(map[string]interface{}, 0)
for key, value := range query {
queryAsMap[key] = value
}
params := nutsDiscoveryClient.SearchPresentationsParams{Query: &queryAsMap}

resp, err := c.discovery().SearchPresentations(ctx, discoveryServiceID, &params)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions nuts/client/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"context"
"encoding/json"
"errors"
nutsIamClient "github.com/nuts-foundation/nuts-demo-ehr/nuts/client/iam"
"net/http"
"time"
Expand Down Expand Up @@ -64,14 +65,14 @@ func (c HTTPClient) GetAuthenticationResult(token string) (*nutsIamClient.TokenR
}

func (c HTTPClient) RequestServiceAccessToken(ctx context.Context, relyingPartyDID, authorizationServerDID string, scope string) (string, error) {
response, err := c.iam().RequestServiceAccessToken(ctx, relyingPartyDID, iam.RequestServiceAccessTokenJSONRequestBody{
response, err := c.iam().RequestServiceAccessToken(ctx, relyingPartyDID, nutsIamClient.RequestServiceAccessTokenJSONRequestBody{
Scope: scope,
Verifier: authorizationServerDID,
})
if err != nil {
return "", err
}
tokenResponse, err := iam.ParseRequestServiceAccessTokenResponse(response)
tokenResponse, err := nutsIamClient.ParseRequestServiceAccessTokenResponse(response)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion nuts/client/vdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func (c HTTPClient) ResolveServiceEndpoint(ctx context.Context, did string, serviceType string, endpointType string) (interface{}, error) {
ep := vdr_v2.FilterServicesParamsEndpointType(endpointType)
response, err := c.vdr().FilterServices(ctx, did, "whatever", &vdr_v2.FilterServicesParams{EndpointType: &ep, Type: &serviceType})
response, err := c.vdr().FilterServices(ctx, did, &vdr_v2.FilterServicesParams{EndpointType: &ep, Type: &serviceType})
if err != nil {
return "", err
}
Expand Down
Loading

0 comments on commit 4ab0882

Please sign in to comment.