Skip to content

Commit

Permalink
#494: Added measure support for the release operation
Browse files Browse the repository at this point in the history
  • Loading branch information
brynrhodes committed Jul 23, 2024
1 parent 92fdbfb commit 8b54a24
Show file tree
Hide file tree
Showing 18 changed files with 762 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import ca.uhn.fhir.parser.DataFormatException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
Expand Down Expand Up @@ -51,12 +52,78 @@ public static IBaseResource readRepository(Repository repository, IIdType id) {
*/
public static <CanonicalType extends IPrimitiveType<String>> IBaseResource searchRepositoryByCanonical(
Repository repository, CanonicalType canonical) {
var resourceType = repository

var resourceType = getResourceType(repository, canonical);
return searchRepositoryByCanonical(repository, canonical, resourceType);
}

/**
* Gets the resource type for the given canonical, based on the convention that canonical
* URLs are of the form [base]/[resourceType]/[tail]
*
* If the URL does not conform to the convention, the cqf-resourceType extension is used
* to determine the type of the resource, if present.
*
* If no extension is present, the type of the canonical is assumed to be CodeSystem, on
* the grounds that most (if not all) non-conventional URLs are for CodeSystem uris.
*
* @param <CanonicalType>
* @param repository the repository to search
* @param canonical the canonical url to search for
* @return
*/
private static <CanonicalType extends IPrimitiveType<String>> Class<? extends IBaseResource> getResourceType(Repository repository, CanonicalType canonical) {
Class<? extends IBaseResource> resourceType = null;
try {
resourceType = repository
.fhirContext()
.getResourceDefinition(Canonicals.getResourceType(canonical))
.getImplementingClass();
}
catch (DataFormatException e) {
// TODO: Use the "cqf-resourceType" extension to figure this out, if it's present
// NOTE: This is based on the assumption that only CodeSystems don't follow the canonical pattern...
resourceType = repository
.fhirContext()
.getResourceDefinition("CodeSystem")
.getImplementingClass();
}

return searchRepositoryByCanonical(repository, canonical, resourceType);
return resourceType;
}

/**
* Gets the resource type for the given canonical, based on the convention that canonical
* URLs are of the form [base]/[resourceType]/[tail]
*
* If the URL does not conform to the convention, the cqf-resourceType extension is used
* to determine the type of the resource, if present.
*
* If no extension is present, the type of the canonical is assumed to be CodeSystem, on
* the grounds that most (if not all) non-conventional URLs are for CodeSystem uris.
*
* @param repository
* @param canonical
* @return
*/
private static Class<? extends IBaseResource> getResourceType(Repository repository, String canonical) {
Class<? extends IBaseResource> resourceType = null;
try {
resourceType = repository
.fhirContext()
.getResourceDefinition(Canonicals.getResourceType(canonical))
.getImplementingClass();
}
catch (RuntimeException e) {
// TODO: Use the "cqf-resourceType" extension to figure this out, if it's present
// NOTE: This is based on the assumption that only CodeSystems don't follow the canonical pattern...
resourceType = repository
.fhirContext()
.getResourceDefinition("CodeSystem")
.getImplementingClass();
}

return resourceType;
}

/**
Expand Down Expand Up @@ -95,11 +162,7 @@ IBaseResource searchRepositoryByCanonical(
*/
public static <CanonicalType extends IPrimitiveType<String>> IBaseBundle searchRepositoryByCanonicalWithPaging(
Repository repository, CanonicalType canonical) {
var resourceType = repository
.fhirContext()
.getResourceDefinition(Canonicals.getResourceType(canonical))
.getImplementingClass();

var resourceType = getResourceType(repository, canonical);
return searchRepositoryByCanonicalWithPaging(repository, canonical, resourceType);
}

Expand All @@ -113,11 +176,7 @@ public static <CanonicalType extends IPrimitiveType<String>> IBaseBundle searchR
*/
public static <CanonicalType extends IPrimitiveType<String>> IBaseBundle searchRepositoryByCanonicalWithPaging(
Repository repository, String canonical) {
var resourceType = repository
.fhirContext()
.getResourceDefinition(Canonicals.getResourceType(canonical))
.getImplementingClass();

var resourceType = getResourceType(repository, canonical);
return searchRepositoryByCanonicalWithPaging(repository, canonical, resourceType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ default void setId(IIdType id) {

void setName(String name);

boolean hasTitle();

String getTitle();

void setTitle(String title);

default String getDescriptor() {
return String.format("%s %s%s", this.get().fhirType(), this.hasTitle() ? this.getTitle() : this.getName(), this.hasVersion() ? ", " + this.getVersion() : "");
}

boolean hasUrl();

String getUrl();
Expand Down Expand Up @@ -78,22 +88,25 @@ default void setId(IIdType id) {

@SuppressWarnings("unchecked")
static <T extends ICompositeType & IBaseHasExtensions> T newRelatedArtifact(
FhirVersionEnum version, String type, String reference) {
FhirVersionEnum version, String type, String reference, String display) {
switch (version) {
case DSTU3:
var dstu3 = new org.hl7.fhir.dstu3.model.RelatedArtifact();
dstu3.setType(org.hl7.fhir.dstu3.model.RelatedArtifact.RelatedArtifactType.fromCode(type))
.setResource(new Reference(reference));
.setResource(new Reference(reference))
.setDisplay(display);
return (T) dstu3;
case R4:
var r4 = new org.hl7.fhir.r4.model.RelatedArtifact();
r4.setType(org.hl7.fhir.r4.model.RelatedArtifact.RelatedArtifactType.fromCode(type))
.setResource(reference);
.setResource(reference)
.setDisplay(display);
return (T) r4;
case R5:
var r5 = new org.hl7.fhir.r5.model.RelatedArtifact();
r5.setType(org.hl7.fhir.r5.model.RelatedArtifact.RelatedArtifactType.fromCode(type))
.setResource(reference);
.setResource(reference)
.setDisplay(display);
return (T) r5;

default:
Expand Down Expand Up @@ -150,32 +163,35 @@ private static String getRelatedArtifactType(org.hl7.fhir.r5.model.RelatedArtifa
}

static <T extends ICompositeType & IBaseHasExtensions> void setRelatedArtifactReference(
T relatedArtifact, String reference) {
T relatedArtifact, String reference, String display) {
if (relatedArtifact instanceof org.hl7.fhir.dstu3.model.RelatedArtifact) {
setRelatedArtifactReference((org.hl7.fhir.dstu3.model.RelatedArtifact) relatedArtifact, reference);
setRelatedArtifactReference((org.hl7.fhir.dstu3.model.RelatedArtifact) relatedArtifact, reference, display);
} else if (relatedArtifact instanceof org.hl7.fhir.r4.model.RelatedArtifact) {
setRelatedArtifactReference((org.hl7.fhir.r4.model.RelatedArtifact) relatedArtifact, reference);
setRelatedArtifactReference((org.hl7.fhir.r4.model.RelatedArtifact) relatedArtifact, reference, display);
} else if (relatedArtifact instanceof org.hl7.fhir.r5.model.RelatedArtifact) {
setRelatedArtifactReference((org.hl7.fhir.r5.model.RelatedArtifact) relatedArtifact, reference);
setRelatedArtifactReference((org.hl7.fhir.r5.model.RelatedArtifact) relatedArtifact, reference, display);
} else {
throw new UnprocessableEntityException("Must be a valid RelatedArtifact");
}
}
;

private static void setRelatedArtifactReference(
org.hl7.fhir.dstu3.model.RelatedArtifact relatedArtifact, String reference) {
org.hl7.fhir.dstu3.model.RelatedArtifact relatedArtifact, String reference, String display) {
relatedArtifact.getResource().setReference(reference);
relatedArtifact.setDisplay(display);
}

private static void setRelatedArtifactReference(
org.hl7.fhir.r4.model.RelatedArtifact relatedArtifact, String reference) {
org.hl7.fhir.r4.model.RelatedArtifact relatedArtifact, String reference, String display) {
relatedArtifact.setResource(reference);
relatedArtifact.setDisplay(display);
}

private static void setRelatedArtifactReference(
org.hl7.fhir.r5.model.RelatedArtifact relatedArtifact, String reference) {
org.hl7.fhir.r5.model.RelatedArtifact relatedArtifact, String reference, String display) {
relatedArtifact.setResource(reference);
relatedArtifact.setDisplay(display);
}

void setEffectivePeriod(ICompositeType effectivePeriod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public String getName() {
return this.get().getName();
}

@Override
public boolean hasTitle() {
return this.get().hasTitle();
}

@Override
public String getTitle() {
return this.get().getTitle();
}

@Override
public String getPurpose() {
return null;
Expand All @@ -87,6 +97,11 @@ public void setName(String name) {
this.get().setName(name);
}

@Override
public void setTitle(String title) {
this.get().setTitle(title);
}

@Override
public Date getApprovalDate() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ public String getName() {
return this.getLibrary().getName();
}

@Override
public boolean hasTitle() {
return this.getLibrary().hasTitle();
}

@Override
public String getTitle() {
return this.getLibrary().getTitle();
}

@Override
public String getPurpose() {
return this.getLibrary().getPurpose();
Expand All @@ -89,6 +99,11 @@ public void setName(String name) {
this.getLibrary().setName(name);
}

@Override
public void setTitle(String title) {
this.getLibrary().setTitle(title);
}

@Override
public String getUrl() {
return this.getLibrary().getUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public String getName() {
return this.getPlanDefinition().getName();
}

@Override
public boolean hasTitle() {
return this.getPlanDefinition().hasTitle();
}

@Override
public String getTitle() {
return this.getPlanDefinition().getTitle();
}

@Override
public String getPurpose() {
return this.getPlanDefinition().getPurpose();
Expand All @@ -85,6 +95,11 @@ public void setName(String name) {
this.getPlanDefinition().setName(name);
}

@Override
public void setTitle(String title) {
this.getPlanDefinition().setTitle(title);
}

@Override
public String getUrl() {
return this.getPlanDefinition().getUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ public String getName() {
return this.getValueSet().getName();
}

@Override
public boolean hasTitle() {
return this.getValueSet().hasTitle();
}

@Override
public String getTitle() {
return this.getValueSet().getTitle();
}

@Override
public String getPurpose() {
return this.getValueSet().getPurpose();
Expand All @@ -84,6 +94,11 @@ public void setName(String name) {
this.getValueSet().setName(name);
}

@Override
public void setTitle(String title) {
this.getValueSet().setTitle(title);
}

@Override
public String getUrl() {
return this.getValueSet().getUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.hl7.fhir.instance.model.api.ICompositeType;
import org.hl7.fhir.instance.model.api.IDomainResource;
import org.hl7.fhir.r4.model.Library;
import org.hl7.fhir.r4.model.Measure;
import org.hl7.fhir.r4.model.MetadataResource;
import org.hl7.fhir.r4.model.PlanDefinition;
import org.hl7.fhir.r4.model.ValueSet;
Expand All @@ -29,6 +30,8 @@ public KnowledgeArtifactAdapter createKnowledgeArtifactAdapter(IDomainResource r
KnowledgeArtifactAdapter retval;
if (resource instanceof Library) {
retval = createLibrary(resource);
} else if (resource instanceof Measure) {
retval = new org.opencds.cqf.fhir.utility.adapter.r4.MeasureAdapter((Measure)resource);
} else if (resource instanceof PlanDefinition) {
retval = new org.opencds.cqf.fhir.utility.adapter.r4.PlanDefinitionAdapter((PlanDefinition) resource);
} else if (resource instanceof ValueSet) {
Expand All @@ -39,7 +42,7 @@ public KnowledgeArtifactAdapter createKnowledgeArtifactAdapter(IDomainResource r
(MetadataResource) resource);
} else {
throw new UnprocessableEntityException(
String.format("Resouce must be instance of %s", MetadataResource.class.getName()));
String.format("Resource must be instance of %s", MetadataResource.class.getName()));
}
}
return retval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public String getName() {
return this.get().getName();
}

@Override
public boolean hasTitle() {
return this.get().hasTitle();
}

@Override
public String getTitle() {
return this.get().getTitle();
}

@Override
public String getPurpose() {
return null;
Expand All @@ -87,6 +97,11 @@ public void setName(String name) {
this.get().setName(name);
}

@Override
public void setTitle(String title) {
this.get().setTitle(title);
}

@Override
public Date getApprovalDate() {
return null;
Expand Down
Loading

0 comments on commit 8b54a24

Please sign in to comment.