From 262e39e57a07b503787e882c58c011a09df2e277 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Sat, 6 May 2017 11:41:30 +0200 Subject: [PATCH] Work on term --- .../ca/uhn/fhir/jpa/entity/TermConcept.java | 7 +- .../fhir/jpa/entity/TermConceptProperty.java | 71 +++++++++++++++++++ .../FhirResourceDaoDstu3TerminologyTest.java | 2 + .../jpa/term/TerminologyLoaderSvcTest.java | 11 +++ 4 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConceptProperty.java diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConcept.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConcept.java index 5ae32fdd272..800e71ee10f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConcept.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConcept.java @@ -66,7 +66,6 @@ import org.hibernate.search.annotations.TokenizerDef; import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink.RelationshipTypeEnum; import ca.uhn.fhir.jpa.search.DeferConceptIndexingInterceptor; -//@formatter:off @Entity @Indexed(interceptor=DeferConceptIndexingInterceptor.class) @Table(name="TRM_CONCEPT", uniqueConstraints= { @@ -80,7 +79,6 @@ import ca.uhn.fhir.jpa.search.DeferConceptIndexingInterceptor; filters = { }) }) -//@formatter:on public class TermConcept implements Serializable { private static final int MAX_DESC_LENGTH = 400; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TermConcept.class); @@ -102,7 +100,6 @@ public class TermConcept implements Serializable { @Fields({ @Field(name = "myCodeSystemVersionPid") }) private long myCodeSystemVersionPid; - //@formatter:off @Column(name="DISPLAY", length=MAX_DESC_LENGTH, nullable=true) @Fields({ @Field(name = "myDisplay", index = org.hibernate.search.annotations.Index.YES, store = Store.YES, analyze = Analyze.YES, analyzer = @Analyzer(definition = "standardAnalyzer")), @@ -111,8 +108,10 @@ public class TermConcept implements Serializable { @Field(name = "myDisplayPhonetic", index = org.hibernate.search.annotations.Index.YES, store = Store.NO, analyze = Analyze.YES, analyzer = @Analyzer(definition = "autocompletePhoneticAnalyzer")) }) private String myDisplay; - //@formatter:on + @OneToMany(mappedBy="myConcept") + private Collection myProperties; + @Id() @SequenceGenerator(name = "SEQ_CONCEPT_PID", sequenceName = "SEQ_CONCEPT_PID") @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_CONCEPT_PID") diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConceptProperty.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConceptProperty.java new file mode 100644 index 00000000000..0cfd3905469 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermConceptProperty.java @@ -0,0 +1,71 @@ +package ca.uhn.fhir.jpa.entity; + +/* + * #%L + * HAPI FHIR JPA Server + * %% + * Copyright (C) 2014 - 2017 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import java.io.Serializable; + +import javax.persistence.*; + +@Entity +@Table(name = "TRM_CONCEPT_PROPERTY", uniqueConstraints = { +}, indexes = { +}) +public class TermConceptProperty implements Serializable { + + private static final long serialVersionUID = 1L; + + @ManyToOne + @JoinColumn(name = "CONCEPT_PID", referencedColumnName = "PID", foreignKey = @ForeignKey(name = "FK_CONCEPTPROP_CONCEPT")) + private TermConcept myConcept; + + @Id() + @SequenceGenerator(name = "SEQ_CONCEPT_PROP_PID", sequenceName = "SEQ_CONCEPT_PROP_PID") + @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_CONCEPT_PROP_PID") + @Column(name = "PID") + private Long myId; + + @Column(name="PROP_KEY", length=200, nullable=false) + private String myKey; + + @Column(name="PROP_VAL", length=200, nullable=true) + private String myValue; + + public String getKey() { + return myKey; + } + + public String getValue() { + return myValue; + } + + public void setConcept(TermConcept theConcept) { + myConcept = theConcept; + } + + public void setKey(String theKey) { + myKey = theKey; + } + + public void setValue(String theValue) { + myValue = theValue; + } + +} diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java index 694cf096705..eaac8e6b18c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java @@ -290,6 +290,8 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { @Test public void testExpandWithOpEquals() { + + ValueSet result = myValueSetDao.expandByIdentifier("http://hl7.org/fhir/ValueSet/doc-typecodes", ""); ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result)); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcTest.java index 3a07b2b0578..cb46e32a458 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcTest.java @@ -8,6 +8,7 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import java.io.ByteArrayOutputStream; @@ -78,8 +79,18 @@ public class TerminologyLoaderSvcTest { RequestDetails details = mock(RequestDetails.class); mySvc.loadLoinc(list(bos1.toByteArray(), bos2.toByteArray()), details); + + verify(myTermSvc, times(1)).storeNewCodeSystemVersion(mySystemCaptor.capture(), myCsvCaptor.capture(), any(RequestDetails.class)); + + TermCodeSystemVersion ver = myCsvCaptor.getValue(); + TermConcept code = ver.getConcepts().iterator().next(); + assertEquals("10013-1", code.getCode()); + } + @Captor + private ArgumentCaptor mySystemCaptor; + /** * This is just for trying stuff, it won't run without