Skip to content

Commit

Permalink
Remove a hack used to retrieve schematized data from HL7v2 messages, … (
Browse files Browse the repository at this point in the history
apache#11969)

* Remove a hack used to retrieve schematized data from HL7v2 messages, now that the schamatized parser is available publicly. Also removed a few methods that are not used anywhere.

* Upgrade the healthcare client library, fix code format.

* Added back the `toModel` method which is used by `Hl7v2IOTestUtil`.
  • Loading branch information
lastomato committed Jun 12, 2020
1 parent 2c60ce2 commit b0d8f3b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ class BeamModulePlugin implements Plugin<Project> {
google_api_services_clouddebugger : "com.google.apis:google-api-services-clouddebugger:v2-rev20200313-$google_clients_version",
google_api_services_cloudresourcemanager : "com.google.apis:google-api-services-cloudresourcemanager:v1-rev20200311-$google_clients_version",
google_api_services_dataflow : "com.google.apis:google-api-services-dataflow:v1b3-rev20200305-$google_clients_version",
google_api_services_healthcare : "com.google.apis:google-api-services-healthcare:v1beta1-rev20200307-$google_clients_version",
google_api_services_healthcare : "com.google.apis:google-api-services-healthcare:v1beta1-rev20200525-$google_clients_version",
google_api_services_pubsub : "com.google.apis:google-api-services-pubsub:v1-rev20200312-$google_clients_version",
google_api_services_storage : "com.google.apis:google-api-services-storage:v1-rev20200226-$google_clients_version",
google_auth_library_credentials : "com.google.auth:google-auth-library-credentials:$google_auth_version",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.api.services.healthcare.v1beta1.model.Message;
import com.google.api.services.healthcare.v1beta1.model.SchematizedData;
import java.io.IOException;
import java.util.Map;
import javax.annotation.Nullable;

/** The type HL7v2 message to wrap the {@link Message} model. */
public class HL7v2Message {
private static final String schematizedDataKey = "schematizedData";
private static final String schematizedDataPrefix = "{data=";
private final String name;
private final String messageType;
private final String sendTime;
Expand All @@ -36,26 +35,6 @@ public class HL7v2Message {
private String schematizedData;
private final Map<String, String> labels;

private static String extractDataJson(String schematizedData) {
String jsonData;
final ObjectMapper mapper = new ObjectMapper();
if (schematizedData != null
&& schematizedData.startsWith(schematizedDataPrefix)
&& schematizedData.endsWith("}}")) {
jsonData =
schematizedData.substring(schematizedDataPrefix.length(), schematizedData.length() - 1);
} else {
jsonData = schematizedData;
}
try {
mapper.readTree(jsonData);
return jsonData;
} catch (IOException e) {
throw new IllegalArgumentException(
String.format("Could not validate inner schematizedData JSON: %s", e.getMessage()));
}
}

@Override
public String toString() {
ObjectMapper mapper = new ObjectMapper();
Expand All @@ -73,41 +52,18 @@ public String toString() {
* @return the hl7v2 message
*/
public static HL7v2Message fromModel(Message msg) {
final String schematizedData;
if (msg.get(schematizedDataKey) != null) {
schematizedData = extractDataJson(msg.get(schematizedDataKey).toString());
} else {
schematizedData = null;
}
SchematizedData schematizedData = msg.getSchematizedData();
return new HL7v2Message(
msg.getName(),
msg.getMessageType(),
msg.getSendTime(),
msg.getCreateTime(),
msg.getData(),
msg.getSendFacility(),
schematizedData,
schematizedData != null ? schematizedData.getData() : null,
msg.getLabels());
}

public static HL7v2Message fromMap(Map msg) {
final String schematizedData;
if (msg.get(schematizedDataKey) != null) {
schematizedData = extractDataJson(msg.get(schematizedDataKey).toString());
} else {
schematizedData = null;
}

return new HL7v2Message(
msg.get("name").toString(),
msg.get("messageType").toString(),
null,
msg.get("createTime").toString(),
msg.get("data").toString(),
msg.get("sendFacility").toString(),
schematizedData,
null);
}
/**
* To model message.
*
Expand All @@ -121,7 +77,7 @@ public Message toModel() {
out.setCreateTime(this.getCreateTime());
out.setData(this.getData());
out.setSendFacility(this.getSendFacility());
out.set(schematizedDataKey, this.getSchematizedData());
out.setSchematizedData(new SchematizedData().setData(this.schematizedData));
out.setLabels(this.labels);
return out;
}
Expand Down

0 comments on commit b0d8f3b

Please sign in to comment.