diff --git a/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/modelBuilders/AbstractClinicalTrialUSBuilder.java b/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/modelBuilders/AbstractClinicalTrialUSBuilder.java new file mode 100644 index 0000000..66f6588 --- /dev/null +++ b/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/modelBuilders/AbstractClinicalTrialUSBuilder.java @@ -0,0 +1,63 @@ +package gov.hhs.gsrs.clinicaltrial.us.modelBuilders; + +import com.fasterxml.jackson.databind.JsonNode; +import gov.hhs.gsrs.clinicaltrial.us.models.ClinicalTrialUS; +import ix.core.controllers.EntityFactory; +import ix.core.models.Group; +import ix.core.models.Keyword; +import ix.core.models.Principal; + +import java.util.*; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +public abstract class AbstractClinicalTrialUSBuilder >{ + Function xandThen = (f->f); + + public abstract Supplier getSupplier(); + + protected abstract T getThis(); + + public T setTitle(String title) { + return andThen(s -> { + s.trialNumber = title; + }); + } + public T setTrialNumber(String trialNumber) { + return andThen(s -> {s.trialNumber=trialNumber;}); + } + + public T andThen(Consumer fun){ + xandThen = xandThen.andThen(s ->{ fun.accept(s); return s;}); + return getThis(); + } + + public S build(){ + S s = getSupplier().get(); + return additionalSetup().apply(afterCreate().apply(s)); + } + + public final Function afterCreate(){ + return xandThen; + } + + public Function additionalSetup(){ + return Function.identity(); + } + public AbstractClinicalTrialUSBuilder(){ + } + + public AbstractClinicalTrialUSBuilder(ClinicalTrialUS copy) { + + String trialNumber = copy.getTrialNumber(); + if (trialNumber != null) { + setTrialNumber(trialNumber); + } + + } + + +} \ No newline at end of file diff --git a/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/modelBuilders/ClinicalTrialUSBuilder.java b/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/modelBuilders/ClinicalTrialUSBuilder.java new file mode 100644 index 0000000..19a2b0e --- /dev/null +++ b/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/modelBuilders/ClinicalTrialUSBuilder.java @@ -0,0 +1,59 @@ +package gov.hhs.gsrs.clinicaltrial.us.modelBuilders; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import gov.hhs.gsrs.clinicaltrial.us.models.ClinicalTrialUS; +import ix.core.controllers.EntityFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.function.Supplier; + +public class ClinicalTrialUSBuilder extends AbstractClinicalTrialUSBuilder { + + private static final ObjectMapper mapper = EntityFactory.EntityMapper.FULL_ENTITY_MAPPER(); + + public ClinicalTrialUSBuilder() { + } + + public ClinicalTrialUSBuilder(ClinicalTrialUS copy) { + super(copy); + } + + @Override + public Supplier getSupplier() { + return ClinicalTrialUS::new; + } + + @Override + protected ClinicalTrialUSBuilder getThis() { + return this; + } + + protected ClinicalTrialUSBuilder(AbstractClinicalTrialUSBuilder builder){ + this.xandThen = (s)-> (ClinicalTrialUS) builder.xandThen.apply((S) s); + } + + public static > B from(String json) throws IOException { + return from(mapper.readTree(json)); + } + public static > B from(File json) throws IOException{ + return from(mapper.readTree(json)); + } + public static > B from(InputStream json) throws IOException{ + return from(mapper.readTree(json)); + } + public static > B from(JsonNode json){ + ClinicalTrialUS ctus = null; + try { + ctus = mapper.treeToValue(json, ClinicalTrialUS.class); + return (B) new ClinicalTrialUSBuilder(ctus); + + } catch (JsonProcessingException e) { + throw new IllegalStateException("JSON parse error:" + e.getMessage(), e); + } + } + +} \ No newline at end of file diff --git a/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/models/ClinicalTrialUS.java b/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/models/ClinicalTrialUS.java index 08d21cf..6a55e29 100644 --- a/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/models/ClinicalTrialUS.java +++ b/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/models/ClinicalTrialUS.java @@ -1,10 +1,12 @@ package gov.hhs.gsrs.clinicaltrial.us.models; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import gsrs.security.GsrsSecurityUtils; import ix.core.models.*; import gov.hhs.gsrs.clinicaltrial.base.models.ClinicalTrialBase; +import ix.core.util.EntityUtils; import ix.ginas.models.serialization.GsrsDateDeserializer; import ix.ginas.models.serialization.GsrsDateSerializer; import lombok.*; @@ -262,5 +264,13 @@ public String toString() { rtsb.setExcludeNullValues(true); return rtsb.toString(); } + public JsonNode toInternalJsonNode(){ + return EntityUtils.EntityWrapper.of(this).toInternalJsonNode(); + } + + @Override + protected Object clone() throws CloneNotSupportedException { + return super.clone(); + } } diff --git a/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/scrubbers/BasicCtusScrubber.java b/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/scrubbers/BasicCtusScrubber.java new file mode 100644 index 0000000..27c2808 --- /dev/null +++ b/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/scrubbers/BasicCtusScrubber.java @@ -0,0 +1,101 @@ +package gov.hhs.gsrs.clinicaltrial.us.scrubbers; + + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; +import java.util.function.Consumer; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import com.jayway.jsonpath.DocumentContext; +import com.jayway.jsonpath.JsonPath; +import com.jayway.jsonpath.PathNotFoundException; +import com.jayway.jsonpath.Predicate; + +import gov.hhs.gsrs.clinicaltrial.ClinicalTrialDataSourceConfig; +import gov.hhs.gsrs.clinicaltrial.us.models.ClinicalTrialUS; +import gov.nih.ncats.common.stream.StreamUtil; +import ix.core.EntityFetcher; +import ix.core.models.Group; +import ix.core.util.EntityUtils; +import ix.ginas.exporters.RecordScrubber; +// import ix.ginas.modelBuilders.SubstanceBuilder; +import ix.ginas.models.GinasAccessControlled; +// import ix.ginas.models.GinasAccessReferenceControlled; +import ix.ginas.models.GinasCommonData; +; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import net.minidev.json.JSONArray; + +/* +Note: as of 22 September, most of this class is commented out and a quick and dirty implementation is in place. +This will change in the ensuing weeks + */ +@Slf4j +public class BasicCtusScrubber implements RecordScrubber{ + + +private static final String TO_DELETE = "TO_DELETE"; +private static final String TO_FORCE_KEEP = "TO_FORCE_KEEP"; +private BasicCtusScrubberParameters scrubberSettings; +private static Set toDelete = new HashSet<>(); +private static Set toKeep = new HashSet<>(); + + + +public BasicCtusScrubber(BasicCtusScrubberParameters scrubberSettings){ +this.scrubberSettings = scrubberSettings; +} + +//public void setResolver( ClinicalTrialUSReferenceResolver newResolver) { +//this.resolver= newResolver; +//} + + + @SneakyThrows + @Override + public Optional scrub(ClinicalTrialUS ctus) { + log.trace("starting in scrub"); + String ctusJson; + try { + ctusJson = ctus.toInternalJsonNode().toString(); + } catch (Exception ex){ + log.error("Error retrieving substance; using alternative method"); + EntityUtils.Key trialNumber = EntityUtils.Key.of(ClinicalTrialUS.class, ctus.trialNumber); + Optional ctusRefetch = EntityFetcher.of(trialNumber).getIfPossible().map(o->(ClinicalTrialUS) o); + ctusJson = ctusRefetch.get().toInternalJsonNode().toString(); + } + +// try { +// //TODO: confirm if this forces as a concept. It should not, +// // but we need to check. +//// ClinicalTrialUS ctusNew = ClinicalTrialUSBuilder.from(ctusJson).build(); +// // return Optional.of(ctusNew); +// } +// catch (Exception ex) { +// log.warn("error processing record; Will return empty", ex); +// } + return Optional.empty(); + } + + + + + + + + + + +} diff --git a/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/scrubbers/BasicCtusScrubberFactory.java b/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/scrubbers/BasicCtusScrubberFactory.java new file mode 100644 index 0000000..841953d --- /dev/null +++ b/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/scrubbers/BasicCtusScrubberFactory.java @@ -0,0 +1,74 @@ +package gov.hhs.gsrs.clinicaltrial.us.scrubbers; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import gov.nih.ncats.common.util.CachedSupplier; +import gsrs.springUtils.AutowireHelper; +import ix.ginas.exporters.RecordScrubber; +import ix.ginas.exporters.RecordScrubberFactory; +import gov.hhs.gsrs.clinicaltrial.us.models.ClinicalTrialUS; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.io.ClassPathResource; +import org.springframework.util.FileCopyUtils; +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.Optional; + +@Slf4j +public class BasicCtusScrubberFactory implements RecordScrubberFactory { +private final static String JSONSchema = getSchemaString(); + +private static CachedSupplier schemaSupplier = CachedSupplier.of(()->{ +ObjectMapper mapper =new ObjectMapper(); +try { +JsonNode schemaNode=mapper.readTree(JSONSchema); +return schemaNode; +} catch (JsonProcessingException e) { +e.printStackTrace(); +} +return null;//todo: alternate return? +}); + +@Override +public RecordScrubber createScrubber(JsonNode settings) { +log.trace("in BasicCtusScrubberFactory.createScrubber"); +BasicCtusScrubberParameters settingsObject = (new ObjectMapper()).convertValue(settings, BasicCtusScrubberParameters.class); +log.trace(" settingsObject: {}", (settingsObject==null || settings.size()==0 ? "null" : "not null")); + +if(settingsObject==null){ +log.warn("no settings supplied to createScrubber"); +RecordScrubber identityScrubber = (t)-> Optional.of(t); +return identityScrubber; +} + +BasicCtusScrubber scrubber = new BasicCtusScrubber(settingsObject); +scrubber= AutowireHelper.getInstance().autowireAndProxy(scrubber); + +return scrubber; +} + +@Override +public JsonNode getSettingsSchema() { +return schemaSupplier.get(); +} + +private static String readFileAsString(File textFile)throws Exception +{ +String data = ""; +data = new String(Files.readAllBytes(textFile.toPath())); +return data; +} + +@SneakyThrows +private static String getSchemaString() { +log.trace("starting getSchemaString"); +ClassPathResource fileResource = new ClassPathResource("schemas/scrubberSchema.json"); +byte[] binaryData = FileCopyUtils.copyToByteArray(fileResource.getInputStream()); +String schemaString =new String(binaryData, StandardCharsets.UTF_8); +//log.trace("read schema:{}", schemaString); +return schemaString; +} +} diff --git a/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/scrubbers/BasicCtusScrubberParameters.java b/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/scrubbers/BasicCtusScrubberParameters.java new file mode 100644 index 0000000..c66e158 --- /dev/null +++ b/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/main/java/gov/hhs/gsrs/clinicaltrial/us/scrubbers/BasicCtusScrubberParameters.java @@ -0,0 +1,409 @@ +package gov.hhs.gsrs.clinicaltrial.us.scrubbers; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Generated; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import lombok.Data; + +/** + * Scrubber Parameters + *

