Skip to content

Instantly share code, notes, and snippets.

@davidoevans
davidoevans / HealthChainSocketIO.cs
Last active April 23, 2019 16:50
Subscribing to HealthChain Events
// Establish a socket.io Connection with the PharmacyApplication
var options = new IO.Options();
options.Query = new Dictionary<string, string>();
options.Query.Add("token", "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0aWNpcGFudF90eXBlX2lkIjoxMDIsInByb3ZpZGVyX2tleSI6IjkxZGQ4MzYwLTE5Y2MtNGIyOC1hMDdjLWI5MWNkMGU0ZGVmOCIsInByb3ZpZGVyX25hbWUiOiJvcmcuaGVhbHRoY2hhaW4uUGhhcm1hY3lMb2NhdGlvbkFwcGxpY2F0aW9uIiwiYXBwX25hbWUiOiJEYXZpZCdzIFBoYXJtYWN5IEFwcCIsImFwcF9pZCI6IjkxZGQ4MzYwLTE5Y2MtNGIyOC1hMDdjLWI5MWNkMGU0ZGVmOCIsImFwcF91cmkiOiJvcmcuaGVhbHRoY2hhaW4uUGhhcm1hY3lMb2NhdGlvbkFwcGxpY2F0aW9uIzkxZGQ4MzYwLTE5Y2MtNGIyOC1hMDdjLWI5MWNkMGU0ZGVmOCIsInBhcnRpY2lwYW50VHlwZUlkcyI6WyIxMDIiXSwicGhhcm1hY3lfbG9jYXRpb25fdXJpIjoib3JnLmhlYWx0aGNoYWluLlBoYXJtYWN5TG9jYXRpb24jNDBkNTU1YmMtMDUzOC00ZmNiLWFmNTItNTQ3YTFmOWE1M2JlIiwiaXNzdWVkIjoxNTU1NTk5NTI3MjUwLCJpYXQiOjE1NTU1OTk1Mjd9.WHDoIrZVzR0k6QpL9Hx2fRo4oOpa8VyMUaNlfufsRAxEERzH0rtN5JHbj2fA8_ImUQhMh6uCcp1lt72_quU3UP7rH8bGhgY2VSrJ6ok8uLRHSLH8oXE3h8VVr3-TT_PgurMEi1khGF80tvFhx5VWqI6EkA8eM9X1rub1qx
@davidoevans
davidoevans / RenewalRequest.cs
Created April 22, 2019 19:38
Request a Renewal
// Requesting a renewal based on the id of an existing medication request
MedicationRequest medicationRequest = this.pharmacyLocationClient.getMedicationRequestsApi().renewMedicationRequest(existingMedicationRequest.id);
@davidoevans
davidoevans / IncludeResources.cs
Created April 22, 2019 19:34
Include (or resolve) Resource URI's
// Provide a comma separated list to the `_include` query param to have URI references resolved
IDictionary<string, string> queryParams = new Dictionary<string, string>();
queryParams.Add("_include", "prescriber,onBehalfOf,recorder,medication");
MedicationRequest resolvedMedicationRequest = this.clinicLocationClient.getMedicationRequestsApi().getMedicationRequest(medicationRequest.getId(), queryParams);
@davidoevans
davidoevans / QueryMedicationRequestsAssigned.cs
Created April 22, 2019 19:30
MedicationRequests assigned but not acknowledged
// Query for MedicationRequests assigned to current pharmacy, but not yet acknowledged
IDictionary<string, string> queryParams = new Dictionary<string, string>();
queryParams.Add("status", "active");
queryParams.Add("acknowledged", "false");
queryParams.Add("assignedPharmacy", this.testPharmacyLocation.id);
List<MedicationRequest> medicationRequestsNotAcknowledged = this.pharmacyLocationClient.getMedicationRequestsApi().searchMedicationRequests(queryParams);
@davidoevans
davidoevans / ActAsPharmacyLocation.cs
Created April 22, 2019 19:26
Act as a PharmacyLocation
// Act as the pharmacy location based on their OCP assigned accredication number.
Identifier identifier = new Identifier()
identifier.assigner = "ca-on-pharmacy-id-ocp";
identifier.value = "9999";
pharmacyLocationClient.actAs(Persona.PHARMACY_LOCATION, identifier);
// Act as a Dispenser based on unique identifier
pharmacyLocationClient.actAs(Persona.DISPENSER, identifier);
@davidoevans
davidoevans / IssueIdentity.cs
Created April 22, 2019 19:20
Issue a Dispenser
// Create an Identifier
Identifier identifier = new Identifier()
identifier.assigner = "internal";
identifier.value = "123";
// Issue identity for the dispenser that is bound to the current application
pharmacyLocationClient.issueIdentity(Persona.DISPENSER, identifier);
@davidoevans
davidoevans / PortageClient.cs
Created April 22, 2019 19:17
Create a PortageClient
// Load PKCS12 cer/key bundle from store
byte[] pharmacyCertificate = ReadFile("my-test-pharmacy-cert.pfx");
// Create a PortageClient instance on the https://testnet.healthchain.ca environment
PortageClient pharmacyLocationClient = new PortageClient("testnet");
// Configure the PortageClient with the application credentials
pharmacyLocationClient.setApplication(pharmacyCertificate, "passphrase");
@davidoevans
davidoevans / create-pkcs12-bundle.sh
Last active May 22, 2019 14:52
Create a PKCS12 bundle
# Create a PKCS12 bundle that includes the cert and private key - remember the passphrase
openssl pkcs12 -export -in my-test-pharmacy-cert.pem -inkey my-test-pharmacy-key.pem -out my-test-pharmacy-cert.pfx

Keybase proof

I hereby claim:

  • I am davidoevans on github.
  • I am davidoevans (https://keybase.io/davidoevans) on keybase.
  • I have a public key ASDN-ahDwoRuMXt9t-Myz2AOR-dSqB3CLRQ8S43xMJoS9Ao

To claim this, I am signing this object: