Skip to content

Commit 9902a64

Browse files
authored
#97 mCSD admin: Connect endpoint to Organization (#114)
1 parent 50c30cd commit 9902a64

File tree

5 files changed

+77
-11
lines changed

5 files changed

+77
-11
lines changed

component/mcsdadmin/component.go

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"github.com/nuts-foundation/nuts-knooppunt/component/mcsdadmin/static"
1414
tmpls "github.com/nuts-foundation/nuts-knooppunt/component/mcsdadmin/templates"
1515
"github.com/nuts-foundation/nuts-knooppunt/component/mcsdadmin/valuesets"
16+
"github.com/nuts-foundation/nuts-knooppunt/lib/coding"
17+
"github.com/nuts-foundation/nuts-knooppunt/lib/to"
1618
"github.com/rs/zerolog/log"
1719
"github.com/zorgbijjou/golang-fhir-models/fhir-models/caramel"
1820
"github.com/zorgbijjou/golang-fhir-models/fhir-models/fhir"
@@ -198,6 +200,14 @@ func newOrganizationPost(w http.ResponseWriter, r *http.Request) {
198200
var org fhir.Organization
199201
name := r.PostForm.Get("name")
200202
org.Name = &name
203+
uraString := r.PostForm.Get("identifier")
204+
if uraString == "" {
205+
http.Error(w, "Bad request: missing URA identifier", http.StatusBadRequest)
206+
return
207+
}
208+
org.Identifier = []fhir.Identifier{
209+
uraIdentifier(uraString),
210+
}
201211

202212
orgTypeCode := r.PostForm.Get("type")
203213
orgType, ok := valuesets.CodableFrom("organization-type", orgTypeCode)
@@ -280,6 +290,10 @@ func newEndpointPost(w http.ResponseWriter, r *http.Request) {
280290

281291
var endpoint fhir.Endpoint
282292
address := r.PostForm.Get("address")
293+
if address == "" {
294+
http.Error(w, "bad request: missing address", http.StatusBadRequest)
295+
return
296+
}
283297
endpoint.Address = address
284298

285299
var payloadType fhir.CodeableConcept
@@ -288,7 +302,8 @@ func newEndpointPost(w http.ResponseWriter, r *http.Request) {
288302
if ok {
289303
endpoint.PayloadType = []fhir.CodeableConcept{payloadType}
290304
} else {
291-
log.Warn().Msg("Failed to find referred payload type")
305+
http.Error(w, "bad request: missing payload type", http.StatusBadRequest)
306+
return
292307
}
293308

294309
periodStart := r.PostForm.Get("period-start")
@@ -298,8 +313,6 @@ func newEndpointPost(w http.ResponseWriter, r *http.Request) {
298313
Start: &periodStart,
299314
End: &periodEnd,
300315
}
301-
} else {
302-
log.Warn().Msg("Missing period")
303316
}
304317

305318
contactValue := r.PostForm.Get("contact")
@@ -308,8 +321,6 @@ func newEndpointPost(w http.ResponseWriter, r *http.Request) {
308321
Value: &contactValue,
309322
}
310323
endpoint.Contact = []fhir.ContactPoint{contact}
311-
} else {
312-
log.Warn().Msg("Missing contact value")
313324
}
314325

315326
orgFormStr := r.PostForm.Get("managing-org")
@@ -323,12 +334,13 @@ func newEndpointPost(w http.ResponseWriter, r *http.Request) {
323334
}
324335
err = client.Read(reference, &managingOrg)
325336
if err != nil {
326-
log.Error().Err(err).Msg("Failed to find referred organisation")
337+
http.Error(w, "internal error: could not find organization", http.StatusInternalServerError)
327338
return
328339
}
329340
endpoint.ManagingOrganization.Display = managingOrg.Name
330341
} else {
331-
log.Warn().Msg("Missing organisation value")
342+
http.Error(w, "bad request: missing managing organization", http.StatusBadRequest)
343+
return
332344
}
333345

334346
var connectionType fhir.Coding
@@ -337,7 +349,8 @@ func newEndpointPost(w http.ResponseWriter, r *http.Request) {
337349
if ok {
338350
endpoint.ConnectionType = connectionType
339351
} else {
340-
log.Warn().Msg("Failed to find referred connection type")
352+
http.Error(w, "bad request: missing connection type", http.StatusBadRequest)
353+
return
341354
}
342355

343356
purposeOfUseId := r.PostForm.Get("purpose-of-use")
@@ -348,14 +361,23 @@ func newEndpointPost(w http.ResponseWriter, r *http.Request) {
348361
ValueCodeableConcept: &purposeOfUse,
349362
}
350363
endpoint.Extension = append(endpoint.Extension, extension)
351-
} else {
352-
log.Warn().Msg("Failed to find referred purpose of use")
353364
}
354365

