Skip to content

Commit

Permalink
Merge pull request #393 from onc-healthit/LANTERN-580-IntegraConnectW…
Browse files Browse the repository at this point in the history
…ebscraper

LANTERN-580: Updated the Integra Connect URL webscraper
  • Loading branch information
vishnu-mettles authored Sep 10, 2024
2 parents 30223d5 + 2de4b02 commit f9fb586
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ var medinfoengineeringURL = "https://docs.webchartnow.com/resources/system-speci
var relimedsolutionsURL = "https://help.relimedsolutions.com/fhir/fhir-service-urls.csv"
var eclinicalworksURL = "https://fhir.eclinicalworks.com/ecwopendev"

// No endpoint listed
// var integraconnectURL = "https://www.integraconnect.com/certifications/"
var integraconnectURL = "https://portal.minerva.integracloud.com/minerva/fhir/r4/us-core/bundle"
var streamlinemdURL = "https://patientportal.streamlinemd.com/FHIRReg/Practice%20Service%20based%20URL%20List.csv"
var bridgepatientportalURL = "https://bridgepatientportal.docs.apiary.io/#/introduction/fhir-bridge-patient-portal/fhir-endpoints"
var medicalmineURL = "https://www.charmhealth.com/resources/fhir/index.html#api-endpoints"
Expand Down Expand Up @@ -261,8 +260,8 @@ func QueryCHPLEndpointList(chplURL string, fileToWriteTo string) {
CSVParser(chplURL, fileToWriteTo, "./fhir_service_urls.csv", 1, 3, true, 1, -1)
} else if URLsEqual(chplURL, eclinicalworksURL) {
eClinicalWorksBundleParser("https://fhir.eclinicalworks.com/ecwopendev/external/practiceList", fileToWriteTo)
// } else if URLsEqual(chplURL, integraconnectURL) {
// IntegraConnectWebscraper(chplURL, fileToWriteTo)
} else if URLsEqual(chplURL, integraconnectURL) {
IntegraConnectWebscraper(chplURL, fileToWriteTo)
} else if URLsEqual(chplURL, streamlinemdURL) {
StreamlineMDCSVParser(chplURL, fileToWriteTo)
} else if URLsEqual(chplURL, bridgepatientportalURL) {
Expand Down
60 changes: 34 additions & 26 deletions endpointmanager/pkg/chplendpointquerier/integraconnectwebscraper.go
Original file line number Diff line number Diff line change
@@ -1,49 +1,57 @@
package chplendpointquerier

import (
"encoding/json"
"strings"

"github.com/PuerkitoBio/goquery"
"github.com/onc-healthit/lantern-back-end/endpointmanager/pkg/helpers"
log "github.com/sirupsen/logrus"
)

func IntegraConnectWebscraper(CHPLURL string, fileToWriteTo string) {

var lanternEntryList []LanternEntry
var endpointEntryList EndpointList

doc, err := helpers.ChromedpQueryEndpointList(CHPLURL, "")
respBody, err := helpers.QueryEndpointList(CHPLURL)
if err != nil {
log.Fatal(err)
}

doc.Find("table").Each(func(index int, tablehtml *goquery.Selection) {
tablehtml.Find("tbody").Each(func(indextr int, rowhtml *goquery.Selection) {
rowhtml.Find("tr").Each(func(indextr int, rowbodyhtml *goquery.Selection) {
var entry LanternEntry
tableEntries := rowbodyhtml.Find("td")
if tableEntries.Length() > 0 {
organizationName := strings.TrimSpace(tableEntries.Eq(0).Text())

aElemURL := tableEntries.Eq(1).Find("a")
hrefText, exists := aElemURL.Eq(0).Attr("href")
if exists {
URL := strings.TrimSpace(hrefText)
entry.URL = URL
entry.OrganizationName = organizationName
lanternEntryList = append(lanternEntryList, entry)
}
}
})
})
})

endpointEntryList.Endpoints = lanternEntryList
var data map[string]interface{}
err = json.Unmarshal([]byte(respBody), &data)
if err != nil {
log.Println("Error unmarshaling JSON:", err)
return
}

entries := data["entry"].([]interface{})

var filteredEntries []map[string]interface{}

// Filter the entries based on the resourceType set to Organization or Endpoint
for _, entry := range entries {
resource := entry.(map[string]interface{})["resource"].(map[string]interface{})
if strings.EqualFold(strings.TrimSpace(resource["resourceType"].(string)), "Organization") ||
strings.EqualFold(strings.TrimSpace(resource["resourceType"].(string)), "Endpoint") {
filteredEntries = append(filteredEntries, entry.(map[string]interface{}))
}
}

// Update the data with the filtered entries
data["entry"] = filteredEntries

// Marshal the data into json file
newJsonData, err := json.MarshalIndent(data, "", " ")
if err != nil {
log.Println("Error marshaling JSON:", err)
return
}

// convert bundle data to lantern format
endpointEntryList.Endpoints = BundleToLanternFormat(newJsonData)

err = WriteCHPLFile(endpointEntryList, fileToWriteTo)
if err != nil {
log.Fatal(err)
}

}
2 changes: 1 addition & 1 deletion resources/dev_resources/CHPLEndpointResourcesList.json
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@
},
{
"FormatType": "Lantern",
"URL": "https://www.integraconnect.com/certifications/",
"URL": "https://portal.minerva.integracloud.com/minerva/fhir/r4/us-core/bundle",
"EndpointName": "Integra Connect Newco, LLC",
"FileName": "Integra_Connect_Newco_LLC_EndpointSources.json"
},
Expand Down
2 changes: 1 addition & 1 deletion resources/prod_resources/CHPLEndpointResourcesList.json
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@
},
{
"FormatType": "Lantern",
"URL": "https://www.integraconnect.com/certifications/",
"URL": "https://portal.minerva.integracloud.com/minerva/fhir/r4/us-core/bundle",
"EndpointName": "Integra Connect Newco, LLC",
"FileName": "Integra_Connect_Newco_LLC_EndpointSources.json"
},
Expand Down

0 comments on commit f9fb586

Please sign in to comment.