anylist r5 support

also added another accessor
This commit is contained in:
Ken Stevens 2019-09-03 15:05:44 -04:00 committed by James Agnew
parent 490ae597d3
commit 1ca0e7bd53
5 changed files with 124 additions and 0 deletions

View File

@ -46,6 +46,11 @@
<artifactId>hapi-fhir-structures-r4</artifactId> <artifactId>hapi-fhir-structures-r4</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-r5</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>ca.uhn.hapi.fhir</groupId> <groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-hl7org-dstu2</artifactId> <artifactId>hapi-fhir-structures-hl7org-dstu2</artifactId>

View File

@ -43,6 +43,8 @@ public class AnyListResource {
return new AnyListResource(new org.hl7.fhir.dstu3.model.ListResource()); return new AnyListResource(new org.hl7.fhir.dstu3.model.ListResource());
case R4: case R4:
return new AnyListResource(new org.hl7.fhir.r4.model.ListResource()); return new AnyListResource(new org.hl7.fhir.r4.model.ListResource());
case R5:
return new AnyListResource(new org.hl7.fhir.r5.model.ListResource());
default: default:
throw new UnsupportedOperationException(version + " not supported"); throw new UnsupportedOperationException(version + " not supported");
} }
@ -63,6 +65,11 @@ public class AnyListResource {
myListResource = theListResourceR4; myListResource = theListResourceR4;
} }
public AnyListResource(org.hl7.fhir.r5.model.ListResource theListResourceR5) {
myFhirVersion = FhirVersionEnum.R5;
myListResource = theListResourceR5;
}
public static AnyListResource fromResource(IBaseResource theListResource) { public static AnyListResource fromResource(IBaseResource theListResource) {
if (theListResource instanceof ca.uhn.fhir.model.dstu2.resource.ListResource) { if (theListResource instanceof ca.uhn.fhir.model.dstu2.resource.ListResource) {
return new AnyListResource((ca.uhn.fhir.model.dstu2.resource.ListResource) theListResource); return new AnyListResource((ca.uhn.fhir.model.dstu2.resource.ListResource) theListResource);
@ -70,6 +77,8 @@ public class AnyListResource {
return new AnyListResource((org.hl7.fhir.dstu3.model.ListResource) theListResource); return new AnyListResource((org.hl7.fhir.dstu3.model.ListResource) theListResource);
} else if (theListResource instanceof org.hl7.fhir.r4.model.ListResource) { } else if (theListResource instanceof org.hl7.fhir.r4.model.ListResource) {
return new AnyListResource((org.hl7.fhir.r4.model.ListResource) theListResource); return new AnyListResource((org.hl7.fhir.r4.model.ListResource) theListResource);
} else if (theListResource instanceof org.hl7.fhir.r5.model.ListResource) {
return new AnyListResource((org.hl7.fhir.r5.model.ListResource) theListResource);
} else { } else {
throw new UnsupportedOperationException("Cannot convert " + theListResource.getClass().getName() + " to AnyList"); throw new UnsupportedOperationException("Cannot convert " + theListResource.getClass().getName() + " to AnyList");
} }
@ -94,6 +103,11 @@ public class AnyListResource {
return (org.hl7.fhir.r4.model.ListResource) get(); return (org.hl7.fhir.r4.model.ListResource) get();
} }
public org.hl7.fhir.r5.model.ListResource getR5() {
Validate.isTrue(myFhirVersion == FhirVersionEnum.R5);
return (org.hl7.fhir.r5.model.ListResource) get();
}
public FhirVersionEnum getFhirVersion() { public FhirVersionEnum getFhirVersion() {
return myFhirVersion; return myFhirVersion;
} }
@ -106,6 +120,9 @@ public class AnyListResource {
case R4: case R4:
getR4().getCode().addCoding().setSystem(theSystem).setCode(theCode); getR4().getCode().addCoding().setSystem(theSystem).setCode(theCode);
break; break;
case R5:
getR5().getCode().addCoding().setSystem(theSystem).setCode(theCode);
break;
default: default:
throw new UnsupportedOperationException(myFhirVersion + " not supported"); throw new UnsupportedOperationException(myFhirVersion + " not supported");
} }
@ -119,6 +136,9 @@ public class AnyListResource {
case R4: case R4:
getR4().getIdentifier().add(new org.hl7.fhir.r4.model.Identifier().setSystem(theSystem).setValue(theValue)); getR4().getIdentifier().add(new org.hl7.fhir.r4.model.Identifier().setSystem(theSystem).setValue(theValue));
break; break;
case R5:
getR5().getIdentifier().add(new org.hl7.fhir.r5.model.Identifier().setSystem(theSystem).setValue(theValue));
break;
default: default:
throw new UnsupportedOperationException(myFhirVersion + " not supported"); throw new UnsupportedOperationException(myFhirVersion + " not supported");
} }
@ -132,6 +152,9 @@ public class AnyListResource {
case R4: case R4:
getR4().addExtension().setUrl(theUrl).setValue(new org.hl7.fhir.r4.model.StringType(theValue)); getR4().addExtension().setUrl(theUrl).setValue(new org.hl7.fhir.r4.model.StringType(theValue));
break; break;
case R5:
getR5().addExtension().setUrl(theUrl).setValue(new org.hl7.fhir.r5.model.StringType(theValue));
break;
default: default:
throw new UnsupportedOperationException(myFhirVersion + " not supported"); throw new UnsupportedOperationException(myFhirVersion + " not supported");
} }
@ -143,6 +166,8 @@ public class AnyListResource {
return getStringExtensionValueOrNullDstu3(theUrl); return getStringExtensionValueOrNullDstu3(theUrl);
case R4: case R4:
return getStringExtensionValueOrNullR4(theUrl); return getStringExtensionValueOrNullR4(theUrl);
case R5:
return getStringExtensionValueOrNullR5(theUrl);
default: default:
throw new UnsupportedOperationException(myFhirVersion + " not supported"); throw new UnsupportedOperationException(myFhirVersion + " not supported");
} }
@ -166,6 +191,15 @@ public class AnyListResource {
return targetType.getValue(); return targetType.getValue();
} }
private String getStringExtensionValueOrNullR5(String theUrl) {
List<org.hl7.fhir.r5.model.Extension> targetTypes = getR5().getExtensionsByUrl(theUrl);
if (targetTypes.size() < 1) {
return null;
}
org.hl7.fhir.r5.model.StringType targetType = (org.hl7.fhir.r5.model.StringType) targetTypes.get(0).getValue();
return targetType.getValue();
}
public void addReference(IBaseReference theReference) { public void addReference(IBaseReference theReference) {
switch (myFhirVersion) { switch (myFhirVersion) {
case DSTU3: case DSTU3:
@ -174,6 +208,9 @@ public class AnyListResource {
case R4: case R4:
getR4().addEntry().setItem((org.hl7.fhir.r4.model.Reference) theReference); getR4().addEntry().setItem((org.hl7.fhir.r4.model.Reference) theReference);
break; break;
case R5:
getR5().addEntry().setItem((org.hl7.fhir.r5.model.Reference) theReference);
break;
default: default:
throw new UnsupportedOperationException(myFhirVersion + " not supported"); throw new UnsupportedOperationException(myFhirVersion + " not supported");
} }
@ -187,6 +224,9 @@ public class AnyListResource {
case R4: case R4:
getR4().addEntry().setItem(new org.hl7.fhir.r4.model.Reference(theReferenceId)); getR4().addEntry().setItem(new org.hl7.fhir.r4.model.Reference(theReferenceId));
break; break;
case R5:
getR5().addEntry().setItem(new org.hl7.fhir.r5.model.Reference(theReferenceId));
break;
default: default:
throw new UnsupportedOperationException(myFhirVersion + " not supported"); throw new UnsupportedOperationException(myFhirVersion + " not supported");
} }
@ -202,6 +242,10 @@ public class AnyListResource {
return getR4().getEntry().stream() return getR4().getEntry().stream()
.map(entry -> entry.getItem().getReference()) .map(entry -> entry.getItem().getReference())
.map(reference -> new org.hl7.fhir.r4.model.IdType(reference).toUnqualifiedVersionless().getValue()); .map(reference -> new org.hl7.fhir.r4.model.IdType(reference).toUnqualifiedVersionless().getValue());
case R5:
return getR5().getEntry().stream()
.map(entry -> entry.getItem().getReference())
.map(reference -> new org.hl7.fhir.r5.model.IdType(reference).toUnqualifiedVersionless().getValue());
default: default:
throw new UnsupportedOperationException(myFhirVersion + " not supported"); throw new UnsupportedOperationException(myFhirVersion + " not supported");
} }
@ -213,6 +257,8 @@ public class AnyListResource {
return removeItemDstu3(theReferenceId); return removeItemDstu3(theReferenceId);
case R4: case R4:
return removeItemR4(theReferenceId); return removeItemR4(theReferenceId);
case R5:
return removeItemR5(theReferenceId);
default: default:
throw new UnsupportedOperationException(myFhirVersion + " not supported"); throw new UnsupportedOperationException(myFhirVersion + " not supported");
} }
@ -250,6 +296,22 @@ public class AnyListResource {
return removed; return removed;
} }
private boolean removeItemR5(String theReferenceId) {
boolean removed = false;
for (org.hl7.fhir.r5.model.ListResource.ListEntryComponent entry : getR5().getEntry()) {
if (theReferenceId.equals(entry.getItem().getReference()) && !entry.getDeleted()) {
entry.setDeleted(true);
removed = true;
break;
}
}
if (removed) {
getR5().getEntry().removeIf(entry -> entry.getDeleted());
}
return removed;
}
public TokenParam getCodeFirstRep() { public TokenParam getCodeFirstRep() {
switch (myFhirVersion) { switch (myFhirVersion) {
case DSTU3: case DSTU3:
@ -258,17 +320,40 @@ public class AnyListResource {
case R4: case R4:
org.hl7.fhir.r4.model.Coding codingR4 = getR4().getCode().getCodingFirstRep(); org.hl7.fhir.r4.model.Coding codingR4 = getR4().getCode().getCodingFirstRep();
return new TokenParam(codingR4.getSystem(), codingR4.getCode()); return new TokenParam(codingR4.getSystem(), codingR4.getCode());
case R5:
org.hl7.fhir.r5.model.Coding codingR5 = getR5().getCode().getCodingFirstRep();
return new TokenParam(codingR5.getSystem(), codingR5.getCode());
default: default:
throw new UnsupportedOperationException(myFhirVersion + " not supported"); throw new UnsupportedOperationException(myFhirVersion + " not supported");
} }
} }
public TokenParam getIdentifierirstRep() {
switch (myFhirVersion) {
case DSTU3:
org.hl7.fhir.dstu3.model.Identifier identDstu3 = getDstu3().getIdentifierFirstRep();
return new TokenParam(identDstu3.getSystem(), identDstu3.getValue());
case R4:
org.hl7.fhir.r4.model.Identifier identR4 = getR4().getIdentifierFirstRep();
return new TokenParam(identR4.getSystem(), identR4.getValue());
case R5:
org.hl7.fhir.r5.model.Identifier identR5 = getR5().getIdentifierFirstRep();
return new TokenParam(identR5.getSystem(), identR5.getValue());
default:
throw new UnsupportedOperationException(myFhirVersion + " not supported");
}
}
public boolean isEmpty() { public boolean isEmpty() {
switch (myFhirVersion) { switch (myFhirVersion) {
case DSTU3: case DSTU3:
return getDstu3().getEntry().isEmpty(); return getDstu3().getEntry().isEmpty();
case R4: case R4:
return getR4().getEntry().isEmpty(); return getR4().getEntry().isEmpty();
case R5:
return getR5().getEntry().isEmpty();
default: default:
throw new UnsupportedOperationException(myFhirVersion + " not supported"); throw new UnsupportedOperationException(myFhirVersion + " not supported");
} }

View File

@ -0,0 +1,24 @@
package ca.uhn.fhir.jpa.model.any;
import org.hl7.fhir.r5.model.ListResource;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class AnyListResourceTest {
@Test
public void getCodeFirstRep() {
AnyListResource listResource = AnyListResource.fromResource(new ListResource());
listResource.addCode("foo", "bar");
assertEquals("foo", listResource.getCodeFirstRep().getSystem());
assertEquals("bar", listResource.getCodeFirstRep().getValue());
}
@Test
public void getIdentifierFirstRep() {
AnyListResource listResource = AnyListResource.fromResource(new ListResource());
listResource.addIdentifier("foo", "bar");
assertEquals("foo", listResource.getIdentifierirstRep().getSystem());
assertEquals("bar", listResource.getIdentifierirstRep().getValue());
}
}

View File

@ -389,6 +389,11 @@ public final class HapiWorkerContext implements IWorkerContext, ValueSetExpander
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public String getLinkForUrl(String theS, String theS1) {
return null;
}
@Override @Override
public List<String> getTypeNames() { public List<String> getTypeNames() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();

View File

@ -353,6 +353,11 @@ public final class HapiWorkerContext implements IWorkerContext, ValueSetExpander
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public String getLinkForUrl(String theS, String theS1) {
return null;
}
@Override @Override
public boolean isNoTerminologyServer() { public boolean isNoTerminologyServer() {
return false; return false;