Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* (C) Copyright IBM Corp. 2020, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/
package io.github.linuxforhealth.hl7.data;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.commons.text.StringTokenizer;
import org.hl7.fhir.r4.model.Enumerations;
import org.hl7.fhir.r4.model.Immunization;
import org.hl7.fhir.r4.model.codesystems.EncounterStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.jayway.jsonpath.JsonPath;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.Segment;
import ca.uhn.hl7v2.model.Type;
import io.github.linuxforhealth.api.ResourceValue;
import io.github.linuxforhealth.core.ObjectMapperUtil;
import io.github.linuxforhealth.hl7.data.date.DateUtil;
public class Hl7RelatedGeneralUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(Hl7RelatedGeneralUtils.class);
private Hl7RelatedGeneralUtils() {
}
// IMPORTANT NOTES about Extracting the low and high number. Description of these numbers is:
// "When the observation quantifies the amount of a toxic substance, then the upper limit of the range identifies the toxic limit.
// If the observation quantifies a drug, the lower limits identify the lower therapeutic bounds and the upper limits represent
// the upper therapeutic bounds above which toxic side effects are common.
// We don't know if it's a toxic substance or a drug, but we understand that:
// 1. Two numbers means we have lower and upper limits.
// 2. One number means only the upper limit.
// NOTE: the current implementation does not pay attention to >, <, -, or other notation. Just a first (and second) decimal number.
// Thus ">0.50" "<0.50" and "-0.50" are all treated the same and a high number is found.
// Thus "0.50-2.50" "0.50 2.50" "<0.50 < 2.50" and ">0.50 > 2.50" are all the same, the first is low, the second is high.
// This may need to be changed in the future if we find actual data is different.
// This regex extracts 2 sets of numbers (including decimal points) from a string.
// For example, from the string "1.1 mL - 1.5 mL" the first group is 1.1, and the second group is 1.5
// This regex has any number of non-numeric (non greedy), a number, characters, a number, optional additional characters.
// ^ beginning of line
// \D*? any number of non-numeric characters (non greedy)
// ([\\d.]+) capture as first group a set of digits and period (at least one digit required)
// \D* any number of non-numeric characters
// ([\\d.]+) capture as second group a set of digits and period (will be empty if not found)
// .* any number of characters
private static final String REGEX_FIRST_TWO_NUMBERS_AMID_OTHER_TEXT = "^\\D*?([\\d.]+)\\D*([\\d.]*).*";
// Compile this into a pattern for reuse
private static final Pattern PATTERN_FIRST_TWO_NUMBERS_AMID_OTHER_TEXT = Pattern
.compile(REGEX_FIRST_TWO_NUMBERS_AMID_OTHER_TEXT);
// Uses JsonPath to extract the value from an object.
public static Object extractAttribute(Object resource, String path, String klass) {
if (resource == null) {
return null;
}
Object data = resource;
if (resource instanceof ResourceValue) {
ResourceValue rv = (ResourceValue) resource;
data = rv.getResource();
}
try {
String json = ObjectMapperUtil.getJSONInstance().writeValueAsString(data);
List> val = JsonPath.parse(json).read(path, List.class);
ValueExtractor