Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Commit c36bcd2

Browse files
authored
Merge pull request #13 from jiyer-nmdp/develop
Develop
2 parents f28b454 + 4086047 commit c36bcd2

File tree

19 files changed

+510
-59
lines changed

19 files changed

+510
-59
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2020 Be The Match operated by National Marrow Donor Program (NMDP).
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed
11+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
12+
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for
13+
* the specific language governing permissions and limitations under the License.
14+
*/
15+
16+
package org.nmdp.config;
17+
18+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
19+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
20+
21+
public class WebConfig implements WebMvcConfigurer {
22+
@Override
23+
public void addCorsMappings(CorsRegistry registry) {
24+
registry.addMapping("/**");
25+
}
26+
}

src/main/java/org/nmdp/controller/TarrInputController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ public class TarrInputController implements TarrApi {
3838

3939
@RequestMapping(path = "/convert2Fhir", headers="Accept=application/xml", consumes = MediaType.APPLICATION_XML_VALUE, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE, method = RequestMethod.POST)
4040
@ResponseBody
41-
public ResponseEntity<String> tarr2fhir(@ApiParam(value = "" ,required=true ) @Valid @RequestBody String xml) {
41+
public ResponseEntity<String> tarr2fhir(@ApiParam(value = "" ,required=true ) @Valid @RequestBody String xml, @RequestParam String labName, @RequestParam String reportingCenter, @RequestParam String sampleType, @RequestParam String crid, @RequestParam String relationship) {
4242
try {
4343
ParseInputFiles aParser = new ParseInputFiles();
4444
List<String> aXmlInput = new ArrayList<>();
4545
aXmlInput.add(xml);
4646
aParser.setMyInputFiles(aXmlInput);
47+
aParser.setMetaData(labName, reportingCenter, sampleType, crid, relationship);
4748
aParser.process();
4849
if (aParser.getMyFhirBundleOutput() == null)
4950
return new ResponseEntity<>("Errors" , HttpStatus.PAYMENT_REQUIRED);
@@ -53,15 +54,14 @@ public ResponseEntity<String> tarr2fhir(@ApiParam(value = "" ,required=true ) @
5354
{
5455
return new ResponseEntity<>("Errors" , HttpStatus.INTERNAL_SERVER_ERROR);
5556
}
56-
5757
}
5858

5959
@RequestMapping(value = "/convertZip",
6060
produces = {"application/json"},
6161
headers = "Accept=*",
6262
method = RequestMethod.POST)
6363
@ResponseBody
64-
public ResponseEntity<String> tarr2fhirmulti(@ApiParam(value = "The file to upload.") @Valid @RequestPart(value="upfile", required=false) MultipartFile upfile) {
64+
public ResponseEntity<String> tarr2fhirmulti(@ApiParam(value = "The file to upload.") @Valid @RequestPart(value="upfile", required=false) MultipartFile upfile, @RequestParam String labName, @RequestParam String reportingCenter, @RequestParam String sampleType, @RequestParam String crid, @RequestParam String relationship) {
6565
try {
6666
MultipartFile aMPF = (MultipartFile)upfile;
6767
if (aMPF.isEmpty())
@@ -70,6 +70,8 @@ public ResponseEntity<String> tarr2fhirmulti(@ApiParam(value = "The file to uplo
7070
ParseInputFiles aParser = new ParseInputFiles();
7171
ZipFile aZipFile = new ZipFile(convert(aMPF));
7272
aParser.unzipFile(aZipFile);
73+
aParser.setMetaData(labName, reportingCenter, sampleType, crid, relationship);
74+
aParser.process();
7375
return new ResponseEntity<>(aParser.getMyFhirBundleOutput(), HttpStatus.OK);
7476
}
7577
catch (Exception e)

src/main/java/org/nmdp/fhirconversion/FhirGenerator.java

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515

1616
package org.nmdp.fhirconversion;
1717

18-
import org.hl7.fhir.r4.model.DiagnosticReport;
19-
import org.hl7.fhir.r4.model.Identifier;
20-
import org.hl7.fhir.r4.model.Observation;
21-
import org.hl7.fhir.r4.model.Reference;
18+
import org.hl7.fhir.r4.model.*;
2219
import org.modelmapper.ModelMapper;
2320
import org.nmdp.fhirsubmission.hapi.models.*;
2421
import org.nmdp.mapping.DiagnosticReportMap;
22+
import org.nmdp.mapping.SpecimenMap;
2523
import org.nmdp.tarrbean.SampleBean;
24+
import org.springframework.util.StringUtils;
2625

2726
import java.util.ArrayList;
2827
import java.util.List;
@@ -36,9 +35,25 @@ public void generateFhirBundle(SampleBean theSampleBean)
3635
{
3736
myBundleResource = new BundleResource();
3837
List<String> aProvenanceReferences = new ArrayList<>();
38+
39+
/**
40+
* Generate Organization Resources from Meta-data input in UI
41+
*/
42+
43+
OrganizationResources aOrgResources = new OrganizationResources();
44+
if (!StringUtils.isEmpty(theSampleBean.getMyLabName()) && !theSampleBean.getMyLabName().equals("undefined"))
45+
{
46+
aOrgResources.generateOrganization("Lab (Performer)", theSampleBean.getMyLabName(), aProvenanceReferences);
47+
}
48+
49+
if (!StringUtils.isEmpty(theSampleBean.getMyReportingCenter()) && !theSampleBean.getMyReportingCenter().equals("undefined"))
50+
{
51+
aOrgResources.generateOrganization("Reporting Organization ", theSampleBean.getMyReportingCenter(), aProvenanceReferences);
52+
}
53+
3954
/*
40-
* Generate MolecularSequences from xml
41-
* */
55+
* Generate MolecularSequences from xml
56+
* */
4257
MolecularSequences aMS = new MolecularSequences();
4358
aMS.generateMolecularSequences(theSampleBean, aProvenanceReferences);
4459

@@ -62,13 +77,25 @@ public void generateFhirBundle(SampleBean theSampleBean)
6277
diagnosticReport.setSubject(new Reference().setIdentifier(aSpecimenId));
6378
aProvenanceReferences.add(diagnosticReport.getIdElement().getValue());
6479

80+
Specimen aSpecimen = mapper.map(theSampleBean, Specimen.class);
81+
aProvenanceReferences.add(aSpecimen.getIdElement().getValue());
82+
83+
// Patient aPatient = mapper.map(theSampleBean, Patient.class);
84+
// aProvenanceReferences.add(aPatient.getIdElement().getValue());
85+
6586
DeviceResource aDR = new DeviceResource();
6687
aDR.generateDeviceResource(aProvenanceReferences);
6788

6889
ProvenanceResource aPR = new ProvenanceResource();
6990
aPR.generateProvenanceResource(aProvenanceReferences);
91+
aPR.setAgent(aDR.getMyDevice().getIdElement().getValue());
7092

7193
myBundleResource.addSequences(aMS.getMyMolecularSequences());
94+
myBundleResource.addResource(aSpecimen);
95+
//myBundleResource.addResource(aPatient);
96+
aOrgResources.getMyOrganizations().stream().filter(Objects::nonNull)
97+
.forEach(aOrg -> myBundleResource.addResource(aOrg));
98+
// myBundleResource.addResource(aReportingCenterOrganization.getMyOrganization());
7299
myBundleResource.addObservations(observations);
73100
myBundleResource.addResource(diagnosticReport);
74101
myBundleResource.addResource(aDR.getMyDevice());
@@ -89,6 +116,7 @@ public BundleResource getMyBundleResource() {
89116
protected ModelMapper createMapper() {
90117
ModelMapper aMapper = new ModelMapper();
91118
aMapper.addConverter(new DiagnosticReportMap());
119+
aMapper.addConverter(new SpecimenMap());
92120
return aMapper;
93121
}
94122
}

src/main/java/org/nmdp/fhirconversion/ParseInputFiles.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public void unzipFile(ZipFile aZipFile)
9898
e.printStackTrace();
9999
}
100100
}
101-
process();
102101
}
103102

104103
public void process()
@@ -108,4 +107,13 @@ public void process()
108107
setupFhir();
109108
}
110109

110+
public void setMetaData(String theLabName, String theReportingCenter, String theSampleType, String crid, String relationship)
111+
{
112+
mySampleBean.setMyLabName(theLabName);
113+
mySampleBean.setMyReportingCenter(theReportingCenter);
114+
mySampleBean.setMySampleType(theSampleType);
115+
mySampleBean.setMyCrid(crid);
116+
mySampleBean.setMyRelationship(relationship);
117+
}
118+
111119
}

src/main/java/org/nmdp/fhirsubmission/hapi/models/DeviceResource.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ public void generateDeviceResource(List<String> theProvenanceReferences)
4242
myDevice.setDeviceName(aDNameList);
4343
myDevice.setText((new NarrativeText()).
4444
getNarrative("software device: Tarr2Fhir"));
45+
List<Device.DeviceVersionComponent> deviceVersions = new ArrayList<>();
46+
Device.DeviceVersionComponent aDeviceVersion = new Device.DeviceVersionComponent();
47+
aDeviceVersion.setValue("1.0");
48+
deviceVersions.add(aDeviceVersion);
49+
myDevice.setVersion(deviceVersions);
4550
myDevice.setId(FhirGuid.genereateUrn());
46-
theProvenanceReferences.add(myDevice.getIdElement().getValue());
47-
4851
}
4952
}

src/main/java/org/nmdp/fhirsubmission/hapi/models/IdentifierSetup.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ public List<Identifier> getIdentifiers()
2929
}
3030
public IdentifierSetup(String theSampleId, String thePatientType, String theCenterCode)
3131
{
32+
myIdentifiers = new ArrayList<>();
3233
if (thePatientType.equals("RECIPIENT"))
3334
{
3435
setCridIdentifier(theSampleId, thePatientType, theCenterCode);
3536
}
3637
setHmlSampleIdentifier(theSampleId, thePatientType, theCenterCode);
3738
}
39+
40+
public IdentifierSetup()
41+
{
42+
myIdentifiers = new ArrayList<>();
43+
}
3844
public void setHmlSampleIdentifier(String theSampleId, String thePatientType, String theCenterCode)
3945
{
4046
Identifier aSampleIdentifier = new Identifier();
@@ -66,10 +72,10 @@ public void setCridIdentifier(String theSampleId, String thePatientType, String
6672

6773
}
6874

69-
public void setOrganizationIdentifier(String theSampleId, String thePatientType, String theCenterCode)
75+
public void setHmlOrganizationIdentifier(String theSampleId, String thePatientType, String theCenterCode)
7076
{
7177
Identifier aSampleIdentifier = new Identifier();
72-
aSampleIdentifier.setSystem("http://nmdp.org/identifier/hml-sample");
78+
aSampleIdentifier.setSystem("http://terminology.nmdp.org/identifier/hml-sample");
7379
aSampleIdentifier.setValue(theSampleId);
7480

7581
CodeableConcept aCodableConcept = new CodeableConcept();
@@ -91,4 +97,30 @@ public void setOrganizationIdentifier(String theSampleId, String thePatientType,
9197
aSampleIdentifier.setExtension(aExtensionList);
9298
myIdentifiers.add(aSampleIdentifier);
9399
}
100+
101+
public void setOrganizationIdentifier(String theType, String theValue)
102+
{
103+
Identifier aSampleIdentifier = new Identifier();
104+
aSampleIdentifier.setSystem("http://terminology.nmdp.org/identifier/"+theType);
105+
aSampleIdentifier.setValue(theValue);
106+
107+
// CodeableConcept aCodableConcept = new CodeableConcept();
108+
// Coding aCoding = new Coding();
109+
// aCoding.setSystem("http://terminology.cibmtr.org/codesystem/subject-type");
110+
// aCoding.setCode(thePatientType);
111+
// List<Coding> aCodingList = new ArrayList<>();
112+
// aCodingList.add(aCoding);
113+
// aCodableConcept.setCoding(aCodingList);
114+
// aSampleIdentifier.setType(aCodableConcept);
115+
//
116+
// Extension aExtension = new Extension();
117+
// List<Extension> aExtensionList = new ArrayList<>();
118+
// aExtension.setUrl("http://hl7.org/fhir/StructureDefinition/rendered-value");
119+
// aExtension.addChild("valueString");
120+
// aExtension.setValue(new StringType(String.format("< sample id=%s center-code=%s >", theSampleId, theCenterCode)));
121+
// aExtensionList.add(aExtension);
122+
//
123+
// aSampleIdentifier.setExtension(aExtensionList);
124+
myIdentifiers.add(aSampleIdentifier);
125+
}
94126
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.nmdp.fhirsubmission.hapi.models;
2+
3+
import org.hl7.fhir.r4.model.Organization;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class OrganizationResources
9+
{
10+
private List<Organization> myOrganizations;
11+
12+
public OrganizationResources(){myOrganizations = new ArrayList<>();
13+
}
14+
15+
public List<Organization> getMyOrganizations() {
16+
return myOrganizations;
17+
}
18+
19+
public void generateOrganization(String theType, String theIdentifer, List<String> theProvenanceReferences)
20+
{
21+
Organization aOrg = new Organization();
22+
aOrg.setText((new NarrativeText()).
23+
getNarrative("Organization: " +theType +" " + theIdentifer ));
24+
aOrg.setId(FhirGuid.genereateUrn());
25+
IdentifierSetup aIS = new IdentifierSetup();
26+
aIS.setOrganizationIdentifier(theType, theIdentifer);
27+
aOrg.setIdentifier(aIS.getIdentifiers());
28+
theProvenanceReferences.add(aOrg.getIdElement().getValue());
29+
myOrganizations.add(aOrg);
30+
}
31+
}

src/main/java/org/nmdp/fhirsubmission/hapi/models/ProvenanceResource.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.hl7.fhir.r4.model.Provenance;
1919
import org.hl7.fhir.r4.model.Reference;
2020

21+
import java.util.ArrayList;
2122
import java.util.List;
2223
import java.util.Objects;
2324

@@ -40,4 +41,13 @@ public void generateProvenanceResource(List<String> theReferences)
4041
theReferences.stream().filter(Objects::nonNull)
4142
.forEach(aRefString -> myProvenance.addTarget(new Reference(aRefString)));
4243
}
44+
45+
public void setAgent(String theDeviceResource)
46+
{
47+
List<Provenance.ProvenanceAgentComponent> aProvAgents = new ArrayList<>();
48+
Provenance.ProvenanceAgentComponent aProvAgent = new Provenance.ProvenanceAgentComponent();
49+
aProvAgent.setWho(new Reference(theDeviceResource));
50+
aProvAgents.add(aProvAgent);
51+
myProvenance.setAgent(aProvAgents);
52+
}
4353
}

0 commit comments

Comments
 (0)