-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1175 from usnistgov/feature/multiple-fixes-pre-de…
…ployment Feature/multiple fixes pre deployment
- Loading branch information
Showing
58 changed files
with
3,095 additions
and
2,444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
bootstrap/src/main/java/gov/nist/hit/hl7/igamt/bootstrap/data/CodeFixer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** | ||
* This software was developed at the National Institute of Standards and Technology by employees of | ||
* the Federal Government in the course of their official duties. Pursuant to title 17 Section 105 | ||
* of the United States Code this software is not subject to copyright protection and is in the | ||
* public domain. This is an experimental system. NIST assumes no responsibility whatsoever for its | ||
* use by other parties, and makes no guarantees, expressed or implied, about its quality, | ||
* reliability, or any other characteristic. We would appreciate acknowledgement if the software is | ||
* used. This software can be redistributed and/or modified freely provided that any derivative | ||
* works bear some notice that they are derived from it, and any modified versions bear some notice | ||
* that they have been modified. | ||
*/ | ||
package gov.nist.hit.hl7.igamt.bootstrap.data; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.util.ResourceUtils; | ||
|
||
import com.opencsv.CSVReader; | ||
|
||
import gov.nist.hit.hl7.igamt.common.base.domain.Scope; | ||
import gov.nist.hit.hl7.igamt.datatype.repository.DatatypeRepository; | ||
import gov.nist.hit.hl7.igamt.valueset.domain.Valueset; | ||
import gov.nist.hit.hl7.igamt.valueset.service.ValuesetService; | ||
|
||
/** | ||
* @author Abdelghani El Ouakili | ||
* | ||
*/ | ||
@Service | ||
public class CodeFixer { | ||
|
||
@Autowired | ||
private DatatypeRepository datatypeRepository; | ||
|
||
@Autowired | ||
private ValuesetService valueSetService; | ||
|
||
public void fixTableHL70125() { | ||
List<Valueset> vss = valueSetService.findByDomainInfoScopeAndBindingIdentifier(Scope.HL7STANDARD.toString(), "HL70125"); | ||
|
||
for(Valueset vs: vss) { | ||
vs.getCodes().removeIf((x) -> !datatypeRepository.existsByNameAndDomainInfoScopeAndDomainInfoVersion(x.getValue(), Scope.HL7STANDARD, vs.getDomainInfo().getVersion())); | ||
vs.setNumberOfCodes(vs.getCodes().size()); | ||
valueSetService.save(vs); | ||
|
||
} | ||
} | ||
|
||
public void fixFromCSV() throws FileNotFoundException { | ||
|
||
File file = ResourceUtils.getFile("classpath:deprecatedCodes.csv"); | ||
System.out.println(file.exists()); | ||
CSVReader reader = null; | ||
Map<String, Set<String>> map = new HashMap<String, Set<String>>(); | ||
try { | ||
reader = new CSVReader(new FileReader(file)); | ||
String[] line1= reader.readNext(); | ||
while ((line1 = reader.readNext()) != null) { | ||
String id = line1[1]+"V"+line1[0].replaceAll("\\.", "-"); | ||
if(map.containsKey(id)) { | ||
Set<String> codes = map.get(id); | ||
if(codes != null) { | ||
codes.add(line1[2]); | ||
} | ||
|
||
}else { | ||
Set<String> codes = new HashSet<String>(); | ||
codes.add(line1[2]); | ||
map.put(id, codes); | ||
} | ||
|
||
} | ||
fix(map); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
/** | ||
* @param map | ||
*/ | ||
private void fix(Map<String, Set<String>> map) { | ||
// TODO Auto-generated method stub | ||
List<Valueset> valuesets= valueSetService.findByIdIn(map.keySet()); | ||
|
||
valuesets.forEach(x -> { | ||
x.getCodes().forEach((c) -> { | ||
if(map.get(x.getId()).contains(c.getValue())) { | ||
c.setDeprecated(true); | ||
} | ||
}); | ||
valueSetService.save(x); | ||
}); | ||
} | ||
|
||
} |
103 changes: 103 additions & 0 deletions
103
bootstrap/src/main/java/gov/nist/hit/hl7/igamt/bootstrap/data/DynamicMappingFixer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* This software was developed at the National Institute of Standards and Technology by employees of | ||
* the Federal Government in the course of their official duties. Pursuant to title 17 Section 105 | ||
* of the United States Code this software is not subject to copyright protection and is in the | ||
* public domain. This is an experimental system. NIST assumes no responsibility whatsoever for its | ||
* use by other parties, and makes no guarantees, expressed or implied, about its quality, | ||
* reliability, or any other characteristic. We would appreciate acknowledgement if the software is | ||
* used. This software can be redistributed and/or modified freely provided that any derivative | ||
* works bear some notice that they are derived from it, and any modified versions bear some notice | ||
* that they have been modified. | ||
*/ | ||
package gov.nist.hit.hl7.igamt.bootstrap.data; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import gov.nist.hit.hl7.igamt.common.base.domain.Scope; | ||
import gov.nist.hit.hl7.igamt.common.base.domain.ValuesetBinding; | ||
import gov.nist.hit.hl7.igamt.common.binding.domain.StructureElementBinding; | ||
import gov.nist.hit.hl7.igamt.datatype.domain.Datatype; | ||
import gov.nist.hit.hl7.igamt.datatype.service.DatatypeService; | ||
import gov.nist.hit.hl7.igamt.segment.domain.DynamicMappingInfo; | ||
import gov.nist.hit.hl7.igamt.segment.domain.DynamicMappingItem; | ||
import gov.nist.hit.hl7.igamt.segment.domain.Segment; | ||
import gov.nist.hit.hl7.igamt.segment.service.SegmentService; | ||
import gov.nist.hit.hl7.igamt.valueset.domain.Code; | ||
import gov.nist.hit.hl7.igamt.valueset.domain.Valueset; | ||
import gov.nist.hit.hl7.igamt.valueset.service.ValuesetService; | ||
|
||
/** | ||
* @author Abdelghani El Ouakili | ||
* | ||
*/ | ||
@Service | ||
public class DynamicMappingFixer { | ||
|
||
@Autowired | ||
SegmentService segmentsService; | ||
|
||
@Autowired | ||
ValuesetService valueSetService; | ||
|
||
@Autowired | ||
DatatypeService datatypeService; | ||
|
||
|
||
public void processSegments() { | ||
List<Segment> obxs = segmentsService.findByName("OBX"); | ||
obxs.forEach((x) -> {processSegment(x);}); | ||
} | ||
|
||
|
||
/** | ||
* @param x | ||
*/ | ||
private void processSegment(Segment s) { | ||
// TODO Auto-generated method stub | ||
s.setDynamicMappingInfo(new DynamicMappingInfo("2", "5", null)); | ||
String vsId = findObx2VsId(s); | ||
|
||
if(vsId != null) { | ||
Valueset vs = valueSetService.findById(vsId); | ||
for(Code c : vs.getCodes()) { | ||
if(c.getValue() !=null) { | ||
Datatype d = datatypeService.findOneByNameAndVersionAndScope(c.getValue(),s.getDomainInfo().getVersion(), Scope.HL7STANDARD.toString()); | ||
if(d != null) { | ||
s.getDynamicMappingInfo().addItem(new DynamicMappingItem(d.getId(), c.getValue())); | ||
} | ||
} | ||
} | ||
} | ||
segmentsService.save(s); | ||
} | ||
|
||
|
||
/** | ||
* @param s | ||
* @return | ||
*/ | ||
private String findObx2VsId(Segment s) { | ||
// TODO Auto-generated method stub | ||
if(s.getBinding() != null && s.getBinding().getChildren() != null) { | ||
for(StructureElementBinding child : s.getBinding().getChildren()) { | ||
if(child.getLocationInfo() != null && child.getLocationInfo().getPosition() ==2) { | ||
if(child.getValuesetBindings() != null) { | ||
Optional<ValuesetBinding> vs = child.getValuesetBindings().stream().findAny(); | ||
if(vs.isPresent() && vs.get().getValueSets() !=null && !vs.get().getValueSets().isEmpty()) { | ||
return vs.get().getValueSets().get(0); | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.