Skip to content

Commit

Permalink
feat: create test result FHIR observation (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
Salaton committed Mar 28, 2022
1 parent 96fc9e3 commit f44e255
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 22 deletions.
16 changes: 16 additions & 0 deletions pkg/clinical/application/dto/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,19 @@ type CreateMedicationPubSubMessage struct {
type MedicationDrug struct {
ConceptID *string `json:"conceptId"`
}

// CreatePatientTestResultPubSubMessage models details that are published to the test results topic
type CreatePatientTestResultPubSubMessage struct {
PatientID string `json:"patientID"`
OrganizationID string `json:"organizationID"`
Name string `json:"name"`
ConceptID *string `json:"conceptId"`
Date time.Time `json:"date"`
Result TestResult `json:"result"`
}

// TestResult ...
type TestResult struct {
Name string `json:"name"`
ConceptID *string `json:"conceptId"`
}
44 changes: 22 additions & 22 deletions pkg/clinical/domain/concept.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import "time"

// Concept models a concept type from OpenConceptLab
type Concept struct {
ConceptClass string `json:"concept_class"`
DataType string `json:"datatype"`
DisplayLocale string `json:"display_locale"`
DisplayName string `json:"display_name"`
ExternalID string `json:"external_id"`
ID string `json:"id"`
IsLatestVersion bool `json:"is_latest_version"`
Locale *string `json:"locale"`
Owner string `json:"owner"`
OwnerType string `json:"owner_type"`
OwnerURL string `json:"owner_url"`
Retired bool `json:"retired"`
Source string `json:"source"`
Type string `json:"type"`
UpdateComment string `json:"update_comment"`
URL string `json:"url"`
UUID string `json:"uuid"`
Version string `json:"version"`
VersionCreatedBy string `json:"version_created_by"`
VersionCreatedOn *time.Time `json:"version_created_on"`
VersionURL string `json:"version_url"`
VersionsURL string `json:"versions_url"`
ConceptClass string `mapstructure:"concept_class" json:"concept_class"`
DataType string `mapstructure:"datatype" json:"datatype"`
DisplayLocale string `mapstructure:"display_locale" json:"display_locale"`
DisplayName string `mapstructure:"display_name" json:"display_name"`
ExternalID string `mapstructure:"external_id" json:"external_id"`
ID string `mapstructure:"id" json:"id"`
IsLatestVersion bool `mapstructure:"is_latest_version" json:"is_latest_version"`
Locale *string `mapstructure:"locale" json:"locale"`
Owner string `mapstructure:"owner" json:"owner"`
OwnerType string `mapstructure:"owner_type" json:"owner_type"`
OwnerURL string `mapstructure:"owner_url" json:"owner_url"`
Retired bool `mapstructure:"retired" json:"retired"`
Source string `mapstructure:"source" json:"source"`
Type string `mapstructure:"type" json:"type"`
UpdateComment string `mapstructure:"update_comment" json:"update_comment"`
URL string `mapstructure:"url" json:"url"`
UUID string `mapstructure:"uuid" json:"uuid"`
Version string `mapstructure:"version" json:"version"`
VersionCreatedBy string `mapstructure:"version_created_by" json:"version_created_by"`
VersionCreatedOn *time.Time `mapstructure:"version_created_on" json:"version_created_on"`
VersionURL string `mapstructure:"version_url" json:"version_url"`
VersionsURL string `mapstructure:"versions_url" json:"versions_url"`
}
86 changes: 86 additions & 0 deletions pkg/clinical/infrastructure/services/pubsub/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,92 @@ func (ps ServicePubSubMessaging) ReceivePubSubPushMessages(
return
}

case ps.AddPubSubNamespace(common.TestResultTopicName, ClinicalServiceName):
var data dto.CreatePatientTestResultPubSubMessage
err := json.Unmarshal(message.Message.Data, &data)
if err != nil {
serverutils.WriteJSONResponse(w, errorcodeutil.CustomError{
Err: err,
Message: err.Error(),
}, http.StatusBadRequest)
return
}

response, err := ps.ocl.GetConcept(
ctx,
"CIEL",
"CIEL",
*data.ConceptID,
false,
false,
)
if err != nil {
serverutils.WriteJSONResponse(w, errorcodeutil.CustomError{
Err: err,
Message: err.Error(),
}, http.StatusBadRequest)
return
}

var ConceptPayload domain.Concept
err = mapstructure.Decode(response, &ConceptPayload)
if err != nil {
serverutils.WriteJSONResponse(w, errorcodeutil.CustomError{
Err: err,
Message: err.Error(),
}, http.StatusBadRequest)
return
}

year, month, day := data.Date.Date()
system := "http://terminology.hl7.org/CodeSystem/observation-category"
subjectReference := fmt.Sprintf("Patient/%v", data.PatientID)
status := domain.ObservationStatusEnumPreliminary
input := domain.FHIRObservationInput{
Status: &status,
Category: []*domain.FHIRCodeableConceptInput{
{
Coding: []*domain.FHIRCodingInput{
{
System: (*scalarutils.URI)(&system),
Code: "laboratory",
Display: "Laboratory",
},
},
Text: "Laboratory",
},
},

Code: domain.FHIRCodeableConceptInput{
Coding: []*domain.FHIRCodingInput{
{
System: (*scalarutils.URI)(&ConceptPayload.URL),
Code: scalarutils.Code(ConceptPayload.ID),
Display: ConceptPayload.DisplayName,
},
},
Text: ConceptPayload.DisplayName,
},
ValueString: &data.Result.Name,
EffectiveDateTime: &scalarutils.Date{
Year: year,
Month: int(month),
Day: day,
},
Subject: &domain.FHIRReferenceInput{
Reference: &subjectReference,
Display: data.PatientID,
},
}

_, err = ps.fhir.CreateFHIRObservation(ctx, input)
if err != nil {
serverutils.WriteJSONResponse(w, errorcodeutil.CustomError{
Err: err,
Message: err.Error(),
}, http.StatusBadRequest)
return
}
}

resp := map[string]string{"Status": "Success"}
Expand Down

0 comments on commit f44e255

Please sign in to comment.