Created
September 25, 2021 01:36
-
-
Save swhume/c40e626ae35472b0c70e884155e880ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
USERNAME = "username" | |
PWD = "password" | |
URL = "http://68.183.158.128:5000/odm" | |
codelist = { | |
"_use": "collection", | |
"OID": "CL.Test.02", | |
"Name": "Test CodeList", | |
"DataType": "text", | |
"Description": [ | |
{"TranslatedText": {"xml_lang": "en", "_content": "This is a test CodeList"}} | |
], | |
"EnumeratedItem": [ | |
{ | |
"CodedValue": "ENDOMETRIUM", | |
"OrderNumber": 1, | |
"Alias": [{"Context": "nciodm_ExtCodeID", "Name": "C12313"}] | |
}, | |
{ | |
"CodedValue": "EPICARDIUM", | |
"OrderNumber": 2, | |
"Alias": [{"Context": "nciodm_ExtCodeID", "Name": "C13164"}] | |
} | |
], | |
"Alias": [ | |
{"Context": "nciodm_ExtCodeID", "Name": "C74456"}, | |
{"Context": "Abbreviation", "Name": "CL"} | |
] | |
} | |
r = requests.post(URL + "/codelist", data=json.dumps(codelist), headers={"Content-Type": "application/json"}, auth=(USERNAME, PWD)) | |
object_id = "" | |
if r.status_code == 201: | |
object_id = json.loads(r.text).get("_id") | |
print(f"codelist successfully inserted with _id {object_id}") | |
else: | |
print(f"Error loading codelist: {r.status_code}.") | |
print(r.text) | |
exit(0) | |
r = requests.get(URL + "/codelist/" + object_id, auth=(USERNAME, PWD)) | |
if r.status_code == 200: | |
print(r.text) | |
else: | |
print(f"unexpected return code getting codelist: {r.status_code}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment