Skip to content

Commit

Permalink
refactor: refactor organization mediator to sync data with openIMIS A…
Browse files Browse the repository at this point in the history
…B#18688
  • Loading branch information
Idiono-mfon committed Nov 15, 2023
1 parent 0b581d3 commit dd54685
Showing 1 changed file with 43 additions and 20 deletions.
63 changes: 43 additions & 20 deletions mediators/organisation_mediator/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,36 @@
import http.client
import base64

# Add this temprarily for testing purposes
# Will be taken out upon configuration of SSL certificate
from urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
from helpers.helpers import requests, initAuth, getPortPart, getPaginatedRecords, initAuth


@api_view(['GET', 'POST'])
@api_view(['GET', 'POST', 'PUT'])
def getOrganisation(request):

print("======Executing getOrganisation======")

result = configview()
configurations = result.__dict__
# username:password-openhimclient:openhimclientPasskey
authvars = configurations["data"]["openimis_user"] + \
":"+configurations["data"]["openimis_passkey"]
# Standard Base64 Encoding
encodedBytes = base64.b64encode(authvars.encode("utf-8"))
encodedStr = str(encodedBytes, "utf-8")
auth_openimis = "Basic " + encodedStr

url = configurations["data"]["openimis_url"]+getPortPart(
configurations["data"]["openimis_port"])+"/api/api_fhir_r4/Organization"
# result = configview()
# configurations = result.__dict__
# # username:password-openhimclient:openhimclientPasskey
# authvars = configurations["data"]["openimis_user"] + \
# ":"+configurations["data"]["openimis_passkey"]
# # Standard Base64 Encoding
# encodedBytes = base64.b64encode(authvars.encode("utf-8"))
# encodedStr = str(encodedBytes, "utf-8")
# auth_openimis = "Basic " + encodedStr

auth_data = initAuth()

url = auth_data['config']["data"]["openimis_url"]+getPortPart(
auth_data['config']["data"]["openimis_port"])+"/api/api_fhir_r4/Organization"

# Query the upstream server via openHIM mediator port 8000
# Caution: To secure the endpoint with SSL certificate,FQDN is required
if request.method == 'GET':
querystring = {"": ""}
payload = ""
headers = {'Authorization': auth_openimis}
headers = {'Authorization': auth_data["auth"]}

print(f'Organization headers {headers}')
response = requests.request(
Expand All @@ -78,16 +77,40 @@ def getOrganisation(request):
return Response(datac)

elif request.method == 'POST':
url = url + "/"

print("Create Organization resource")

querystring = {"": ""}
data = json.dumps(request.data)
payload = data
headers = {
'Content-Type': "application/json",
'Authorization': auth_data['auth']
}
response = requests.request(
"POST", url, data=payload, headers=headers, params=querystring, verify=False)
datac = json.loads(response.text)

return Response(datac)


elif request.method == 'PUT':
url = url + "/"

print("Update Organization resource")

querystring = {"": ""}
data = json.dumps(request.data)
payload = data
headers = {
'Content-Type': "application/json",
'Authorization': auth_openimis
'Authorization': auth_data['auth']
}
response = requests.request(
"POST", url, data=payload, headers=headers, params=querystring)
"PUT", url, data=payload, headers=headers, params=querystring, verify=False)
datac = json.loads(response.text)

return Response(datac)

# if request.method == 'GET':
Expand Down

0 comments on commit dd54685

Please sign in to comment.