Skip to content

Added support for resource Id with type UUID and OID #527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions src/main/java/io/github/linuxforhealth/hl7/data/DataEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.github.linuxforhealth.hl7.data;

public class DataEnum {
public enum ResourceIdType {
UUID, OID
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.commons.text.StringTokenizer;
Expand Down Expand Up @@ -172,6 +173,25 @@ public static String generateResourceId() {
return nano.toString() + "." + UUID.randomUUID().toString();
}

/**
* Generates a resource id when provide type.
* Format can be urn:uuid:<random-uuid>, urn:oid:<random-int> default is <current nano second>.<random-uuid>
*/
public static String generateResourceId(String type) {
if(type == null || type.isEmpty()) {
return generateResourceId();
}
DataEnum.ResourceIdType resourceIdType = DataEnum.ResourceIdType.valueOf(type);
switch (resourceIdType) {
case UUID:
return "urn:uuid:" + UUID.randomUUID();
case OID:
return "urn:oid:" + (int)(Math.random() * 1000000);
default:
return generateResourceId();
}
}

// Special extractor only for use with PV1 records.
// Extract the admit and discharge time and calculate duration length.
// Returns null if for any reason the data is not usable, which
Expand Down Expand Up @@ -463,6 +483,31 @@ public static String getNarrativeDiv(String text) {
return String.format(divText, StringEscapeUtils.escapeHtml4(text).replace("~", "<br />"));
}

public static Integer getDurationInMinutes(Integer duration, String unit) {
if (duration == null) {
return null;
}

if (unit == null) {
return duration / 60; // Convert seconds to minutes
}

switch (unit.toLowerCase().trim()) {
case "":
case "s":
case "sec":
return duration / 60; // Convert seconds to minutes
case "h":
case "hr":
return duration * 60; // Convert hours to minutes
case "d":
case "day":
return duration * 24 * 60; // Convert days to minutes
default:
return duration; // Assume already in minutes
}
}

// Private method to split and format the 7 digit local telecom number
private static String formatLocalNumber(String localNumber) {
// Split after the 3rd digit, add a space, add the rest of the number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public enum SimpleDataTypeMapper {
DIAGNOSTIC_REPORT_STATUS(SimpleDataValueResolver.DIAGNOSTIC_REPORT_STATUS_CODES),
ARRAY(SimpleDataValueResolver.ARRAY),
OBSERVATION_STATUS(SimpleDataValueResolver.OBSERVATION_STATUS_CODE_FHIR),
SERVICE_REQUEST_STATUS(SimpleDataValueResolver.SERVICE_REQUEST_STATUS),
APPOINTMENT_STATUS_CODE_FHIR(SimpleDataValueResolver.APPOINTMENT_STATUS_CODE_FHIR),
SERVICE_REQUEST_STATUS(SimpleDataValueResolver.SERVICE_REQUEST_STATUS),
RELATIVE_REFERENCE(SimpleDataValueResolver.RELATIVE_REFERENCE),
MESSAGE_REASON_ENCOUNTER(SimpleDataValueResolver.MESSAGE_REASON_ENCOUNTER),
SPECIMEN_STATUS(SimpleDataValueResolver.SPECIMEN_STATUS_CODE_FHIR),
Expand Down Expand Up @@ -78,7 +79,8 @@ public enum SimpleDataTypeMapper {
CLEAN_SSN(SimpleDataValueResolver.CLEAN_SSN),
ENCOUNTER_MODE_ARRIVAL_DISPLAY(SimpleDataValueResolver.ENCOUNTER_MODE_ARRIVAL_DISPLAY),
CONTACT_POINT_SYSTEM(SimpleDataValueResolver.CONTACT_POINT_SYSTEM),
CONTACT_POINT_USE(SimpleDataValueResolver.CONTACT_POINT_USE);
CONTACT_POINT_USE(SimpleDataValueResolver.CONTACT_POINT_USE),
ALLERGY_INTOLERANCE_SEVERITY(SimpleDataValueResolver.ALLERGY_INTOLERANCE_SEVERITY_CODE_FHIR);

private ValueExtractor<Object, ?> valueResolver;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.commons.lang3.math.NumberUtils;
import org.hl7.fhir.dstu3.model.codesystems.MedicationRequestCategory;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.model.AllergyIntolerance;
import org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCategory;
import org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticality;
import org.hl7.fhir.r4.model.DiagnosticReport.DiagnosticReportStatus;
Expand All @@ -44,6 +45,7 @@
import org.hl7.fhir.r4.model.ServiceRequest.ServiceRequestStatus;
import org.hl7.fhir.r4.model.Specimen.SpecimenStatus;

import org.hl7.fhir.r4.model.codesystems.Appointmentstatus;
import org.hl7.fhir.r4.model.codesystems.V3ActCode;
import org.hl7.fhir.r4.model.codesystems.V3MaritalStatus;
import org.hl7.fhir.r4.model.codesystems.ConditionCategory;
Expand Down Expand Up @@ -209,6 +211,12 @@ public class SimpleDataValueResolver {
return getFHIRCode(val, ObservationStatus.class);
};


public static final ValueExtractor<Object, String> APPOINTMENT_STATUS_CODE_FHIR = (Object value) -> {
String val = Hl7DataHandlerUtil.getStringValue(value);
return getFHIRCode(val, Appointmentstatus.class);
};

// Handlers for searching Immunization.education siblings.
public static final ValueExtractor<Object, String> FIND_EDUCATION_REFERENCE_TEXT = (Object value) -> {
return getSelectedSiblingObservationTEXTfromObxGroup(value, "30956-7");
Expand Down Expand Up @@ -942,4 +950,9 @@ public static String getFHIRCode(String hl7Value, String fhirMappingConceptName)
}
return null;
};

public static final ValueExtractor<Object, String> ALLERGY_INTOLERANCE_SEVERITY_CODE_FHIR = (Object value) -> {
String val = Hl7DataHandlerUtil.getStringValue(value);
return getFHIRCode(val, AllergyIntolerance.AllergyIntoleranceSeverity.class);
};
}
19 changes: 18 additions & 1 deletion src/main/resources/hl7/codesystem/v2ToFhirMapping.yml
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,21 @@ ContactPointUse:
VHN: home
NET: home
WPN: work
PRS: mobile
PRS: mobile
Appointmentstatus:
PROPOSED: proposed
PENDING: pending
WAITLIST: waitlist
BOOKED: booked
STARTED: checked-in
COMPLETE: fulfilled
CANCELLED: cancelled
DC: cancelled
DISCONTINUED: cancelled
DELETED: entered-in-error
OVERBOOK: booked
NOSHOW: noshow
AllergyIntoleranceSeverity:
MI: mild
MO: moderate
SV: severe
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.google.common.collect.Lists;

import org.hl7.fhir.r4.model.codesystems.EncounterStatus;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -424,4 +428,18 @@ void get_datetime_value_null() {
assertThat(Hl7RelatedGeneralUtils.dateTimeWithZoneId(null,null)).isNull();
}

@ParameterizedTest
@ValueSource(strings = { "UUID", "OID", ""})
void getResourceIdWithType(String type) {
String resourceId = Hl7RelatedGeneralUtils.generateResourceId(type);
System.out.println("ResourceId: " + resourceId);
assertThat(resourceId).isNotNull();
if(type.equals("UUID")) {
assertThat(resourceId).startsWith("urn:uuid:");
} else if (type.equals("OID")) {
assertThat(resourceId).startsWith("urn:oid:");
} else {
assertThat(resourceId).contains(".");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,25 @@ void testContactPointUse(String hl7Code) throws DataTypeException {
break;
}
}

@ParameterizedTest
@ValueSource(strings = { "MI", "MO", "SV"})
void testAllergyIntoleranceSeverity(String hl7Code) {
String severity = SimpleDataValueResolver.ALLERGY_INTOLERANCE_SEVERITY_CODE_FHIR.apply(hl7Code);
switch (hl7Code) {
case "MI":
assertThat(severity).isEqualTo("mild");
break;
case "MO":
assertThat(severity).isEqualTo("moderate");
break;
case "SV":
assertThat(severity).isEqualTo("severe");
break;
default:
assertThat(severity).isNull();
break;
}

}
}
Loading