Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Java-Demo/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target/*
*.key
*.key
run.bat
2 changes: 1 addition & 1 deletion Java-Demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Edit your `.key` file to include only the key, nothing else.
### Optional
To create a deployable Java program, create a `libs` folder and run:
`mvn dependency:copy-dependencies -DoutputDirectory=libs`
That will put all the dependencies into the libs folder. Then you can run it with something like:
That will put all the dependencies into the libs folder.
```
mvn compile package
java -cp "target\moh-erx-java-1.0.0.jar;./libs/*" demo.PharmaNetClaim PNET-39999999
Expand Down
24 changes: 23 additions & 1 deletion Java-Demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,33 @@
<configuration>
<archive>
<manifest>
<mainClass>gerry.PharmaNetClaim</mainClass>
<mainClass>demo.PharmaNetClaim</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>demo.PharmaNetClaim</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
27 changes: 13 additions & 14 deletions Java-Demo/src/main/java/demo/PharmaNetClaim.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
public class PharmaNetClaim {

public static void main(String[] args) throws Exception {
boolean debug = false;
String KeycloakUrl = "https://common-logon-test.hlth.gov.bc.ca/auth/realms/moh_applications/protocol/openid-connect/token";
String PharmaNetUrl = "https://pnet-vs1.api.gov.bc.ca/api/v1/Claim"; // different HL7 message types use

if (args.length < 1) {
System.out.println("Usage: java PharmaNetClaim <ClientId>");
System.exit(1);
}

String ClientId = args[0];
String KeycloakUrl = "https://common-logon-test.hlth.gov.bc.ca/auth/realms/moh_applications/protocol/openid-connect/token";
String PharmaNetUrl = "https://pnet-vs1.api.gov.bc.ca/api/v1/Claim"; // different HL7 message types use
String keycloak = "https://common-logon-test.hlth.gov.bc.ca/auth/realms/moh_applications/protocol/openid-connect/token";
// different endpoints
String Scope = "openid system/Claim.write system/Claim.read"; // different HL7 message types require different
String quick = JwtService.quick(ClientId, keycloak);
String quick = JwtService.quick(ClientId, KeycloakUrl);

String tokenRequestBody = "grant_type=client_credentials"
+ "&client_id=" + URLEncoder.encode(ClientId, StandardCharsets.UTF_8)
Expand Down Expand Up @@ -58,10 +57,11 @@ public static void main(String[] args) throws Exception {
System.out.println(tokenResponse.body());
System.exit(1);
}
// System.out.print("Keycloak access Token: " + accessToken);
if (debug)
System.out.println("Keycloak access Token: " + accessToken);

// not a valid HL7 message, but used for testing the FHIR envelope and PharmaNet response
String hl7 = "MSH|^~&|DESKTOP|PNET-39999999|PNP|PP||GERRYWASHERE,,WL*E5R:SS0AR|ZPN|631708|P|2.1||\n"
// not a valid HL7 message
String hl7 = "MSH|^~&|DESKTOP|" + ClientId + "|PNP|PP||GERRYWASHERE,,WL*E5R:SS0AR|ZPN|631708|P|2.1||\n"
+ "ZCA|000001|03|00|AR|04\n"
+ "ZCB|BC00000000|260806|631708\n"
+ "ZZZ|TDR||631708|P1|07963|||";
Expand Down Expand Up @@ -99,16 +99,15 @@ public static void main(String[] args) throws Exception {
.build();

HttpResponse<String> claimResponse = client.send(claimRequest, HttpResponse.BodyHandlers.ofString());

JsonNode responseJson = objectMapper.readTree(claimResponse.body());
String responseData = responseJson.path("content").path(0).path("attachment").path("data").asText();

if (responseData.isEmpty()) {
System.out.println("Unexpected response from PharmaNet, no data payload received");
System.out.println(claimResponse.body());
System.exit(1);
System.out.println("HL7v2 Authorization Failed, transaction ignored.");
return;
}

if (debug)
System.out.println(claimResponse.body());
String hl7Response = new String(Base64.getDecoder().decode(responseData), "UTF-8");
System.out.println(hl7Response.replace("\r", "\n"));
}
Expand Down