355366
status := r.PostForm.Get("status")
356367
endpoint.Status, ok = valuesets.EndpointStatusFrom(status)
357368
if !ok {
358-
log.Warn().Msg("Failed to determine status, default to active")
369+
http.Error(w, "bad request: missing status", http.StatusBadRequest)
370+
return
371+
}
372+
373+
forOrgStr := r.PostForm.Get("endpoint-for")
374+
var owningOrg fhir.Organization
375+
if len(forOrgStr) > 0 {
376+
err = client.Read("Organization/"+forOrgStr, &owningOrg)
377+
if err != nil {
378+
http.Error(w, "bad request: could not find organization", http.StatusBadRequest)
379+
return
380+
}
359381
}
360382

361383
var resEp fhir.Endpoint
@@ -365,6 +387,18 @@ func newEndpointPost(w http.ResponseWriter, r *http.Request) {
365387
return
366388
}
367389

390+
var epRef fhir.Reference
391+
epRef.Type = to.Ptr("Endpoint")
392+
epRef.Reference = to.Ptr("Endpoint/" + *resEp.Id)
393+
394+
owningOrg.Endpoint = append(owningOrg.Endpoint, epRef)
395+
396+
var updatedOrg fhir.Organization
397+
err = client.Update("Organization/"+*owningOrg.Id, owningOrg, updatedOrg)
398+
if err != nil {
399+
http.Error(w, err.Error(), http.StatusInternalServerError)
400+
}
401+
368402
w.WriteHeader(http.StatusCreated)
369403
renderList[fhir.Endpoint, tmpls.EpListProps](client, w, tmpls.MakeEpListXsProps)
370404
}
@@ -528,3 +562,10 @@ func renderList[R any, DTO any](fhirClient fhirclient.Client, httpResponse http.
528562
Items: dtoFunc(items),
529563
})
530564
}
565+
566+
func uraIdentifier(uraString string) fhir.Identifier {
567+
var identifier fhir.Identifier
568+
identifier.Value = to.Ptr(uraString)
569+
identifier.System = to.Ptr(coding.URANamingSystem)
570+
return identifier
571+
}

component/mcsdadmin/templates/endpoint_edit.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ <h4>Edit Endpoint</h4>
7373
{{ end }}
7474
</select>
7575
</div>
76+
<div class="mb-3">
77+
<label for="endpoint-for" class="form-label">Endpoint of:</label>
78+
<select name="endpoint-for" id="endpoint-for" class="form-select">
79+
<option value="">--Please choose an option--</option>
80+
{{range .Organizations}}
81+
<option value="{{ .Id }}">{{ .Name }}</option>
82+
{{ end }}
83+
</select>
84+
</div>
7685
<div class="mb-3">
7786
<button type="submit" class="btn btn-primary">Submit</button>
7887
</div>

component/mcsdadmin/templates/organization_edit.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ <h4>Edit Organization</h4>
99
<label for="name" class="form-label">Name of the organization:</label>
1010
<input id="name" type="text" name="name" class="form-control" placeholder="Enter name here" required>
1111
</div>
12+
<div class="mb-3">
13+
<label for="identifier" class="form-label">URA identifier:</label>
14+
<input id="identifier" type="text" name="identifier" class="form-control" placeholder="Enter identifier here" required>
15+
</div>
1216
<div class="mb-3">
1317
<label for="type-select" class="form-label">Choose a type:</label>
1418
<select name="type" id="type-select" class="form-select">

component/mcsdadmin/templates/organization_list.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ <h2>Organizations</h2>
99
<thead class="table-light">
1010
<tr>
1111
<th scope="col">Name</th>
12+
<th scope="col">URA</th>
1213
<th scope="col">Type</th>
1314
<th scope="col">Active</th>
1415
<th scope="col">Actions</th>
@@ -18,6 +19,7 @@ <h2>Organizations</h2>
1819
{{range .Items}}
1920
<tr id="row-{{.Id}}">
2021
<th scope="row">{{ .Name }}</th>
22+
<th scope="row">{{ .Ura }}</th>
2123
<td>{{.Type}}</td>
2224
<td>
2325
{{if .Active }}

component/mcsdadmin/templates/templates.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"html/template"
66
"io"
77

8+
"github.com/nuts-foundation/nuts-knooppunt/lib/coding"
89
"github.com/rs/zerolog/log"
910
"github.com/zorgbijjou/golang-fhir-models/fhir-models/fhir"
1011
)
@@ -120,6 +121,7 @@ func MakeEpListXsProps(eps []fhir.Endpoint) []EpListProps {
120121
type OrgListProps struct {
121122
Id string
122123
Name string
124+
URA string
123125
Type string
124126
Active bool
125127
}
@@ -135,6 +137,14 @@ func MakeOrgListProps(org fhir.Organization) (out OrgListProps) {
135137
out.Name = unknownStr
136138
}
137139

140+
for _, idn := range org.Identifier {
141+
if idn.System != nil && idn.Value != nil {
142+
if *idn.System == coding.URANamingSystem {
143+
out.URA = *idn.Value
144+
}
145+
}
146+
}
147+
138148
if len(org.Type) > 0 {
139149
out.Type = fmtCodable(org.Type[0])
140150
} else {

0 commit comments

Comments
 (0)