More JPA work
This commit is contained in:
parent
4002cc8824
commit
27dab8a442
|
@ -24,18 +24,18 @@ import ca.uhn.fhir.context.FhirContext;
|
|||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
|
||||
public class StringParameter extends StringDt {
|
||||
public class StringParam extends StringDt {
|
||||
|
||||
private boolean myExact;
|
||||
|
||||
public StringParameter() {
|
||||
public StringParam() {
|
||||
}
|
||||
|
||||
public StringParameter(String theValue) {
|
||||
public StringParam(String theValue) {
|
||||
setValue(theValue);
|
||||
}
|
||||
|
||||
public StringParameter(String theValue, boolean theExact) {
|
||||
public StringParam(String theValue, boolean theExact) {
|
||||
setValue(theValue);
|
||||
setExact(theExact);
|
||||
}
|
|
@ -59,7 +59,7 @@ import ca.uhn.fhir.rest.client.api.IRestfulClient;
|
|||
import ca.uhn.fhir.rest.param.CodingListParam;
|
||||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||
import ca.uhn.fhir.rest.param.QualifiedDateParam;
|
||||
import ca.uhn.fhir.rest.param.StringParameter;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
|
||||
|
@ -82,7 +82,7 @@ public List<Organization> getAllOrganizations() {
|
|||
//START SNIPPET: underlyingReq
|
||||
@Search
|
||||
public List<Patient> findPatients(
|
||||
@RequiredParam(name="foo") StringParameter theParameter,
|
||||
@RequiredParam(name="foo") StringParam theParameter,
|
||||
HttpServletRequest theRequest,
|
||||
HttpServletResponse theResponse) {
|
||||
List<Patient> retVal=new ArrayList<Patient>(); // populate this
|
||||
|
@ -146,7 +146,7 @@ public Patient getResourceById(@IdParam IdDt theId,
|
|||
|
||||
//START SNIPPET: searchStringParam
|
||||
@Search()
|
||||
public List<Patient> searchByLastName(@RequiredParam(name=Patient.SP_FAMILY) StringParameter theFamily) {
|
||||
public List<Patient> searchByLastName(@RequiredParam(name=Patient.SP_FAMILY) StringParam theFamily) {
|
||||
List<Patient> retVal = new ArrayList<Patient>();
|
||||
|
||||
String valueToMatch = theFamily.getValue();
|
||||
|
@ -164,7 +164,7 @@ public List<Patient> searchByLastName(@RequiredParam(name=Patient.SP_FAMILY) Str
|
|||
|
||||
//START SNIPPET: searchNamedQuery
|
||||
@Search(queryName="namedQuery1")
|
||||
public List<Patient> searchByNamedQuery(@RequiredParam(name="someparam") StringParameter theSomeParam) {
|
||||
public List<Patient> searchByNamedQuery(@RequiredParam(name="someparam") StringParam theSomeParam) {
|
||||
List<Patient> retVal = new ArrayList<Patient>();
|
||||
// ...populate...
|
||||
return retVal;
|
||||
|
@ -185,8 +185,8 @@ public List<Patient> searchByIdentifier(@RequiredParam(name=Patient.SP_IDENTIFIE
|
|||
|
||||
//START SNIPPET: searchOptionalParam
|
||||
@Search()
|
||||
public List<Patient> searchByNames( @RequiredParam(name=Patient.SP_FAMILY) StringParameter theFamilyName,
|
||||
@OptionalParam(name=Patient.SP_GIVEN) StringParameter theGivenName ) {
|
||||
public List<Patient> searchByNames( @RequiredParam(name=Patient.SP_FAMILY) StringParam theFamilyName,
|
||||
@OptionalParam(name=Patient.SP_GIVEN) StringParam theGivenName ) {
|
||||
String familyName = theFamilyName.getValue();
|
||||
String givenName = theGivenName != null ? theGivenName.getValue() : null;
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ import ca.uhn.fhir.model.dstu.resource.Patient;
|
|||
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.param.StringParameter;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
|
||||
public class StringClientTest {
|
||||
|
@ -58,7 +58,7 @@ public class StringClientTest {
|
|||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(createBundle()), Charset.forName("UTF-8")));
|
||||
|
||||
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
|
||||
client.searchWithParam(new StringParameter("hello"));
|
||||
client.searchWithParam(new StringParam("hello"));
|
||||
|
||||
assertEquals(HttpGet.class, capt.getValue().getClass());
|
||||
HttpGet get = (HttpGet) capt.getValue();
|
||||
|
@ -90,7 +90,7 @@ public class StringClientTest {
|
|||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(createBundle()), Charset.forName("UTF-8")));
|
||||
|
||||
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
|
||||
client.searchWithParam(new StringParameter("hello", true));
|
||||
client.searchWithParam(new StringParam("hello", true));
|
||||
|
||||
assertEquals(HttpGet.class, capt.getValue().getClass());
|
||||
HttpGet get = (HttpGet) capt.getValue();
|
||||
|
@ -106,7 +106,7 @@ public class StringClientTest {
|
|||
private interface IClient extends IBasicClient {
|
||||
|
||||
@Search(type=Patient.class)
|
||||
public List<Patient> searchWithParam(@RequiredParam(name="withParam") StringParameter theString);
|
||||
public List<Patient> searchWithParam(@RequiredParam(name="withParam") StringParam theString);
|
||||
|
||||
@Search(type=Patient.class)
|
||||
public List<Patient> searchWithoutParam(@RequiredParam(name="withoutParam") String theString);
|
||||
|
|
|
@ -24,7 +24,7 @@ import ca.uhn.fhir.model.api.IResource;
|
|||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.param.StringParameter;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.testutil.RandomServerPortProvider;
|
||||
|
||||
/**
|
||||
|
@ -138,7 +138,7 @@ public class StringParameterTest {
|
|||
public static class DummyPatientResourceProvider implements IResourceProvider {
|
||||
|
||||
@Search
|
||||
public List<Patient> findPatient(@RequiredParam(name = "str") StringParameter theParam) {
|
||||
public List<Patient> findPatient(@RequiredParam(name = "str") StringParam theParam) {
|
||||
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
||||
|
||||
if (theParam.isExact() && theParam.getValue().equals("aaa")) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.dao;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
|
@ -16,19 +17,20 @@ import ca.uhn.fhir.rest.annotation.Update;
|
|||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
|
||||
public abstract class BaseResourceProvider<T extends IResource> implements IResourceProvider {
|
||||
public abstract class BaseJpaResourceProvider<T extends IResource> implements IResourceProvider {
|
||||
|
||||
private FhirContext myContext=new FhirContext();
|
||||
private IFhirResourceDao<T> myDao;
|
||||
|
||||
public void setDao(IFhirResourceDao<T> theDao) {
|
||||
myDao = theDao;
|
||||
}
|
||||
|
||||
@Read()
|
||||
public T read(@IdParam IdDt theId) {
|
||||
return myDao.read(theId);
|
||||
@Create
|
||||
public MethodOutcome create(@ResourceParam T theResource) {
|
||||
return myDao.create(theResource);
|
||||
}
|
||||
|
||||
public FhirContext getContext() {
|
||||
return myContext;
|
||||
}
|
||||
|
||||
public IFhirResourceDao<T> getDao() {
|
||||
return myDao;
|
||||
}
|
||||
|
@ -37,20 +39,24 @@ public abstract class BaseResourceProvider<T extends IResource> implements IReso
|
|||
public List<T> history(@IdParam IdDt theId) {
|
||||
return myDao.history(theId);
|
||||
}
|
||||
|
||||
@Read()
|
||||
public T read(@IdParam IdDt theId) {
|
||||
return myDao.read(theId);
|
||||
}
|
||||
|
||||
@Update
|
||||
public MethodOutcome update(@ResourceParam T theResource, @IdParam IdDt theId) {
|
||||
return myDao.update(theResource, theId);
|
||||
}
|
||||
|
||||
@Create
|
||||
public MethodOutcome create(@ResourceParam T theResource) {
|
||||
return myDao.create(theResource);
|
||||
}
|
||||
|
||||
@Search
|
||||
public List<T> search() {
|
||||
return myDao.search(new HashMap<String, IQueryParameterType>());
|
||||
}
|
||||
|
||||
public void setDao(IFhirResourceDao<T> theDao) {
|
||||
myDao = theDao;
|
||||
}
|
||||
|
||||
@Update
|
||||
public MethodOutcome update(@ResourceParam T theResource, @IdParam IdDt theId) {
|
||||
return myDao.update(theResource, theId);
|
||||
}
|
||||
|
||||
}
|
|
@ -71,7 +71,7 @@ import ca.uhn.fhir.rest.api.MethodOutcome;
|
|||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||
import ca.uhn.fhir.rest.param.QualifiedDateParam;
|
||||
import ca.uhn.fhir.rest.param.ReferenceParam;
|
||||
import ca.uhn.fhir.rest.param.StringParameter;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.server.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
|
@ -348,7 +348,7 @@ public class FhirResourceDao<T extends IResource, X extends BaseResourceTable<T>
|
|||
}
|
||||
|
||||
Predicate singleCode = builder.equal(from.get("myValueNormalized"), normalizeString(string));
|
||||
if (params instanceof StringParameter && ((StringParameter) params).isExact()) {
|
||||
if (params instanceof StringParam && ((StringParam) params).isExact()) {
|
||||
Predicate exactCode = builder.equal(from.get("myValueExact"), string);
|
||||
singleCode = builder.and(singleCode, exactCode);
|
||||
}
|
||||
|
@ -846,12 +846,12 @@ public class FhirResourceDao<T extends IResource, X extends BaseResourceTable<T>
|
|||
|
||||
@Override
|
||||
public List<T> search(Map<String, IQueryParameterType> theParams) {
|
||||
Map<String, List<List<IQueryParameterType>>> map = new HashMap<String, List<List<IQueryParameterType>>>();
|
||||
SearchParameterMap map = new SearchParameterMap();
|
||||
for (Entry<String, IQueryParameterType> nextEntry : theParams.entrySet()) {
|
||||
map.put(nextEntry.getKey(), new ArrayList<List<IQueryParameterType>>());
|
||||
map.get(nextEntry.getKey()).add(Collections.singletonList(nextEntry.getValue()));
|
||||
}
|
||||
return searchWithAndOr(map);
|
||||
return search(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -934,7 +934,7 @@ public class FhirResourceDao<T extends IResource, X extends BaseResourceTable<T>
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<T> searchWithAndOr(Map<String, List<List<IQueryParameterType>>> theParams) {
|
||||
public List<T> search(SearchParameterMap theParams) {
|
||||
|
||||
Set<Long> pids;
|
||||
if (theParams.isEmpty()) {
|
||||
|
|
|
@ -31,7 +31,7 @@ public interface IFhirResourceDao<T extends IResource> {
|
|||
|
||||
List<T> search(String theParameterName, IQueryParameterType theValue);
|
||||
|
||||
List<T> searchWithAndOr(Map<String, List<List<IQueryParameterType>>> theMap);
|
||||
List<T> search(SearchParameterMap theMap);
|
||||
|
||||
Class<T> getResourceType();
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package ca.uhn.fhir.jpa.dao;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import ca.uhn.fhir.model.api.IQueryParameterAnd;
|
||||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||
import ca.uhn.fhir.rest.method.QualifiedParamList;
|
||||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||
|
||||
public class SearchParameterMap extends HashMap<String, List<List<IQueryParameterType>>> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public void add(String theName, IQueryParameterType theParam) {
|
||||
if (!containsKey(theName)) {
|
||||
put(theName, new ArrayList<List<IQueryParameterType>>());
|
||||
}
|
||||
ArrayList<IQueryParameterType> list = new ArrayList<IQueryParameterType>();
|
||||
list.add(theParam);
|
||||
get(theName).add(list);
|
||||
}
|
||||
|
||||
public void add(String theName, IQueryParameterAnd theBirthdate) {
|
||||
if (!containsKey(theName)) {
|
||||
put(theName, new ArrayList<List<IQueryParameterType>>());
|
||||
}
|
||||
|
||||
for (QualifiedParamList next : theBirthdate.getValuesAsQueryTokens()) {
|
||||
next.get
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -41,7 +41,7 @@ import ca.uhn.fhir.model.primitive.StringDt;
|
|||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.param.QualifiedDateParam;
|
||||
import ca.uhn.fhir.rest.param.ReferenceParam;
|
||||
import ca.uhn.fhir.rest.param.StringParameter;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
|
||||
public class FhirResourceDaoTest {
|
||||
|
@ -197,7 +197,7 @@ public class FhirResourceDaoTest {
|
|||
map.put(Patient.SP_GENDER, new ArrayList<List<IQueryParameterType>>());
|
||||
map.get(Patient.SP_GENDER).add(new ArrayList<IQueryParameterType>());
|
||||
map.get(Patient.SP_GENDER).get(0).add(new IdentifierDt(null, "M"));
|
||||
found = ourPatientDao.searchWithAndOr(map);
|
||||
found = ourPatientDao.search(map);
|
||||
assertEquals(1, found.size());
|
||||
assertEquals(id, found.get(0).getId().asLong().longValue());
|
||||
|
||||
|
@ -208,7 +208,7 @@ public class FhirResourceDaoTest {
|
|||
map.put(Patient.SP_GENDER, new ArrayList<List<IQueryParameterType>>());
|
||||
map.get(Patient.SP_GENDER).add(new ArrayList<IQueryParameterType>());
|
||||
map.get(Patient.SP_GENDER).get(0).add(new IdentifierDt(null, "F"));
|
||||
found = ourPatientDao.searchWithAndOr(map);
|
||||
found = ourPatientDao.search(map);
|
||||
assertEquals(0, found.size());
|
||||
|
||||
}
|
||||
|
@ -410,7 +410,7 @@ public class FhirResourceDaoTest {
|
|||
List<Patient> patients = ourPatientDao.search(params);
|
||||
assertEquals(2, patients.size());
|
||||
|
||||
StringParameter parameter = new StringParameter("testSearchStringParamWithNonNormalized_hora");
|
||||
StringParam parameter = new StringParam("testSearchStringParamWithNonNormalized_hora");
|
||||
parameter.setExact(true);
|
||||
params.put(Patient.SP_FAMILY, parameter);
|
||||
patients = ourPatientDao.search(params);
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.BaseResourceProvider;
|
||||
import ca.uhn.fhir.jpa.dao.BaseJpaResourceProvider;
|
||||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.annotation.Description;
|
||||
|
@ -14,7 +14,7 @@ import ca.uhn.fhir.rest.annotation.OptionalParam;
|
|||
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
|
||||
public class PatientResourceProvider extends BaseResourceProvider<Patient> {
|
||||
public class PatientResourceProvider extends BaseJpaResourceProvider<Patient> {
|
||||
|
||||
@Override
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package ca.uhn.fhir.jpa.test;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.BaseResourceProvider;
|
||||
import ca.uhn.fhir.jpa.dao.BaseJpaResourceProvider;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.dstu.resource.Questionnaire;
|
||||
|
||||
public class QuestionnaireResourceProvider extends BaseResourceProvider<Questionnaire> {
|
||||
public class QuestionnaireResourceProvider extends BaseJpaResourceProvider<Questionnaire> {
|
||||
|
||||
@Override
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
|
||||
<classpathentry kind="src" path="target/gen"/>
|
||||
<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
|
||||
<classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
|
||||
<classpathentry kind="var" path="M2_REPO/javax/json/javax.json-api/1.0/javax.json-api-1.0.jar" sourcepath="M2_REPO/javax/json/javax.json-api/1.0/javax.json-api-1.0-sources.jar"/>
|
||||
|
@ -92,5 +93,6 @@
|
|||
<classpathentry kind="var" path="M2_REPO/org/codehaus/plexus/plexus-classworlds/2.4/plexus-classworlds-2.4.jar" sourcepath="M2_REPO/org/codehaus/plexus/plexus-classworlds/2.4/plexus-classworlds-2.4-sources.jar"/>
|
||||
<classpathentry kind="var" path="M2_REPO/org/apache/maven/plugin-tools/maven-plugin-annotations/3.2/maven-plugin-annotations-3.2.jar" sourcepath="M2_REPO/org/apache/maven/plugin-tools/maven-plugin-annotations/3.2/maven-plugin-annotations-3.2-sources.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/hapi-fhir-base"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/hapi-fhir-jpaserver-base"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -29,6 +29,8 @@ import ca.uhn.fhir.rest.client.api.IBasicClient;
|
|||
import ca.uhn.fhir.tinder.model.BaseRootType;
|
||||
import ca.uhn.fhir.tinder.model.RestResourceTm;
|
||||
import ca.uhn.fhir.tinder.model.SearchParameter;
|
||||
import ca.uhn.fhir.tinder.parser.ProfileParser;
|
||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
||||
|
||||
@Mojo(name = "generate-client", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
|
||||
public class TinderClientMojo extends AbstractMojo {
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
package ca.uhn.fhir.tinder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.ParseException;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance.Rest;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance.RestResource;
|
||||
import ca.uhn.fhir.model.dstu.resource.Profile;
|
||||
import ca.uhn.fhir.model.dstu.valueset.RestfulConformanceModeEnum;
|
||||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.tinder.model.BaseRootType;
|
||||
import ca.uhn.fhir.tinder.model.RestResourceTm;
|
||||
import ca.uhn.fhir.tinder.model.SearchParameter;
|
||||
import ca.uhn.fhir.tinder.parser.ProfileParser;
|
||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
||||
import edu.emory.mathcs.backport.java.util.Collections;
|
||||
|
||||
@Mojo(name = "generate-jparest-server", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
|
||||
public class TinderJpaRestServerMojo extends AbstractMojo {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TinderJpaRestServerMojo.class);
|
||||
|
||||
@Parameter(required = true, defaultValue = "${project.build.directory}/generated-sources/tinder")
|
||||
private File targetDirectory;
|
||||
|
||||
@Parameter(required = true)
|
||||
private String packageBase;
|
||||
|
||||
@Parameter(required = true)
|
||||
private List<String> resources;
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
|
||||
File directoryBase = new File(targetDirectory, packageBase.replace(".", File.separatorChar + ""));
|
||||
directoryBase.mkdirs();
|
||||
|
||||
ResourceGeneratorUsingSpreadsheet gen = new ResourceGeneratorUsingSpreadsheet();
|
||||
gen.setBaseResourceNames(resources);
|
||||
|
||||
gen.setFilenameSuffix("ResourceProvider");
|
||||
gen.setTemplate("/vm/jpa_resource_provider.vm");
|
||||
|
||||
try {
|
||||
gen.parse();
|
||||
gen.writeAll(directoryBase, packageBase);
|
||||
} catch (Exception e) {
|
||||
throw new MojoFailureException("Failed to generate server",e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void write() throws IOException {
|
||||
// File directoryBase;
|
||||
// directoryBase.mkdirs();
|
||||
//
|
||||
// File file = new File(directoryBase, myClientClassSimpleName + ".java");
|
||||
// FileWriter w = new FileWriter(file, false);
|
||||
//
|
||||
// ourLog.info("Writing file: {}", file.getAbsolutePath());
|
||||
//
|
||||
// VelocityContext ctx = new VelocityContext();
|
||||
// ctx.put("packageBase", packageBase);
|
||||
// ctx.put("className", myClientClassSimpleName);
|
||||
// ctx.put("resources", myResources);
|
||||
//
|
||||
// VelocityEngine v = new VelocityEngine();
|
||||
// v.setProperty("resource.loader", "cp");
|
||||
// v.setProperty("cp.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
||||
// v.setProperty("runtime.references.strict", Boolean.TRUE);
|
||||
//
|
||||
// InputStream templateIs = ResourceGeneratorUsingSpreadsheet.class.getResourceAsStream("/vm/client.vm");
|
||||
// InputStreamReader templateReader = new InputStreamReader(templateIs);
|
||||
// v.evaluate(ctx, w, "", templateReader);
|
||||
//
|
||||
// w.close();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws ParseException, IOException, MojoFailureException, MojoExecutionException {
|
||||
|
||||
// PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
||||
// HttpClientBuilder builder = HttpClientBuilder.create();
|
||||
// builder.setConnectionManager(connectionManager);
|
||||
// CloseableHttpClient client = builder.build();
|
||||
//
|
||||
// HttpGet get = new HttpGet("http://fhir.healthintersections.com.au/open/metadata");
|
||||
// CloseableHttpResponse response = client.execute(get);
|
||||
//
|
||||
// String metadataString = EntityUtils.toString(response.getEntity());
|
||||
//
|
||||
// ourLog.info("Metadata String: {}", metadataString);
|
||||
|
||||
// String metadataString = IOUtils.toString(new FileInputStream("src/test/resources/healthintersections-metadata.xml"));
|
||||
// Conformance conformance = new FhirContext(Conformance.class).newXmlParser().parseResource(Conformance.class, metadataString);
|
||||
|
||||
TinderJpaRestServerMojo mojo = new TinderJpaRestServerMojo();
|
||||
mojo.packageBase = "ca.uhn.test";
|
||||
mojo.resources =java.util.Collections.singletonList("patient");
|
||||
mojo.targetDirectory = new File("target/gen");
|
||||
mojo.execute();
|
||||
}
|
||||
|
||||
}
|
|
@ -16,6 +16,9 @@ import org.apache.maven.plugins.annotations.Mojo;
|
|||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import ca.uhn.fhir.tinder.parser.DatatypeGeneratorUsingSpreadsheet;
|
||||
import ca.uhn.fhir.tinder.parser.ProfileParser;
|
||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
||||
import edu.emory.mathcs.backport.java.util.Collections;
|
||||
|
||||
@Mojo(name = "generate-structures", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
|
||||
|
|
|
@ -32,6 +32,7 @@ import ca.uhn.fhir.model.primitive.CodeDt;
|
|||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
|
||||
import ca.uhn.fhir.tinder.model.ValueSetTm;
|
||||
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
|
||||
|
||||
public class ValueSetGenerator {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.uhn.fhir.tinder;
|
||||
package ca.uhn.fhir.tinder.parser;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.defaultString;
|
||||
import static org.apache.commons.lang.StringUtils.isNotBlank;
|
||||
|
@ -31,6 +31,8 @@ import ca.uhn.fhir.model.api.ExtensionDt;
|
|||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.annotation.SimpleSetter;
|
||||
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
|
||||
import ca.uhn.fhir.tinder.TinderStructuresMojo;
|
||||
import ca.uhn.fhir.tinder.ValueSetGenerator;
|
||||
import ca.uhn.fhir.tinder.model.BaseElement;
|
||||
import ca.uhn.fhir.tinder.model.BaseRootType;
|
||||
import ca.uhn.fhir.tinder.model.Child;
|
||||
|
@ -274,9 +276,9 @@ public abstract class BaseStructureParser {
|
|||
if (theResource.getDeclaringClassNameComplete() != null) {
|
||||
ctx.put("className", theResource.getDeclaringClassNameComplete());
|
||||
} else {
|
||||
ctx.put("className", translateClassName(theResource.getName()));
|
||||
ctx.put("className", (theResource.getName()));
|
||||
} // HumanName}
|
||||
ctx.put("classNameComplete", translateClassName(theResource.getName()) + getFilenameSuffix()); // HumanNameDt
|
||||
ctx.put("classNameComplete", (theResource.getName()) + getFilenameSuffix()); // HumanNameDt
|
||||
ctx.put("shortName", defaultString(theResource.getShortName()));
|
||||
ctx.put("definition", defaultString(theResource.getDefinition()));
|
||||
ctx.put("requirements", defaultString(theResource.getRequirement()));
|
||||
|
@ -328,7 +330,8 @@ public abstract class BaseStructureParser {
|
|||
scanForTypeNameConflicts(next);
|
||||
fixResourceReferenceClassNames(next, thePackageBase);
|
||||
|
||||
File f = new File(theOutputDirectory, translateClassName(next.getDeclaringClassNameComplete()) /*+ getFilenameSuffix()*/ + ".java");
|
||||
// File f = new File(theOutputDirectory, (next.getDeclaringClassNameComplete()) /*+ getFilenameSuffix()*/ + ".java");
|
||||
File f = new File(theOutputDirectory, (next.getElementName()) + getFilenameSuffix() + ".java");
|
||||
try {
|
||||
write(next, f, thePackageBase);
|
||||
} catch (IOException e) {
|
||||
|
@ -344,10 +347,6 @@ public abstract class BaseStructureParser {
|
|||
// return theName;
|
||||
// }
|
||||
|
||||
private String translateClassName(String theName) {
|
||||
return theName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: Encounter has an internal block class named "Location", but it
|
||||
* also has a reference to the Location resource type, so we need to use the
|
|
@ -1,4 +1,4 @@
|
|||
package ca.uhn.fhir.tinder;
|
||||
package ca.uhn.fhir.tinder.parser;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
|
@ -1,4 +1,4 @@
|
|||
package ca.uhn.fhir.tinder;
|
||||
package ca.uhn.fhir.tinder.parser;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
|
@ -1,4 +1,4 @@
|
|||
package ca.uhn.fhir.tinder;
|
||||
package ca.uhn.fhir.tinder.parser;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.capitalize;
|
||||
import static org.apache.commons.lang.StringUtils.isBlank;
|
|
@ -1,10 +1,9 @@
|
|||
package ca.uhn.fhir.tinder;
|
||||
package ca.uhn.fhir.tinder.parser;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
|
@ -15,14 +14,55 @@ import ca.uhn.fhir.tinder.model.Resource;
|
|||
|
||||
|
||||
public class ResourceGeneratorUsingSpreadsheet extends BaseStructureSpreadsheetParser {
|
||||
|
||||
|
||||
private ArrayList<InputStream> myInputStreams;
|
||||
private String myFilenameSuffix = "";
|
||||
private List<String> myInputStreamNames;
|
||||
private ArrayList<InputStream> myInputStreams;
|
||||
private String myTemplate="/vm/resource.vm";
|
||||
|
||||
public List<String> getInputStreamNames() {
|
||||
return myInputStreamNames;
|
||||
}
|
||||
|
||||
public void setBaseResourceNames(List<String> theBaseResourceNames) throws MojoFailureException {
|
||||
myInputStreamNames = theBaseResourceNames;
|
||||
myInputStreams = new ArrayList<InputStream>();
|
||||
|
||||
for (String next : theBaseResourceNames) {
|
||||
InputStream nextRes = getClass().getResourceAsStream("/res/" + next + "-spreadsheet.xml");
|
||||
myInputStreams.add(nextRes);
|
||||
if (nextRes == null) {
|
||||
throw new MojoFailureException("Unknown base resource name: " + next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setFilenameSuffix(String theFilenameSuffix) {
|
||||
myFilenameSuffix = theFilenameSuffix;
|
||||
}
|
||||
|
||||
public void setTemplate(String theTemplate) {
|
||||
myTemplate = theTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseRootType createRootType() {
|
||||
return new Resource();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getFilenameSuffix() {
|
||||
return myFilenameSuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<InputStream> getInputStreams() {
|
||||
return myInputStreams;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTemplate() {
|
||||
return "/vm/resource.vm";
|
||||
return myTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,12 +70,6 @@ public class ResourceGeneratorUsingSpreadsheet extends BaseStructureSpreadsheetP
|
|||
return theFileName.endsWith("spreadsheet.xml");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFilenameSuffix() {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ResourceGeneratorUsingSpreadsheet p = new ResourceGeneratorUsingSpreadsheet();
|
||||
ArrayList<String> names = new ArrayList<String>();
|
||||
|
@ -142,31 +176,4 @@ public class ResourceGeneratorUsingSpreadsheet extends BaseStructureSpreadsheetP
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<InputStream> getInputStreams() {
|
||||
return myInputStreams;
|
||||
}
|
||||
|
||||
public void setBaseResourceNames(List<String> theBaseResourceNames) throws MojoFailureException {
|
||||
myInputStreamNames = theBaseResourceNames;
|
||||
myInputStreams = new ArrayList<InputStream>();
|
||||
|
||||
for (String next : theBaseResourceNames) {
|
||||
InputStream nextRes = getClass().getResourceAsStream("/res/" + next + "-spreadsheet.xml");
|
||||
myInputStreams.add(nextRes);
|
||||
if (nextRes == null) {
|
||||
throw new MojoFailureException("Unknown base resource name: " + next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getInputStreamNames() {
|
||||
return myInputStreamNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseRootType createRootType() {
|
||||
return new Resource();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +1,54 @@
|
|||
|
||||
package ${packageBase};
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.BaseJpaResourceProvider;
|
||||
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import ca.uhn.fhir.model.api.annotation.*;
|
||||
import ca.uhn.fhir.model.dstu.composite.*;
|
||||
import ca.uhn.fhir.model.dstu.resource.*;
|
||||
import ca.uhn.fhir.rest.annotation.*;
|
||||
import ca.uhn.fhir.rest.param.*;
|
||||
|
||||
public class ${className}ResourceTable extends BaseResourceTable<${className}> {
|
||||
|
||||
@Entity
|
||||
@DiscriminatorValue("${className}")
|
||||
public class PatientResourceTable extends BaseResourceTable<Patient> {
|
||||
public class ${className}ResourceProvider extends BaseJpaResourceProvider<${className}> {
|
||||
|
||||
@Override
|
||||
public Class<${className}> getResourceType() {
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
return ${className}.class;
|
||||
}
|
||||
|
||||
@Search()
|
||||
List<${className}> search(
|
||||
#foreach ( $param in $searchParams ) #{if}(true) #{end}
|
||||
|
||||
@Description(shortDefinition="${param.description}")
|
||||
@OptionalParam(name="${param.name}")
|
||||
#if (${param.type} == 'string' )
|
||||
StringParam the${param.nameCapitalized} #{if}($foreach.hasNext), #{end}
|
||||
#elseif (${param.type} == 'token' )
|
||||
IdentifierDt the${param.nameCapitalized} #{if}($foreach.hasNext), #{end}
|
||||
#elseif (${param.type} == 'date' )
|
||||
DateRangeParam the${param.nameCapitalized} #{if}($foreach.hasNext), #{end}
|
||||
#elseif (${param.type} == 'quantity' )
|
||||
QuantityDt the${param.nameCapitalized} #{if}($foreach.hasNext), #{end}
|
||||
#elseif (${param.type} == 'number' )
|
||||
QuantityDt the${param.nameCapitalized} #{if}($foreach.hasNext), #{end}
|
||||
#elseif (${param.type} == 'reference' )
|
||||
ReferenceParam the${param.nameCapitalized} #{if}($foreach.hasNext), #{end}
|
||||
#end
|
||||
#end
|
||||
) {
|
||||
SearchParameterMap paramMap = new SearchParameterMap();
|
||||
|
||||
#foreach ( $param in $searchParams )
|
||||
paramMap.add("${param.name}", the${param.nameCapitalized});
|
||||
#end
|
||||
|
||||
return getDao().search(paramMap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,44 +4,16 @@ package ${packageBase};
|
|||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import ca.uhn.fhir.model.dstu.resource.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.BaseResourceProvider;
|
||||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.annotation.Description;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.rest.annotation.OptionalParam;
|
||||
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
public class ${className}ResourceTable extends BaseResourceTable<${className}> {
|
||||
|
||||
|
||||
public class ${className}ResourceProvider extends BaseResourceProvider<${className}> {
|
||||
@Entity
|
||||
@DiscriminatorValue("${className}")
|
||||
public class PatientResourceTable extends BaseResourceTable<Patient> {
|
||||
|
||||
@Override
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
public Class<${className}> getResourceType() {
|
||||
return ${className}.class;
|
||||
}
|
||||
|
||||
#foreach ( $param in $searchParams )
|
||||
@Description(shortDefinition="${param.description}")
|
||||
@OptionalParam(name="${param.name}")
|
||||
#if (${param.type} == 'string' )
|
||||
StringParam the${param.nameCapitalized} #{if}($foreach.hasNext), #{end}
|
||||
#elseif (${param.type} == 'token' )
|
||||
IdentifierDt the${param.nameCapitalized} #{if}($foreach.hasNext), #{end}
|
||||
#elseif (${param.type} == 'date' )
|
||||
DateRangeParam the${param.nameCapitalized} #{if}($foreach.hasNext), #{end}
|
||||
#elseif (${param.type} == 'quantity' )
|
||||
QuantityDt the${param.nameCapitalized} #{if}($foreach.hasNext), #{end}
|
||||
#elseif (${param.type} == 'number' )
|
||||
QuantityDt the${param.nameCapitalized} #{if}($foreach.hasNext), #{end}
|
||||
#elseif (${param.type} == 'reference' )
|
||||
ReferenceParam the${param.nameCapitalized} #{if}($foreach.hasNext), #{end}
|
||||
#end
|
||||
#end
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue