Skip to content

Commit

Permalink
[APHL-551] artifactAssessment update (#457)
Browse files Browse the repository at this point in the history
* [APHL-551] artifactAssessment update

* spotless

* make them codetype

---------

Co-authored-by: [email protected] <[email protected]>
  • Loading branch information
TahaAttari and [email protected] authored May 7, 2024
1 parent 9ce3f02 commit aaa2636
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.hl7.fhir.dstu3.model.Base;
import org.hl7.fhir.dstu3.model.Basic;
import org.hl7.fhir.dstu3.model.BooleanType;
import org.hl7.fhir.dstu3.model.CodeType;
import org.hl7.fhir.dstu3.model.CodeableConcept;
import org.hl7.fhir.dstu3.model.Configuration;
import org.hl7.fhir.dstu3.model.DateTimeType;
Expand Down Expand Up @@ -1004,7 +1005,7 @@ public ArtifactAssessment(UriType artifact) {
}

public ArtifactAssessment createArtifactComment(
ArtifactAssessmentContentInformationType type,
CodeType type,
Reference targetReference,
Optional<UriType> derivedFromUri,
Optional<MarkdownType> text,
Expand Down Expand Up @@ -1037,7 +1038,7 @@ public ArtifactAssessment createArtifactComment(
}

public ArtifactAssessment createArtifactComment(
ArtifactAssessmentContentInformationType type,
CodeType type,
UriType targetReference,
Optional<UriType> derivedFromUri,
Optional<MarkdownType> text,
Expand Down Expand Up @@ -1133,9 +1134,8 @@ public boolean checkArtifactCommentParams(
int infoTypeIndex = findIndex(ArtifactAssessmentContentExtension.INFOTYPE, null, contentExt.getExtension());
if (infoTypeIndex != -1) {
Extension infoTypeExt = contentExt.getExtension().get(infoTypeIndex);
infoTypeCorrect = ((Enumeration<?>) infoTypeExt.getValue())
.getValueAsString()
.equals(artifactAssessmentType);
infoTypeCorrect =
((CodeType) infoTypeExt.getValue()).getValueAsString().equals(artifactAssessmentType);
}
int summaryIndex = findIndex(ArtifactAssessmentContentExtension.SUMMARY, null, contentExt.getExtension());
if (summaryIndex != -1) {
Expand Down Expand Up @@ -1386,8 +1386,7 @@ public ArtifactAssessmentContentExtension() throws FHIRException {
super(CONTENT);
}

ArtifactAssessmentContentExtension setInfoType(ArtifactAssessmentContentInformationType infoType)
throws FHIRException {
ArtifactAssessmentContentExtension setInfoType(CodeType infoType) throws FHIRException {
if (infoType != null) {
int index = findIndex(INFOTYPE, null, this.getExtension());
if (index != -1) {
Expand Down Expand Up @@ -1504,14 +1503,11 @@ ArtifactAssessmentContentExtension addPathExtension(UriType path) {
isSpecialization = true,
profileOf = Extension.class)
private class ArtifactAssessmentContentInformationTypeExtension extends Extension {
public ArtifactAssessmentContentInformationTypeExtension(
ArtifactAssessmentContentInformationType informationTypeCode) {
public ArtifactAssessmentContentInformationTypeExtension(CodeType informationTypeCode) {
super(INFOTYPE);
Enumeration<ArtifactAssessmentContentInformationType> informationType =
new Enumeration<ArtifactAssessmentContentInformationType>(
new ArtifactAssessmentContentInformationTypeEnumFactory());
informationType.setValue(informationTypeCode);
this.setValue(informationType);
// validate code
ArtifactAssessmentContentInformationType.fromCode(informationTypeCode.getValue());
this.setValue(informationTypeCode);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.hl7.fhir.r4.model.Basic;
import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.CanonicalType;
import org.hl7.fhir.r4.model.CodeType;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Configuration;
import org.hl7.fhir.r4.model.DateTimeType;
Expand Down Expand Up @@ -1010,7 +1011,7 @@ public ArtifactAssessment(UriType artifact) {
}

public ArtifactAssessment createArtifactComment(
ArtifactAssessmentContentInformationType type,
CodeType type,
Reference targetReference,
Optional<CanonicalType> derivedFromUri,
Optional<MarkdownType> text,
Expand Down Expand Up @@ -1043,7 +1044,7 @@ public ArtifactAssessment createArtifactComment(
}

public ArtifactAssessment createArtifactComment(
ArtifactAssessmentContentInformationType type,
CodeType type,
CanonicalType targetReference,
Optional<CanonicalType> derivedFromUri,
Optional<MarkdownType> text,
Expand Down Expand Up @@ -1076,7 +1077,7 @@ public ArtifactAssessment createArtifactComment(
}

public ArtifactAssessment createArtifactComment(
ArtifactAssessmentContentInformationType type,
CodeType type,
UriType targetReference,
Optional<CanonicalType> derivedFromUri,
Optional<MarkdownType> text,
Expand Down Expand Up @@ -1168,53 +1169,52 @@ public boolean checkArtifactCommentParams(
boolean artifactCorrect = false;
int contentIndex = findIndex(CONTENT, null, this.getExtension());
if (contentIndex != -1) {
Extension contentExt = this.getExtension().get(contentIndex);
var contentExt = this.getExtension().get(contentIndex);
int infoTypeIndex = findIndex(ArtifactAssessmentContentExtension.INFOTYPE, null, contentExt.getExtension());
if (infoTypeIndex != -1) {
Extension infoTypeExt = contentExt.getExtension().get(infoTypeIndex);
infoTypeCorrect =
((Enumeration<?>) infoTypeExt.getValue()).getCode().equals(artifactAssessmentType);
var infoTypeExt = contentExt.getExtension().get(infoTypeIndex);
infoTypeCorrect = ((CodeType) infoTypeExt.getValue()).getCode().equals(artifactAssessmentType);
}
int summaryIndex = findIndex(ArtifactAssessmentContentExtension.SUMMARY, null, contentExt.getExtension());
if (summaryIndex != -1) {
Extension summaryExt = contentExt.getExtension().get(summaryIndex);
var summaryExt = contentExt.getExtension().get(summaryIndex);
summaryCorrect = ((StringType) summaryExt.getValue()).getValue().equals(artifactAssessmentSummary);
}
List<Extension> relatedArtifactList = contentExt.getExtension().stream()
var relatedArtifactList = contentExt.getExtension().stream()
.filter(e -> e.getUrl().equals(ArtifactAssessmentContentExtension.RELATEDARTIFACT))
.collect(Collectors.toList());
if (relatedArtifactList.size() > 0) {
Optional<Extension> maybeCitation = relatedArtifactList.stream()
var maybeCitation = relatedArtifactList.stream()
.filter(ext ->
((RelatedArtifact) ext.getValue()).getType().equals(RelatedArtifactType.CITATION))
.findAny();
Optional<Extension> maybeDerivedFrom = relatedArtifactList.stream()
var maybeDerivedFrom = relatedArtifactList.stream()
.filter(ext ->
((RelatedArtifact) ext.getValue()).getType().equals(RelatedArtifactType.DERIVEDFROM))
.findAny();
if (maybeCitation.isPresent()) {
Extension citation = maybeCitation.get();
var citation = maybeCitation.get();
citationRelatedArtifactCorrect = ((RelatedArtifact) citation.getValue())
.getResource()
.equals(artifactAssessmentRelatedArtifact);
}
if (maybeDerivedFrom.isPresent()) {
Extension derivedFrom = maybeDerivedFrom.get();
var derivedFrom = maybeDerivedFrom.get();
derivedFromRelatedArtifactCorrect = ((RelatedArtifact) derivedFrom.getValue())
.getResource()
.equals(derivedFromRelatedArtifactUrl);
}
}
int authorIndex = findIndex(ArtifactAssessmentContentExtension.AUTHOR, null, contentExt.getExtension());
if (authorIndex != -1) {
Extension authorExt = contentExt.getExtension().get(authorIndex);
var authorExt = contentExt.getExtension().get(authorIndex);
authorCorrect =
((Reference) authorExt.getValue()).getReference().equals(artifactAssessmentAuthor);
}
}
int artifactIndex = findIndex(ARTIFACT, null, this.getExtension());
if (artifactIndex != -1) {
Extension artifactExt = this.getExtension().get(artifactIndex);
var artifactExt = this.getExtension().get(artifactIndex);
artifactCorrect =
((Reference) artifactExt.getValue()).getReference().equals(artifactAssessmentTargetReference);
}
Expand All @@ -1235,7 +1235,7 @@ public boolean isValidArtifactComment() {
boolean artifactExists = findIndex(ARTIFACT, null, this.getExtension()) != -1;
int contentIndex = findIndex(CONTENT, null, this.getExtension());
if (contentIndex != -1) {
Extension content = this.getExtension().get(contentIndex);
var content = this.getExtension().get(contentIndex);
infoTypeExists = findIndex(ArtifactAssessmentContentExtension.INFOTYPE, null, content.getExtension()) != -1;
summaryExists = findIndex(ArtifactAssessmentContentExtension.SUMMARY, null, content.getExtension()) != -1;
relatedArtifactExists =
Expand Down Expand Up @@ -1434,8 +1434,7 @@ public ArtifactAssessmentContentExtension() throws FHIRException {
super(CONTENT);
}

ArtifactAssessmentContentExtension setInfoType(ArtifactAssessmentContentInformationType infoType)
throws FHIRException {
ArtifactAssessmentContentExtension setInfoType(CodeType infoType) throws FHIRException {
if (infoType != null) {
int index = findIndex(INFOTYPE, null, this.getExtension());
if (index != -1) {
Expand Down Expand Up @@ -1552,14 +1551,11 @@ ArtifactAssessmentContentExtension addPathExtension(UriType path) {
isSpecialization = true,
profileOf = Extension.class)
private class ArtifactAssessmentContentInformationTypeExtension extends Extension {
public ArtifactAssessmentContentInformationTypeExtension(
ArtifactAssessmentContentInformationType informationTypeCode) {
public ArtifactAssessmentContentInformationTypeExtension(CodeType informationTypeCode) {
super(INFOTYPE);
Enumeration<ArtifactAssessmentContentInformationType> informationType =
new Enumeration<ArtifactAssessmentContentInformationType>(
new ArtifactAssessmentContentInformationTypeEnumFactory());
informationType.setValue(informationTypeCode);
this.setValue(informationType);
// validate code
ArtifactAssessmentContentInformationType.fromCode(informationTypeCode.getValue());
this.setValue(informationTypeCode);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private IBaseResource createApprovalAssessment(
return org.opencds.cqf.fhir.utility.visitor.dstu3.KnowledgeArtifactApproveVisitor
.createApprovalAssessment(
id,
artifactAssessmentType,
new org.hl7.fhir.dstu3.model.CodeType(artifactAssessmentType),
artifactAssessmentSummary.map(t -> new org.hl7.fhir.dstu3.model.MarkdownType(t)),
artifactAssessmentTargetCanonical.map(t -> new org.hl7.fhir.dstu3.model.UriType(t)),
artifactAssessmentRelatedArtifact.map(t -> new org.hl7.fhir.dstu3.model.UriType(t)),
Expand All @@ -98,7 +98,7 @@ private IBaseResource createApprovalAssessment(
case R4:
return org.opencds.cqf.fhir.utility.visitor.r4.KnowledgeArtifactApproveVisitor.createApprovalAssessment(
id,
artifactAssessmentType,
new org.hl7.fhir.r4.model.CodeType(artifactAssessmentType),
artifactAssessmentSummary.map(t -> new org.hl7.fhir.r4.model.MarkdownType(t)),
artifactAssessmentTargetCanonical.map(t -> new org.hl7.fhir.r4.model.CanonicalType(t)),
artifactAssessmentRelatedArtifact.map(t -> new org.hl7.fhir.r4.model.CanonicalType(t)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import java.util.Optional;
import org.hl7.fhir.dstu3.model.CodeType;
import org.hl7.fhir.dstu3.model.MarkdownType;
import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.fhir.dstu3.model.UriType;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.api.IIdType;
import org.opencds.cqf.fhir.utility.dstu3.ArtifactAssessment;
import org.opencds.cqf.fhir.utility.dstu3.ArtifactAssessment.ArtifactAssessmentContentInformationType;

public class KnowledgeArtifactApproveVisitor {

public static ArtifactAssessment createApprovalAssessment(
IIdType id,
String artifactAssessmentType,
CodeType artifactAssessmentType,
Optional<MarkdownType> artifactAssessmentSummary,
Optional<UriType> artifactAssessmentTargetCanonical,
Optional<UriType> artifactAssessmentRelatedArtifact,
Expand All @@ -26,7 +26,7 @@ public static ArtifactAssessment createApprovalAssessment(
try {
artifactAssessment = new ArtifactAssessment(new Reference(id));
artifactAssessment.createArtifactComment(
ArtifactAssessmentContentInformationType.fromCode(artifactAssessmentType),
artifactAssessmentType,
artifactTargetReference,
artifactAssessmentTargetCanonical,
artifactAssessmentSummary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.CanonicalType;
import org.hl7.fhir.r4.model.CodeType;
import org.hl7.fhir.r4.model.MarkdownType;
import org.hl7.fhir.r4.model.Reference;
import org.opencds.cqf.fhir.utility.r4.ArtifactAssessment;
import org.opencds.cqf.fhir.utility.r4.ArtifactAssessment.ArtifactAssessmentContentInformationType;

public class KnowledgeArtifactApproveVisitor {

public static ArtifactAssessment createApprovalAssessment(
IIdType id,
String artifactAssessmentType,
CodeType artifactAssessmentType,
Optional<MarkdownType> artifactAssessmentSummary,
Optional<CanonicalType> artifactAssessmentTargetCanonical,
Optional<CanonicalType> artifactAssessmentRelatedArtifact,
Expand All @@ -26,7 +26,7 @@ public static ArtifactAssessment createApprovalAssessment(
try {
artifactAssessment = new ArtifactAssessment(new Reference(id));
artifactAssessment.createArtifactComment(
ArtifactAssessmentContentInformationType.fromCode(artifactAssessmentType),
artifactAssessmentType,
artifactTargetReference,
artifactAssessmentTargetCanonical,
artifactAssessmentSummary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.List;
import java.util.Optional;
import org.hl7.fhir.dstu3.model.BooleanType;
import org.hl7.fhir.dstu3.model.CodeType;
import org.hl7.fhir.dstu3.model.CodeableConcept;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.DateType;
Expand Down Expand Up @@ -269,7 +270,7 @@ void valid_comment() {
var referenceString = "Library/123";
ArtifactAssessment artifactAssessment = new ArtifactAssessment();
artifactAssessment.createArtifactComment(
ArtifactAssessmentContentInformationType.fromCode("comment"),
new CodeType("comment"),
new Reference(referenceString),
Optional.ofNullable(null),
Optional.ofNullable(null),
Expand All @@ -287,7 +288,7 @@ void valid_comment() {
assertFalse(artifactAssessment.isValidArtifactComment());
artifactAssessment = new ArtifactAssessment();
artifactAssessment.createArtifactComment(
ArtifactAssessmentContentInformationType.fromCode("comment"),
new CodeType("comment"),
new Reference((String) null),
Optional.ofNullable(null),
Optional.ofNullable(null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.CanonicalType;
import org.hl7.fhir.r4.model.CodeType;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.DateType;
Expand Down Expand Up @@ -277,7 +278,7 @@ void valid_comment() {
var referenceString = "Library/123";
ArtifactAssessment artifactAssessment = new ArtifactAssessment();
artifactAssessment.createArtifactComment(
ArtifactAssessmentContentInformationType.fromCode("comment"),
new CodeType("comment"),
new Reference(referenceString),
Optional.ofNullable(null),
Optional.ofNullable(null),
Expand All @@ -295,7 +296,7 @@ void valid_comment() {
assertFalse(artifactAssessment.isValidArtifactComment());
artifactAssessment = new ArtifactAssessment();
artifactAssessment.createArtifactComment(
ArtifactAssessmentContentInformationType.fromCode("comment"),
new CodeType("comment"),
new Reference((String) null),
Optional.ofNullable(null),
Optional.ofNullable(null),
Expand Down

0 comments on commit aaa2636

Please sign in to comment.