+ * Factors that control the behavior of a Java class that removes private parts + * of a data object before the object is shared + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ "removeDates", "auditInformationCleanupDeidentifyAuditUser", "removeAllLocked", "removeAllLockedAccessGroupsToInclude", +"removeAllLockedRemoveElementsIfNoExportablePublicRef", "statusesToInclude", +"removeElementsIfNoExportablePublicRefElementsToRemove", "removeCodesBySystem", +"removeCodesBySystemCodeSystemsToRemove", "removeCodesBySystemCodeSystemsToKeep", "removeReferencesByCriteria", +"removeReferencesByCriteriaReferenceTypesToRemove", "removeReferencesByCriteriaCitationPatternsToRemove", +"removeReferencesByCriteriaExcludeReferenceByPattern", "substanceReferenceCleanup", +"substanceReferenceCleanupActionForDefinitionalDependentScrubbedSubstanceReferences", +"substanceReferenceCleanupActionForRelationalScrubbedSubstanceReferences", "removeNotes", "removeChangeReason", +"approvalIdCleanup", "approvalIdCleanupRemoveApprovalId", "approvalIdCleanupCopyApprovalIdToCode", +"approvalIdCleanupApprovalIdCodeSystem", "regenerateUUIDs", "changeAllStatuses", +"changeAllStatusesNewStatusValue", "auditInformationCleanup", "auditInformationCleanupNewAuditorValue", +"removeBasedOnStatus", "scrubbedDefinitionHandling", +"scrubbedDefinitionHandlingRemoveScrubbedDefinitionalElementsEntirely", +"scrubbedDefinitionHandlingSetScrubbedDefinitionalElementsIncomplete", +"scrubbedDefinitionHandlingConvertScrubbedDefinitionsToConcepts", +"scrubbedDefinitionHandlingAddNoteToScrubbedDefinitions", +"scrubbedDefinitionHandlingTreatPartialDefinitionsAsMissingDefinitions", +"scrubbedDefinitionHandlingRemoveScrubbedPartialDefinitionalElementsEntirely", +"scrubbedDefinitionHandlingSetScrubbedPartialDefinitionalElementsIncomplete", +"scrubbedDefinitionHandlingConvertScrubbedPartialDefinitionsToConcepts", +"scrubbedDefinitionHandlingAddNoteToScrubbedPartialDefinitions" }) +@Generated("jsonschema2pojo") +@Data +public class BasicCtusScrubberParameters { + +/** + * Remove Date + *

+ * + * + */ +@JsonProperty("removeDates") +public Boolean removeDates = false; +/** + * Deidentify Audit User + *

+ * + * + */ +@JsonProperty("auditInformationCleanupDeidentifyAuditUser") +public Boolean auditInformationCleanupDeidentifyAuditUser = false; +/** + * Remove all Locked + *

+ * + * + */ +@JsonProperty("removeAllLocked") +public Boolean removeAllLocked= false; +/** + * Access Groups to Include + *

+ * + * + */ +@JsonProperty("removeAllLockedAccessGroupsToInclude") +public List removeAllLockedAccessGroupsToInclude = null; +/** + * Remove Elements if no exportable selected public domain reference + *

+ * + * + */ +@JsonProperty("removeAllLockedRemoveElementsIfNoExportablePublicRef") +public Boolean removeAllLockedRemoveElementsIfNoExportablePublicRef= false; +/** + * Statuses to include + *

+ * + * + */ +@JsonProperty("statusesToInclude") +public List statusesToInclude = null; +/** + * Elements to remove + *

+ * + * + */ +@JsonProperty("removeElementsIfNoExportablePublicRefElementsToRemove") +public List removeElementsIfNoExportablePublicRefElementsToRemove = null; +/** + * Remove Codes by System + *

+ * + * + */ +@JsonProperty("removeCodesBySystem") +public Boolean removeCodesBySystem = false; +/** + * Code Systems to Remove + *

+ * + * + */ +@JsonProperty("removeCodesBySystemCodeSystemsToRemove") +public List removeCodesBySystemCodeSystemsToRemove = null; +/** + * Code Systems to Keep + *

+ * + * + */ +@JsonProperty("removeCodesBySystemCodeSystemsToKeep") +public List removeCodesBySystemCodeSystemsToKeep = null; +/** + * Remove References by Criteria + *

+ * + * + */ +@JsonProperty("removeReferencesByCriteria") +public Boolean removeReferencesByCriteria = false; +/** + * Reference Types to Remove + *

+ * + * + */ +@JsonProperty("removeReferencesByCriteriaReferenceTypesToRemove") +public List removeReferencesByCriteriaReferenceTypesToRemove = null; +/** + * Citation Patterns to Remove + *

+ * + * + */ +@JsonProperty("removeReferencesByCriteriaCitationPatternsToRemove") +public String removeReferencesByCriteriaCitationPatternsToRemove; +/** + * Exclude Reference by Pattern + *

+ * + * + */ +@JsonProperty("removeReferencesByCriteriaExcludeReferenceByPattern") +public Boolean removeReferencesByCriteriaExcludeReferenceByPattern = false; +/** + * Substance Reference Cleanup + *

+ * + * + */ +@JsonProperty("substanceReferenceCleanup") +public Boolean substanceReferenceCleanup = false; +/** + * What action should be taken when a definition depends on a referenced + * substance which would be scrubbed out? + *

+ * + * + */ +@JsonProperty("substanceReferenceCleanupActionForDefinitionalDependentScrubbedSubstanceReferences") +public String substanceReferenceCleanupActionForDefinitionalDependentScrubbedSubstanceReferences; +/** + * What action should be taken when a record references a scrubbed-out substance + * in a non-defining way (e.g. relationships)? + *

+ * + * + */ +@JsonProperty("substanceReferenceCleanupActionForRelationalScrubbedSubstanceReferences") +public String substanceReferenceCleanupActionForRelationalScrubbedSubstanceReferences; +/** + * Remove Notes + *

+ * + * + */ +@JsonProperty("removeNotes") +public Boolean removeNotes = false; +/** + * Remove Change Reason + *

+ * + * + */ +@JsonProperty("removeChangeReason") +public Boolean removeChangeReason = false; +/** + * Approval Id clean-up + *

+ * + * + */ +@JsonProperty("approvalIdCleanup") +public Boolean approvalIdCleanup = false; +/** + * Remove Approval Id + *

+ * + * + */ +@JsonProperty("approvalIdCleanupRemoveApprovalId") +public Boolean approvalIdCleanupRemoveApprovalId = false; +/** + * Copy Approval Id to code if code not already present + *

+ * + * + */ +@JsonProperty("approvalIdCleanupCopyApprovalIdToCode") +public Boolean approvalIdCleanupCopyApprovalIdToCode = false; +/** + * Remove Approval Id + *

+ * + * + */ +@JsonProperty("approvalIdCleanupApprovalIdCodeSystem") +public String approvalIdCleanupApprovalIdCodeSystem; +/** + * Clean up (top-level) UUIDs + *

+ * + * + */ +@JsonProperty("UUIDCleanup") +public Boolean UUIDCleanup=false; +/** + * Regenerate UUIDs + *

+ * + * + */ +@JsonProperty("regenerateUUIDs") +public Boolean regenerateUUIDs =false; +/** + * Copy UUID to code if code not already present + *

+ * + * + */ +@JsonProperty("UUIdCleanupCopyUUIDIdToCode") +public Boolean uUIdCleanupCopyUUIDIdToCode = false; +/** + * Copy UUID to code with following code system (if not already present) + *

+ * + * + */ +@JsonProperty("UUIDCleanupUUIDCodeSystem") +public String UUIDCleanupUUIDCodeSystem =""; +/** + * Remove Standardized Names + */ +@JsonProperty("removeStdNames") +public Boolean removeStdNames = false; + +/** + * Change All Statuses + *

+ * + * + */ +@JsonProperty("changeAllStatuses") +public Boolean changeAllStatuses = false; +/** + * New Status Value + *

+ * + * + */ +@JsonProperty("changeAllStatusesNewStatusValue") +public String changeAllStatusesNewStatusValue; +/** + * Audit Information clean-up + *

+ * + * + */ +@JsonProperty("auditInformationCleanup") +public Boolean auditInformationCleanup = false; +/** + * New Auditor Value + *

+ * + * + */ +@JsonProperty("auditInformationCleanupNewAuditorValue") +public String auditInformationCleanupNewAuditorValue; +/** + * Delete records based on status + *

+ * + * + */ +@JsonProperty("removeBasedOnStatus") +public Boolean removeBasedOnStatus = false; +/** + * Scrubbed Definition Handling + *

+ * + * + */ +@JsonProperty("scrubbedDefinitionHandling") +public Boolean scrubbedDefinitionHandling = false; +/** + * Remove partially/fully scrubbed definitional records entirely + *

+ * + * + */ +@JsonProperty("scrubbedDefinitionHandlingRemoveScrubbedDefinitionalElementsEntirely") +public Boolean scrubbedDefinitionHandlingRemoveScrubbedDefinitionalElementsEntirely = false; +/** + * Set partially/fully scrubbed definitional records to definitional level + * "Incomplete" + *

+ * + * + */ +@JsonProperty("scrubbedDefinitionHandlingSetScrubbedDefinitionalElementsIncomplete") +public Boolean scrubbedDefinitionHandlingSetScrubbedDefinitionalElementsIncomplete = false; +/** + * Convert partially/fully scrubbed definitional records to "Concepts" + *

+ * + * + */ +@JsonProperty("scrubbedDefinitionHandlingConvertScrubbedDefinitionsToConcepts") +public Boolean scrubbedDefinitionHandlingConvertScrubbedDefinitionsToConcepts = false; +/** + * add a note to partially/fully scrubbed definitional records + *

+ * + * + */ +@JsonProperty("scrubbedDefinitionHandlingAddNoteToScrubbedDefinitions") +public String scrubbedDefinitionHandlingAddNoteToScrubbedDefinitions; +/** + * Treat partially scrubbed definitions with same settings + *

+ * + * + */ +@JsonProperty("scrubbedDefinitionHandlingTreatPartialDefinitionsAsMissingDefinitions") +public Boolean scrubbedDefinitionHandlingTreatPartialDefinitionsAsMissingDefinitions = false; +/** + * Remove PARTIALLY scrubbed definitional records entirely + *

+ * + * + */ +@JsonProperty("scrubbedDefinitionHandlingRemoveScrubbedPartialDefinitionalElementsEntirely") +public Boolean scrubbedDefinitionHandlingRemoveScrubbedPartialDefinitionalElementsEntirely = false; +/** + * Set PARTIALLY scrubbed definitional records to definitional level + * "Incomplete" + *

+ * + * + */ +@JsonProperty("scrubbedDefinitionHandlingSetScrubbedPartialDefinitionalElementsIncomplete") +public Boolean scrubbedDefinitionHandlingSetScrubbedPartialDefinitionalElementsIncomplete = false; +/** + * Convert PARTIALLY scrubbed definitional records to "Concepts" + *

+ * + * + */ +@JsonProperty("scrubbedDefinitionHandlingConvertScrubbedPartialDefinitionsToConcepts") +public Boolean scrubbedDefinitionHandlingConvertScrubbedPartialDefinitionsToConcepts = false; +/** + * add a note to PARTIALLY scrubbed definitional records + * d + * + * + */ +@JsonProperty("scrubbedDefinitionHandlingAddNoteToScrubbedPartialDefinitions") +public String scrubbedDefinitionHandlingAddNoteToScrubbedPartialDefinitions; +@JsonIgnore +private Map additionalProperties = new HashMap(); + +@JsonAnyGetter +public Map getAdditionalProperties() { +return this.additionalProperties; +} + +@JsonAnySetter +public void setAdditionalProperty(String name, Object value) { +this.additionalProperties.put(name, value); +} +} \ No newline at end of file diff --git a/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/test/java/gov/nih/ncats/clinicaltrial/us/modelBuilders/ClinicalTrialUSBuilderTest.java b/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/test/java/gov/nih/ncats/clinicaltrial/us/modelBuilders/ClinicalTrialUSBuilderTest.java new file mode 100644 index 0000000..0075b2d --- /dev/null +++ b/gsrs-module-clinical-trials-spring-boot-autoconfigure/src/test/java/gov/nih/ncats/clinicaltrial/us/modelBuilders/ClinicalTrialUSBuilderTest.java @@ -0,0 +1,149 @@ +package gov.nih.ncats.clinicaltrial.us.modelBuilders; + +import gov.hhs.gsrs.clinicaltrial.us.models.ClinicalTrialUS; +import gov.hhs.gsrs.clinicaltrial.us.models.ClinicalTrialUSDrug; +import gov.hhs.gsrs.clinicaltrial.us.models.SubstanceRole; +import gov.hhs.gsrs.clinicaltrial.us.repositories.ClinicalTrialUSRepository; +import gsrs.services.PrincipalService; +import gsrs.springUtils.AutowireHelper; +import ix.core.models.Principal; +import oracle.ons.Cli; +import org.checkerframework.dataflow.qual.TerminatesExecution; +import org.junit.Before; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.function.Function; + +import gov.hhs.gsrs.clinicaltrial.us.modelBuilders.ClinicalTrialUSBuilder; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.junit4.SpringRunner; + +// import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +//@RunWith(SpringRunner.class) +//@Import(AutowireHelper.class) +public class ClinicalTrialUSBuilderTest { + +// @MockBean +// ClinicalTrialUSRepository clinicalTrialUSRepository; + +// @Before +// public void setup(){ +// ClinicalTrialUS setupCtus = new ClinicalTrialUS(); +// setupCtus.trialNumber="NCT099"; +// setupCtus.title="setupCtus title"; +// Mockito.when(clinicalTrialUSRepository.save(setupCtus)).thenReturn(setupCtus); +// } + + + @Test +public void xyzTest(){ + Function appendA = s -> s+"A"; + Function appendB = s -> s+"B"; + Function appendC = s -> s+"C"; + System.out.println(appendA.apply("boat")); + System.out.println(appendA.andThen(appendB).andThen(appendC).apply("boat")); + System.out.println(appendA.compose(appendB).compose(appendC).apply("boat")); +} + + + @Test + public void setTitleTest(){ + ClinicalTrialUS ctus = new ClinicalTrialUSBuilder() + .setTitle("foo") + .build(); + assertEquals("foo", ctus.getTitle()); + } + + @Test + public void builderTest(){ + ClinicalTrialUS ctus = new ClinicalTrialUS(); + ctus.setTrialNumber("NCT001"); + ctus.setTitle("Trial 1"); + ClinicalTrialUSDrug s = new ClinicalTrialUSDrug(); + s.setOwner(ctus); + s.setId(0L); + ctus.getClinicalTrialUSDrug().add(s); + UUID u = UUID.randomUUID(); + s.setSubstanceKey(u.toString()); + s.setSubstanceKeyType("UUID"); + List srl = new ArrayList(); + SubstanceRole sr1 = new SubstanceRole(); + sr1.setOwner(s); + sr1.setSubstanceRole("Role 1"); + srl.add(sr1); + SubstanceRole sr2 = new SubstanceRole(); + sr2.setOwner(s); + sr2.setSubstanceRole("Role 2"); + srl.add(sr2); + ClinicalTrialUSBuilder testBuilder = new ClinicalTrialUSBuilder(ctus); + ClinicalTrialUS newCtus = testBuilder.build(); + assertEquals(ctus.getTrialNumber(), newCtus.getTrialNumber()); + } + + + + + + + +// +// @org.junit.Test +// public void ChemicalSubstanceFromJsonInputStream() throws Exception{ +// try(InputStream in = getClass().getResourceAsStream("/testJSON/pass/2moities.json")){ +// assertNotNull(in); +// ChemicalSubstanceBuilder builder = SubstanceBuilder.from(in); +// +// assert2MoietiesBuiltCorrectly(builder); +// } +// } +// +// @org.junit.Test +// public void ChemicalSubstanceFromJsonFile() throws Exception{ +// ChemicalSubstanceBuilder builder = SubstanceBuilder.from(new File(getClass().getResource("/testJSON/pass/2moities.json").getFile())); +// +// assert2MoietiesBuiltCorrectly(builder); +// +// } +// +// private void assert2MoietiesBuiltCorrectly(ChemicalSubstanceBuilder builder) { +// ChemicalSubstance substance = builder.build(); +// +// Assertions.assertEquals("1db30542-0cc4-4098-9d89-8340926026e9", substance.getUuid().toString()); +// Assertions.assertEquals(2, substance.moieties.size()); +// } +// +// @org.junit.Test +// public void modifyChemicalSubstanceFromJson() throws Exception{ +// ///home/katzelda/GIT/inxight3/modules/ginas/test/testJSON/pass/2moities.json +// String path = "test/testJSON/pass/2moities.json"; +// +// try(InputStream in = getClass().getResourceAsStream("/testJSON/pass/2moities.json")){ +// assertNotNull(in); +// ChemicalSubstanceBuilder builder = SubstanceBuilder.from(in); +// +// UUID uuid = UUID.randomUUID(); +// builder.setUUID( uuid); +// ChemicalSubstance substance = builder.build(); +// +// Assertions.assertEquals(uuid, substance.getUuid()); +// Assertions.assertEquals(2, substance.moieties.size()); +// } +// } +// } +// +// + +} +