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 1 commit 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
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(".");
}
}
}
Loading