// This application will create a new record set in the patient matching test // harness. This record set will be associated with a FHIR resource tag. // It will generate a pair of matching patient records, apply the tag, and // then upload them to the FHIR server. It will also upload an answer key. func main() { fhirURL := flag.String("fhirURL", "", "URL for the patient matching test harness server") recordSetName := flag.String("name", "", "Name of the record set") flag.Parse() trimmedFhirURL := strings.TrimRight(*fhirURL, "/") recordSet := &ptm_models.RecordSet{Name: *recordSetName} recordSet.ResourceType = "Patient" recordSet.Parameters = generateRecordSetParameters(trimmedFhirURL, *recordSetName) recordSetURL := trimmedFhirURL + "/RecordSet" rsj, err := json.Marshal(recordSet) if err != nil { return } body := bytes.NewReader(rsj) resp, err := http.Post(recordSetURL, "application/json", body) if err != nil { fmt.Printf("Couldn't upload the resource: %s\n", err.Error()) return } decoder := json.NewDecoder(resp.Body) decoder.Decode(recordSet) fuzzers := []PatientFuzzer{AbbreviateFirstName, TransposeBirthDayMonth, ShuffleLastName} tagCoding := models.Coding{System: tagURL, Code: tagValue(*recordSetName)} meta := &models.Meta{Tag: []models.Coding{tagCoding}} patientURL := trimmedFhirURL + "/Patient" var matches []Match for i := 0; i < 300; i++ { patient := ptgen.GenerateDemographics() patient.Meta = meta source, err := PostAndGetLocation(patient, patientURL) if err != nil { return } fuzzer := fuzzers[rand.Intn(3)] copy := CopyPatient(&patient) fuzzer(copy) target, err := PostAndGetLocation(copy, patientURL) if err != nil { return } matches = append(matches, Match{source, target}) } bundle := &models.Bundle{} bundle.Type = "document" bundle.Id = bson.NewObjectId().Hex() comp := models.Composition{} comp.Date = &models.FHIRDateTime{Time: time.Now(), Precision: models.Timestamp} comp.Type = &models.CodeableConcept{Coding: []models.Coding{models.Coding{System: "http://loinc.org", Code: "11503-0"}}} comp.Title = "Answer Key for " + *recordSetName comp.Status = "final" comp.Subject = &models.Reference{Reference: fmt.Sprintf("%s/RecordSet/%s", trimmedFhirURL, recordSet.ID.Hex())} compEntry := models.BundleEntryComponent{} compEntry.Resource = &comp bundle.Entry = append(bundle.Entry, compEntry) for _, match := range matches { entry := models.BundleEntryComponent{} entry.FullUrl = match.Source linkType := models.BundleLinkComponent{Relation: "type", Url: "http://hl7.org/fhir/Patient"} linkRelated := models.BundleLinkComponent{Relation: "related", Url: match.Target} entry.Link = []models.BundleLinkComponent{linkType, linkRelated} score := 1.0 entry.Search = &models.BundleEntrySearchComponent{Score: &score} bundle.Entry = append(bundle.Entry, entry) } PostAnswerKey(bundle, recordSet.ID.Hex(), trimmedFhirURL+"/AnswerKey") }