forked from PSMRI/HWC-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Added Model MedicalStatement resource along with extensions.
2. Created provider and service classes to Create the resource(for beneficiary medication history details). 3. Added validations for the same resource. 4. Mapped MedicationStatement resource to MedicationHistoryDTO. 5. Exception handling. 6. Change in mapper class -> Reading benRegID from display instead of reference in Immunization resource. 7. Appropriate validation for above change.
- Loading branch information
1 parent
28014fd
commit 435d009
Showing
10 changed files
with
326 additions
and
4 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
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
99 changes: 99 additions & 0 deletions
99
src/main/java/com/iemr/hwc/fhir/model/medicationStatement/MedicationStatementExt.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,99 @@ | ||
package com.iemr.hwc.fhir.model.medicationStatement; | ||
|
||
import ca.uhn.fhir.model.api.annotation.Child; | ||
import ca.uhn.fhir.model.api.annotation.Description; | ||
import ca.uhn.fhir.model.api.annotation.Extension; | ||
import ca.uhn.fhir.model.api.annotation.ResourceDef; | ||
import ca.uhn.fhir.util.ElementUtil; | ||
import org.hl7.fhir.r4.model.MedicationStatement; | ||
import org.hl7.fhir.r4.model.StringType; | ||
|
||
@ResourceDef(name = "MedicationStatement") | ||
public class MedicationStatementExt extends MedicationStatement { | ||
|
||
@Description(shortDefinition = "Contains providerServiceMapId ") | ||
@Extension(url = "http://hl7.org/fhir/StructureDefinition/MedicationStatement#MedicationStatement.providerServiceMapId", isModifier = false, definedLocally = true) | ||
@Child(name = "providerServiceMapId") | ||
private StringType providerServiceMapId; | ||
|
||
@Description(shortDefinition = "Contains vanID ") | ||
@Extension(url = "http://hl7.org/fhir/StructureDefinition/MedicationStatement#MedicationStatement.vanID", isModifier = false, definedLocally = true) | ||
@Child(name = "vanID") | ||
private StringType vanID; | ||
|
||
@Description(shortDefinition = "Contains parkingPlaceID ") | ||
@Extension(url = "http://hl7.org/fhir/StructureDefinition/MedicationStatement#MedicationStatement.parkingPlaceID", isModifier = false, definedLocally = true) | ||
@Child(name = "parkingPlaceID") | ||
private StringType parkingPlaceID; | ||
|
||
@Description(shortDefinition = "Contains createdBy ") | ||
@Extension(url = "http://hl7.org/fhir/StructureDefinition/MedicationStatement#MedicationStatement.createdBy", isModifier = false, definedLocally = true) | ||
@Child(name = "createdBy") | ||
private StringType createdBy; | ||
|
||
@Description(shortDefinition = "Contains benFlowID ") | ||
@Extension(url = "http://hl7.org/fhir/StructureDefinition/MedicationStatement#MedicationStatement.benFlowID", isModifier = false, definedLocally = true) | ||
@Child(name = "benFlowID") | ||
private StringType benFlowID; | ||
|
||
public StringType getProviderServiceMapId() { | ||
if (providerServiceMapId == null) { | ||
providerServiceMapId = new StringType(); | ||
} | ||
return providerServiceMapId; | ||
} | ||
|
||
public void setProviderServiceMapId(StringType providerService_MapId) { | ||
providerServiceMapId = providerService_MapId; | ||
} | ||
|
||
public StringType getVanID() { | ||
if (vanID == null) { | ||
vanID = new StringType(); | ||
} | ||
return vanID; | ||
} | ||
|
||
public void setVanID(StringType van_ID) { | ||
vanID = van_ID; | ||
} | ||
|
||
public StringType getParkingPlaceID() { | ||
if (parkingPlaceID == null) { | ||
parkingPlaceID = new StringType(); | ||
} | ||
return parkingPlaceID; | ||
} | ||
|
||
public void setParkingPlaceID(StringType parking_PlaceID) { | ||
parkingPlaceID = parking_PlaceID; | ||
} | ||
|
||
public StringType getCreatedBy() { | ||
if (createdBy == null) { | ||
createdBy = new StringType(); | ||
} | ||
return createdBy; | ||
} | ||
|
||
public void setCreatedBy(StringType created_By) { | ||
createdBy = created_By; | ||
} | ||
|
||
public StringType getBenFlowID() { | ||
if (benFlowID == null) { | ||
benFlowID = new StringType(); | ||
} | ||
return benFlowID; | ||
} | ||
|
||
public void setBenFlowID(StringType benFlow_ID) { | ||
benFlowID = benFlow_ID; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return super.isEmpty() && ElementUtil.isEmpty(benFlowID , providerServiceMapId , | ||
vanID , parkingPlaceID , createdBy ); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...n/java/com/iemr/hwc/fhir/provider/medicationStatement/MedicationStatementExtProvider.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,36 @@ | ||
package com.iemr.hwc.fhir.provider.medicationStatement; | ||
|
||
import ca.uhn.fhir.rest.annotation.Create; | ||
import ca.uhn.fhir.rest.annotation.ResourceParam; | ||
import ca.uhn.fhir.rest.api.MethodOutcome; | ||
import ca.uhn.fhir.rest.server.IResourceProvider; | ||
import com.iemr.hwc.fhir.model.medicationStatement.MedicationStatementExt; | ||
import com.iemr.hwc.fhir.service.medicationStatement.MedicationService; | ||
import org.hl7.fhir.instance.model.api.IBaseResource; | ||
import org.hl7.fhir.r4.model.OperationOutcome; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
@Component | ||
public class MedicationStatementExtProvider implements IResourceProvider { | ||
|
||
@Autowired | ||
private MedicationService medicationService; | ||
|
||
@Override | ||
public Class<? extends IBaseResource> getResourceType() { | ||
return MedicationStatementExt.class; | ||
} | ||
|
||
@Create() | ||
public MethodOutcome createMedicationStatement(HttpServletRequest theRequest, @ResourceParam MedicationStatementExt medicationStatementExt) throws Exception{ | ||
|
||
MethodOutcome method = new MethodOutcome(); | ||
method.setCreated(true); | ||
OperationOutcome opOutcome = new OperationOutcome(); | ||
method.setOperationOutcome(opOutcome); | ||
method.setResource(medicationService.createMedicationStatement(theRequest,medicationStatementExt)); | ||
return method; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/iemr/hwc/fhir/service/medicationStatement/MedicationService.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,8 @@ | ||
package com.iemr.hwc.fhir.service.medicationStatement; | ||
|
||
import com.iemr.hwc.fhir.model.medicationStatement.MedicationStatementExt; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
public interface MedicationService { | ||
MedicationStatementExt createMedicationStatement(HttpServletRequest theRequest, MedicationStatementExt medicationStatementExt) throws Exception; | ||
} |
89 changes: 89 additions & 0 deletions
89
...in/java/com/iemr/hwc/fhir/service/medicationStatement/MedicationStatementServiceImpl.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,89 @@ | ||
package com.iemr.hwc.fhir.service.medicationStatement; | ||
|
||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; | ||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import com.iemr.hwc.data.anc.WrapperMedicationHistory; | ||
import com.iemr.hwc.data.benFlowStatus.BeneficiaryFlowStatus; | ||
import com.iemr.hwc.fhir.dto.historyDetails.medicationHistory.MedicationHistoryDTO; | ||
import com.iemr.hwc.fhir.dto.historyDetails.medicationHistory.MedicationListDTO; | ||
import com.iemr.hwc.fhir.dto.mandatoryFieldsDTO.MandatoryFieldsDTO; | ||
import com.iemr.hwc.fhir.model.medicationStatement.MedicationStatementExt; | ||
import com.iemr.hwc.fhir.utils.mapper.MapperMethods; | ||
import com.iemr.hwc.fhir.utils.mapper.MapperUtils; | ||
import com.iemr.hwc.fhir.utils.validation.MedicationStatementValidation; | ||
import com.iemr.hwc.repo.benFlowStatus.BeneficiaryFlowStatusRepo; | ||
import com.iemr.hwc.service.common.transaction.CommonNurseServiceImpl; | ||
import com.iemr.hwc.utils.exception.IEMRException; | ||
import com.iemr.hwc.utils.mapper.InputMapper; | ||
import org.mapstruct.factory.Mappers; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import javax.servlet.http.HttpServletRequest; | ||
import java.util.ArrayList; | ||
|
||
@Service | ||
public class MedicationStatementServiceImpl implements MedicationService{ | ||
|
||
public MapperUtils mapper = Mappers.getMapper(MapperUtils.class); | ||
|
||
Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName()); | ||
|
||
@Autowired | ||
private MedicationStatementValidation validation; | ||
|
||
@Autowired | ||
private BeneficiaryFlowStatusRepo beneficiaryFlowStatusRepo; | ||
|
||
@Autowired | ||
private CommonNurseServiceImpl commonNurseService; | ||
|
||
@Override | ||
public MedicationStatementExt createMedicationStatement(HttpServletRequest theRequest, MedicationStatementExt medicationStatementExt) throws Exception { | ||
|
||
validation.medicationStatementValidator(medicationStatementExt); | ||
|
||
//Todo - Currently implemented considering all relevant IDs(benRegID, benFlowID) are coming in payload. | ||
//Todo - If not, might need to write new APIs to fetch necessary IDs through some sort of logic. And then use those further. | ||
MandatoryFieldsDTO mandatoryFieldsDTO = mapper.medicationStatementResourceToMandatoryFieldsDTO(medicationStatementExt); | ||
|
||
BeneficiaryFlowStatus beneficiaryFlowStatus = beneficiaryFlowStatusRepo.getBenDetailsForLeftSidePanel(Long.parseLong(mandatoryFieldsDTO.getBenFlowID())); | ||
|
||
if (beneficiaryFlowStatus !=null ) { | ||
mandatoryFieldsDTO.setBenVisitID(beneficiaryFlowStatus.getBenVisitID().toString()); | ||
mandatoryFieldsDTO.setVisitCode(beneficiaryFlowStatus.getBenVisitCode().toString()); | ||
} | ||
else { | ||
logger.error("No beneficiary flow status record found for the provided benFlowID"); | ||
throw new ResourceNotFoundException("No record found for given benFlowID"); | ||
} | ||
|
||
MedicationHistoryDTO medicationHistoryDTO = mapper.mandatoryFieldsDTOToMedicationHistoryDTO(mandatoryFieldsDTO); | ||
|
||
if (medicationStatementExt.getMedicationCodeableConcept().hasCoding()) { | ||
medicationHistoryDTO.setMedicationHistoryList(MapperMethods.medicationToMedicationListDTO(medicationStatementExt)); | ||
} | ||
else { | ||
medicationHistoryDTO.setMedicationHistoryList(new ArrayList<MedicationListDTO>()); | ||
} | ||
|
||
String medicationHistoryDTOGson = new GsonBuilder().create().toJson(medicationHistoryDTO); | ||
JsonObject medicationHistoryDTOJson = new JsonParser().parse(medicationHistoryDTOGson).getAsJsonObject(); | ||
|
||
try{ | ||
WrapperMedicationHistory wrapperMedicationHistory = InputMapper.gson() | ||
.fromJson(medicationHistoryDTOJson, WrapperMedicationHistory.class); | ||
|
||
commonNurseService.updateBenMedicationHistory(wrapperMedicationHistory); | ||
}catch (IEMRException e){ | ||
logger.error("Encountered custom exception - IEMRException while trying to map Json with WrapperMedicationHistory class using Input Mapper " + e); | ||
throw new InternalErrorException("Error mapping json to WrapperMedicationHistory class " + e); | ||
} | ||
|
||
return medicationStatementExt; | ||
} | ||
} |
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
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
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
Oops, something went wrong.